From 2598efecaeddbb0f1e6f810458473ec63524cd0c Mon Sep 17 00:00:00 2001 From: Sebastian Sille Date: Thu, 16 Nov 2023 00:52:11 +0100 Subject: [PATCH 1/2] New addon: Import Autodesk .max A new addon for importing meshes and materials from Autodesk .max files --- io_import_max.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/io_import_max.py b/io_import_max.py index 9734d48..6241949 100644 --- a/io_import_max.py +++ b/io_import_max.py @@ -1243,14 +1243,21 @@ def create_shape(context, pts, indices, node, key, prc, mat): mtx = create_matrix(prc) data = [] if (pts): - shape.vertices.add(len(pts) // 3) - shape.vertices.foreach_set("co", pts) + loopstart = [] + looplines = loop = 0 nbr_faces = len(indices) + for fid in range(nbr_faces): + polyface = indices[fid] + looplines += len(polyface) + shape.vertices.add(len(pts) // 3) + shape.loops.add(looplines) shape.polygons.add(nbr_faces) - shape.loops.add(nbr_faces * 3) + shape.vertices.foreach_set("co", pts) for vtx in indices: + loopstart.append(loop) data.extend(vtx) - shape.polygons.foreach_set("loop_start", range(0, nbr_faces * 3, 3)) + loop += len(vtx) + shape.polygons.foreach_set("loop_start", loopstart) shape.loops.foreach_set("vertex_index", data) if (len(data) > 0): @@ -1375,9 +1382,6 @@ def create_editable_poly(context, node, msh, mat, mtx): coords = point3i = point4i = point6i = pointNi = None name = node.get_first(TYP_NAME).data poly = msh.get_first(0x08FE) - indexList = [] - coordListI = [] - indicesList = [] created = False if (poly): for child in poly.children: -- 2.30.2 From 5158f504070b9fa1a1ee5f171ab672ffacfb6b25 Mon Sep 17 00:00:00 2001 From: Sebastian Sille Date: Thu, 16 Nov 2023 23:56:14 +0100 Subject: [PATCH 2/2] Import_max: Removed unused definitions Removed unused definitions --- io_import_max.py | 52 +++++++++++------------------------------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/io_import_max.py b/io_import_max.py index 6241949..3952e87 100644 --- a/io_import_max.py +++ b/io_import_max.py @@ -278,7 +278,7 @@ class MaxFileDirEntry: self.sizeHigh ) = struct.unpack(MaxFileDirEntry.STRUCT_DIRENTRY, entry) - if self.namelength>64: + if self.namelength > 64: self.namelength = 64 self.name_utf16 = self.name_raw[:(self.namelength - 2)] self.name = maxfile._decode_utf16_str(self.name_utf16) @@ -1324,23 +1324,6 @@ def get_poly_6p(data): return polylist -def get_poly_ngon(polys): - vertex = [] - offset = 0 - while (offset < len(polys)): - num = polys[offset] - offset += 1 - ngon = [] - keys = 0 - while (keys < num): - pt = points[polys[offset]][1] - ngon.append(pt) - offset += 1 - keys += 1 - vertex.extend(ngon) - return vertex - - def get_poly_data(chunk): offset = 0 polylist = [] @@ -1352,6 +1335,17 @@ def get_poly_data(chunk): return polylist +def get_point_array(values): + verts = [] + if len(values) >= 4: + count, offset = get_long(values, 0) + while (count > 0): + floats, offset = get_floats(values, offset, 3) + verts.extend(floats) + count -= 1 + return verts + + def calc_point_3d(chunk): data = chunk.data count, offset = get_long(data, 0) @@ -1391,8 +1385,6 @@ def create_editable_poly(context, node, msh, mat, mtx): point6i = child.data elif (child.types == 0x011A): point4i = calc_point_3d(child) - elif (child.types == 0x0310): - pointNi = child.data if (point4i is not None): vertex = get_poly_4p(point4i) if (len(vertex) > 0): @@ -1403,23 +1395,9 @@ def create_editable_poly(context, node, msh, mat, mtx): elif (point6i is not None): ngons = get_poly_6p(point6i) created = create_shape(context, coords, ngons, node, None, mtx, mat) - elif (pointNi is not None): - ngons = get_poly_ngon(pointNi) - created = create_shape(context, coords, ngons, node, None, mtx, mat) return created -def get_point_array(values): - verts = [] - if len(values) >= 4: - count, offset = get_long(values, 0) - while (count > 0): - floats, offset = get_floats(values, offset, 3) - verts.extend(floats) - count -= 1 - return verts - - def create_editable_mesh(context, node, msh, mat, mtx): name = node.get_first(TYP_NAME).data poly = msh.get_first(0x08FE) @@ -1466,12 +1444,6 @@ def create_shell(context, node, shell, mat, mtx): return created -def create_boolean(context, node, pro, mat, mtx): - name = node.get_first(TYP_NAME).data - pBlocks = get_references(pro) - return True - - def create_skipable(context, node, msh, mat, mtx, skip): name = node.get_first(TYP_NAME).data print(" skipping %s '%s'... " %(skip, name)) -- 2.30.2