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

92 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-03-14 23:58:24 +01:00
type float_node_t = {
base?: logic_node_t;
value?: f32;
image?: image_t;
};
2024-03-21 21:06:41 +01:00
function float_node_create(arg: f32): float_node_t {
2024-03-14 23:58:24 +01:00
let n: float_node_t = {};
n.base = logic_node_create();
n.base.get = float_node_get;
n.base.get_as_image = float_node_get_as_image;
n.base.set = float_node_set;
2024-03-21 21:06:41 +01:00
n.value = arg;
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
}
2024-04-02 15:45:49 +02:00
function float_node_get_as_image(self: float_node_t, from: i32): image_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) {
image_unload(self.image);
}
let b: buffer_t = buffer_create(16);
let v: buffer_view_t = buffer_view_create(b);
buffer_view_set_f32(v, 0, self.value);
buffer_view_set_f32(v, 4, self.value);
buffer_view_set_f32(v, 8, self.value);
buffer_view_set_f32(v, 12, 1.0);
2024-03-14 23:58:24 +01:00
self.image = image_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
}
function float_node_set(self: float_node_t, value: any) {
2024-03-20 16:13:54 +01:00
if (self.base.inputs.length > 0) {
logic_node_input_set(self.base.inputs[0], value);
}
else {
self.value = value;
}
2024-03-14 23:58:24 +01:00
}
let float_node_def: zui_node_t = {
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,
default_value: 0.5,
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-10 19:39:17 +02:00
default_value: 0.5,
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
};