[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4475] trunk/py/scripts/addons: option to apply scale on export.

Campbell Barton ideasman42 at gmail.com
Mon Apr 15 19:21:17 CEST 2013


Revision: 4475
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4475
Author:   campbellbarton
Date:     2013-04-15 17:21:17 +0000 (Mon, 15 Apr 2013)
Log Message:
-----------
option to apply scale on export. also add global scale options for exporters. OBJ/X3D/VRML/PLY/STL

Modified Paths:
--------------
    trunk/py/scripts/addons/io_mesh_ply/__init__.py
    trunk/py/scripts/addons/io_mesh_ply/export_ply.py
    trunk/py/scripts/addons/io_mesh_stl/__init__.py
    trunk/py/scripts/addons/io_mesh_stl/blender_utils.py
    trunk/py/scripts/addons/io_scene_obj/__init__.py
    trunk/py/scripts/addons/io_scene_vrml2/__init__.py
    trunk/py/scripts/addons/object_print3d_utils/__init__.py
    trunk/py/scripts/addons/object_print3d_utils/export.py
    trunk/py/scripts/addons/object_print3d_utils/ui.py

Modified: trunk/py/scripts/addons/io_mesh_ply/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_ply/__init__.py	2013-04-15 16:50:06 UTC (rev 4474)
+++ trunk/py/scripts/addons/io_mesh_ply/__init__.py	2013-04-15 17:21:17 UTC (rev 4475)
@@ -46,8 +46,16 @@
 
 import os
 import bpy
-from bpy.props import CollectionProperty, StringProperty, BoolProperty
-from bpy_extras.io_utils import ImportHelper, ExportHelper
+from bpy.props import (CollectionProperty,
+                       StringProperty,
+                       BoolProperty,
+                       EnumProperty,
+                       FloatProperty,
+                       )
+from bpy_extras.io_utils import (ImportHelper,
+                                 ExportHelper,
+                                 axis_conversion,
+                                 )
 
 
 class ImportPLY(bpy.types.Operator, ImportHelper):
@@ -110,17 +118,60 @@
     use_colors = BoolProperty(
             name="Vertex Colors",
             description="Export the active vertex color layer",
-            default=True)
+            default=True,
+            )
 
+    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',
+            )
+    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',
+            )
+    global_scale = FloatProperty(
+            name="Scale",
+            min=0.01, max=1000.0,
+            default=1.0,
+            )
+
     @classmethod
     def poll(cls, context):
         return context.active_object != None
 
     def execute(self, context):
+        from . import export_ply
+
+        from mathutils import Matrix
+
+        keywords = self.as_keywords(ignore=("axis_forward",
+                                            "axis_up",
+                                            "global_scale",
+                                            "check_existing",
+                                            "filter_glob",
+                                            ))
+        global_matrix = axis_conversion(to_forward=self.axis_forward,
+                                        to_up=self.axis_up,
+                                        ).to_4x4() * Matrix.Scale(self.global_scale, 4)
+        keywords["global_matrix"] = global_matrix
+
         filepath = self.filepath
         filepath = bpy.path.ensure_ext(filepath, self.filename_ext)
-        from . import export_ply
-        keywords = self.as_keywords(ignore=("check_existing", "filter_glob"))
+
         return export_ply.save(self, context, **keywords)
 
     def draw(self, context):
@@ -133,7 +184,11 @@
         row.prop(self, "use_uv_coords")
         row.prop(self, "use_colors")
 
+        layout.prop(self, "axis_forward")
+        layout.prop(self, "axis_up")
+        layout.prop(self, "global_scale")
 
+
 def menu_func_import(self, context):
     self.layout.operator(ImportPLY.bl_idname, text="Stanford (.ply)")
 

Modified: trunk/py/scripts/addons/io_mesh_ply/export_ply.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_ply/export_ply.py	2013-04-15 16:50:06 UTC (rev 4474)
+++ trunk/py/scripts/addons/io_mesh_ply/export_ply.py	2013-04-15 17:21:17 UTC (rev 4475)
@@ -189,13 +189,15 @@
          use_normals=True,
          use_uv_coords=True,
          use_colors=True,
+         global_matrix=None
          ):
 
     scene = context.scene
     obj = context.active_object
 
-    if not obj:
-        raise Exception("Error, Select 1 active object")
+    if global_matrix is None:
+        from mathutils import Matrix
+        global_matrix = Matrix()
 
     if bpy.ops.object.mode_set.poll():
         bpy.ops.object.mode_set(mode='OBJECT')
@@ -208,7 +210,7 @@
     if not mesh:
         raise Exception("Error, could not get mesh data from active object")
 
-    mesh.transform(obj.matrix_world)
+    mesh.transform(global_matrix * obj.matrix_world)
     if use_normals:
         mesh.calc_normals()
 

