Pixel-Composer/scripts/node_3d_extrude/node_3d_extrude.gml

515 lines
17 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_3D_Extrude(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2022-12-12 09:08:03 +01:00
name = "3D Extrude";
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
2022-12-12 09:08:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, def_surf_size2)
2022-12-12 09:08:03 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 2] = nodeValue("Object position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ])
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2022-12-12 09:08:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 3] = nodeValue("Object rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 180, 0 ])
2022-12-12 09:08:03 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 4] = nodeValue("Object scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1, 0.1 ])
2022-12-12 09:08:03 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-01-01 02:06:02 +01:00
2023-05-03 21:42:17 +02:00
inputs[| 5] = nodeValue("Render position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0.5, 0.5 ])
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.vector)
2023-05-03 21:42:17 +02:00
.setUnitRef( function() { return inputs[| 1].getValue(); }, VALUE_UNIT.reference);
2022-12-12 09:08:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 6] = nodeValue("Render rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ])
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 7] = nodeValue("Render scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1 ])
2022-12-12 09:08:03 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-03-28 06:58:28 +02:00
inputs[| 8] = nodeValue("Manual generate", self, JUNCTION_CONNECT.input, VALUE_TYPE.trigger, 0)
2022-12-21 02:30:23 +01:00
.setDisplay(VALUE_DISPLAY.button, [ function() {
2022-12-12 09:08:03 +01:00
generateMesh();
2023-03-28 06:58:28 +02:00
doUpdate();
2022-12-12 09:08:03 +01:00
}, "Generate"] );
2023-02-14 05:32:32 +01:00
inputs[| 9] = nodeValue("Light direction", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
2022-12-12 09:08:03 +01:00
.setDisplay(VALUE_DISPLAY.rotation);
2023-02-14 05:32:32 +01:00
inputs[| 10] = nodeValue("Light height", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.5)
2022-12-12 09:08:03 +01:00
.setDisplay(VALUE_DISPLAY.slider, [-1, 1, 0.01]);
2023-02-14 05:32:32 +01:00
inputs[| 11] = nodeValue("Light intensity", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
2022-12-12 09:08:03 +01:00
.setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
2023-02-14 05:32:32 +01:00
inputs[| 12] = nodeValue("Light color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white);
inputs[| 13] = nodeValue("Ambient color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_grey);
2022-12-12 09:08:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 14] = nodeValue("Height map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
2023-01-01 02:06:02 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 15] = nodeValue("Always update", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
2022-12-13 09:20:36 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 16] = nodeValue("Projection", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Orthographic", "Perspective" ])
.rejectArray();
2023-01-09 03:14:20 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 17] = nodeValue("Field of view", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 60)
2023-05-03 21:42:17 +02:00
.setDisplay(VALUE_DISPLAY.slider, [ 1, 90, 1 ]);
2023-01-09 03:14:20 +01:00
2023-02-23 07:02:19 +01:00
inputs[| 18] = nodeValue("Scale view with dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true)
2023-07-14 20:34:35 +02:00
inputs[| 19] = nodeValue("Smooth", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false)
2023-02-23 07:02:19 +01:00
input_display_list = [
2023-05-03 21:42:17 +02:00
["Output", false], 1, 18,
2023-07-14 20:34:35 +02:00
["Geometry", false], 0, 8, 14, 19,
2023-01-01 02:06:02 +01:00
["Object transform", false], 2, 3, 4,
2023-01-09 03:14:20 +01:00
["Camera", false], 16, 17, 5, 7, 15,
2023-01-01 02:06:02 +01:00
["Light", false], 9, 10, 11, 12, 13,
2022-12-12 09:08:03 +01:00
];
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2022-12-12 09:08:03 +01:00
2023-05-03 21:42:17 +02:00
outputs[| 1] = nodeValue("3D scene", self, JUNCTION_CONNECT.output, VALUE_TYPE.d3object, function(index) { return submit_vertex(index); });
2023-01-01 02:06:02 +01:00
2023-02-14 05:32:32 +01:00
outputs[| 2] = nodeValue("Normal pass", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2023-01-09 03:14:20 +01:00
2023-05-03 21:42:17 +02:00
outputs[| 3] = nodeValue("3D vertex", self, JUNCTION_CONNECT.output, VALUE_TYPE.d3vertex, []);
2023-01-09 03:14:20 +01:00
output_display_list = [
2023-05-03 21:42:17 +02:00
0, 2, 1, 3
2023-01-09 03:14:20 +01:00
]
2023-05-03 21:42:17 +02:00
_3d_node_init(1, /*Transform*/ 5, 7, 2, 3, 4);
2023-01-01 02:06:02 +01:00
2023-05-03 21:42:17 +02:00
vertexObjects = [];
2022-12-12 09:08:03 +01:00
2023-05-16 21:28:16 +02:00
mesh_generating = false;
mesh_genetated = false;
mesh_generate_index = 0;
mesh_generate_amount = 0;
2023-07-14 20:34:35 +02:00
static onValueUpdate = function(index) {
if(index == 19)
generateMesh();
}
2023-01-09 03:14:20 +01:00
static onValueFromUpdate = function(index) {
2023-01-04 02:30:04 +01:00
if(index == 0 || index == 14)
2022-12-12 09:08:03 +01:00
generateMesh();
}
2022-12-22 03:09:55 +01:00
static getHeight = function(h, gw, gh, i, j) {
var _i = round(i * gw);
var _j = round(j * gh);
_i = clamp(_i, 0, array_length(h) - 1);
_j = clamp(_j, 0, array_length(h[_i]) - 1);
return h[_i][_j];
}
2022-12-12 09:08:03 +01:00
static generateMesh = function() {
var _ins = inputs[| 0].getValue();
2023-01-01 02:06:02 +01:00
if(!is_array(_ins)) _ins = [ _ins ];
2023-05-03 21:42:17 +02:00
for( var i = 0; i < array_length(vertexObjects); i++ ) {
if(vertexObjects[i] == noone) continue;
vertexObjects[i].destroy();
}
vertexObjects = [];
2023-05-16 21:28:16 +02:00
mesh_generating = true;
mesh_genetated = false;
mesh_generate_index = 0;
mesh_generate_amount = array_length(_ins);
2023-01-01 02:06:02 +01:00
}
static generateMeshIndex = function(index) {
var _ins = getSingleValue( 0, index);
2023-01-09 03:14:20 +01:00
var _hei = getSingleValue(14, index);
2023-07-14 20:34:35 +02:00
var _smt = getSingleValue(19, index);
2022-12-12 09:08:03 +01:00
2023-07-14 20:34:35 +02:00
if(!is_surface(_ins)) return noone;
2022-12-12 09:08:03 +01:00
var ww = surface_get_width(_ins);
var hh = surface_get_height(_ins);
2023-07-14 20:34:35 +02:00
2022-12-12 09:08:03 +01:00
var tw = 1 / ww;
var th = 1 / hh;
var sw = -ww / 2 * tw;
var sh = -hh / 2 * th;
2022-12-13 09:20:36 +01:00
var useH = is_surface(_hei);
2023-07-14 20:34:35 +02:00
if(_smt) {
var ts = surface_create(ww, hh);
surface_set_shader(ts, sh_3d_extrude_filler);
DRAW_CLEAR
shader_set_f("dimension", ww, hh);
draw_surface(_ins, 0, 0);
surface_reset_shader();
_ins = ts;
if(useH) {
var ds = surface_create(ww, hh);
surface_set_shader(ds, sh_3d_extrude_filler_depth);
DRAW_CLEAR
shader_set_f("dimension", ww, hh);
draw_surface(_hei, 0, 0);
surface_reset_shader();
_hei = ds;
}
}
2022-12-13 09:20:36 +01:00
if(useH) {
2022-12-22 03:09:55 +01:00
var hgw = surface_get_width(_hei);
var hgh = surface_get_height(_hei);
var hgtW = hgw / ww;
var hgtH = hgh / hh;
var height_buffer = buffer_create(hgw * hgh * 4, buffer_fixed, 2);
2022-12-13 09:20:36 +01:00
buffer_get_surface(height_buffer, _hei, 0);
buffer_seek(height_buffer, buffer_seek_start, 0);
2022-12-22 03:09:55 +01:00
var hei = array_create(hgw, hgh);
2022-12-13 09:20:36 +01:00
2022-12-22 03:09:55 +01:00
for( var j = 0; j < hgh; j++ )
for( var i = 0; i < hgw; i++ ) {
2022-12-13 09:20:36 +01:00
var cc = buffer_read(height_buffer, buffer_u32);
var _b = colorBrightness(cc & ~0b11111111);
hei[i][j] = _b;
}
buffer_delete(height_buffer);
}
2022-12-12 09:08:03 +01:00
var surface_buffer = buffer_create(ww * hh * 4, buffer_fixed, 2);
buffer_get_surface(surface_buffer, _ins, 0);
buffer_seek(surface_buffer, buffer_seek_start, 0);
2023-05-03 21:42:17 +02:00
var v = new VertexObject();
2022-12-12 09:08:03 +01:00
var ap = array_create(ww, hh);
for( var j = 0; j < hh; j++ )
for( var i = 0; i < ww; i++ ) {
var cc = buffer_read(surface_buffer, buffer_u32);
var _a = (cc & (0b11111111 << 24)) >> 24;
ap[i][j] = _a;
}
2022-12-13 09:20:36 +01:00
buffer_delete(surface_buffer);
2022-12-12 09:08:03 +01:00
for( var i = 0; i < ww; i++ )
for( var j = 0; j < hh; j++ ) {
2023-07-14 20:34:35 +02:00
if(!_smt && ap[i][j] == 0) continue;
2022-12-12 09:08:03 +01:00
2023-07-14 20:34:35 +02:00
var i0 = sw + i * tw;
var i1 = i0 + tw;
var j0 = sh + j * th;
var j1 = j0 + th;
2022-12-12 09:08:03 +01:00
var tx0 = tw * i, tx1 = tx0 + tw;
var ty0 = th * j, ty1 = ty0 + th;
2022-12-22 03:09:55 +01:00
var dep = (useH? getHeight(hei, hgtW, hgtH, i, j) : 1) * 0.5;
2022-12-13 09:20:36 +01:00
2023-07-14 20:34:35 +02:00
if(_smt) {
var d0, d1, d2, d3;
var d00, d10, d01, d11;
var a, a0, a1, a2, a3;
// d00 | a0 | d10
// a1 | a | a2
// d01 | a3 | d11
if(useH) {
d00 = (i > 0 && j > 0)? getHeight(hei, hgtW, hgtH, i - 1, j - 1) * 0.5 : 0;
d10 = (i < ww - 1 && j > 0)? getHeight(hei, hgtW, hgtH, i + 1, j - 1) * 0.5 : 0;
d01 = (i > 0 && j < hh - 1)? getHeight(hei, hgtW, hgtH, i - 1, j + 1) * 0.5 : 0;
d11 = (i < ww - 1 && j < hh - 1)? getHeight(hei, hgtW, hgtH, i + 1, j + 1) * 0.5 : 0;
d0 = (j > 0)? getHeight(hei, hgtW, hgtH, i, j - 1) * 0.5 : 0;
d1 = (i > 0)? getHeight(hei, hgtW, hgtH, i - 1, j) * 0.5 : 0;
d2 = (i < ww - 1)? getHeight(hei, hgtW, hgtH, i + 1, j) * 0.5 : 0;
d3 = (j < hh - 1)? getHeight(hei, hgtW, hgtH, i, j + 1) * 0.5 : 0;
} else {
d00 = (i > 0 && j > 0)? bool(ap[i - 1][j - 1]) * 0.5 : 0;
d10 = (i < ww - 1 && j > 0)? bool(ap[i + 1][j - 1]) * 0.5 : 0;
d01 = (i > 0 && j < hh - 1)? bool(ap[i - 1][j + 1]) * 0.5 : 0;
d11 = (i < ww - 1 && j < hh - 1)? bool(ap[i + 1][j + 1]) * 0.5 : 0;
d0 = (j > 0)? bool(ap[i][j - 1]) * 0.5 : 0;
d1 = (i > 0)? bool(ap[i - 1][j]) * 0.5 : 0;
d2 = (i < ww - 1)? bool(ap[i + 1][j]) * 0.5 : 0;
d3 = (j < hh - 1)? bool(ap[i][j + 1]) * 0.5 : 0;
}
a = ap[i][j];
a0 = (j > 0)? ap[i][j - 1] : 0;
a1 = (i > 0)? ap[i - 1][j] : 0;
a2 = (i < ww - 1)? ap[i + 1][j] : 0;
a3 = (j < hh - 1)? ap[i][j + 1] : 0;
if(a1 && a0) d00 = (d1 + d0) / 2;
if(a0 && a2) d10 = (d0 + d2) / 2;
if(a2 && a3) d11 = (d2 + d3) / 2;
if(a3 && a1) d01 = (d3 + d1) / 2;
if(a) {
v.addFace( [i1, j0, -d10], [0, 0, -1], [tx1, ty0],
[i0, j0, -d00], [0, 0, -1], [tx0, ty0],
[i1, j1, -d11], [0, 0, -1], [tx1, ty1], false);
2022-12-12 09:08:03 +01:00
2023-07-14 20:34:35 +02:00
v.addFace( [i1, j1, -d11], [0, 0, -1], [tx1, ty1],
[i0, j0, -d00], [0, 0, -1], [tx0, ty0],
[i0, j1, -d01], [0, 0, -1], [tx0, ty1], false);
2022-12-12 09:08:03 +01:00
2023-07-14 20:34:35 +02:00
v.addFace( [i1, j0, d10], [0, 0, 1], [tx1, ty0],
[i0, j0, d00], [0, 0, 1], [tx0, ty0],
[i1, j1, d11], [0, 0, 1], [tx1, ty1], false);
2022-12-12 09:08:03 +01:00
2023-07-14 20:34:35 +02:00
v.addFace( [i1, j1, d11], [0, 0, 1], [tx1, ty1],
[i0, j0, d00], [0, 0, 1], [tx0, ty0],
[i0, j1, d01], [0, 0, 1], [tx0, ty1], false);
} else if(!a0 && !a1 && a2 && a3) {
//var _tx0 = tw * (i + 1), _tx1 = _tx0 + tw;
//var _ty0 = th * (j + 0), _ty1 = _ty0 + th;
d00 *= d0 * d1;
d10 *= d1 * d2;
d01 *= d1 * d3;
v.addFace( [i1, j0, -d10], [0, 0, -1], [tx1, ty0],
[i0, j1, -d01], [0, 0, -1], [tx0, ty1],
[i1, j1, -d11], [0, 0, -1], [tx1, ty1], false);
v.addFace( [i1, j0, d10], [0, 0, 1], [tx1, ty0],
[i0, j1, d01], [0, 0, 1], [tx0, ty1],
[i1, j1, d11], [0, 0, 1], [tx1, ty1], false);
} else if(!a0 && a1 && !a2 && a3) {
//var _tx0 = tw * (i - 1), _tx1 = _tx0 + tw;
//var _ty0 = th * (j + 0), _ty1 = _ty0 + th;
d00 *= d0 * d1;
d10 *= d1 * d2;
d11 *= d2 * d3;
v.addFace( [i1, j1, -d11], [0, 0, -1], [tx1, ty1],
[i0, j0, -d00], [0, 0, -1], [tx0, ty0],
[i0, j1, -d01], [0, 0, -1], [tx0, ty1], false);
v.addFace( [i1, j1, d11], [0, 0, 1], [tx1, ty1],
[i0, j0, d00], [0, 0, 1], [tx0, ty0],
[i0, j1, d01], [0, 0, 1], [tx0, ty1], false);
} else if(a0 && a1 && !a2 && !a3) {
//var _tx0 = tw * (i - 1), _tx1 = _tx0 + tw;
//var _ty0 = th * (j + 0), _ty1 = _ty0 + th;
d10 *= d1 * d2;
d01 *= d1 * d3;
d11 *= d2 * d3;
v.addFace( [i0, j0, -d00], [0, 0, -1], [tx0, ty0], // d00 | a0 | d10
[i0, j1, -d01], [0, 0, -1], [tx0, ty1], // a1 | a | a2
[i1, j0, -d10], [0, 0, -1], [tx1, ty0], false); // d01 | a3 | d11
v.addFace( [i0, j0, d00], [0, 0, 1], [tx0, ty0],
[i0, j1, d01], [0, 0, 1], [tx0, ty1],
[i1, j0, d10], [0, 0, 1], [tx1, ty0], false);
} else if(a0 && !a1 && a2 && !a3) {
//var _tx0 = tw * (i + 1), _tx1 = _tx0 + tw;
//var _ty0 = th * (j + 0), _ty1 = _ty0 + th;
d00 *= d0 * d1;
d01 *= d1 * d3;
d11 *= d2 * d3;
v.addFace( [i1, j0, -d10], [0, 0, -1], [tx1, ty0],
[i0, j0, -d00], [0, 0, -1], [tx0, ty0],
[i1, j1, -d11], [0, 0, -1], [tx1, ty1], false);
v.addFace( [i1, j0, d10], [0, 0, 1], [tx1, ty0],
[i0, j0, d00], [0, 0, 1], [tx0, ty0],
[i1, j1, d11], [0, 0, 1], [tx1, ty1], false);
}
} else {
v.addFace( [i1, j0, -dep], [0, 0, -1], [tx1, ty0],
[i0, j0, -dep], [0, 0, -1], [tx0, ty0],
[i1, j1, -dep], [0, 0, -1], [tx1, ty1], false);
v.addFace( [i1, j1, -dep], [0, 0, -1], [tx1, ty1],
[i0, j0, -dep], [0, 0, -1], [tx0, ty0],
[i0, j1, -dep], [0, 0, -1], [tx0, ty1], false);
2022-12-12 09:08:03 +01:00
2023-07-14 20:34:35 +02:00
v.addFace( [i1, j0, dep], [0, 0, 1], [tx1, ty0],
[i0, j0, dep], [0, 0, 1], [tx0, ty0],
[i1, j1, dep], [0, 0, 1], [tx1, ty1], false);
2022-12-12 09:08:03 +01:00
2023-07-14 20:34:35 +02:00
v.addFace( [i1, j1, dep], [0, 0, 1], [tx1, ty1],
[i0, j0, dep], [0, 0, 1], [tx0, ty0],
[i0, j1, dep], [0, 0, 1], [tx0, ty1], false);
if((useH && dep * 2 > getHeight(hei, hgtW, hgtH, i, j - 1)) || (j == 0 || ap[i][j - 1] == 0)) { //y side
v.addFace( [i0, j0, dep], [0, -1, 0], [tx1, ty0],
[i0, j0, -dep], [0, -1, 0], [tx0, ty0],
[i1, j0, dep], [0, -1, 0], [tx1, ty1], false);
v.addFace( [i0, j0, -dep], [0, -1, 0], [tx1, ty1],
[i1, j0, -dep], [0, -1, 0], [tx0, ty0],
[i1, j0, dep], [0, -1, 0], [tx0, ty1], false);
}
2022-12-12 09:08:03 +01:00
2023-07-14 20:34:35 +02:00
if((useH && dep * 2 > getHeight(hei, hgtW, hgtH, i, j + 1)) || (j == hh - 1 || ap[i][j + 1] == 0)) { //y side
v.addFace( [i0, j1, dep], [0, 1, 0], [tx1, ty0],
[i0, j1, -dep], [0, 1, 0], [tx0, ty0],
[i1, j1, dep], [0, 1, 0], [tx1, ty1], false);
2023-05-03 21:42:17 +02:00
2023-07-14 20:34:35 +02:00
v.addFace( [i0, j1, -dep], [0, 1, 0], [tx1, ty1],
[i1, j1, -dep], [0, 1, 0], [tx0, ty0],
[i1, j1, dep], [0, 1, 0], [tx0, ty1], false);
}
2022-12-12 09:08:03 +01:00
2023-07-14 20:34:35 +02:00
if((useH && dep * 2 > getHeight(hei, hgtW, hgtH, i - 1, j)) || (i == 0 || ap[i - 1][j] == 0)) { //x side
v.addFace( [i0, j0, dep], [1, 0, 0], [tx1, ty0],
[i0, j0, -dep], [1, 0, 0], [tx0, ty0],
[i0, j1, dep], [1, 0, 0], [tx1, ty1], false);
2023-05-03 21:42:17 +02:00
2023-07-14 20:34:35 +02:00
v.addFace( [i0, j0, -dep], [1, 0, 0], [tx1, ty1],
[i0, j1, -dep], [1, 0, 0], [tx0, ty0],
[i0, j1, dep], [1, 0, 0], [tx0, ty1], false);
}
2022-12-12 09:08:03 +01:00
2023-07-14 20:34:35 +02:00
if((useH && dep * 2 > getHeight(hei, hgtW, hgtH, i + 1, j)) || (i == ww - 1 || ap[i + 1][j] == 0)) { //x side
v.addFace( [i1, j0, dep], [-1, 0, 0], [tx1, ty0],
[i1, j0, -dep], [-1, 0, 0], [tx0, ty0],
[i1, j1, dep], [-1, 0, 0], [tx1, ty1], false);
2023-05-03 21:42:17 +02:00
2023-07-14 20:34:35 +02:00
v.addFace( [i1, j0, -dep], [-1, 0, 0], [tx1, ty1],
[i1, j1, -dep], [-1, 0, 0], [tx0, ty0],
[i1, j1, dep], [-1, 0, 0], [tx0, ty1], false);
}
2022-12-12 09:08:03 +01:00
}
}
2023-05-03 21:42:17 +02:00
2023-07-14 20:34:35 +02:00
if(_smt) {
surface_free(_ins);
if(useH) surface_free(_hei);
}
2023-05-03 21:42:17 +02:00
v.createBuffer();
return v;
2022-12-12 09:08:03 +01:00
}
2023-05-16 21:28:16 +02:00
static step = function() {
if(!mesh_generating) return;
vertexObjects[mesh_generate_index] = generateMeshIndex(mesh_generate_index);
mesh_generate_index++;
if(mesh_generate_index >= mesh_generate_amount) {
mesh_generating = false;
mesh_genetated = true;
UPDATE |= RENDER_TYPE.full;
outputs[| 3].setValue(vertexObjects);
}
}
2022-12-19 13:35:30 +01:00
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
2023-01-01 02:06:02 +01:00
_3d_gizmo(active, _x, _y, _s, _mx, _my, _snx, _sny);
}
2023-01-09 03:14:20 +01:00
static submit_vertex = function(index = 0) {
2023-07-14 20:34:35 +02:00
var _ins = array_safe_get(textures, index);
2023-01-01 02:06:02 +01:00
if(!is_surface(_ins)) return;
2023-05-03 21:42:17 +02:00
if(index >= array_length(vertexObjects)) return;
2022-12-12 09:08:03 +01:00
2023-07-14 20:34:35 +02:00
var _lpos = getSingleValue( 2, index);
var _lrot = getSingleValue( 3, index);
var _lsca = getSingleValue( 4, index);
var _smt = getSingleValue(19, index);
2022-12-12 09:08:03 +01:00
2023-05-16 21:28:16 +02:00
if(is_struct(vertexObjects[index])) {
_3d_local_transform(_lpos, _lrot, _lsca);
vertexObjects[index].submit(_ins);
_3d_clear_local_transform();
}
2022-12-12 09:08:03 +01:00
}
2023-07-14 20:34:35 +02:00
textures = [];
2023-01-01 02:06:02 +01:00
static process_data = function(_outSurf, _data, _output_index, _array_index) {
2023-05-16 21:28:16 +02:00
if(mesh_generating) return;
2023-05-03 21:42:17 +02:00
if(_output_index == 3) return vertexObjects;
2023-01-01 02:06:02 +01:00
var _ins = _data[ 0];
var _dim = _data[ 1];
var _lpos = _data[ 2];
var _lrot = _data[ 3];
var _lsca = _data[ 4];
2022-12-12 09:08:03 +01:00
2023-01-01 02:06:02 +01:00
var _pos = _data[ 5];
var _sca = _data[ 7];
2022-12-12 09:08:03 +01:00
2023-01-01 02:06:02 +01:00
var _ldir = _data[ 9];
var _lhgt = _data[10];
var _lint = _data[11];
var _lclr = _data[12];
var _aclr = _data[13];
2022-12-12 09:08:03 +01:00
2023-01-01 02:06:02 +01:00
var _upda = _data[15];
2022-12-12 09:08:03 +01:00
2023-01-09 03:14:20 +01:00
var _proj = _data[16];
var _fov = _data[17];
2023-02-23 07:02:19 +01:00
var _dimS = _data[18];
2023-07-14 20:34:35 +02:00
var _smt = _data[19];
2023-01-09 03:14:20 +01:00
inputs[| 17].setVisible(_proj);
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1]);
2022-12-12 09:08:03 +01:00
if(!is_surface(_ins)) return _outSurf;
2023-01-09 03:14:20 +01:00
var pass = "diff";
switch(_output_index) {
case 0 : pass = "diff" break;
case 2 : pass = "norm" break;
}
2023-07-06 19:49:16 +02:00
if(_upda && PROJECT.animator.frame_progress)
2022-12-21 02:30:23 +01:00
generateMesh();
2023-06-13 14:42:06 +02:00
var _transform = new __3d_transform(_pos,, _sca, _lpos, _lrot, _lsca, false, _dimS );
var _light = new __3d_light(_ldir, _lhgt, _lint, _lclr, _aclr);
var _cam = new __3d_camera(_proj, _fov);
2023-02-23 07:02:19 +01:00
2023-07-14 20:34:35 +02:00
if(_smt) {
var ww = surface_get_width(_ins);
var hh = surface_get_height(_ins);
var ts = surface_create(ww, hh);
surface_set_shader(ts, sh_3d_extrude_corner);
shader_set_f("dimension", ww, hh);
draw_surface(_ins, 0, 0);
surface_reset_shader();
textures[_array_index] = ts;
} else
textures[_array_index] = _ins;
2023-06-13 14:42:06 +02:00
_outSurf = _3d_pre_setup(_outSurf, _dim, _transform, _light, _cam, pass);
2023-01-01 02:06:02 +01:00
submit_vertex(_array_index);
_3d_post_setup();
2022-12-12 09:08:03 +01:00
return _outSurf;
}
2023-01-09 03:14:20 +01:00
2023-05-16 21:28:16 +02:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
if(mesh_generating) {
var cx = xx + w * _s / 2;
var cy = yy + h * _s / 2;
var rr = min(w - 64, h - 64) * _s / 2;
draw_set_color(COLORS._main_icon);
draw_arc(cx, cy, rr, 90, 90 - 360 * mesh_generate_index / mesh_generate_amount, 4 * _s, max(mesh_generate_amount, 32));
}
}
2023-01-09 03:14:20 +01:00
static postConnect = function() {
generateMesh();
}
2022-12-12 09:08:03 +01:00
}