PDA

View Full Version : Image ID from LWTextureFuncs



clintonman
06-19-2013, 11:33 PM
I am trying to get an image id using the LWTextureFuncs but I get an error. The id from the image list is "_d0b53b0c00000000_p_void" but the value from LWTextureFuncs is "(1, <Swig Object of type 'LWSamplerState' at 0x0000000016F66120>)"

The goal is to match the surface names in lightwave with the material names in an exported collada file and using the image references in the lightwave scene to fix the collada references. Lightwave collada will only write the color texture and I want to add some other channels(luminosity, specular etc.).

Any ideas on getting the proper image id?


found lw surface: MySurface
_d0b53b0c00000000_p_void
(1, <Swig Object of type 'LWSamplerState' at 0x0000000016F66120>)
Traceback (most recent call last):
File "C:\Program Files\NewTek\LightWave11.5.1\support\plugins\scrip ts\Python\Layout\Generic\fix_collada.py", line 661, in process
self.fixMaterials(self.libmaterials)
File "C:\Program Files\NewTek\LightWave11.5.1\support\plugins\scrip ts\Python\Layout\Generic\fix_collada.py", line 578, in fixMaterials
imagename = imagelist.name(lwImageID)
File "pcore.py", line 9381, in name
TypeError: Failed to convert LWImageID



def fixMaterials(self, currentNode):
surface_funcs = lwsdk.LWSurfaceFuncs()
texture_funcs = lwsdk.LWTextureFuncs()
imagelist = lwsdk.LWImageList()

for material in currentNode:
id = material.attrib.get('id')
# lightwave collada renames Default to Default_1
# much better to name the surface than use the default name
# TODO: adjust for renaming, like space -> underscore
if id == "Default_1":
id = "Default"
surface = surface_funcs.first()
while surface:
if surface_funcs.name(surface) == id:
print "found lw surface: %s" % id
LWdiffuseTexture = surface_funcs.getTex( surface, lwsdk.SURF_COLR )
if LWdiffuseTexture:
#tname = texture_funcs.name( LWdiffuseTexture )
#print tname
tlayer = texture_funcs.firstLayer( LWdiffuseTexture )
#type = texture_funcs.layerType( tlayer )
#print type
lwImageID = texture_funcs.getParam( tlayer, lwsdk.TXTAG_IMAGE )
if lwImageID:
image = imagelist.first()
print image
#imagename = imagelist.name(image)
#print "first image name is: %s" % imagename
print lwImageID
imagename = imagelist.name(lwImageID)
#imagename = imagelist.name(lwsdk.itemid_to_str(lwImageID))
#print "image name is: %s" % imagename
surface = surface_funcs.next(surface)

iain_r
06-20-2013, 09:45 AM
surf_funcs = lwsdk.LWSurfaceFuncs()
text_funcs = lwsdk.LWTextureFuncs()
img_list = lwsdk.LWImageList()

surface = surf_funcs.first()
while surface:
surfname = surf_funcs.name(surface)
print "surface name is %s" %surfname
colr_text = surf_funcs.getTex( surface, lwsdk.SURF_COLR)
if colr_text:
tlayr = text_funcs.firstLayer(colr_text)
while tlayr:
tl_type = text_funcs.layerType(tlayr)
if tl_type == lwsdk.TLT_IMAGE:
imageid = text_funcs.getParam(tlayr, lwsdk.TXTAG_IMAGE)
img = img_list.filename(imageid[1], 0)
print "image filename is %s" %img
tlayr = text_funcs.nextLayer(colr_text, tlayr)
surface = surf_funcs.next(surface)



Reading the SDK the LWImageID is a reference to the values in the image list. You need to pass in the second parameter, in this case the "Swig LWSampleState ....." so that it can resolve it against the image list. There are a couple of prints as I need to see where things were going. Hope this helps.

Regards

Iain

clintonman
06-20-2013, 11:13 PM
Thank you. It works like a charm.:thumbsup: