[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1967] trunk/py/scripts/addons: added axis settings to 3ds import/export

Campbell Barton ideasman42 at gmail.com
Thu May 26 10:45:32 CEST 2011


Revision: 1967
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1967
Author:   campbellbarton
Date:     2011-05-26 08:45:31 +0000 (Thu, 26 May 2011)
Log Message:
-----------
added axis settings to 3ds import/export

Modified Paths:
--------------
    trunk/py/scripts/addons/io_scene_3ds/__init__.py
    trunk/py/scripts/addons/io_scene_3ds/export_3ds.py
    trunk/py/scripts/addons/io_scene_3ds/import_3ds.py
    trunk/py/scripts/addons/io_scene_fbx/__init__.py
    trunk/py/scripts/addons/io_scene_fbx/export_fbx.py

Modified: trunk/py/scripts/addons/io_scene_3ds/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_scene_3ds/__init__.py	2011-05-26 07:47:44 UTC (rev 1966)
+++ trunk/py/scripts/addons/io_scene_3ds/__init__.py	2011-05-26 08:45:31 UTC (rev 1967)
@@ -42,8 +42,8 @@
 
 
 import bpy
-from bpy.props import StringProperty, FloatProperty, BoolProperty
-from bpy_extras.io_utils import ImportHelper, ExportHelper
+from bpy.props import StringProperty, FloatProperty, BoolProperty, EnumProperty
+from bpy_extras.io_utils import ImportHelper, ExportHelper, axis_conversion
 
 
 class Import3DS(bpy.types.Operator, ImportHelper):
@@ -58,11 +58,41 @@
     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)
 
+    global_axis_forward = EnumProperty(
+            name="Forward",
+            items=(('X', "X Forward", ""),
+                   ('Y', "Y Forward", ""),
+                   ('Z', "Z Forward", ""),
+                   ('-X', "-X Forward", ""),
+                   ('-Y', "-Y Forward", ""),
+                   ('-Z', "-Z Forward", ""),
+                   ),
+            default='Y',
+            )
+
+    global_axis_up = EnumProperty(
+            name="Up",
+            items=(('X', "X Up", ""),
+                   ('Y', "Y Up", ""),
+                   ('Z', "Z Up", ""),
+                   ('-X', "-X Up", ""),
+                   ('-Y', "-Y Up", ""),
+                   ('-Z', "-Z Up", ""),
+                   ),
+            default='Z',
+            )
+
     def execute(self, context):
         from . import import_3ds
-        return import_3ds.load(self, context, **self.as_keywords(ignore=("filter_glob",)))
 
+        keywords = self.as_keywords(ignore=("global_axis_forward", "global_axis_up", "filter_glob"))
 
+        global_matrix = axis_conversion(from_forward=self.global_axis_forward, from_up=self.global_axis_up).to_4x4()
+        keywords["global_matrix"] = global_matrix
+
+        return import_3ds.load(self, context, **keywords)
+
+
 class Export3DS(bpy.types.Operator, ExportHelper):
     '''Export to 3DS file format (.3ds)'''
     bl_idname = "export_scene.autodesk_3ds"
@@ -73,11 +103,40 @@
 
     use_selection = BoolProperty(name="Selection Only", description="Export selected objects only", default=False)
 
+    global_axis_forward = EnumProperty(
+            name="Forward",
+            items=(('X', "X Forward", ""),
+                   ('Y', "Y Forward", ""),
+                   ('Z', "Z Forward", ""),
+                   ('-X', "-X Forward", ""),
+                   ('-Y', "-Y Forward", ""),
+                   ('-Z', "-Z Forward", ""),
+                   ),
+            default='Y',
+            )
+
+    global_axis_up = EnumProperty(
+            name="Up",
+            items=(('X', "X Up", ""),
+                   ('Y', "Y Up", ""),
+                   ('Z', "Z Up", ""),
+                   ('-X', "-X Up", ""),
+                   ('-Y', "-Y Up", ""),
+                   ('-Z', "-Z Up", ""),
+                   ),
+            default='Z',
+            )
+
     def execute(self, context):
         from . import export_3ds
