Previous Thread  Next Thread

chat icon Exporting obj files using object coordinates

suikki

Posted: Wed Sep 19, 2012 1:32 pm
Joined: 19 Sep 2012
Posts: 2
I'm using the wavefront obj export script. I needed to export objects using local object coordinates instead of global world coordinates.

I modded the official export script and added a checkbox for this.

I don't have previous experience with blender coding, and frankly I don't have the time to investigate how to make a proper patch. So I'll just put this out here if someone else is having the same problem (or some developer checks if I did something crazy stupid).

(Also I'm mainly posting because I googled a bit to solve the problem, only to find out that someone already made this for himself. He just didn't bother publishing the solution)

Here's a diff off the changes I made (I was using the script from 2.63):

Code:

--- __init__.py   Tue Jan 20 00:26:12 1970
+++ __init__.py   Tue Jan 20 00:26:12 1970
@@ -287,6 +287,12 @@
             default=False,
             )
 
+    use_object_coordinates = BoolProperty(
+            name="Use Object Coordinates",
+            description="",
+            default=False,
+            )
+
     global_scale = FloatProperty(
             name="Scale",
             description="Scale all data",
--- export_obj.py   Tue Jan 20 00:26:12 1970
+++ export_obj.py   Tue Jan 20 00:26:12 1970
@@ -228,6 +228,7 @@
                EXPORT_CURVE_AS_NURBS=True,
                EXPORT_GLOBAL_MATRIX=None,
                EXPORT_PATH_MODE='AUTO',
+               EXPORT_OBJECT_COORDINATES=False,
                ):
     '''
     Basic write function. The context and options must be already set
@@ -320,7 +321,11 @@
 
             # Nurbs curve support
             if EXPORT_CURVE_AS_NURBS and test_nurbs_compat(ob):
-                ob_mat = EXPORT_GLOBAL_MATRIX * ob_mat
+                if EXPORT_OBJECT_COORDINATES:
+                    ob_mat = EXPORT_GLOBAL_MATRIX
+                else:
+                    ob_mat = EXPORT_GLOBAL_MATRIX * ob_mat
+
                 totverts += write_nurb(fw, ob, ob_mat)
                 continue
             # END NURBS
@@ -333,7 +338,11 @@
             if me is None:
                 continue
 
-            me.transform(EXPORT_GLOBAL_MATRIX * ob_mat)
+            if EXPORT_OBJECT_COORDINATES:
+                me.transform(EXPORT_GLOBAL_MATRIX)
+            else:
+                me.transform(EXPORT_GLOBAL_MATRIX * ob_mat)
+           
 
             if EXPORT_UV:
                 faceuv = len(me.uv_textures) > 0
@@ -626,6 +635,7 @@
               EXPORT_ANIMATION,
               EXPORT_GLOBAL_MATRIX,
               EXPORT_PATH_MODE,
+              EXPORT_OBJECT_COORDINATES,
               ):  # Not used
 
     base_name, ext = os.path.splitext(filepath)
@@ -675,6 +685,7 @@
                    EXPORT_CURVE_AS_NURBS,
                    EXPORT_GLOBAL_MATRIX,
                    EXPORT_PATH_MODE,
+                   EXPORT_OBJECT_COORDINATES,
                    )
 
     scene.frame_set(orig_frame, 0.0)
@@ -707,7 +718,8 @@
          use_selection=True,
          use_animation=False,
          global_matrix=None,
-         path_mode='AUTO'
+         path_mode='AUTO',
+         use_object_coordinates=False
          ):
 
     _write(context, filepath,
@@ -727,6 +739,7 @@
            EXPORT_ANIMATION=use_animation,
            EXPORT_GLOBAL_MATRIX=global_matrix,
            EXPORT_PATH_MODE=path_mode,
+           EXPORT_OBJECT_COORDINATES=use_object_coordinates
            )
 
     return {'FINISHED'}

Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group