Files
armorpaint/base/sources/ts/nodes/float_node.ts
T

91 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-03-14 23:58:24 +01:00
type float_node_t = {
base?: logic_node_t;
value?: f32;
2025-03-10 20:38:53 +01:00
image?: iron_gpu_texture_t;
2024-03-14 23:58:24 +01:00
};
2024-09-24 16:50:54 +02:00
function float_node_create(raw: ui_node_t, args: f32_array_t): float_node_t {
2024-03-14 23:58:24 +01:00
let n: float_node_t = {};
2024-10-21 19:28:43 +02:00
n.base = logic_node_create(n);
2024-03-14 23:58:24 +01:00
n.base.get = float_node_get;
n.base.get_as_image = float_node_get_as_image;
n.base.set = float_node_set;
2024-09-24 16:50:54 +02:00
n.value = args == null ? 0.5 : args[0];
2024-03-14 23:58:24 +01:00
return n;
}
2024-04-08 17:40:32 +02:00
function float_node_get(self: float_node_t, from: i32): logic_node_value_t {
2024-03-20 16:13:54 +01:00
if (self.base.inputs.length > 0) {
2024-04-02 15:45:49 +02:00
return logic_node_input_get(self.base.inputs[0]);
2024-03-20 16:13:54 +01:00
}
else {
2024-04-08 17:40:32 +02:00
let v: logic_node_value_t = { _f32: self.value };
return v;
2024-03-20 16:13:54 +01:00
}
2024-03-14 23:58:24 +01:00
}
2025-03-10 20:38:53 +01:00
function float_node_get_as_image(self: float_node_t, from: i32): iron_gpu_texture_t {
2024-03-20 16:13:54 +01:00
if (self.base.inputs.length > 0) {
2024-04-02 15:45:49 +02:00
return logic_node_input_get_as_image(self.base.inputs[0]);
2024-03-20 16:13:54 +01:00
}
if (self.image != null) {
2025-03-06 20:42:54 +01:00
iron_unload_image(self.image);
2024-03-20 16:13:54 +01:00
}
let b: buffer_t = buffer_create(16);
2024-07-24 20:04:49 +02:00
buffer_set_f32(b, 0, self.value);
buffer_set_f32(b, 4, self.value);
buffer_set_f32(b, 8, self.value);
buffer_set_f32(b, 12, 1.0);
2025-03-10 20:38:53 +01:00
self.image = gpu_create_texture_from_bytes(b, 1, 1, tex_format_t.RGBA128);
2024-04-02 15:45:49 +02:00
return self.image;
2024-03-14 23:58:24 +01:00
}
2024-05-03 21:29:39 +02:00
function float_node_set(self: float_node_t, value: f32_array_t) {
2024-03-20 16:13:54 +01:00
if (self.base.inputs.length > 0) {
logic_node_input_set(self.base.inputs[0], value);
}
else {
2024-05-03 21:29:39 +02:00
self.value = value[0];
2024-03-20 16:13:54 +01:00
}
2024-03-14 23:58:24 +01:00
}
2024-09-03 15:52:05 +02:00
let float_node_def: ui_node_t = {
2024-03-14 23:58:24 +01:00
id: 0,
name: _tr("Value"),
type: "float_node",
x: 0,
y: 0,
color: 0xffb34f5a,
inputs: [
{
id: 0,
node_id: 0,
name: _tr("Value"),
type: "VALUE",
color: 0xffa1a1a1,
2024-04-24 12:14:47 +02:00
default_value: f32_array_create_x(0.5),
2024-03-14 23:58:24 +01:00
min: 0.0,
2024-04-10 19:39:17 +02:00
max: 10.0,
precision: 100,
display: 0
2024-03-14 23:58:24 +01:00
}
],
outputs: [
{
id: 0,
node_id: 0,
name: _tr("Value"),
type: "VALUE",
color: 0xffa1a1a1,
2024-04-24 12:14:47 +02:00
default_value: f32_array_create_x(0.5),
2024-04-10 19:39:17 +02:00
min: 0.0,
max: 1.0,
precision: 100,
display: 0
2024-03-14 23:58:24 +01:00
}
],
2024-04-10 19:39:17 +02:00
buttons: [],
width: 0
2024-03-14 23:58:24 +01:00
};