PDA

View Full Version : Is there a better way to get the IDs of objects with Bullet-controlled motions?



Celshader
04-09-2012, 05:44 PM
Right now I'm using this code to parse the text of the scene file to get the IDs of objects with Bullet-controlled motions (not displacements):



import lwsdk, re

def getSceneFilename():
info = lwsdk.LWSceneInfo()
return info.filename

def getText(p):
f = open(p, "r")
text = f.read()
f.close()
return text

def getBulletIDs():
p = getSceneFilename()
text = getText(p)
oP = re.compile("\nLoadObjectLayer .*?ShadowOptions", re.DOTALL)
objs = oP.findall(text)
ids = []
for obj in objs:
if obj.find(".DynamicsMotion") != -1:
id = obj.split("\n")[1].split(" ")[2]
ids.append(id)
return ids

It works, but I suspect there's a better way than this. Is there a way I can query for this information directly within LightWave?

Celshader
04-09-2012, 06:16 PM
I just got this response, so I'm sharing the answer here:


lwsdk.LWItemInfo().server(item, "ItemMotionHandler", <index>)

returns the name of a plugin attached to the item, where index goes from
1 up to it returning None. "DisplacementHandler" for checking
displacement plugins.

Celshader
04-09-2012, 07:01 PM
This code works, and does not require parsing the scene file.



def getObjID(pyObj):
return lwsdk.itemid_to_str(pyObj)

def getObjects():
li = []
info = lwsdk.LWItemInfo()
item = info.first(lwsdk.LWI_OBJECT, None)
while(item):
li.append(item)
item = info.next(item)
return li

def getMotionModifiers(item):
li = []
info = lwsdk.LWItemInfo()
i = 1
while 1:
test = info.server(item, "ItemMotionHandler", i)
if test:
print test
li.append(test)
i = i + 1
else:
break
return li

def getBulletIDs():
li = []
objs = getObjects()
for obj in objs:
mods = getMotionModifiers(obj)
if ".DynamicsMotion" in mods:
li.append(getObjID(obj))
return li