Files
armorpaint/paint/sources/material_nodes/material_node.ts
T

198 lines
4.8 KiB
TypeScript
Raw Normal View History

2025-10-01 12:40:05 +02:00
2025-10-07 13:32:44 +02:00
function material_node_init() {
2025-10-15 18:39:55 +02:00
array_push(nodes_material_input, material_node_def);
map_set(parser_material_node_vectors, "MATERIAL", material_node_vector);
2025-10-07 13:32:44 +02:00
map_set(parser_material_node_values, "MATERIAL", material_node_value);
}
2025-10-06 14:06:18 +02:00
function material_node_vector(node: ui_node_t, socket: ui_node_socket_t): string {
2025-10-15 18:39:55 +02:00
let result: string = "float3(0.0, 0.0, 0.0)";
let mi: i32 = node.buttons[0].default_value[0];
if (mi >= project_materials.length) {
return result;
}
let m: slot_material_t = project_materials[mi];
let _nodes: ui_node_t[] = parser_material_nodes;
let _links: ui_node_link_t[] = parser_material_links;
parser_material_nodes = m.canvas.nodes;
parser_material_links = m.canvas.links;
array_push(parser_material_parents, node);
let output_node: ui_node_t = parser_material_node_by_type(parser_material_nodes, "OUTPUT_MATERIAL_PBR");
if (socket == node.outputs[0]) { // Base
result = parser_material_parse_vector_input(output_node.inputs[0]);
}
else if (socket == node.outputs[5]) { // Normal
result = parser_material_parse_vector_input(output_node.inputs[5]);
}
parser_material_nodes = _nodes;
parser_material_links = _links;
array_pop(parser_material_parents);
return result;
2025-10-06 14:06:18 +02:00
}
function material_node_value(node: ui_node_t, socket: ui_node_socket_t): string {
2025-10-15 18:39:55 +02:00
let result: string = "0.0";
let mi: i32 = node.buttons[0].default_value[0];
if (mi >= project_materials.length)
return result;
let m: slot_material_t = project_materials[mi];
let _nodes: ui_node_t[] = parser_material_nodes;
let _links: ui_node_link_t[] = parser_material_links;
parser_material_nodes = m.canvas.nodes;
parser_material_links = m.canvas.links;
array_push(parser_material_parents, node);
let output_node: ui_node_t = parser_material_node_by_type(parser_material_nodes, "OUTPUT_MATERIAL_PBR");
if (socket == node.outputs[1]) { // Opac
result = parser_material_parse_value_input(output_node.inputs[1]);
}
else if (socket == node.outputs[2]) { // Occ
result = parser_material_parse_value_input(output_node.inputs[2]);
}
else if (socket == node.outputs[3]) { // Rough
result = parser_material_parse_value_input(output_node.inputs[3]);
}
else if (socket == node.outputs[4]) { // Metal
result = parser_material_parse_value_input(output_node.inputs[4]);
}
else if (socket == node.outputs[7]) { // Height
result = parser_material_parse_value_input(output_node.inputs[7]);
}
parser_material_nodes = _nodes;
parser_material_links = _links;
array_pop(parser_material_parents);
return result;
2025-10-06 14:06:18 +02:00
}
2025-10-01 12:40:05 +02:00
let material_node_def: ui_node_t = {
2025-10-15 18:39:55 +02:00
id : 0,
name : _tr("Material"),
type : "MATERIAL", // extension
x : 0,
y : 0,
color : 0xff4982a0,
inputs : [],
outputs : [
{
id : 0,
node_id : 0,
name : _tr("Base Color"),
type : "RGBA",
color : 0xffc7c729,
default_value : f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
},
{
id : 0,
node_id : 0,
name : _tr("Opacity"),
type : "VALUE",
color : 0xffa1a1a1,
default_value : f32_array_create_x(1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
},
{
id : 0,
node_id : 0,
name : _tr("Occlusion"),
type : "VALUE",
color : 0xffa1a1a1,
default_value : f32_array_create_x(1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
},
{
id : 0,
node_id : 0,
name : _tr("Roughness"),
type : "VALUE",
color : 0xffa1a1a1,
default_value : f32_array_create_x(1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
},
{
id : 0,
node_id : 0,
name : _tr("Metallic"),
type : "VALUE",
color : 0xffa1a1a1,
default_value : f32_array_create_x(1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
},
{
id : 0,
node_id : 0,
name : _tr("Normal Map"),
type : "VECTOR",
color : -10238109,
default_value : f32_array_create_xyz(0.5, 0.5, 1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
},
{
id : 0,
node_id : 0,
name : _tr("Emission"),
type : "VALUE",
color : 0xffa1a1a1,
default_value : f32_array_create_x(1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
},
{
id : 0,
node_id : 0,
name : _tr("Height"),
type : "VALUE",
color : 0xffa1a1a1,
default_value : f32_array_create_x(1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
},
{
id : 0,
node_id : 0,
name : _tr("Subsurface"),
type : "VALUE",
color : 0xffa1a1a1,
default_value : f32_array_create_x(1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
}
],
buttons : [ {
name : _tr("Material"),
type : "ENUM",
output : -1,
default_value : f32_array_create_x(0),
data : u8_array_create_from_string(""),
min : 0.0,
max : 1.0,
precision : 100,
height : 0
} ],
width : 0,
flags : 0
2025-10-01 12:40:05 +02:00
};