New Addon: Import Autodesk .max #105013

Closed
Sebastian Sille wants to merge 136 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 42345234c6 - Show all commits

View File

@ -223,7 +223,8 @@ SKIPPABLE = {
def get_valid_name(name): def get_valid_name(name):
if (INVALID_NAME.match(name)): return "_%s"%(name.encode('utf8')) if (INVALID_NAME.match(name)):
return "_%s"%(name.encode('utf8'))
return "%s"%(name.encode('utf8')) return "%s"%(name.encode('utf8'))
def i8(data): def i8(data):
@ -774,8 +775,8 @@ class MaxChunk():
def __str__(self): def __str__(self):
if (self.unknown == True): if (self.unknown == True):
return "%s[%4x] %04X: %s" %("" * self.level, self.number, self.types, ":".join("%02x"%(c) for c in self.data)) return "%s[%4x] %04X: %s" %(""*self.level, self.number, self.types, ":".join("%02x"%(c) for c in self.data))
return "%s[%4x] %04X: %s=%s" %("" * self.level, self.number, self.types, self.format, self.data) return "%s[%4x] %04X: %s=%s" %(""*self.level, self.number, self.types, self.format, self.data)
class ByteArrayChunk(MaxChunk): class ByteArrayChunk(MaxChunk):
@ -840,7 +841,7 @@ class ClassIDChunk(ByteArrayChunk):
self.set(data, "struct", '<IQI', 0, 16) # DllIndex, ID, SuperID self.set(data, "struct", '<IQI', 0, 16) # DllIndex, ID, SuperID
else: else:
self.unknown = False self.unknown = False
self.data = ":".join("%02x"%(c) for c in data) self.data = ":".join("%02x"%(c) for c in data)
class DirectoryChunk(ByteArrayChunk): class DirectoryChunk(ByteArrayChunk):
@ -863,8 +864,8 @@ class ContainerChunk(MaxChunk):
def __str__(self): def __str__(self):
if (self.unknown == True): if (self.unknown == True):
return "%s[%4x] %04X" %("" * self.level, self.number, self.types) return "%s[%4x] %04X" %(""*self.level, self.number, self.types)
return "%s[%4x] %04X: %s" %("" * self.level, self.number, self.types, self.format) return "%s[%4x] %04X: %s" %(""*self.level, self.number, self.types, self.format)
def get_first(self, types): def get_first(self, types):
for child in self.children: for child in self.children:
@ -888,8 +889,8 @@ class SceneChunk(ContainerChunk):
def __str__(self): def __str__(self):
if (self.unknown == True): if (self.unknown == True):
return "%s[%4x] %s" %("" * self.level, self.number, get_class_name(self)) return "%s[%4x] %s" %(""*self.level, self.number, get_class_name(self))
return "%s[%4x] %s: %s" %("" * self.level, self.number, get_class_name(self), self.format) return "%s[%4x] %s: %s" %(""*self.level, self.number, get_class_name(self), self.format)
def set_data(self, data): def set_data(self, data):
previous = None previous = None
@ -914,7 +915,7 @@ class ChunkReader():
short, ofst = get_long(data, ofst) short, ofst = get_long(data, ofst)
if (short == 0xB000000): if (short == 0xB000000):
data = zlib.decompress(data, zlib.MAX_WBITS|32) data = zlib.decompress(data, zlib.MAX_WBITS|32)
print(" reading '%s'..."%self.name, len(data)) print(" reading '%s'..." %self.name, len(data))
while offset < len(data): while offset < len(data):
old = offset old = offset
offset, chunk = self.get_next_chunk(data, offset, level, len(chunks), containerReader, primitiveReader) offset, chunk = self.get_next_chunk(data, offset, level, len(chunks), containerReader, primitiveReader)
@ -1047,7 +1048,6 @@ def get_reference(chunk):
references = {} references = {}
refs = chunk.get_first(0x2035) refs = chunk.get_first(0x2035)
if (refs): if (refs):
types = refs.data[0]
offset = 1 offset = 1
while offset < len(refs.data): while offset < len(refs.data):
key = refs.data[offset] key = refs.data[offset]
@ -1466,7 +1466,6 @@ def get_poly_data(chunk):
def create_editable_poly(context, node, msh, mat, mtx, umt, uvm): def create_editable_poly(context, node, msh, mat, mtx, umt, uvm):
coords = point4i = point6i = pointNi = None coords = point4i = point6i = pointNi = None
name = node.get_first(TYP_NAME).data
poly = msh.get_first(0x08FE) poly = msh.get_first(0x08FE)
created = False created = False
lidx = [] lidx = []
@ -1508,7 +1507,6 @@ def create_editable_poly(context, node, msh, mat, mtx, umt, uvm):
def create_editable_mesh(context, node, msh, mat, mtx, umt): def create_editable_mesh(context, node, msh, mat, mtx, umt):
name = node.get_first(TYP_NAME).data
poly = msh.get_first(0x08FE) poly = msh.get_first(0x08FE)
created = False created = False
if (poly): if (poly):
@ -1520,11 +1518,13 @@ def create_editable_mesh(context, node, msh, mat, mtx, umt):
return created return created
def create_shell(context, node, shell, mat, mtx, umt): def create_shell(context, node, shell, mat, mtx, umt, uvm):
name = node.get_first(TYP_NAME).data
refs = get_references(shell) refs = get_references(shell)
msh = refs[-1] msh = refs[-1]
created = create_editable_mesh(context, node, msh, mat, mtx, umt) if (get_class_name(msh) == "'Editable Poly'"):
created = create_editable_poly(context, node, msh, mat, mtx, umt, uvm)
else:
created = create_editable_mesh(context, node, msh, mat, mtx, umt)
return created return created
@ -1543,7 +1543,7 @@ def create_mesh(context, node, msh, mtx, mat, umt, uvm):
elif (uid == 0x192F60981BF8338D): elif (uid == 0x192F60981BF8338D):
created = create_editable_poly(context, node, msh, mat, mtx, umt, uvm) created = create_editable_poly(context, node, msh, mat, mtx, umt, uvm)
elif (uid in {0x2032, 0x2033}): elif (uid in {0x2032, 0x2033}):
created = create_shell(context, node, msh, mat, mtx, umt) created = create_shell(context, node, msh, mat, mtx, umt, uvm)
else: else:
skip = SKIPPABLE.get(uid) skip = SKIPPABLE.get(uid)
if (skip is not None): if (skip is not None):
@ -1604,7 +1604,7 @@ def load(operator, context, filepath="", scale_objects=1.0, use_material=True,
use_uv_mesh=False, use_apply_matrix=False, global_matrix=None): use_uv_mesh=False, use_apply_matrix=False, global_matrix=None):
mscale = mathutils.Matrix.Scale(scale_objects, 4) mscale = mathutils.Matrix.Scale(scale_objects, 4)
if global_matrix is not None: if global_matrix is not None:
mscale = global_matrix @ mscale mscale = global_matrix @ mscale
read(context, filepath, mscale, usemat=use_material, uvmesh=use_uv_mesh, transform=use_apply_matrix) read(context, filepath, mscale, usemat=use_material, uvmesh=use_uv_mesh, transform=use_apply_matrix)
return {'FINISHED'} return {'FINISHED'}