From 818afda046e6cbc6db7a0e77bba8e9cceb33d99f Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Thu, 21 Apr 2011 14:04:05 +0000 Subject: Tag addons for Blender 2.57a release --- io_scene_3ds/__init__.py | 108 +++++ io_scene_3ds/export_3ds.py | 1072 ++++++++++++++++++++++++++++++++++++++++++++ io_scene_3ds/import_3ds.py | 908 +++++++++++++++++++++++++++++++++++++ 3 files changed, 2088 insertions(+) create mode 100644 io_scene_3ds/__init__.py create mode 100644 io_scene_3ds/export_3ds.py create mode 100644 io_scene_3ds/import_3ds.py (limited to 'io_scene_3ds') diff --git a/io_scene_3ds/__init__.py b/io_scene_3ds/__init__.py new file mode 100644 index 00000000..21bed64a --- /dev/null +++ b/io_scene_3ds/__init__.py @@ -0,0 +1,108 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# + +bl_info = { + "name": "Autodesk 3DS format", + "author": "Bob Holcomb, Campbell Barton", + "blender": (2, 5, 7), + "api": 35622, + "location": "File > Import-Export", + "description": "Import-Export 3DS, meshes, uvs, materials, textures, cameras & lamps", + "warning": "", + "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\ + "Scripts/Import-Export/Autodesk_3DS", + "tracker_url": "", + "support": 'OFFICIAL', + "category": "Import-Export"} + +# To support reload properly, try to access a package var, if it's there, reload everything +if "bpy" in locals(): + import imp + if "import_3ds" in locals(): + imp.reload(import_3ds) + if "export_3ds" in locals(): + imp.reload(export_3ds) + + +import bpy +from bpy.props import StringProperty, FloatProperty, BoolProperty +from io_utils import ImportHelper, ExportHelper + + +class Import3DS(bpy.types.Operator, ImportHelper): + '''Import from 3DS file format (.3ds)''' + bl_idname = "import_scene.autodesk_3ds" + bl_label = 'Import 3DS' + + filename_ext = ".3ds" + filter_glob = StringProperty(default="*.3ds", options={'HIDDEN'}) + + constrain_size = FloatProperty(name="Size Constraint", description="Scale the model by 10 until it reacehs the size constraint. Zero Disables.", min=0.0, max=1000.0, soft_min=0.0, soft_max=1000.0, default=10.0) + use_image_search = BoolProperty(name="Image Search", description="Search subdirectories for any assosiated images (Warning, may be slow)", default=True) + use_apply_transform = BoolProperty(name="Apply Transform", description="Workaround for object transformations importing incorrectly", default=True) + + def execute(self, context): + from . import import_3ds + return import_3ds.load(self, context, **self.as_keywords(ignore=("filter_glob",))) + + +class Export3DS(bpy.types.Operator, ExportHelper): + '''Export to 3DS file format (.3ds)''' + bl_idname = "export_scene.autodesk_3ds" + bl_label = 'Export 3DS' + + filename_ext = ".3ds" + filter_glob = StringProperty(default="*.3ds", options={'HIDDEN'}) + + use_selection = BoolProperty(name="Selection Only", description="Export selected objects only", default=False) + + def execute(self, context): + from . import export_3ds + return export_3ds.save(self, context, **self.as_keywords(ignore=("check_existing", "filter_glob"))) + + +# Add to a menu +def menu_func_export(self, context): + self.layout.operator(Export3DS.bl_idname, text="3D Studio (.3ds)") + + +def menu_func_import(self, context): + self.layout.operator(Import3DS.bl_idname, text="3D Studio (.3ds)") + + +def register(): + bpy.utils.register_module(__name__) + + bpy.types.INFO_MT_file_import.append(menu_func_import) + bpy.types.INFO_MT_file_export.append(menu_func_export) + + +def unregister(): + bpy.utils.unregister_module(__name__) + + bpy.types.INFO_MT_file_import.remove(menu_func_import) + bpy.types.INFO_MT_file_export.remove(menu_func_export) + +# NOTES: +# why add 1 extra vertex? and remove it when done? - "Answer - eekadoodle - would need to re-order UV's without this since face order isnt always what we give blender, BMesh will solve :D" +# disabled scaling to size, this requires exposing bb (easy) and understanding how it works (needs some time) + +if __name__ == "__main__": + register() diff --git a/io_scene_3ds/export_3ds.py b/io_scene_3ds/export_3ds.py new file mode 100644 index 00000000..bf7bd990 --- /dev/null +++ b/io_scene_3ds/export_3ds.py @@ -0,0 +1,1072 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# + +# Script copyright (C) Bob Holcomb +# Contributors: Campbell Barton, Bob Holcomb, Richard Lärkäng, Damien McGinnes, Mark Stijnman + +""" +Exporting is based on 3ds loader from www.gametutorials.com(Thanks DigiBen) and using information +from the lib3ds project (http://lib3ds.sourceforge.net/) sourcecode. +""" + +###################################################### +# Data Structures +###################################################### + +#Some of the chunks that we will export +#----- Primary Chunk, at the beginning of each file +PRIMARY = 0x4D4D + +#------ Main Chunks +OBJECTINFO = 0x3D3D # This gives the version of the mesh and is found right before the material and object information +VERSION = 0x0002 # This gives the version of the .3ds file +KFDATA = 0xB000 # This is the header for all of the key frame info + +#------ sub defines of OBJECTINFO +MATERIAL = 45055 # 0xAFFF // This stored the texture info +OBJECT = 16384 # 0x4000 // This stores the faces, vertices, etc... + +#>------ sub defines of MATERIAL +MATNAME = 0xA000 # This holds the material name +MATAMBIENT = 0xA010 # Ambient color of the object/material +MATDIFFUSE = 0xA020 # This holds the color of the object/material +MATSPECULAR = 0xA030 # SPecular color of the object/material +MATSHINESS = 0xA040 # ?? +MATMAP = 0xA200 # This is a header for a new material +MATMAPFILE = 0xA300 # This holds the file name of the texture + +RGB1 = 0x0011 +RGB2 = 0x0012 + +#>------ sub defines of OBJECT +OBJECT_MESH = 0x4100 # This lets us know that we are reading a new object +OBJECT_LIGHT = 0x4600 # This lets un know we are reading a light object +OBJECT_CAMERA = 0x4700 # This lets un know we are reading a camera object + +#>------ sub defines of CAMERA +OBJECT_CAM_RANGES = 0x4720 # The camera range values + +#>------ sub defines of OBJECT_MESH +OBJECT_VERTICES = 0x4110 # The objects vertices +OBJECT_FACES = 0x4120 # The objects faces +OBJECT_MATERIAL = 0x4130 # This is found if the object has a material, either texture map or color +OBJECT_UV = 0x4140 # The UV texture coordinates +OBJECT_TRANS_MATRIX = 0x4160 # The Object Matrix + +#>------ sub defines of KFDATA +KFDATA_KFHDR = 0xB00A +KFDATA_KFSEG = 0xB008 +KFDATA_KFCURTIME = 0xB009 +KFDATA_OBJECT_NODE_TAG = 0xB002 + +#>------ sub defines of OBJECT_NODE_TAG +OBJECT_NODE_ID = 0xB030 +OBJECT_NODE_HDR = 0xB010 +OBJECT_PIVOT = 0xB013 +OBJECT_INSTANCE_NAME = 0xB011 +POS_TRACK_TAG = 0xB020 +ROT_TRACK_TAG = 0xB021 +SCL_TRACK_TAG = 0xB022 + +import struct + +# So 3ds max can open files, limit names to 12 in length +# this is verry annoying for filenames! +name_unique = [] # stores str, ascii only +name_mapping = {} # stores {orig: byte} mapping + + +def sane_name(name): + name_fixed = name_mapping.get(name) + if name_fixed is not None: + return name_fixed + + # strip non ascii chars + new_name_clean = new_name = name.encode("ASCII", "replace").decode("ASCII")[:12] + i = 0 + + while new_name in name_unique: + new_name = new_name_clean + ".%.3d" % i + i += 1 + + # note, appending the 'str' version. + name_unique.append(new_name) + name_mapping[name] = new_name = new_name.encode("ASCII", "replace") + return new_name + + +def uv_key(uv): + return round(uv[0], 6), round(uv[1], 6) + +# size defines: +SZ_SHORT = 2 +SZ_INT = 4 +SZ_FLOAT = 4 + + +class _3ds_short(object): + '''Class representing a short (2-byte integer) for a 3ds file. + *** This looks like an unsigned short H is unsigned from the struct docs - Cam***''' + __slots__ = ("value", ) + + def __init__(self, val=0): + self.value = val + + def get_size(self): + return SZ_SHORT + + def write(self, file): + file.write(struct.pack("= mat_ls_len: + mat_index = f.mat = 0 + mat = mat_ls[mat_index] + mat_name = None if mat is None else mat.name + # else there already set to none + + img = uf.image + img_name = None if img is None else img.name + + materialDict.setdefault((mat_name, img_name), (mat, img)) + + else: + for mat in mat_ls: + if mat: # material may be None so check its not. + materialDict.setdefault((mat.name, None), (mat, None)) + + # Why 0 Why! + for f in data.faces: + if f.material_index >= mat_ls_len: +# if f.mat >= mat_ls_len: + f.material_index = 0 + # f.mat = 0 + + if free: + free_derived_objects(ob) + + # Make material chunks for all materials used in the meshes: + for mat_and_image in materialDict.values(): + object_info.add_subchunk(make_material_chunk(mat_and_image[0], mat_and_image[1])) + + # 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 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, materialDict)) + object_info.add_subchunk(object_chunk) + + ''' # 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 + + i += i + + # 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() + + return {'FINISHED'} diff --git a/io_scene_3ds/import_3ds.py b/io_scene_3ds/import_3ds.py new file mode 100644 index 00000000..1aea6384 --- /dev/null +++ b/io_scene_3ds/import_3ds.py @@ -0,0 +1,908 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# + +# Script copyright (C) Bob Holcomb +# Contributors: Bob Holcomb, Richard L?rk?ng, Damien McGinnes, Campbell Barton, Mario Lapin, Dominique Lorre + +import os +import time +import struct + +from io_utils import load_image + +import bpy +import mathutils + +BOUNDS_3DS = [] + + +###################################################### +# Data Structures +###################################################### + +#Some of the chunks that we will see +#----- Primary Chunk, at the beginning of each file +PRIMARY = 0x4D4D + +#------ Main Chunks +OBJECTINFO = 0x3D3D # This gives the version of the mesh and is found right before the material and object information +VERSION = 0x0002 # This gives the version of the .3ds file +EDITKEYFRAME = 0xB000 # This is the header for all of the key frame info + +#------ sub defines of OBJECTINFO +MATERIAL = 0xAFFF # This stored the texture info +OBJECT = 0x4000 # This stores the faces, vertices, etc... + +#>------ sub defines of MATERIAL +#------ sub defines of MATERIAL_BLOCK +MAT_NAME = 0xA000 # This holds the material name +MAT_AMBIENT = 0xA010 # Ambient color of the object/material +MAT_DIFFUSE = 0xA020 # This holds the color of the object/material +MAT_SPECULAR = 0xA030 # SPecular color of the object/material +MAT_SHINESS = 0xA040 # ?? +MAT_TRANSPARENCY = 0xA050 # Transparency value of material +MAT_SELF_ILLUM = 0xA080 # Self Illumination value of material +MAT_WIRE = 0xA085 # Only render's wireframe + +MAT_TEXTURE_MAP = 0xA200 # This is a header for a new texture map +MAT_SPECULAR_MAP = 0xA204 # This is a header for a new specular map +MAT_OPACITY_MAP = 0xA210 # This is a header for a new opacity map +MAT_REFLECTION_MAP = 0xA220 # This is a header for a new reflection map +MAT_BUMP_MAP = 0xA230 # This is a header for a new bump map +MAT_MAP_FILEPATH = 0xA300 # This holds the file name of the texture + +MAT_FLOAT_COLOR = 0x0010 # color defined as 3 floats +MAT_24BIT_COLOR = 0x0011 # color defined as 3 bytes + +#>------ sub defines of OBJECT +OBJECT_MESH = 0x4100 # This lets us know that we are reading a new object +OBJECT_LAMP = 0x4600 # This lets un know we are reading a light object +OBJECT_LAMP_SPOT = 0x4610 # The light is a spotloght. +OBJECT_LAMP_OFF = 0x4620 # The light off. +OBJECT_LAMP_ATTENUATE = 0x4625 +OBJECT_LAMP_RAYSHADE = 0x4627 +OBJECT_LAMP_SHADOWED = 0x4630 +OBJECT_LAMP_LOCAL_SHADOW = 0x4640 +OBJECT_LAMP_LOCAL_SHADOW2 = 0x4641 +OBJECT_LAMP_SEE_CONE = 0x4650 +OBJECT_LAMP_SPOT_RECTANGULAR = 0x4651 +OBJECT_LAMP_SPOT_OVERSHOOT = 0x4652 +OBJECT_LAMP_SPOT_PROJECTOR = 0x4653 +OBJECT_LAMP_EXCLUDE = 0x4654 +OBJECT_LAMP_RANGE = 0x4655 +OBJECT_LAMP_ROLL = 0x4656 +OBJECT_LAMP_SPOT_ASPECT = 0x4657 +OBJECT_LAMP_RAY_BIAS = 0x4658 +OBJECT_LAMP_INNER_RANGE = 0x4659 +OBJECT_LAMP_OUTER_RANGE = 0x465A +OBJECT_LAMP_MULTIPLIER = 0x465B +OBJECT_LAMP_AMBIENT_LIGHT = 0x4680 + +OBJECT_CAMERA = 0x4700 # This lets un know we are reading a camera object + +#>------ sub defines of CAMERA +OBJECT_CAM_RANGES = 0x4720 # The camera range values + +#>------ sub defines of OBJECT_MESH +OBJECT_VERTICES = 0x4110 # The objects vertices +OBJECT_FACES = 0x4120 # The objects faces +OBJECT_MATERIAL = 0x4130 # This is found if the object has a material, either texture map or color +OBJECT_UV = 0x4140 # The UV texture coordinates +OBJECT_TRANS_MATRIX = 0x4160 # The Object Matrix + +#>------ sub defines of EDITKEYFRAME +ED_KEY_AMBIENT_NODE = 0xB001 +ED_KEY_OBJECT_NODE = 0xB002 +ED_KEY_CAMERA_NODE = 0xB003 +ED_KEY_TARGET_NODE = 0xB004 +ED_KEY_LIGHT_NODE = 0xB005 +ED_KEY_L_TARGET_NODE = 0xB006 +ED_KEY_SPOTLIGHT_NODE = 0xB007 +#>------ sub defines of ED_KEY_OBJECT_NODE +# EK_OB_KEYFRAME_SEG = 0xB008 +# EK_OB_KEYFRAME_CURTIME = 0xB009 +# EK_OB_KEYFRAME_HEADER = 0xB00A +EK_OB_NODE_HEADER = 0xB010 +EK_OB_INSTANCE_NAME = 0xB011 +# EK_OB_PRESCALE = 0xB012 +EK_OB_PIVOT = 0xB013 +# EK_OB_BOUNDBOX = 0xB014 +# EK_OB_MORPH_SMOOTH = 0xB015 +EK_OB_POSITION_TRACK = 0xB020 +EK_OB_ROTATION_TRACK = 0xB021 +EK_OB_SCALE_TRACK = 0xB022 +# EK_OB_CAMERA_FOV_TRACK = 0xB023 +# EK_OB_CAMERA_ROLL_TRACK = 0xB024 +# EK_OB_COLOR_TRACK = 0xB025 +# EK_OB_MORPH_TRACK = 0xB026 +# EK_OB_HOTSPOT_TRACK = 0xB027 +# EK_OB_FALLOF_TRACK = 0xB028 +# EK_OB_HIDE_TRACK = 0xB029 +# EK_OB_NODE_ID = 0xB030 + +ROOT_OBJECT = 0xFFFF + +global scn +scn = None + +object_dictionary = {} +object_matrix = {} + + +#the chunk class +class chunk: + ID = 0 + length = 0 + bytes_read = 0 + + #we don't read in the bytes_read, we compute that + binary_format = " 3): + print('\tNon-Fatal Error: Version greater than 3, may not load correctly: ', version) + + #is it an object info chunk? + elif (new_chunk.ID == OBJECTINFO): + #print 'elif (new_chunk.ID == OBJECTINFO):' + # print 'found an OBJECTINFO chunk' + process_next_chunk(file, new_chunk, importedObjects, IMAGE_SEARCH) + + #keep track of how much we read in the main chunk + new_chunk.bytes_read += temp_chunk.bytes_read + + #is it an object chunk? + elif (new_chunk.ID == OBJECT): + + if CreateBlenderObject: + putContextMesh(contextMesh_vertls, contextMesh_facels, contextMeshMaterials) + contextMesh_vertls = [] + contextMesh_facels = [] + + ## preparando para receber o proximo objeto + contextMeshMaterials = [] # matname:[face_idxs] + contextMeshUV = None + #contextMesh.vertexUV = 1 # Make sticky coords. + # Reset matrix + contextMatrix_rot = None + #contextMatrix_tx = None + + CreateBlenderObject = True + contextObName, read_str_len = read_string(file) + new_chunk.bytes_read += read_str_len + + #is it a material chunk? + elif (new_chunk.ID == MATERIAL): + +# print("read material") + + #print 'elif (new_chunk.ID == MATERIAL):' + contextMaterial = bpy.data.materials.new('Material') + + elif (new_chunk.ID == MAT_NAME): + #print 'elif (new_chunk.ID == MAT_NAME):' + material_name, read_str_len = read_string(file) + +# print("material name", material_name) + + #plus one for the null character that ended the string + new_chunk.bytes_read += read_str_len + + contextMaterial.name = material_name.rstrip() # remove trailing whitespace + MATDICT[material_name] = contextMaterial + + elif (new_chunk.ID == MAT_AMBIENT): + #print 'elif (new_chunk.ID == MAT_AMBIENT):' + read_chunk(file, temp_chunk) + if (temp_chunk.ID == MAT_FLOAT_COLOR): + contextMaterial.mirror_color = read_float_color(temp_chunk) +# temp_data = file.read(struct.calcsize('3f')) +# temp_chunk.bytes_read += 12 +# contextMaterial.mirCol = [float(col) for col in struct.unpack('<3f', temp_data)] + elif (temp_chunk.ID == MAT_24BIT_COLOR): + contextMaterial.mirror_color = read_byte_color(temp_chunk) +# temp_data = file.read(struct.calcsize('3B')) +# temp_chunk.bytes_read += 3 +# contextMaterial.mirCol = [float(col)/255 for col in struct.unpack('<3B', temp_data)] # data [0,1,2] == rgb + else: + skip_to_end(file, temp_chunk) + new_chunk.bytes_read += temp_chunk.bytes_read + + elif (new_chunk.ID == MAT_DIFFUSE): + #print 'elif (new_chunk.ID == MAT_DIFFUSE):' + read_chunk(file, temp_chunk) + if (temp_chunk.ID == MAT_FLOAT_COLOR): + contextMaterial.diffuse_color = read_float_color(temp_chunk) +# temp_data = file.read(struct.calcsize('3f')) +# temp_chunk.bytes_read += 12 +# contextMaterial.rgbCol = [float(col) for col in struct.unpack('<3f', temp_data)] + elif (temp_chunk.ID == MAT_24BIT_COLOR): + contextMaterial.diffuse_color = read_byte_color(temp_chunk) +# temp_data = file.read(struct.calcsize('3B')) +# temp_chunk.bytes_read += 3 +# contextMaterial.rgbCol = [float(col)/255 for col in struct.unpack('<3B', temp_data)] # data [0,1,2] == rgb + else: + skip_to_end(file, temp_chunk) + +# print("read material diffuse color", contextMaterial.diffuse_color) + + new_chunk.bytes_read += temp_chunk.bytes_read + + elif (new_chunk.ID == MAT_SPECULAR): + #print 'elif (new_chunk.ID == MAT_SPECULAR):' + read_chunk(file, temp_chunk) + if (temp_chunk.ID == MAT_FLOAT_COLOR): + contextMaterial.specular_color = read_float_color(temp_chunk) +# temp_data = file.read(struct.calcsize('3f')) +# temp_chunk.bytes_read += 12 +# contextMaterial.mirCol = [float(col) for col in struct.unpack('<3f', temp_data)] + elif (temp_chunk.ID == MAT_24BIT_COLOR): + contextMaterial.specular_color = read_byte_color(temp_chunk) +# temp_data = file.read(struct.calcsize('3B')) +# temp_chunk.bytes_read += 3 +# contextMaterial.mirCol = [float(col)/255 for col in struct.unpack('<3B', temp_data)] # data [0,1,2] == rgb + else: + skip_to_end(file, temp_chunk) + new_chunk.bytes_read += temp_chunk.bytes_read + + elif (new_chunk.ID == MAT_TEXTURE_MAP): + read_texture(new_chunk, temp_chunk, "Diffuse", "COLOR") + + elif (new_chunk.ID == MAT_SPECULAR_MAP): + read_texture(new_chunk, temp_chunk, "Specular", "SPECULARITY") + + elif (new_chunk.ID == MAT_OPACITY_MAP): + read_texture(new_chunk, temp_chunk, "Opacity", "ALPHA") + + elif (new_chunk.ID == MAT_BUMP_MAP): + read_texture(new_chunk, temp_chunk, "Bump", "NORMAL") + + elif (new_chunk.ID == MAT_TRANSPARENCY): + #print 'elif (new_chunk.ID == MAT_TRANSPARENCY):' + read_chunk(file, temp_chunk) + temp_data = file.read(STRUCT_SIZE_UNSIGNED_SHORT) + + temp_chunk.bytes_read += 2 + contextMaterial.alpha = 1 - (float(struct.unpack(' BOUNDS_3DS[i + 3]: + BOUNDS_3DS[i + 3] = v[i] # min + + # Get the max axis x/y/z + max_axis = max(BOUNDS_3DS[3] - BOUNDS_3DS[0], BOUNDS_3DS[4] - BOUNDS_3DS[1], BOUNDS_3DS[5] - BOUNDS_3DS[2]) + # print max_axis + if max_axis < 1 << 30: # Should never be false but just make sure. + + # Get a new scale factor if set as an option + SCALE = 1.0 + while (max_axis * SCALE) > IMPORT_CONSTRAIN_BOUNDS: + SCALE /= 10.0 + + # SCALE Matrix + SCALE_MAT = mathutils.Matrix.Scale(SCALE, 4) + + for ob in importedObjects: + if ob.parent is None: + ob.matrix_world = ob.matrix_world * SCALE_MAT + + # Done constraining to bounds. + + # Select all new objects. + print(" done in %.4f sec." % (time.clock() - time1)) + file.close() + + +def load(operator, context, filepath="", constrain_size=0.0, use_image_search=True, use_apply_transform=True): + load_3ds(filepath, context, IMPORT_CONSTRAIN_BOUNDS=constrain_size, IMAGE_SEARCH=use_image_search, APPLY_MATRIX=use_apply_transform) + return {'FINISHED'} -- cgit v1.2.3