Newer
Older
# Give all objects a unique ID and build a dictionary from object name to object id:
"""
name_to_id = {}
for ob, data in mesh_objects:
name_to_id[ob.name]= len(name_to_id)
#for ob in empty_objects:
# name_to_id[ob.name]= len(name_to_id)
"""
# Create object chunks for all meshes:
i = 0
for ob, blender_mesh, matrix in mesh_objects:
# create a new object chunk
object_chunk = _3ds_chunk(OBJECT)
# set the object name
object_chunk.add_variable("name", _3ds_string(sane_name(ob.name)))
# make a mesh chunk out of the mesh:
object_chunk.add_subchunk(make_mesh_chunk(blender_mesh, matrix, materialDict))
# ensure the mesh has no over sized arrays
# skip ones that do!, otherwise we cant write since the array size wont
# fit into USHORT.
if object_chunk.validate():
object_info.add_subchunk(object_chunk)
else:
operator.report({'WARNING'}, "Object %r can't be written into a 3DS file")
''' # COMMENTED OUT FOR 2.42 RELEASE!! CRASHES 3DS MAX
# make a kf object node for the object:
kfdata.add_subchunk(make_kf_obj_node(ob, name_to_id))
'''
if not blender_mesh.users:
bpy.data.meshes.remove(blender_mesh)
# blender_mesh.vertices = None
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
# Create chunks for all empties:
''' # COMMENTED OUT FOR 2.42 RELEASE!! CRASHES 3DS MAX
for ob in empty_objects:
# Empties only require a kf object node:
kfdata.add_subchunk(make_kf_obj_node(ob, name_to_id))
pass
'''
# Add main object info chunk to primary chunk:
primary.add_subchunk(object_info)
''' # COMMENTED OUT FOR 2.42 RELEASE!! CRASHES 3DS MAX
# Add main keyframe data chunk to primary chunk:
primary.add_subchunk(kfdata)
'''
# At this point, the chunk hierarchy is completely built.
# Check the size:
primary.get_size()
# Open the file for writing:
file = open(filepath, 'wb')
# Recursively write the chunks to file:
primary.write(file)
# Close the file:
file.close()
# Clear name mapping vars, could make locals too
name_unique[:] = []
name_mapping.clear()
# Debugging only: report the exporting time:
# Blender.Window.WaitCursor(0)
print("3ds export time: %.2f" % (time.clock() - time1))
# Debugging only: dump the chunk hierarchy:
#primary.dump()
Campbell Barton
committed
return {'FINISHED'}