if from_node:
if from_node.type=='NORMAL_MAP':
from_node, _ = get_linked_node_and_socket(node_tree, from_node.inputs["Color"])
+ elif from_node.type=='RGBTOBW':
+ from_node, _ = get_linked_node_and_socket(node_tree, from_node.inputs["Color"])
if alpha_socket:
alpha_from, _ = get_linked_node_and_socket(node_tree, alpha_socket)
base_color = self.create_property("base_color", (0.8, 0.8, 0.8, 1.0))
metalness = self.create_property("metalness", 0.0)
roughness = self.create_property("roughness", 0.5)
- normal = self.create_property("normal")
+ normal = self.create_property("normal_map")
emission = self.create_property("emission", (0.0, 0.0, 0.0))
base_color.set_from_input(material.node_tree, surface_node.inputs["Base Color"], surface_node.inputs["Alpha"])
roughness.set_from_input(material.node_tree, surface_node.inputs["Roughness"])
normal.set_from_input(material.node_tree, surface_node.inputs["Normal"])
emission.set_from_input(material.node_tree, surface_node.inputs["Emission"])
+ elif surface_node.type=='EMISSION':
+ self.type = "unlit"
+
+ color = self.create_property("color", "texture", (1.0, 1.0, 1.0, 1.0))
+
+ color.set_from_input(material.node_tree, surface_node.inputs["Color"])
else:
raise Exception("Unsupported surface node type "+surface_node.type)
return prop
-class MaterialMap:
+class MaterialAtlas:
def __init__(self, materials):
self.render_mode = materials[0].render_mode
if self.render_mode=='EXTERNAL':
- raise Exception("Material map with external render mode does not make sense")
+ raise Exception("Material atlas with external render mode does not make sense")
self.shader = materials[0].shader
if self.shader:
- self.name = "material_map_"+os.path.splitext(self.shader)[0]
+ self.name = "material_atlas_"+os.path.splitext(self.shader)[0]
else:
- self.name = "material_map"
+ self.name = "material_atlas"
self.materials = materials
self.material_names = [m.name for m in self.materials]
for m in self.materials:
if m.render_mode!=self.render_mode:
- raise Exception("Conflicting render modes in MaterialMap constructor")
+ raise Exception("Conflicting render modes in MaterialAtlas constructor")
if self.render_mode=='CUSTOM' and m.shader!=self.shader:
- raise Exception("Conflicting shaders in MaterialMap constructor")
+ raise Exception("Conflicting shaders in MaterialAtlas constructor")
count = len(self.materials)
size = 1
self.base_color_data = ""
for m in map(Material, self.materials):
if any(p.texture for p in m.properties):
- raise Exception("Texturing is incompatible with material map")
+ raise Exception("Texturing is incompatible with material atlas")
base_color = [int(cm(c)*255) for c in m.base_color.value]
self.base_color_data += "\\x{:02X}\\x{:02X}\\x{:02X}\\xFF".format(*base_color)
self.base_color_data += "\\x00\\x00\\x00\\x00"*(self.size[0]*self.size[1]-count)
y = index//self.size[0]
return ((x+0.5)/self.size[0], (y+0.5)/self.size[1])
-def create_material_map(context, material):
- if not material.material_map:
- raise Exception("Material is not part of a material map")
+def create_material_atlas(context, material):
+ if not material.material_atlas:
+ raise Exception("Material is not part of a material atlas")
shader = material.shader
materials = []
for m in context.blend_data.materials:
- if m.material_map and m.shader==shader:
+ if m.material_atlas and m.shader==shader:
materials.append(m)
- mat_map = MaterialMap(materials)
+ mat_map = MaterialAtlas(materials)
return mat_map