[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1554] trunk/py/scripts/addons/ io_scene_3ds/import_3ds.py: bugfix [#25382] Loading 3ds file messed up when the file has hierachy
Campbell Barton
ideasman42 at gmail.com
Tue Feb 8 00:45:52 CET 2011
Revision: 1554
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1554
Author: campbellbarton
Date: 2011-02-07 23:45:51 +0000 (Mon, 07 Feb 2011)
Log Message:
-----------
bugfix [#25382] Loading 3ds file messed up when the file has hierachy
from Dominique Lorre with own modifications.
Modified Paths:
--------------
trunk/py/scripts/addons/io_scene_3ds/import_3ds.py
Modified: trunk/py/scripts/addons/io_scene_3ds/import_3ds.py
===================================================================
--- trunk/py/scripts/addons/io_scene_3ds/import_3ds.py 2011-02-07 13:37:16 UTC (rev 1553)
+++ trunk/py/scripts/addons/io_scene_3ds/import_3ds.py 2011-02-07 23:45:51 UTC (rev 1554)
@@ -124,7 +124,7 @@
EK_OB_NODE_HEADER = 0xB010
EK_OB_INSTANCE_NAME = 0xB011
# EK_OB_PRESCALE = 0xB012
-# EK_OB_PIVOT = 0xB013
+EK_OB_PIVOT = 0xB013
# EK_OB_BOUNDBOX = 0xB014
# EK_OB_MORPH_SMOOTH = 0xB015
EK_OB_POSITION_TRACK = 0xB020
@@ -143,10 +143,11 @@
global scn
scn = None
-global object_dictionary # dictionary for object hierarchy
-object_dictionary = {}
+object_dictionary = {}
+object_matrix = {}
+
#the chunk class
class chunk:
ID = 0
@@ -265,6 +266,7 @@
# only init once
object_list = [] # for hierarchy
object_parent = [] # index of parent in hierarchy, 0xFFFF = no parent
+ pivot_list = [] # pivots with hierarchy handling
def putContextMesh(myContextMesh_vertls, myContextMesh_facels, myContextMeshMaterials):
bmesh = bpy.data.meshes.new(contextObName)
@@ -333,6 +335,7 @@
if contextMatrix_rot:
ob.matrix_local = contextMatrix_rot
+ object_matrix[ob] = contextMatrix_rot.copy()
importedObjects.append(ob)
bmesh.update_tag()
@@ -648,13 +651,21 @@
object_list.append(child)
object_parent.append(hierarchy)
+ pivot_list.append(mathutils.Vector((0.0, 0.0, 0.0)))
elif new_chunk.ID == EK_OB_INSTANCE_NAME:
object_name, read_str_len = read_string(file)
child.name = object_name
object_dictionary[object_name] = child
new_chunk.bytes_read += read_str_len
+ # print("new instance object:", object_name)
+ elif new_chunk.ID == EK_OB_PIVOT: # translation
+ temp_data = file.read(STRUCT_SIZE_3FLOAT)
+ pivot = struct.unpack('<3f', temp_data)
+ new_chunk.bytes_read += STRUCT_SIZE_3FLOAT
+ pivot_list[len(pivot_list)-1] = mathutils.Vector(pivot)
+
elif new_chunk.ID == EK_OB_POSITION_TRACK: # translation
new_chunk.bytes_read += STRUCT_SIZE_UNSIGNED_SHORT * 5
temp_data = file.read(STRUCT_SIZE_UNSIGNED_SHORT * 5)
@@ -740,6 +751,14 @@
ob.parent = None
else:
ob.parent = object_list[parent]
+ # pivot_list[ind] += pivot_list[parent] # XXX, not sure this is correct, should parent space matrix be applied before combining?
+ # fix pivots
+ for ind, ob in enumerate(object_list):
+ if ob.type == 'MESH':
+ pivot = pivot_list[ind]
+ pivot_matrix = object_matrix.get(ob, mathutils.Matrix()) # unlikely to fail
+ pivot_matrix = mathutils.Matrix.Translation(-pivot * pivot_matrix.to_3x3())
+ ob.data.transform(pivot_matrix)
def load_3ds(filepath, context, IMPORT_CONSTRAIN_BOUNDS=10.0, IMAGE_SEARCH=True, APPLY_MATRIX=True):
@@ -800,6 +819,7 @@
# fixme, make unglobal, clear incase
object_dictionary.clear()
+ object_matrix.clear()
scn = context.scene
# scn = bpy.data.scenes.active
@@ -812,6 +832,7 @@
# fixme, make unglobal
object_dictionary.clear()
+ object_matrix.clear()
# Link the objects into this scene.
# Layers = scn.Layers
More information about the Bf-extensions-cvs
mailing list