3
11

io_scene_3ds: cleanup texture handling #10

Merged
Sebastian Sille merged 5 commits from :main into main 2023-02-28 18:43:57 +01:00
2 changed files with 13 additions and 17 deletions
Showing only changes of commit f09c84b4e4 - Show all commits

View File

@ -731,8 +731,8 @@ def make_material_chunk(material, image):
diffuse = [] diffuse = []
for link in wrap.material.node_tree.links: for link in wrap.material.node_tree.links:
if link.from_node.type == 'TEX_IMAGE' and link.to_node.type != 'BSDF_PRINCIPLED': if link.from_node.type == 'TEX_IMAGE' and link.to_node.type == 'MIX_RGB':
diffuse = [link.from_node.image] if not wrap.normalmap_texture else None diffuse = [link.from_node.image]
if diffuse: if diffuse:
if primary_tex == False: if primary_tex == False:

View File

@ -323,7 +323,7 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, IMAGE_SE
contextMesh_smooth = None contextMesh_smooth = None
contextMeshUV = None contextMeshUV = None
TEXTURE_DICT = {} #TEXTURE_DICT = {}
MATDICT = {} MATDICT = {}
# Localspace variable names, faster. # Localspace variable names, faster.
@ -379,23 +379,19 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, IMAGE_SE
else: else:
bmat = MATDICT.get(matName) bmat = MATDICT.get(matName)
# in rare cases no materials defined. # in rare cases no materials defined.
if bmat:
img = TEXTURE_DICT.get(bmat.name)
else:
print(" warning: material %r not defined!" % matName)
bmat = MATDICT[matName] = bpy.data.materials.new(matName)
img = None
bmesh.materials.append(bmat) # can be None bmesh.materials.append(bmat) # can be None
for fidx in faces:
bmesh.polygons[fidx].material_index = mat_idx
if uv_faces and img: # if uv_faces and img:
for fidx in faces: # for fidx in faces:
bmesh.polygons[fidx].material_index = mat_idx # bmesh.polygons[fidx].material_index = mat_idx
# TODO: How to restore this? # # TODO: How to restore this?
# uv_faces[fidx].image = img # # uv_faces[fidx].image = img
else: # else:
for fidx in faces: # for fidx in faces:
bmesh.polygons[fidx].material_index = mat_idx # bmesh.polygons[fidx].material_index = mat_idx
if uv_faces: if uv_faces:
uvl = bmesh.uv_layers.active.data[:] uvl = bmesh.uv_layers.active.data[:]