Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-02-08 02:45:51 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-02-08 02:45:51 +0300
commit17696ce3b8b7ea77bed96ec78cc08d37536f4ccd (patch)
tree5223d2b1cdcbe93a8e241f76847b45bc56998279 /io_scene_3ds
parent79f0394d647c0d6d107d3038548c7ecebc339559 (diff)
bugfix [#25382] Loading 3ds file messed up when the file has hierachy
from Dominique Lorre with own modifications.
Diffstat (limited to 'io_scene_3ds')
-rw-r--r--io_scene_3ds/import_3ds.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/io_scene_3ds/import_3ds.py b/io_scene_3ds/import_3ds.py
index 7a418787..e3b2eb74 100644
--- a/io_scene_3ds/import_3ds.py
+++ b/io_scene_3ds/import_3ds.py
@@ -124,7 +124,7 @@ ED_KEY_OBJECT_NODE = 0xB002
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,8 +143,9 @@ ROOT_OBJECT = 0xFFFF
global scn
scn = None
-global object_dictionary # dictionary for object hierarchy
-object_dictionary = {}
+
+object_dictionary = {}
+object_matrix = {}
#the chunk class
@@ -265,6 +266,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
# 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 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
if contextMatrix_rot:
ob.matrix_local = contextMatrix_rot
+ object_matrix[ob] = contextMatrix_rot.copy()
importedObjects.append(ob)
bmesh.update_tag()
@@ -648,12 +651,20 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
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
@@ -740,6 +751,14 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
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 @@ def load_3ds(filepath, context, IMPORT_CONSTRAIN_BOUNDS=10.0, IMAGE_SEARCH=True,
# fixme, make unglobal, clear incase
object_dictionary.clear()
+ object_matrix.clear()
scn = context.scene
# scn = bpy.data.scenes.active
@@ -812,6 +832,7 @@ def load_3ds(filepath, context, IMPORT_CONSTRAIN_BOUNDS=10.0, IMAGE_SEARCH=True,
# fixme, make unglobal
object_dictionary.clear()
+ object_matrix.clear()
# Link the objects into this scene.
# Layers = scn.Layers