[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34305] trunk/blender/release/scripts/op/ io_scene_x3d: fix for x3d importer

Campbell Barton ideasman42 at gmail.com
Thu Jan 13 23:44:48 CET 2011


Revision: 34305
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34305
Author:   campbellbarton
Date:     2011-01-13 22:44:47 +0000 (Thu, 13 Jan 2011)
Log Message:
-----------
fix for x3d importer
- files blender exports (blender uses unusual array formatting).
- scene needed to be rotated on import.
- lamp spot size was half as big as it needed to be.

x3d export typo broke image export.

Modified Paths:
--------------
    trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py
    trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py

Modified: trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py	2011-01-13 21:44:18 UTC (rev 34304)
+++ trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py	2011-01-13 22:44:47 UTC (rev 34305)
@@ -396,7 +396,7 @@
                         self.writeImageTexture(image)
 
                         if mesh_materials_use_face_texture[material_index]:
-                            if image.use_tile:
+                            if image.use_tiles:
                                 self.write_indented("<TextureTransform scale=\"%s %s\" />\n" % (image.tiles_x, image.tiles_y))
                         else:
                             # transform by mtex

Modified: trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py	2011-01-13 21:44:18 UTC (rev 34304)
+++ trunk/blender/release/scripts/op/io_scene_x3d/import_x3d.py	2011-01-13 22:44:47 UTC (rev 34305)
@@ -736,6 +736,19 @@
         '''
         For this parser arrays are children
         '''
+
+        def array_as_number(array_string):
+            array_data = []
+            try:
+                array_data = [int(val) for val in array_string]
+            except:
+                try:
+                    array_data = [float(val) for val in array_string]
+                except:
+                    print('\tWarning, could not parse array data from field')
+
+            return array_data
+
         self_real = self.getRealNode()  # incase we're an instance
 
         child_array = self_real.getFieldName(field, ancestry, True)
@@ -743,8 +756,7 @@
         #if type(child_array)==list: # happens occasionaly
         #   array_data = child_array
 
-        if child_array == None:
-
+        if child_array is None:
             # For x3d, should work ok with vrml too
             # for x3d arrays are fields, vrml they are nodes, annoying but not tooo bad.
             data_split = self.getFieldName(field, ancestry)
@@ -756,14 +768,14 @@
 
             array_data = array_data.replace(',', ' ')
             data_split = array_data.split()
-            try:
-                array_data = [int(val) for val in data_split]
-            except:
-                try:
-                    array_data = [float(val) for val in data_split]
-                except:
-                    print('\tWarning, could not parse array data from field')
-                    array_data = []
+
+            array_data = array_as_number(data_split)
+
+        elif type(child_array) == list:
+            # x3d creates these
+            data_split = [w.strip(",") for w in child_array]
+
+            array_data = array_as_number(data_split)
         else:
             # print(child_array)
             # Normal vrml
@@ -1529,6 +1541,11 @@
     return new_mat
 
 
+# 90d X rotation
+import math
+MATRIX_Z_TO_Y = Matrix.Rotation(math.pi / 2.0, 4, 'X')
+
+
 def getFinalMatrix(node, mtx, ancestry):
 
     transform_nodes = [node_tx for node_tx in ancestry if node_tx.getSpec() == 'Transform']
@@ -1541,8 +1558,11 @@
 
     for node_tx in transform_nodes:
         mat = translateTransform(node_tx, ancestry)
-        mtx =  mat * mtx
+        mtx = mat * mtx
 
+    # worldspace matrix
+    mtx = MATRIX_Z_TO_Y * mtx
+
     return mtx
 
 
@@ -1902,11 +1922,7 @@
 
 GLOBALS['CIRCLE_DETAIL'] = 12
 
-# 90d X rotation
-import math
-MATRIX_Z_TO_Y = Matrix.Rotation(math.pi/2, 4, 'X')
 
-
 def bpy_ops_add_object_hack():  # XXX25, evil
     scene = bpy.context.scene
     obj = scene.objects[0]
@@ -2015,7 +2031,7 @@
 def importMesh_Box(geom, ancestry):
     # bpymesh = bpy.data.meshes.new()
 
-    size = geom.getFieldAsFloatTuple('size', (2.0, 2.0, 2.0), ancestry) 
+    size = geom.getFieldAsFloatTuple('size', (2.0, 2.0, 2.0), ancestry)
 
     # bpymesh = Mesh.Primitives.Cube(1.0)
     bpy.ops.mesh.primitive_cube_add(view_align=False,
@@ -2266,7 +2282,7 @@
     # attenuation = geom.getFieldAsFloatTuple('attenuation', (1.0, 0.0, 0.0), ancestry) # TODO
     beamWidth = node.getFieldAsFloat('beamWidth', 1.570796, ancestry)  # max is documented to be 1.0 but some files have higher.
     color = node.getFieldAsFloatTuple('color', (1.0, 1.0, 1.0), ancestry)
-    cutOffAngle = node.getFieldAsFloat('cutOffAngle', 0.785398, ancestry)  # max is documented to be 1.0 but some files have higher.
+    cutOffAngle = node.getFieldAsFloat('cutOffAngle', 0.785398, ancestry) * 2.0  # max is documented to be 1.0 but some files have higher.
     direction = node.getFieldAsFloatTuple('direction', (0.0, 0.0, -1.0), ancestry)
     intensity = node.getFieldAsFloat('intensity', 1.0, ancestry)  # max is documented to be 1.0 but some files have higher.
     location = node.getFieldAsFloatTuple('location', (0.0, 0.0, 0.0), ancestry)




More information about the Bf-blender-cvs mailing list