-        return export_3ds.save(self, context, **self.as_keywords(ignore=("check_existing", "filter_glob")))
 
+        keywords = self.as_keywords(ignore=("global_axis_forward", "global_axis_up", "filter_glob", "check_existing"))
+        global_matrix = axis_conversion(to_forward=self.global_axis_forward, to_up=self.global_axis_up).to_4x4()
+        keywords["global_matrix"] = global_matrix
 
+        return export_3ds.save(self, context, **keywords)
+
+
 # Add to a menu
 def menu_func_export(self, context):
     self.layout.operator(Export3DS.bl_idname, text="3D Studio (.3ds)")

Modified: trunk/py/scripts/addons/io_scene_3ds/export_3ds.py
===================================================================
--- trunk/py/scripts/addons/io_scene_3ds/export_3ds.py	2011-05-26 07:47:44 UTC (rev 1966)
+++ trunk/py/scripts/addons/io_scene_3ds/export_3ds.py	2011-05-26 08:45:31 UTC (rev 1967)
@@ -485,11 +485,8 @@
 
     else:
         material_chunk.add_subchunk(make_material_subchunk(MATAMBIENT, [a * material.ambient for a in material.diffuse_color]))
-# 		material_chunk.add_subchunk(make_material_subchunk(MATAMBIENT, [a*material.amb for a in material.rgbCol] ))
         material_chunk.add_subchunk(make_material_subchunk(MATDIFFUSE, material.diffuse_color))
-# 		material_chunk.add_subchunk(make_material_subchunk(MATDIFFUSE, material.rgbCol))
         material_chunk.add_subchunk(make_material_subchunk(MATSPECULAR, material.specular_color))
-# 		material_chunk.add_subchunk(make_material_subchunk(MATSPECULAR, material.specCol))
 
         images = get_material_images(material)  # can be None
         if image:
