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 9fa89fd6d7 - Show all commits

View File

@ -37,6 +37,11 @@ PCT_FLOAT = 0x0031 # percentage float
MASTERSCALE = 0x0100 # Master scale factor MASTERSCALE = 0x0100 # Master scale factor
# >----- sub defines of OBJECTINFO # >----- sub defines of OBJECTINFO
USE_BITMAP = 0x1101 # The background image flag
SOLIDBACKGND = 0x1200 # The background color (RGB)
USE_SOLIDBGND = 0x1201 # The background color flag
VGRADIENT = 0x1300 # The background gradient colors
USE_VGRADIENT = 0x1301 # The background gradient flag
AMBIENTLIGHT = 0x2100 # The color of the ambient light AMBIENTLIGHT = 0x2100 # The color of the ambient light
MATERIAL = 0xAFFF # This stored the texture info MATERIAL = 0xAFFF # This stored the texture info
OBJECT = 0x4000 # This stores the faces, vertices, etc... OBJECT = 0x4000 # This stores the faces, vertices, etc...
@ -363,24 +368,24 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
pivot_list = [] # pivots with hierarchy handling pivot_list = [] # pivots with hierarchy handling
trackposition = {} # keep track to position for target calculation trackposition = {} # keep track to position for target calculation
def putContextMesh(context, myContextMesh_vertls, myContextMesh_facels, myContextMesh_flag, def putContextMesh(context, ContextMesh_vertls, ContextMesh_facels, ContextMesh_flag,
myContextMeshMaterials, myContextMesh_smooth, WORLD_MATRIX): ContextMeshMaterials, ContextMesh_smooth, WORLD_MATRIX):
bmesh = bpy.data.meshes.new(contextObName) bmesh = bpy.data.meshes.new(contextObName)
if myContextMesh_facels is None: if ContextMesh_facels is None:
myContextMesh_facels = [] ContextMesh_facels = []
if myContextMesh_vertls: if ContextMesh_vertls:
bmesh.vertices.add(len(myContextMesh_vertls) // 3) bmesh.vertices.add(len(ContextMesh_vertls) // 3)
bmesh.vertices.foreach_set("co", myContextMesh_vertls) bmesh.vertices.foreach_set("co", ContextMesh_vertls)
nbr_faces = len(myContextMesh_facels) nbr_faces = len(ContextMesh_facels)
bmesh.polygons.add(nbr_faces) bmesh.polygons.add(nbr_faces)
bmesh.loops.add(nbr_faces * 3) bmesh.loops.add(nbr_faces * 3)
eekadoodle_faces = [] eekadoodle_faces = []
for v1, v2, v3 in myContextMesh_facels: for v1, v2, v3 in ContextMesh_facels:
eekadoodle_faces.extend((v3, v1, v2) if v3 == 0 else (v1, v2, v3)) eekadoodle_faces.extend((v3, v1, v2) if v3 == 0 else (v1, v2, v3))
bmesh.polygons.foreach_set("loop_start", range(0, nbr_faces * 3, 3)) bmesh.polygons.foreach_set("loop_start", range(0, nbr_faces * 3, 3))
bmesh.loops.foreach_set("vertex_index", eekadoodle_faces) bmesh.loops.foreach_set("vertex_index", eekadoodle_faces)
@ -391,7 +396,7 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
else: else:
uv_faces = None uv_faces = None
for mat_idx, (matName, faces) in enumerate(myContextMeshMaterials): for mat_idx, (matName, faces) in enumerate(ContextMeshMaterials):
if matName is None: if matName is None:
bmat = None bmat = None
else: else:
@ -405,7 +410,7 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
if uv_faces: if uv_faces:
uvl = bmesh.uv_layers.active.data[:] uvl = bmesh.uv_layers.active.data[:]
for fidx, pl in enumerate(bmesh.polygons): for fidx, pl in enumerate(bmesh.polygons):
face = myContextMesh_facels[fidx] face = ContextMesh_facels[fidx]
v1, v2, v3 = face v1, v2, v3 = face
# eekadoodle # eekadoodle
@ -425,12 +430,12 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
context.view_layer.active_layer_collection.collection.objects.link(ob) context.view_layer.active_layer_collection.collection.objects.link(ob)
imported_objects.append(ob) imported_objects.append(ob)
if myContextMesh_flag: if ContextMesh_flag:
"""Bit 0 (0x1) sets edge CA visible, Bit 1 (0x2) sets edge BC visible and """Bit 0 (0x1) sets edge CA visible, Bit 1 (0x2) sets edge BC visible and
Bit 2 (0x4) sets edge AB visible. In Blender we use sharp edges for those flags.""" Bit 2 (0x4) sets edge AB visible. In Blender we use sharp edges for those flags."""
for f, pl in enumerate(bmesh.polygons): for f, pl in enumerate(bmesh.polygons):
face = myContextMesh_facels[f] face = ContextMesh_facels[f]
faceflag = myContextMesh_flag[f] faceflag = ContextMesh_flag[f]
edge_ab = bmesh.edges[bmesh.loops[pl.loop_start].edge_index] edge_ab = bmesh.edges[bmesh.loops[pl.loop_start].edge_index]
edge_bc = bmesh.edges[bmesh.loops[pl.loop_start + 1].edge_index] edge_bc = bmesh.edges[bmesh.loops[pl.loop_start + 1].edge_index]
edge_ca = bmesh.edges[bmesh.loops[pl.loop_start + 2].edge_index] edge_ca = bmesh.edges[bmesh.loops[pl.loop_start + 2].edge_index]
@ -443,9 +448,9 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
if faceflag & 0x4: if faceflag & 0x4:
edge_ab.use_edge_sharp = True edge_ab.use_edge_sharp = True
if myContextMesh_smooth: if ContextMesh_smooth:
for f, pl in enumerate(bmesh.polygons): for f, pl in enumerate(bmesh.polygons):
smoothface = myContextMesh_smooth[f] smoothface = ContextMesh_smooth[f]
if smoothface > 0: if smoothface > 0:
bmesh.polygons[f].use_smooth = True bmesh.polygons[f].use_smooth = True
else: else:
@ -507,7 +512,7 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
tintcolor = None tintcolor = None
extend = 'wrap' extend = 'wrap'
alpha = False alpha = False
pct = 50 pct = 70
contextWrapper.base_color = contextColor[:] contextWrapper.base_color = contextColor[:]
contextWrapper.metallic = contextMaterial.metallic contextWrapper.metallic = contextMaterial.metallic
@ -601,8 +606,7 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
parent_list[child_id] = childs_list[parent_id] parent_list[child_id] = childs_list[parent_id]
def calc_target(loca, target): def calc_target(loca, target):
pan = 0.0 pan = tilt = 0.0
tilt = 0.0
plane = loca + target plane = loca + target
angle = math.radians(90) # Target triangulation angle = math.radians(90) # Target triangulation
check_sign = abs(loca.y) < abs(target.y) check_sign = abs(loca.y) < abs(target.y)