I use Blender 2.62.
I'd like to use blender as editor for tiled 3d world. I have models for different tiles, and I place linked duplicates of these models in another layer to construct a map.
Now I'd like to export this map in some understandable format (sth like [ [x, y, z, tileNo], [x, y, z, tileNo], ...]). I can iterate through all objects in given layer with code like below, but I can't find a way to get the source of the duplicated object. Is this possible?
def layerNos(o):
return [ln for (ln, l) in enumerate(o.layers) if l]
def exportObjectsFromLayer(choosenLayerNo):
for o in bpy.data.objects:
if choosenLayerNo in layerNos(o):
yield exportTile(o)
def exportTile(o):
return ("[%d,%d,%d]" % (
round(x.location.x),
round(x.location.z),
round(x.location.y),
getTileNumber(x)))
def getTileNumber(x):
return None # this is where I'd like to access
# the source of the duplicated object
# and get its name to lookup its number
# and return it as a tile number
EDIT: I've found a way to do the reverse - from the source of duplication I can find all the duplicated objects by using:
bpy.data.objects['Cube.121'].dupli_list_create(bpy.context.scene)
for dupliObj in bpy.data.objects['Cube.121'].dupli_list:
#do sth with duplicated object
bpy.data.objects['Cube.121'].dupli_list_clear()
So I can always use this and iterate through all my model tiles, looking up where their duplicates are placed instead. Still I'd prefer to do this the way I've described above, so I leave this question for a while.