@@ -522,22 +519,15 @@
     If the mesh contains quads, they will be split into triangles.'''
     tri_list = []
     do_uv = len(mesh.uv_textures)
-# 	do_uv = mesh.faceUV
 
-# 	if not do_uv:
-# 		face_uv = None
-
     img = None
     for i, face in enumerate(mesh.faces):
         f_v = face.vertices
-# 		f_v = face.v
 
         uf = mesh.uv_textures.active.data[i] if do_uv else None
 
         if do_uv:
             f_uv = uf.uv
-            # f_uv =  (uf.uv1, uf.uv2, uf.uv3, uf.uv4) if face.vertices[3] else (uf.uv1, uf.uv2, uf.uv3)
-# 			f_uv = face.uv
             img = uf.image if uf else None
             if img is not None:
                 img = img.name
@@ -545,16 +535,13 @@
         # if f_v[3] == 0:
         if len(f_v) == 3:
             new_tri = tri_wrapper((f_v[0], f_v[1], f_v[2]), face.material_index, img)
-# 			new_tri = tri_wrapper((f_v[0].index, f_v[1].index, f_v[2].index), face.mat, img)
             if (do_uv):
                 new_tri.faceuvs = uv_key(f_uv[0]), uv_key(f_uv[1]), uv_key(f_uv[2])
             tri_list.append(new_tri)
 
         else:  # it's a quad
             new_tri = tri_wrapper((f_v[0], f_v[1], f_v[2]), face.material_index, img)
-# 			new_tri = tri_wrapper((f_v[0].index, f_v[1].index, f_v[2].index), face.mat, img)
             new_tri_2 = tri_wrapper((f_v[0], f_v[2], f_v[3]), face.material_index, img)
-# 			new_tri_2 = tri_wrapper((f_v[0].index, f_v[2].index, f_v[3].index), face.mat, img)
 
             if (do_uv):
                 new_tri.faceuvs = uv_key(f_uv[0]), uv_key(f_uv[1]), uv_key(f_uv[2])
@@ -887,11 +874,15 @@
 """
 
 
-def save(operator, context, filepath="",
-          use_selection=True,
-          ):
+def save(operator,
+         context, filepath="",
+         use_selection=True,
+         global_matrix=None,
+         ):
 
     import bpy
+    import mathutils
+
     import time
     from bpy_extras.io_utils import create_derived_objects, free_derived_objects
 
@@ -901,6 +892,9 @@
     time1 = time.clock()
 #	Blender.Window.WaitCursor(1)
 
+    if global_matrix is None:
+        global_matrix = mathutils.Matrix()
+
     if bpy.ops.object.mode_set.poll():
         bpy.ops.object.mode_set(mode='OBJECT')
 
@@ -939,8 +933,6 @@
             continue
 
         for ob_derived, mat in derived:
-# 		for ob_derived, mat in getDerivedObjects(ob, False):
-
             if ob.type not in ('MESH', 'CURVE', 'SURFACE', 'FONT', 'META'):
                 continue
 
@@ -950,7 +942,7 @@
                 data = None
 
             if data:
-                data.transform(mat)
+                data.transform(global_matrix * mat)
 # 				data.transform(mat, recalc_normals=False)
                 mesh_objects.append((ob_derived, data))
                 mat_ls = data.materials
@@ -965,7 +957,6 @@
                     for f, uf in zip(data.faces, data.uv_textures.active.data):
                         if mat_ls:
                             mat_index = f.material_index
-# 							mat_index = f.mat
                             if mat_index >= mat_ls_len:
                                 mat_index = f.mat = 0
                             mat = mat_ls[mat_index]

Modified: trunk/py/scripts/addons/io_scene_3ds/import_3ds.py
===================================================================
--- trunk/py/scripts/addons/io_scene_3ds/import_3ds.py	2011-05-26 07:47:44 UTC (rev 1966)
+++ trunk/py/scripts/addons/io_scene_3ds/import_3ds.py	2011-05-26 08:45:31 UTC (rev 1967)
@@ -339,18 +339,12 @@
         ob = bpy.data.objects.new(contextObName, bmesh)
         object_dictionary[contextObName] = ob
         SCN.objects.link(ob)
+        importedObjects.append(ob)
 
-        '''
-        if contextMatrix_tx:
-            ob.setMatrix(contextMatrix_tx)
-        '''
-
         if contextMatrix_rot:
             ob.matrix_local = contextMatrix_rot
             object_matrix[ob] = contextMatrix_rot.copy()
 
-        importedObjects.append(ob)
-
     #a spare chunk
     new_chunk = chunk()
     temp_chunk = chunk()
@@ -667,6 +661,7 @@
             if child is None:
                 child = bpy.data.objects.new(object_name, None)  # create an empty object
                 SCN.objects.link(child)
+                importedObjects.append(child)
 
             object_list.append(child)
             object_parent.append(hierarchy)
@@ -779,7 +774,12 @@
             ob.data.transform(pivot_matrix)
 
 
-def load_3ds(filepath, context, IMPORT_CONSTRAIN_BOUNDS=10.0, IMAGE_SEARCH=True, APPLY_MATRIX=True):
+def load_3ds(filepath,
+             context,
+             IMPORT_CONSTRAIN_BOUNDS=10.0,
+             IMAGE_SEARCH=True,
+             APPLY_MATRIX=True,
+             global_matrix=None):
     global SCN
 
     # XXX
@@ -838,6 +838,13 @@
                 me = ob.data
                 me.transform(ob.matrix_local.inverted())
 
+    # print(importedObjects)
+    if global_matrix:
+        for ob in importedObjects:
+            if ob.parent is None:
+                ob.matrix_world = ob.matrix_world * global_matrix
+
+
     # Done DUMMYVERT
     """
     if IMPORT_AS_INSTANCE:
@@ -903,6 +910,21 @@
     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)
+def load(operator,
+         context,
+         filepath="",
+         constrain_size=0.0,
+         use_image_search=True,

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list