PDA

View Full Version : Loading an image map?



stevecullum
04-16-2014, 09:39 PM
Does anyone know how to load an image map into the image editor with python?
I'm trying create a simple modelling script, and would like to apply some textures to it.

Thanks

ernpchan
04-18-2014, 04:57 PM
## Given a string ("p") containing a file path to an image, the following
## attempts to load that image into the Image Editor. It then
## returns the name of that image and the image ID.

def loadImage(p):
IM = lwsdk.LWImageList()
id = IM.load(p)
name = IM.name(id)
return name, id

stevecullum
04-18-2014, 06:38 PM
Awesome - thanks Ernie! Will give this a try tomorrow.

ernpchan
04-19-2014, 01:02 PM
Celshader would really be the one to thank. I just passed along what I found.

stevecullum
04-20-2014, 07:50 AM
In that case 'Thanks Celshader!'

If I can put together anything that works and is useful, from the information I've been given here and elsewhere, I'll be sure to share it. ;)

stevecullum
04-20-2014, 09:36 AM
Got a bit stuck again with this. The code snippet worked fine for loading a texture (although I need to find a better path reference than an explicit one - problem for later). Now what I've been trying to figure out is how to set that image in the surface. The functions I have are:

def loadImage(self,p):
IM = lwsdk.LWImageList()
id = IM.load(p)
name = IM.name(id)
return name, id

def setTex (self):
statefunc = lwsdk.LWStateQueryFuncs()
objname = statefunc.object()
surf_func = lwsdk.LWSurfaceFuncs()
surf = surf_func.byObject(objname)
texfunc = lwsdk.LWTextureFuncs()
#print(surf)
texture = surf_func.getTex(surf[0],lwsdk.SURF_COLR)
texfunc.layerAdd(texture,lwsdk.TLT_IMAGE)
#print(texture)

However my setTex one crashes modeller, because the getTex method is returning 'None' as an ID. I assume this is because is trying to read an active 'T' button in the surface editor? And of course I currently don't have one of those. I looked at the SDK for LWTextureFuncs and I can see there is a 'create' method. But that seems to be if you were trying to use a texture directly within the plugin, where as I want to create one in the main surface editor. Any ideas?

Thanks