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 28 additions and 18 deletions

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

@ -302,6 +302,20 @@ def add_texture_to_material(image, contextWrapper, pct, extend, alpha, scale, of
elif extend == 'noWrap': elif extend == 'noWrap':
img_wrap.extension = 'CLIP' img_wrap.extension = 'CLIP'
if alpha == 'alpha': if alpha == 'alpha':
for link in links:
if link.from_node.type == 'TEX_IMAGE' and link.to_node.type == 'MIX_RGB':
tex = link.from_node.image.name
own_node = img_wrap.node_image
own_map = img_wrap.node_mapping
if tex == image.name:
links.new(link.from_node.outputs['Alpha'], img_wrap.socket_dst)
nodes.remove(own_map)
nodes.remove(own_node)
for imgs in bpy.data.images:
if imgs.name[-3:].isdigit():
if not imgs.users:
bpy.data.images.remove(imgs)
else:
links.new(img_wrap.node_image.outputs['Alpha'], img_wrap.socket_dst) links.new(img_wrap.node_image.outputs['Alpha'], img_wrap.socket_dst)
shader.location = (300, 300) shader.location = (300, 300)
@ -323,7 +337,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 +393,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[:]