Modified: trunk/py/scripts/addons/io_mesh_stl/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_stl/__init__.py	2013-04-15 16:50:06 UTC (rev 4474)
+++ trunk/py/scripts/addons/io_mesh_stl/__init__.py	2013-04-15 17:21:17 UTC (rev 4475)
@@ -58,8 +58,16 @@
 import os
 
 import bpy
-from bpy.props import StringProperty, BoolProperty, CollectionProperty
-from bpy_extras.io_utils import ExportHelper, ImportHelper
+from bpy.props import (StringProperty,
+                       BoolProperty,
+                       CollectionProperty,
+                       EnumProperty,
+                       FloatProperty,
+                       )
+from bpy_extras.io_utils import (ImportHelper,
+                                 ExportHelper,
+                                 axis_conversion,
+                                 )
 from bpy.types import Operator, OperatorFileListElement
 
 
@@ -126,13 +134,46 @@
             default=True,
             )
 
+    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',
+            )
+    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',
+            )
+    global_scale = FloatProperty(
+            name="Scale",
+            min=0.01, max=1000.0,
+            default=1.0,
+            )
+
     def execute(self, context):
         from . import stl_utils
         from . import blender_utils
         import itertools
+        from mathutils import Matrix
 
+        global_matrix = axis_conversion(to_forward=self.axis_forward,
+                                        to_up=self.axis_up,
+                                        ).to_4x4() * Matrix.Scale(self.global_scale, 4)
+
         faces = itertools.chain.from_iterable(
-            blender_utils.faces_from_mesh(ob, self.use_mesh_modifiers)
+            blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers)
             for ob in context.selected_objects)
 
         stl_utils.write_stl(self.filepath, faces, self.ascii)

Modified: trunk/py/scripts/addons/io_mesh_stl/blender_utils.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_stl/blender_utils.py	2013-04-15 16:50:06 UTC (rev 4474)
+++ trunk/py/scripts/addons/io_mesh_stl/blender_utils.py	2013-04-15 17:21:17 UTC (rev 4475)
@@ -42,7 +42,7 @@
     obj.select = True
 
 
-def faces_from_mesh(ob, use_mesh_modifiers=False, triangulate=True):
+def faces_from_mesh(ob, global_matrix, use_mesh_modifiers=False, triangulate=True):
     """
     From an object, return a generator over a list of faces.
 
@@ -65,7 +65,7 @@
     except RuntimeError:
         raise StopIteration
 
-    mesh.transform(ob.matrix_world)
+    mesh.transform(global_matrix * ob.matrix_world)
 
     if triangulate:
         # From a list of faces, return the face triangulated if needed.

Modified: trunk/py/scripts/addons/io_scene_obj/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_scene_obj/__init__.py	2013-04-15 16:50:06 UTC (rev 4474)
+++ trunk/py/scripts/addons/io_scene_obj/__init__.py	2013-04-15 17:21:17 UTC (rev 4475)
@@ -46,8 +46,8 @@
                        StringProperty,
                        EnumProperty,
                        )
-from bpy_extras.io_utils import (ExportHelper,
-                                 ImportHelper,
+from bpy_extras.io_utils import (ImportHelper,
+                                 ExportHelper,
                                  path_reference_mode,
                                  axis_conversion,
                                  )
@@ -302,7 +302,6 @@
                    ),
             default='-Z',
             )
-
     axis_up = EnumProperty(
             name="Up",
             items=(('X', "X Up", ""),

Modified: trunk/py/scripts/addons/io_scene_vrml2/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_scene_vrml2/__init__.py	2013-04-15 16:50:06 UTC (rev 4474)
+++ trunk/py/scripts/addons/io_scene_vrml2/__init__.py	2013-04-15 17:21:17 UTC (rev 4475)
@@ -39,8 +39,16 @@
 
 import os
 import bpy
-from bpy.props import CollectionProperty, StringProperty, BoolProperty, EnumProperty
-from bpy_extras.io_utils import ExportHelper, path_reference_mode, axis_conversion
+from bpy.props import (CollectionProperty,
+                       StringProperty,
+                       BoolProperty,
+                       EnumProperty,
+                       FloatProperty,
+                       )
+from bpy_extras.io_utils import (ExportHelper,
+                                 path_reference_mode,
+                                 axis_conversion,
+                                 )
 
 class ExportVRML(bpy.types.Operator, ExportHelper):
     """Export mesh objects as a VRML2, """ \
@@ -101,6 +109,11 @@
                    ),
             default='Y',
             )
+    global_scale = FloatProperty(
+            name="Scale",
+            min=0.01, max=1000.0,
+            default=1.0,
+            )
 
     path_mode = path_reference_mode
 
@@ -110,20 +123,24 @@
         return (obj is not None) and obj.type == 'MESH'
 
     def execute(self, context):
-        filepath = self.filepath
-        filepath = bpy.path.ensure_ext(filepath, self.filename_ext)

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list