From 86bd3cc31b636070da779f21b1fdc128faf1fc5d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 24 May 2011 22:20:54 +0000 Subject: axis conversion for X3D and OBJ operators --- io_scene_fbx/__init__.py | 2 +- io_scene_obj/__init__.py | 77 +++++++++++++++++++++++++++++++++++++++++----- io_scene_obj/export_obj.py | 25 ++++++--------- io_scene_obj/import_obj.py | 24 ++++++++------- io_scene_x3d/__init__.py | 67 +++++++++++++++++++++++++++++++++++++--- io_scene_x3d/export_x3d.py | 13 +++++--- io_scene_x3d/import_x3d.py | 58 ++++++++++++++++++---------------- 7 files changed, 197 insertions(+), 69 deletions(-) diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index dafc4e15..ff87d29b 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -144,7 +144,7 @@ class ExportFBX(bpy.types.Operator, ExportHelper): keywords = self.as_keywords(ignore=("global_axis_forward", "global_axis_up", "global_scale", "check_existing", "filter_glob")) keywords["GLOBAL_MATRIX"] = GLOBAL_MATRIX - print(GLOBAL_MATRIX) + from . import export_fbx return export_fbx.save(self, context, **keywords) diff --git a/io_scene_obj/__init__.py b/io_scene_obj/__init__.py index b5f3cb9b..64d429d5 100644 --- a/io_scene_obj/__init__.py +++ b/io_scene_obj/__init__.py @@ -43,7 +43,7 @@ if "bpy" in locals(): import bpy from bpy.props import BoolProperty, FloatProperty, StringProperty, EnumProperty -from bpy_extras.io_utils import ExportHelper, ImportHelper, path_reference_mode +from bpy_extras.io_utils import ExportHelper, ImportHelper, path_reference_mode, axis_conversion class ImportOBJ(bpy.types.Operator, ImportHelper): @@ -64,8 +64,6 @@ class ImportOBJ(bpy.types.Operator, ImportHelper): use_groups_as_vgroups = BoolProperty(name="Poly Groups", description="Import OBJ groups as vertex groups.", default=False) - use_rotate_x90 = BoolProperty(name="-X90", description="Rotate X 90.", default=True) - global_clamp_size = FloatProperty(name="Clamp Scale", description="Clamp the size to this maximum (Zero to Disable)", min=0.0, max=1000.0, soft_min=0.0, soft_max=1000.0, default=0.0) use_image_search = BoolProperty(name="Image Search", description="Search subdirs for any assosiated images (Warning, may be slow)", default=True) split_mode = EnumProperty( @@ -75,12 +73,38 @@ class ImportOBJ(bpy.types.Operator, ImportHelper): ), ) + global_clamp_size = FloatProperty(name="Clamp Scale", description="Clamp the size to this maximum (Zero to Disable)", min=0.0, max=1000.0, soft_min=0.0, soft_max=1000.0, default=0.0) + 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='-Z', + ) + + 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='Y', + ) + # fake prop, only disables split. # keep_vertex_order = BoolProperty(name="Keep Vert Order", description="Keep vert and face order, disables split options, enable for morph targets", default= True) def execute(self, context): # print("Selected: " + context.active_object.name) from . import import_obj + from mathutils import Matrix if self.split_mode == 'OFF': self.use_split_objects = False @@ -88,7 +112,12 @@ class ImportOBJ(bpy.types.Operator, ImportHelper): else: self.use_groups_as_vgroups = False - return import_obj.load(self, context, **self.as_keywords(ignore=("filter_glob", "split_mode"))) + keywords = self.as_keywords(ignore=("global_axis_forward", "global_axis_up", "filter_glob", "split_mode")) + + 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_obj.load(self, context, **keywords) def draw(self, context): layout = self.layout @@ -113,7 +142,8 @@ class ImportOBJ(bpy.types.Operator, ImportHelper): row = layout.split(percentage=0.67) row.prop(self, "global_clamp_size") - row.prop(self, "use_rotate_x90") + layout.prop(self, "global_axis_forward") + layout.prop(self, "global_axis_up") layout.prop(self, "use_image_search") @@ -138,7 +168,6 @@ class ExportOBJ(bpy.types.Operator, ExportHelper): # object group use_apply_modifiers = BoolProperty(name="Apply Modifiers", description="Apply modifiers (preview resolution)", default=True) - use_rotate_x90 = BoolProperty(name="Rotate X90", description="", default=True) # extra data group use_edges = BoolProperty(name="Edges", description="", default=True) @@ -157,11 +186,45 @@ class ExportOBJ(bpy.types.Operator, ExportHelper): group_by_material = BoolProperty(name="Material Groups", description="", default=False) keep_vertex_order = BoolProperty(name="Keep Vertex Order", description="", default=False) + global_scale = FloatProperty(name="Scale", description="Scale all data, (Note! some imports dont support scaled armatures)", min=0.01, max=1000.0, soft_min=0.01, soft_max=1000.0, default=1.0) + + 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='-Z', + ) + + 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='Y', + ) + path_mode = path_reference_mode def execute(self, context): from . import export_obj - return export_obj.save(self, context, **self.as_keywords(ignore=("check_existing", "filter_glob"))) + + from mathutils import Matrix + keywords = self.as_keywords(ignore=("global_axis_forward", "global_axis_up", "global_scale", "check_existing", "filter_glob")) + + global_matrix = Matrix() + global_matrix[0][0] = global_matrix[1][1] = global_matrix[2][2] = self.global_scale + global_matrix = 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_obj.save(self, context, **keywords) def menu_func_import(self, context): diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py index 03a866ca..7e2aa1ed 100644 --- a/io_scene_obj/export_obj.py +++ b/io_scene_obj/export_obj.py @@ -236,13 +236,13 @@ def write_file(filepath, objects, scene, EXPORT_UV=True, EXPORT_MTL=True, EXPORT_APPLY_MODIFIERS=True, - EXPORT_ROTX90=True, EXPORT_BLEN_OBS=True, EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False, EXPORT_KEEP_VERT_ORDER=False, EXPORT_POLYGROUPS=False, EXPORT_CURVE_AS_NURBS=True, + EXPORT_GLOBAL_MATRIX=None, EXPORT_PATH_MODE='AUTO', ): ''' @@ -252,6 +252,9 @@ def write_file(filepath, objects, scene, write( 'c:\\test\\foobar.obj', Blender.Object.GetSelected() ) # Using default options. ''' + if EXPORT_GLOBAL_MATRIX is None: + EXPORT_GLOBAL_MATRIX = mathutils.Matrix() + # XXX import math @@ -303,9 +306,6 @@ def write_file(filepath, objects, scene, mtlfilepath = os.path.splitext(filepath)[0] + ".mtl" file.write('mtllib %s\n' % repr(os.path.basename(mtlfilepath))[1:-1]) # filepath can contain non utf8 chars, use repr - if EXPORT_ROTX90: - mat_xrot90 = mathutils.Matrix.Rotation(-math.pi / 2.0, 4, 'X') - # Initialize totals, these are updated each object totverts = totuvco = totno = 1 @@ -345,8 +345,7 @@ def write_file(filepath, objects, scene, # Nurbs curve support if EXPORT_CURVE_AS_NURBS and test_nurbs_compat(ob): - if EXPORT_ROTX90: - ob_mat = ob_mat * mat_xrot90 + ob_mat = ob_mat * EXPORT_GLOBAL_MATRIX totverts += write_nurb(file, ob, ob_mat) continue # END NURBS @@ -355,11 +354,7 @@ def write_file(filepath, objects, scene, continue me = ob.to_mesh(scene, EXPORT_APPLY_MODIFIERS, 'PREVIEW') - - if EXPORT_ROTX90: - me.transform(mat_xrot90 * ob_mat) - else: - me.transform(ob_mat) + me.transform(ob_mat * EXPORT_GLOBAL_MATRIX) # # Will work for non meshes now! :) # me= BPyMesh.getMeshFromObject(ob, containerMesh, EXPORT_APPLY_MODIFIERS, EXPORT_POLYGROUPS, scn) @@ -670,7 +665,6 @@ def _write(context, filepath, EXPORT_UV, # ok EXPORT_MTL, EXPORT_APPLY_MODIFIERS, # ok - EXPORT_ROTX90, # wrong EXPORT_BLEN_OBS, EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_MAT, @@ -680,6 +674,7 @@ def _write(context, filepath, EXPORT_SEL_ONLY, # ok EXPORT_ALL_SCENES, # XXX not working atm EXPORT_ANIMATION, + EXPORT_GLOBAL_MATRIX, EXPORT_PATH_MODE, ): # Not used @@ -739,13 +734,13 @@ def _write(context, filepath, EXPORT_UV, EXPORT_MTL, EXPORT_APPLY_MODIFIERS, - EXPORT_ROTX90, EXPORT_BLEN_OBS, EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_MAT, EXPORT_KEEP_VERT_ORDER, EXPORT_POLYGROUPS, EXPORT_CURVE_AS_NURBS, + EXPORT_GLOBAL_MATRIX, EXPORT_PATH_MODE, ) @@ -771,7 +766,6 @@ def save(operator, context, filepath="", use_uvs=True, use_materials=True, use_apply_modifiers=True, - use_rotate_x90=True, use_blen_objects=True, group_by_object=False, group_by_material=False, @@ -781,6 +775,7 @@ def save(operator, context, filepath="", use_selection=True, use_all_scenes=False, use_animation=False, + global_matrix=None, path_mode='AUTO' ): @@ -792,7 +787,6 @@ def save(operator, context, filepath="", EXPORT_UV=use_uvs, EXPORT_MTL=use_materials, EXPORT_APPLY_MODIFIERS=use_apply_modifiers, - EXPORT_ROTX90=use_rotate_x90, EXPORT_BLEN_OBS=use_blen_objects, EXPORT_GROUP_BY_OB=group_by_object, EXPORT_GROUP_BY_MAT=group_by_material, @@ -802,6 +796,7 @@ def save(operator, context, filepath="", EXPORT_SEL_ONLY=use_selection, EXPORT_ALL_SCENES=use_all_scenes, EXPORT_ANIMATION=use_animation, + EXPORT_GLOBAL_MATRIX=global_matrix, EXPORT_PATH_MODE=path_mode, ) diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py index a9708121..23f42446 100644 --- a/io_scene_obj/import_obj.py +++ b/io_scene_obj/import_obj.py @@ -961,10 +961,13 @@ def get_float_func(filepath): line = line.lstrip() if line.startswith(b'v'): # vn vt v if b',' in line: + file.close() return lambda f: float(f.replace(b',', b'.')) elif b'.' in line: + file.close() return float + file.close() # incase all vert values were ints return float @@ -976,9 +979,10 @@ def load(operator, context, filepath, use_edges=True, use_split_objects=True, use_split_groups=True, - use_rotate_x90=True, use_image_search=True, - use_groups_as_vgroups=False): + use_groups_as_vgroups=False, + global_matrix=None, + ): ''' Called by the user interface or another script. load_obj(path) - should give acceptable results. @@ -989,6 +993,9 @@ def load(operator, context, filepath, filepath = os.fsencode(filepath) + if global_matrix is None: + global_matrix = mathutils.Matrix() + if use_split_objects or use_split_groups: use_groups_as_vgroups = False @@ -1039,8 +1046,7 @@ def load(operator, context, filepath, if line.startswith(b"v "): line_split = line.split() - # rotate X90: (x,-z,y) - verts_loc.append((float_func(line_split[1]), -float_func(line_split[3]), float_func(line_split[2]))) + verts_loc.append((float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]))) elif line.startswith(b"vn "): pass @@ -1247,9 +1253,6 @@ def load(operator, context, filepath, print("%.4f sec" % (time_new - time_sub)) time_sub = time_new - if not use_rotate_x90: - verts_loc[:] = [(v[0], v[2], -v[1]) for v in verts_loc] - # deselect all if bpy.ops.object.select_all.poll(): bpy.ops.object.select_all(action='DESELECT') @@ -1278,6 +1281,9 @@ def load(operator, context, filepath, base = scene.objects.link(obj) base.select = True + # we could apply this anywhere before scaling. + obj.matrix_world = global_matrix + scene.update() axis_min = [1000000000] * 3 @@ -1303,10 +1309,6 @@ def load(operator, context, filepath, for obj in new_objects: obj.scale = scale, scale, scale - # Better rotate the vert locations - #if not use_rotate_x90: - # for ob in new_objects: - # ob.RotX = -1.570796326794896558 time_new = time.time() diff --git a/io_scene_x3d/__init__.py b/io_scene_x3d/__init__.py index 9da01735..dd0e1e03 100644 --- a/io_scene_x3d/__init__.py +++ b/io_scene_x3d/__init__.py @@ -40,8 +40,8 @@ if "bpy" in locals(): import bpy -from bpy.props import StringProperty, BoolProperty -from bpy_extras.io_utils import ImportHelper, ExportHelper +from bpy.props import StringProperty, BoolProperty, EnumProperty +from bpy_extras.io_utils import ImportHelper, ExportHelper, axis_conversion class ImportX3D(bpy.types.Operator, ImportHelper): @@ -52,9 +52,38 @@ class ImportX3D(bpy.types.Operator, ImportHelper): filename_ext = ".x3d" filter_glob = StringProperty(default="*.x3d;*.wrl", options={'HIDDEN'}) + 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='Z', + ) + + 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='-Y', + ) + def execute(self, context): from . import import_x3d - return import_x3d.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_x3d.load(self, context, **keywords) class ExportX3D(bpy.types.Operator, ExportHelper): @@ -70,9 +99,39 @@ class ExportX3D(bpy.types.Operator, ExportHelper): use_triangulate = BoolProperty(name="Triangulate", description="Triangulate quads.", default=False) use_compress = BoolProperty(name="Compress", description="GZip the resulting file, requires a full python install", 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='Z', + ) + + 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='-Y', + ) + def execute(self, context): from . import export_x3d - return export_x3d.save(self, context, **self.as_keywords(ignore=("check_existing", "filter_glob"))) + from mathutils import Matrix + + keywords = self.as_keywords(ignore=("global_axis_forward", "global_axis_up", "check_existing", "filter_glob")) + 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_x3d.save(self, context, **keywords) def menu_func_import(self, context): diff --git a/io_scene_x3d/export_x3d.py b/io_scene_x3d/export_x3d.py index 43033a0c..86d2209b 100644 --- a/io_scene_x3d/export_x3d.py +++ b/io_scene_x3d/export_x3d.py @@ -745,10 +745,12 @@ def export(file, def save(operator, context, filepath="", - use_selection=True, - use_apply_modifiers=False, - use_triangulate=False, - use_compress=False): + use_selection=True, + use_apply_modifiers=False, + use_triangulate=False, + use_compress=False, + global_matrix=None, + ): if use_compress: if not filepath.lower().endswith('.x3dz'): @@ -772,7 +774,8 @@ def save(operator, context, filepath="", if file is None: file = open(filepath, "w") - global_matrix = mathutils.Matrix.Rotation(-(math.pi / 2.0), 4, 'X') + if global_matrix is None: + global_matrix = mathutils.Matrix() export(file, global_matrix, diff --git a/io_scene_x3d/import_x3d.py b/io_scene_x3d/import_x3d.py index 2ad2b172..9fb40288 100644 --- a/io_scene_x3d/import_x3d.py +++ b/io_scene_x3d/import_x3d.py @@ -25,10 +25,7 @@ import os def imageConvertCompat(path): - try: - import os - except: - return path + if os.sep == '\\': return path # assime win32 has quicktime, dont convert @@ -258,10 +255,10 @@ def is_nodeline(i, words): # Ok, we have a { after some values # Check the values are not fields for i, val in enumerate(words): - if i != 0 and words[i - 1] in ('DEF', 'USE'): + if i != 0 and words[i - 1] in {'DEF', 'USE'}: # ignore anything after DEF, it is a ID and can contain any chars. pass - elif val[0].isalpha() and val not in ('TRUE', 'FALSE'): + elif val[0].isalpha() and val not in {'TRUE', 'FALSE'}: pass else: # There is a number in one of the values, therefor we are not a node. @@ -1180,7 +1177,7 @@ class vrmlNode(object): value_all = value.split() def iskey(k): - if k[0] != '"' and k[0].isalpha() and k.upper() not in ('TRUE', 'FALSE'): + if k[0] != '"' and k[0].isalpha() and k.upper() not in {'TRUE', 'FALSE'}: return True return False @@ -1328,7 +1325,7 @@ class x3dNode(vrmlNode): return for x3dChildNode in self.x3dNode.childNodes: - if x3dChildNode.nodeType in (x3dChildNode.TEXT_NODE, x3dChildNode.COMMENT_NODE, x3dChildNode.CDATA_SECTION_NODE): + if x3dChildNode.nodeType in {x3dChildNode.TEXT_NODE, x3dChildNode.COMMENT_NODE, x3dChildNode.CDATA_SECTION_NODE}: continue node_type = NODE_NORMAL @@ -1539,7 +1536,7 @@ import math MATRIX_Z_TO_Y = Matrix.Rotation(math.pi / 2.0, 4, 'X') -def getFinalMatrix(node, mtx, ancestry): +def getFinalMatrix(node, mtx, ancestry, global_matrix): transform_nodes = [node_tx for node_tx in ancestry if node_tx.getSpec() == 'Transform'] if node.getSpec() == 'Transform': @@ -1554,7 +1551,7 @@ def getFinalMatrix(node, mtx, ancestry): mtx = mat * mtx # worldspace matrix - mtx = MATRIX_Z_TO_Y * mtx + mtx = mtx * global_matrix return mtx @@ -2040,7 +2037,7 @@ def importMesh_Box(geom, ancestry): return bpymesh -def importShape(node, ancestry): +def importShape(node, ancestry, global_matrix): vrmlname = node.getDefName() if not vrmlname: vrmlname = 'Shape' @@ -2217,7 +2214,7 @@ def importShape(node, ancestry): # Can transform data or object, better the object so we can instance the data #bpymesh.transform(getFinalMatrix(node)) - bpyob.matrix_world = getFinalMatrix(node, None, ancestry) + bpyob.matrix_world = getFinalMatrix(node, None, ancestry, global_matrix) def importLamp_PointLight(node, ancestry): @@ -2303,7 +2300,7 @@ def importLamp_SpotLight(node, ancestry): return bpylamp, mtx -def importLamp(node, spec, ancestry): +def importLamp(node, spec, ancestry, global_matrix): if spec == 'PointLight': bpylamp, mtx = importLamp_PointLight(node, ancestry) elif spec == 'DirectionalLight': @@ -2317,10 +2314,10 @@ def importLamp(node, spec, ancestry): bpyob = node.blendObject = bpy.data.objects.new("TODO", bpylamp) bpy.context.scene.objects.link(bpyob) - bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry) + bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry. global_matrix) -def importViewpoint(node, ancestry): +def importViewpoint(node, ancestry, global_matrix): name = node.getDefName() if not name: name = 'Viewpoint' @@ -2339,10 +2336,10 @@ def importViewpoint(node, ancestry): bpyob = node.blendObject = bpy.data.objects.new("TODO", bpycam) bpy.context.scene.objects.link(bpyob) - bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry) + bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry, global_matrix) -def importTransform(node, ancestry): +def importTransform(node, ancestry, global_matrix): name = node.getDefName() if not name: name = 'Transform' @@ -2350,7 +2347,7 @@ def importTransform(node, ancestry): bpyob = node.blendObject = bpy.data.objects.new(name, None) bpy.context.scene.objects.link(bpyob) - bpyob.matrix_world = getFinalMatrix(node, None, ancestry) + bpyob.matrix_world = getFinalMatrix(node, None, ancestry, global_matrix) # so they are not too annoying bpyob.empty_draw_type = 'PLAIN_AXES' @@ -2516,7 +2513,7 @@ ROUTE champFly001.bindTime TO vpTs.set_startTime set_data_from_node = defDict[from_id] translatePositionInterpolator(set_data_from_node, action, ancestry) - if to_type in ('set_orientation', 'rotation'): + if to_type in {'set_orientation', 'rotation'}: action = getIpo(to_id) set_data_from_node = defDict[from_id] translateOrientationInterpolator(set_data_from_node, action, ancestry) @@ -2532,7 +2529,12 @@ ROUTE champFly001.bindTime TO vpTs.set_startTime translateTimeSensor(time_node, action, ancestry) -def load_web3d(path, PREF_FLAT=False, PREF_CIRCLE_DIV=16, HELPER_FUNC=None): +def load_web3d(path, + PREF_FLAT=False, + PREF_CIRCLE_DIV=16, + global_matrix=None, + HELPER_FUNC=None, + ): # Used when adding blender primitives GLOBALS['CIRCLE_DETAIL'] = PREF_CIRCLE_DIV @@ -2547,6 +2549,9 @@ def load_web3d(path, PREF_FLAT=False, PREF_CIRCLE_DIV=16, HELPER_FUNC=None): print(msg) return + if global_matrix is None: + global_matrix = Matrix() + # fill with tuples - (node, [parents-parent, parent]) all_nodes = root_node.getSerialized([], []) @@ -2566,15 +2571,15 @@ def load_web3d(path, PREF_FLAT=False, PREF_CIRCLE_DIV=16, HELPER_FUNC=None): # by an external script. - gets first pick pass if spec == 'Shape': - importShape(node, ancestry) - elif spec in ('PointLight', 'DirectionalLight', 'SpotLight'): - importLamp(node, spec, ancestry) + importShape(node, ancestry, global_matrix) + elif spec in {'PointLight', 'DirectionalLight', 'SpotLight'}: + importLamp(node, spec, ancestry, global_matrix) elif spec == 'Viewpoint': - importViewpoint(node, ancestry) + importViewpoint(node, ancestry, global_matrix) elif spec == 'Transform': # Only use transform nodes when we are not importing a flat object hierarchy if PREF_FLAT == False: - importTransform(node, ancestry) + importTransform(node, ancestry, global_matrix) ''' # These are delt with later within importRoute elif spec=='PositionInterpolator': @@ -2641,11 +2646,12 @@ def load_web3d(path, PREF_FLAT=False, PREF_CIRCLE_DIV=16, HELPER_FUNC=None): del child_dict -def load(operator, context, filepath=""): +def load(operator, context, filepath="", global_matrix=None): load_web3d(filepath, PREF_FLAT=True, PREF_CIRCLE_DIV=16, + global_matrix=global_matrix, ) return {'FINISHED'} -- cgit v1.2.3