Pixel-Composer/scripts/node_3d_repeat/node_3d_repeat.gml

207 lines
7.6 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_3D_Repeat(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-01-01 02:06:02 +01:00
name = "3D Repeat";
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, def_surf_size2)
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 1] = 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);
2023-02-14 05:32:32 +01:00
inputs[| 2] = nodeValue("Object 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[| 3] = nodeValue("Object scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1, 1 ])
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-05-03 21:42:17 +02:00
inputs[| 4] = 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[| 0].getValue(); }, VALUE_UNIT.reference);
2023-01-01 02:06:02 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 5] = nodeValue("Render scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1 ])
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 6] = nodeValue("Light direction", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.rotation);
2023-02-14 05:32:32 +01:00
inputs[| 7] = nodeValue("Light height", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.5)
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.slider, [-1, 1, 0.01]);
2023-02-14 05:32:32 +01:00
inputs[| 8] = nodeValue("Light intensity", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
2023-02-14 05:32:32 +01:00
inputs[| 9] = nodeValue("Light color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white);
2023-01-01 02:06:02 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 10] = nodeValue("Ambient color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_grey);
2023-01-01 02:06:02 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 11] = nodeValue("3D object", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3object, noone)
2023-01-01 02:06:02 +01:00
.setVisible(true, true);
2023-02-14 05:32:32 +01:00
inputs[| 12] = nodeValue("Repeat", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1, "Amount of copies to be generated.");
2023-01-01 02:06:02 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 13] = nodeValue("Repeat position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 0, 0 ])
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 14] = nodeValue("Repeat 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[| 15] = nodeValue("Repeat scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1, 1 ])
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 16] = nodeValue("Repeat pattern", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Linear", "Circular" ])
.rejectArray();
2023-01-01 02:06:02 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 17] = nodeValue("Axis", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.enum_button, [ "x", "y", "z" ]);
2023-02-14 05:32:32 +01:00
inputs[| 18] = nodeValue("Radius", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1);
2023-01-01 02:06:02 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 19] = nodeValue("Rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [ 0, 360 ])
2023-01-01 02:06:02 +01:00
.setDisplay(VALUE_DISPLAY.rotation_range);
2023-02-14 05:32:32 +01:00
inputs[| 20] = 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[| 21] = 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[| 22] = nodeValue("Scale view with dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true)
input_display_list = [ 11,
2023-05-03 21:42:17 +02:00
["Output", false], 0, 22,
2023-01-01 02:06:02 +01:00
["Object transform", true], 1, 2, 3,
2023-01-09 03:14:20 +01:00
["Camera", true], 20, 21, 4, 5,
2023-01-01 02:06:02 +01:00
["Light", true], 6, 7, 8, 9, 10,
["Repeat", false], 12, 16, 13, 14, 15, 17, 18, 19
];
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2023-01-09 03:14:20 +01:00
2023-02-14 05:32:32 +01:00
outputs[| 1] = nodeValue("3D objects", self, JUNCTION_CONNECT.output, VALUE_TYPE.d3object, function() { return submit_vertex(); });
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
output_display_list = [
0, 2, 1
]
2023-05-03 21:42:17 +02:00
_3d_node_init(1, /*Transform*/ 4, 5, 1, 2, 3);
2023-01-01 02:06:02 +01:00
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
_3d_gizmo(active, _x, _y, _s, _mx, _my, _snx, _sny);
}
static submit_vertex = function() {
var _lpos = inputs[| 1].getValue();
var _lrot = inputs[| 2].getValue();
var _lsca = inputs[| 3].getValue();
var sv = inputs[| 11].getValue();
if(sv == noone) return;
var _samo = inputs[| 12].getValue();
var _patt = inputs[| 16].getValue();
var _srot = inputs[| 14].getValue();
var _ssca = inputs[| 15].getValue();
var _spos = inputs[| 13].getValue();
var _raxs = inputs[| 17].getValue();
var _rrad = inputs[| 18].getValue();
var _rrot = inputs[| 19].getValue();
_3d_local_transform(_lpos, _lrot, _lsca);
for( var i = 0; i < _samo; i++ ) {
if(_patt == 0) {
2023-05-03 21:42:17 +02:00
matrix_stack_push(matrix_build( _spos[0] * i, _spos[1] * i, _spos[2] * i, 0, 0, 0, 1, 1, 1 ));
matrix_stack_push(matrix_build( 0, 0, 0, _srot[0] * i, _srot[1] * i, _srot[2] * i, 1, 1, 1 ));
matrix_stack_push(matrix_build( 0, 0, 0, 0, 0, 0, power(_ssca[0], i), power(_ssca[1], i), power(_ssca[2], i)));
2023-01-01 02:06:02 +01:00
} else if(_patt == 1) {
var angle = _rrot[0] + i * (_rrot[1] - _rrot[0]) / _samo;
var ldx = lengthdir_x(_rrad, angle);
var ldy = lengthdir_y(_rrad, angle);
switch(_raxs) {
2023-05-03 21:42:17 +02:00
case 0 : matrix_stack_push(matrix_build( 0, ldx, ldy, 0, 0, 0, 1, 1, 1 )); break;
case 1 : matrix_stack_push(matrix_build( ldy, 0, ldx, 0, 0, 0, 1, 1, 1 )); break;
case 2 : matrix_stack_push(matrix_build( ldx, ldy, 0, 0, 0, 0, 1, 1, 1 )); break;
2023-01-01 02:06:02 +01:00
}
2023-05-03 21:42:17 +02:00
matrix_stack_push(matrix_build( 0, 0, 0, _srot[0] * i, _srot[1] * i, _srot[2] * i, 1, 1, 1));
matrix_stack_push(matrix_build( 0, 0, 0, 0, 0, 0, power(_ssca[0], i), power(_ssca[1], i), power(_ssca[2], i)));
2023-01-01 02:06:02 +01:00
}
matrix_set(matrix_world, matrix_stack_top());
if(is_array(sv)) {
2023-02-20 10:16:31 +01:00
var index = safe_mod(i, array_length(sv));
2023-01-01 02:06:02 +01:00
var _sv = sv[index];
_sv(index);
} else
sv();
matrix_stack_pop();
2023-05-03 21:42:17 +02:00
matrix_stack_pop();
matrix_stack_pop();
2023-01-01 02:06:02 +01:00
}
_3d_clear_local_transform();
}
2023-02-14 05:32:32 +01:00
static step = function() {
var _proj = inputs[| 20].getValue();
var _patt = inputs[| 16].getValue();
inputs[| 13].setVisible(_patt == 0);
inputs[| 17].setVisible(_patt == 1);
inputs[| 18].setVisible(_patt == 1);
inputs[| 19].setVisible(_patt == 1);
inputs[| 21].setVisible(_proj);
}
2023-07-06 19:49:16 +02:00
function update(frame = PROJECT.animator.current_frame) {
2023-01-01 02:06:02 +01:00
var _dim = inputs[| 0].getValue();
var _lpos = inputs[| 1].getValue();
var _lrot = inputs[| 2].getValue();
var _lsca = inputs[| 3].getValue();
var _pos = inputs[| 4].getValue();
var _sca = inputs[| 5].getValue();
var _ldir = inputs[| 6].getValue();
var _lhgt = inputs[| 7].getValue();
var _lint = inputs[| 8].getValue();
var _lclr = inputs[| 9].getValue();
var _aclr = inputs[| 10].getValue();
2023-01-09 03:14:20 +01:00
var _proj = inputs[| 20].getValue();
var _fov = inputs[| 21].getValue();
2023-02-23 07:02:19 +01:00
var _dimS = inputs[| 22].getValue();
2023-01-09 03:14:20 +01:00
2023-01-01 02:06:02 +01:00
var _patt = inputs[| 16].getValue();
2023-01-09 03:14:20 +01:00
for( var i = 0; i < array_length(output_display_list) - 1; i++ ) {
var ind = output_display_list[i];
var _outSurf = outputs[| ind].getValue();
var pass = "diff";
switch(ind) {
case 0 : pass = "diff" break;
case 2 : pass = "norm" break;
}
2023-01-01 02:06:02 +01:00
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-06-13 14:42:06 +02:00
_outSurf = _3d_pre_setup(_outSurf, _dim, _transform, _light, _cam, pass);
2023-01-09 03:14:20 +01:00
submit_vertex();
_3d_post_setup();
2023-05-03 21:42:17 +02:00
outputs[| ind].setValue(_outSurf);
2023-01-09 03:14:20 +01:00
}
2023-01-01 02:06:02 +01:00
}
}