3
11

New Addon: Import Autodesk .max #22

Closed
Sebastian Sille wants to merge 38 commits from (deleted):nrgsille-import_max into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Showing only changes of commit b9ce4686a8 - Show all commits

View File

@ -246,6 +246,11 @@ def _clsid(clsid):
((i32(clsid, 0), i16(clsid, 4), i16(clsid, 6)) + ((i32(clsid, 0), i16(clsid, 4), i16(clsid, 6)) +
tuple(map(i8, clsid[8:16])))) tuple(map(i8, clsid[8:16]))))
###############
# DATA IMPORT #
###############
def is_maxfile (filename): def is_maxfile (filename):
"""Test if file is a MAX OLE2 container.""" """Test if file is a MAX OLE2 container."""
if hasattr(filename, 'read'): if hasattr(filename, 'read'):
@ -392,7 +397,7 @@ class MaxFileDirEntry:
class ImportMaxFile: class ImportMaxFile:
"""Representing an interface for importing .max files.""" """Representing an interface for importing .max files."""
def __init__(self, filename=None, write_mode=False, debug=False): def __init__(self, filename=None, write_mode=False):
self.write_mode = write_mode self.write_mode = write_mode
self._filesize = None self._filesize = None
self.byte_order = None self.byte_order = None
@ -717,6 +722,10 @@ class ImportMaxFile:
return data return data
###################
# DATA PROCESSING #
###################
class MaxChunk(): class MaxChunk():
"""Representing a chunk of a .max file.""" """Representing a chunk of a .max file."""
def __init__(self, types, size, level, number): def __init__(self, types, size, level, number):
@ -1169,19 +1178,19 @@ def create_matrix(prc):
def get_matrix_mesh_material(node): def get_matrix_mesh_material(node):
refs = get_reference(node) refs = get_reference(node)
if (refs): if (refs):
mtx = refs.get(0, None) prs = refs.get(0, None)
msh = refs.get(1, None) msh = refs.get(1, None)
mat = refs.get(3, None) mat = refs.get(3, None)
lyr = refs.get(6, None) lyr = refs.get(6, None)
else: else:
refs = get_references(node) refs = get_references(node)
mtx = refs[0] prs = refs[0]
msh = refs[1] msh = refs[1]
mat = refs[3] mat = refs[3]
lyr = None lyr = None
if (len(refs) > 6): if (len(refs) > 6):
lyr = refs[6] lyr = refs[6]
return mtx, msh, mat, lyr return prs, msh, mat, lyr
def get_property(properties, idx): def get_property(properties, idx):
@ -1497,15 +1506,15 @@ def create_object(context, node, mscale, transform):
parent = get_node_parent(node) parent = get_node_parent(node)
node.parent = parent node.parent = parent
name = get_node_name(node) name = get_node_name(node)
mtx, msh, mat, lyr = get_matrix_mesh_material(node) prs, msh, mat, lyr = get_matrix_mesh_material(node)
while ((parent is not None) and (get_guid(parent) != 0x0002)): while ((parent is not None) and (get_guid(parent) != 0x0002)):
name = "%s/%s" %(get_node_name(parent), name) name = "%s/%s" %(get_node_name(parent), name)
parent_mtx = parent.matrix parent_mtx = parent.matrix
if (parent_mtx): if (parent_mtx):
mtx = mtx.dot(parent_mtx) prs = prs.dot(parent_mtx)
parent = get_node_parent(parent) parent = get_node_parent(parent)
if (transform): if (transform):
mtx = create_matrix(mtx) @ mscale mtx = create_matrix(prs) @ mscale
else: else:
mtx = mscale mtx = mscale
created, uid = create_mesh(context, node, msh, mtx, mat) created, uid = create_mesh(context, node, msh, mtx, mat)