2019-10-18 16:31:30 +02:00
|
|
|
|
2024-04-02 15:45:49 +02:00
|
|
|
let plugin = plugin_create();
|
2019-10-18 16:31:30 +02:00
|
|
|
|
2024-04-02 15:45:49 +02:00
|
|
|
let category_name = "My Nodes";
|
|
|
|
|
let node_name = "Hello World";
|
|
|
|
|
let node_type = "HELLO_WORLD";
|
2019-10-18 16:31:30 +02:00
|
|
|
|
|
|
|
|
// Create new node category
|
2024-08-22 23:07:22 +02:00
|
|
|
let node_list = [
|
2019-10-18 16:31:30 +02:00
|
|
|
{
|
|
|
|
|
id: 0,
|
2024-04-02 15:45:49 +02:00
|
|
|
name: node_name,
|
|
|
|
|
type: node_type,
|
2019-10-18 16:31:30 +02:00
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
color: 0xffb34f5a,
|
2020-01-23 18:02:01 +01:00
|
|
|
inputs: [
|
|
|
|
|
{
|
|
|
|
|
id: 0,
|
|
|
|
|
node_id: 0,
|
|
|
|
|
name: "Scale",
|
|
|
|
|
type: "VALUE",
|
|
|
|
|
color: 0xffa1a1a1,
|
2024-08-22 23:07:22 +02:00
|
|
|
default_value__f32: [1.0],
|
|
|
|
|
min__f32: 0.0,
|
|
|
|
|
max__f32: 5.0,
|
|
|
|
|
precision__f32: 100.0,
|
|
|
|
|
display: 0
|
2020-01-23 18:02:01 +01:00
|
|
|
}
|
|
|
|
|
],
|
2019-10-18 16:31:30 +02:00
|
|
|
outputs: [
|
|
|
|
|
{
|
|
|
|
|
id: 0,
|
|
|
|
|
node_id: 0,
|
|
|
|
|
name: "Color",
|
|
|
|
|
type: "RGBA",
|
|
|
|
|
color: 0xffc7c729,
|
2024-08-22 23:07:22 +02:00
|
|
|
default_value__f32: [0.8, 0.8, 0.8, 1.0],
|
|
|
|
|
min__f32: 0.0,
|
|
|
|
|
max__f32: 1.0,
|
|
|
|
|
precision__f32: 100.0,
|
|
|
|
|
display: 0
|
2020-09-18 13:46:40 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
|
|
|
|
node_id: 0,
|
|
|
|
|
name: "Fac",
|
|
|
|
|
type: "VALUE",
|
|
|
|
|
color: 0xffa1a1a1,
|
2024-08-22 23:07:22 +02:00
|
|
|
default_value__f32: [1.0],
|
|
|
|
|
min__f32: 0.0,
|
|
|
|
|
max__f32: 1.0,
|
|
|
|
|
precision__f32: 100.0,
|
|
|
|
|
display: 0
|
2019-10-18 16:31:30 +02:00
|
|
|
}
|
|
|
|
|
],
|
2024-08-22 23:07:22 +02:00
|
|
|
buttons: [],
|
|
|
|
|
width: 0
|
2019-10-18 16:31:30 +02:00
|
|
|
}
|
|
|
|
|
];
|
2024-08-22 23:07:22 +02:00
|
|
|
|
|
|
|
|
nodes_material_category_add(category_name, armpack_encode(node_list));
|
2019-10-18 16:31:30 +02:00
|
|
|
|
|
|
|
|
// Node shader
|
2024-08-22 23:07:22 +02:00
|
|
|
parser_material_custom_nodes_set(node_type, function(node, socket_name) {
|
2025-04-02 22:52:04 +02:00
|
|
|
let kong = parser_material_kong_get();
|
2024-08-22 23:07:22 +02:00
|
|
|
let scale = parser_material_parse_value_input(node, 0);
|
|
|
|
|
let my_out = "my_out";
|
2020-01-23 18:02:01 +01:00
|
|
|
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong,
|
2025-07-18 16:50:01 +02:00
|
|
|
"var " + my_out + ": float = cos(sin(tex_coord.x * 200.0 * " + scale + ") + cos(tex_coord.y * 200.0 * " + scale + "));"
|
2024-04-02 15:45:49 +02:00
|
|
|
);
|
2020-09-18 13:46:40 +02:00
|
|
|
|
2024-08-22 23:07:22 +02:00
|
|
|
if (socket_name == "Color") {
|
2025-04-03 21:29:51 +02:00
|
|
|
return "float3(" + my_out + ", " + my_out + ", " + my_out + ")";
|
2020-09-18 13:46:40 +02:00
|
|
|
}
|
2024-08-22 23:07:22 +02:00
|
|
|
else if (socket_name == "Fac") {
|
2020-09-18 13:46:40 +02:00
|
|
|
return my_out;
|
|
|
|
|
}
|
2019-10-18 16:31:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Cleanup
|
2024-08-22 23:07:22 +02:00
|
|
|
plugin_notify_on_delete(plugin, function() {
|
|
|
|
|
parser_material_custom_nodes_delete(node_type);
|
|
|
|
|
nodes_material_category_remove(category_name);
|
|
|
|
|
});
|