Import skingroups as separate materials with skins as textures

This commit is contained in:
khreathor 2019-01-08 03:55:13 +01:00 committed by Bill Currie
parent ae86790e6c
commit 66fe862a87

View file

@ -98,6 +98,16 @@ def load_skins(mdl):
else: else:
load_skin(skin, "%s_%d" % (mdl.name, i)) load_skin(skin, "%s_%d" % (mdl.name, i))
def setup_main_material(mdl):
mat = bpy.data.materials.new(mdl.name)
mat.blend_method = 'OPAQUE'
mat.diffuse_color = (1, 1, 1)
mat.metallic = 1
mat.roughness = 1
mat.specular_intensity = 0
mat.use_nodes = True
return mat
def setup_skins(mdl, uvs): def setup_skins(mdl, uvs):
load_skins(mdl) load_skins(mdl)
# img = mdl.images[0] # use the first skin for now # img = mdl.images[0] # use the first skin for now
@ -112,36 +122,40 @@ def setup_skins(mdl, uvs):
for j,k in enumerate(poly.loop_indices): for j,k in enumerate(poly.loop_indices):
uvloop.data[k].uv = mdl_uv[j] uvloop.data[k].uv = mdl_uv[j]
# Create main material #Load all skins
mat = bpy.data.materials.new(mdl.name) for i, skin in enumerate(mdl.skins):
mat.blend_method = 'OPAQUE' if skin.type:
mat.diffuse_color = (1,1,1) mat = setup_main_material(mdl)
mat.metallic = 1 emissionNode = mat.node_tree.nodes.new("ShaderNodeEmission")
mat.roughness = 1 shaderOut = mat.node_tree.nodes["Material Output"]
mat.specular_intensity = 0 mat.node_tree.nodes.remove(mat.node_tree.nodes["Principled BSDF"])
mat.use_nodes = True
# TODO: turn transform to True and position it properly in editor for j, subskin in enumerate(skin.skins):
emissionNode = mat.node_tree.nodes.new("ShaderNodeEmission") tex_node = mat.node_tree.nodes.new("ShaderNodeTexImage")
shaderOut = mat.node_tree.nodes["Material Output"] tex_node.image = mdl.images[i + j]
bdsf_node = mat.node_tree.nodes["Principled BSDF"] tex_node.interpolation = "Closest"
mat.node_tree.nodes.remove(bdsf_node) if j == 0:
# connect only first texture (we'll need something smarter in the future)
mat.node_tree.links.new(tex_node.outputs[0], emissionNode.inputs[0])
#Add skingroup mat.node_tree.links.new(emissionNode.outputs[0], shaderOut.inputs[0])
#bpy.ops.object.material_slot_add() mdl.mesh.materials.append(mat)
#bpy.ops.material.new()
else:
mat = setup_main_material(mdl)
# TODO: turn transform to True and position it properly in editor
emissionNode = mat.node_tree.nodes.new("ShaderNodeEmission")
shaderOut = mat.node_tree.nodes["Material Output"]
mat.node_tree.nodes.remove(mat.node_tree.nodes["Principled BSDF"])
tex_node = mat.node_tree.nodes.new("ShaderNodeTexImage")
tex_node.image = mdl.images[i]
tex_node.interpolation = "Closest"
#Add all existing textures to shader node
for i in range(len(mdl.images)):
tex_node = mat.node_tree.nodes.new("ShaderNodeTexImage")
tex_node.image = mdl.images[i]
tex_node.interpolation = "Closest"
if i == 0:
# connect only first texture (we'll need something smarter in the future)
mat.node_tree.links.new(tex_node.outputs[0], emissionNode.inputs[0]) mat.node_tree.links.new(tex_node.outputs[0], emissionNode.inputs[0])
mat.node_tree.links.new(emissionNode.outputs[0], shaderOut.inputs[0])
mat.node_tree.links.new(emissionNode.outputs[0], shaderOut.inputs[0]) mdl.mesh.materials.append(mat)
mdl.mesh.materials.append(mat)
def make_shape_key(mdl, framenum, subframenum=0): def make_shape_key(mdl, framenum, subframenum=0):
frame = mdl.frames[framenum] frame = mdl.frames[framenum]