Import_3ds: Added world matrix transform #104532

Merged
Sebastian Sille merged 1 commits from nrgsille-io_scene_3ds into main 2023-04-08 12:32:50 +02:00

View File

@ -308,7 +308,7 @@ def add_texture_to_material(image, contextWrapper, pct, extend, alpha, scale, of
contextWrapper._grid_to_location(1, 0, dst_node=contextWrapper.node_out, ref_node=shader) contextWrapper._grid_to_location(1, 0, dst_node=contextWrapper.node_out, ref_node=shader)
def process_next_chunk(context, file, previous_chunk, imported_objects, IMAGE_SEARCH, KEYFRAME): def process_next_chunk(context, file, previous_chunk, imported_objects, IMAGE_SEARCH, WORLD_MATRIX, KEYFRAME):
from bpy_extras.image_utils import load_image from bpy_extras.image_utils import load_image
contextObName = None contextObName = None
@ -348,6 +348,7 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, IMAGE_SE
myContextMesh_flag, myContextMesh_flag,
myContextMeshMaterials, myContextMeshMaterials,
myContextMesh_smooth, myContextMesh_smooth,
WORLD_MATRIX,
): ):
bmesh = bpy.data.meshes.new(contextObName) bmesh = bpy.data.meshes.new(contextObName)
@ -447,6 +448,9 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, IMAGE_SE
bmesh.polygons[f].use_smooth = True bmesh.polygons[f].use_smooth = True
if contextMatrix: if contextMatrix:
if WORLD_MATRIX:
ob.matrix_world = contextMatrix
else:
ob.matrix_local = contextMatrix ob.matrix_local = contextMatrix
object_matrix[ob] = contextMatrix.copy() object_matrix[ob] = contextMatrix.copy()
@ -627,7 +631,7 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, IMAGE_SE
# is it an object info chunk? # is it an object info chunk?
elif new_chunk.ID == OBJECTINFO: elif new_chunk.ID == OBJECTINFO:
process_next_chunk(context, file, new_chunk, imported_objects, IMAGE_SEARCH, KEYFRAME) process_next_chunk(context, file, new_chunk, imported_objects, IMAGE_SEARCH, WORLD_MATRIX, KEYFRAME)
# keep track of how much we read in the main chunk # keep track of how much we read in the main chunk
new_chunk.bytes_read += temp_chunk.bytes_read new_chunk.bytes_read += temp_chunk.bytes_read
@ -643,6 +647,7 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, IMAGE_SE
contextMesh_flag, contextMesh_flag,
contextMeshMaterials, contextMeshMaterials,
contextMesh_smooth, contextMesh_smooth,
WORLD_MATRIX
) )
contextMesh_vertls = [] contextMesh_vertls = []
contextMesh_facels = [] contextMesh_facels = []
@ -1079,6 +1084,7 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, IMAGE_SE
contextMesh_flag, contextMesh_flag,
contextMeshMaterials, contextMeshMaterials,
contextMesh_smooth, contextMesh_smooth,
WORLD_MATRIX
) )
# Assign parents to objects # Assign parents to objects
@ -1110,6 +1116,7 @@ def load_3ds(filepath,
context, context,
IMPORT_CONSTRAIN_BOUNDS=10.0, IMPORT_CONSTRAIN_BOUNDS=10.0,
IMAGE_SEARCH=True, IMAGE_SEARCH=True,
WORLD_MATRIX=False,
KEYFRAME=True, KEYFRAME=True,
APPLY_MATRIX=True, APPLY_MATRIX=True,
global_matrix=None): global_matrix=None):
@ -1152,7 +1159,7 @@ def load_3ds(filepath,
scn = context.scene scn = context.scene
imported_objects = [] # Fill this list with objects imported_objects = [] # Fill this list with objects
process_next_chunk(context, file, current_chunk, imported_objects, IMAGE_SEARCH, KEYFRAME) process_next_chunk(context, file, current_chunk, imported_objects, IMAGE_SEARCH, WORLD_MATRIX, KEYFRAME)
# fixme, make unglobal # fixme, make unglobal
object_dictionary.clear() object_dictionary.clear()
@ -1244,6 +1251,7 @@ def load(operator,
filepath="", filepath="",
constrain_size=0.0, constrain_size=0.0,
use_image_search=True, use_image_search=True,
use_world_matrix=False,
read_keyframe=True, read_keyframe=True,
use_apply_transform=True, use_apply_transform=True,
global_matrix=None, global_matrix=None,
@ -1253,6 +1261,7 @@ def load(operator,
context, context,
IMPORT_CONSTRAIN_BOUNDS=constrain_size, IMPORT_CONSTRAIN_BOUNDS=constrain_size,
IMAGE_SEARCH=use_image_search, IMAGE_SEARCH=use_image_search,
WORLD_MATRIX=use_world_matrix,
KEYFRAME=read_keyframe, KEYFRAME=read_keyframe,
APPLY_MATRIX=use_apply_transform, APPLY_MATRIX=use_apply_transform,
global_matrix=global_matrix, global_matrix=global_matrix,