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