3d anchor

This commit is contained in:
MakhamDev 2023-10-08 14:22:01 +07:00
parent ccc84a082b
commit f9dd8a8964
11 changed files with 71 additions and 44 deletions

View file

@ -15,6 +15,7 @@ function Node_3D(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constr
static getPreviewObject = function() { #region
if(ds_list_empty(outputs)) return noone;
switch(outputs[| preview_channel].type) {
case VALUE_TYPE.d3Mesh :
case VALUE_TYPE.d3Light :
@ -25,8 +26,7 @@ function Node_3D(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constr
}
var _obj = outputs[| 0].getValue();
if(is_array(_obj))
_obj = array_safe_get(_obj, preview_index, noone);
if(is_array(_obj)) _obj = array_safe_get(_obj, preview_index, noone);
return _obj;
} #endregion

View file

@ -14,9 +14,12 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
inputs[| 2] = nodeValue("Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1, 1 ])
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 3] = nodeValue("Anchor", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ])
.setDisplay(VALUE_DISPLAY.vector);
in_d3d = ds_list_size(inputs);
#macro __d3d_input_list_transform ["Transform", false], 0, 1, 2
#macro __d3d_input_list_transform ["Transform", false], 0, 3, 1, 2
#region ---- overlay ----
drag_axis = noone;
@ -594,8 +597,10 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
var _pos = _data[0];
var _rot = _data[1];
var _sca = _data[2];
var _anc = _data[3];
object.transform.position.set( _pos[0], _pos[1], _pos[2]);
object.transform.anchor.set( _anc[0], _anc[1], _anc[2]);
object.transform.rotation.set( _rot[0], _rot[1], _rot[2], _rot[3]);
object.transform.scale.set( _sca[0], _sca[1], _sca[2]);

View file

@ -1,5 +1,6 @@
function __3dGroup() constructor {
objects = [];
transform = new __transform();
static getCenter = function() { #region
@ -49,6 +50,11 @@ function __3dGroup() constructor {
return new __bbox3D(_m0, _m1);
} #endregion
static addObject = function(_obj) { #region
gml_pragma("forceinline");
array_push(objects, _obj);
} #endregion
static submit = function(scene = {}, shader = noone) {
transform.submitMatrix();
for( var i = 0, n = array_length(objects); i < n; i++ )
@ -77,7 +83,7 @@ function __3dGroup() constructor {
static submitShadow = function(scene = {}, object = noone) {
for( var i = 0, n = array_length(objects); i < n; i++ )
objects[i].submitShadow(scene, object.objects);
objects[i].submitShadow(scene, object);
}
static map = function(callback, scene = {}) { #region

View file

@ -38,12 +38,7 @@ function __3dLight() : __3dObject() constructor {
if(!shadow_active) return;
shadowProjectBegin();
for( var i = 0, n = array_length(objects); i < n; i++ ) {
var _prev = objects[i];
if(!is_struct(_prev)) continue;
_prev.submit(scene, shadow_mapper);
}
objects.submit(scene, shadow_mapper);
shadowProjectEnd();
} #endregion
}

View file

@ -96,11 +96,7 @@ function __3dLightPoint() : __3dLight() constructor {
for( var j = 0; j < 6; j++ ) { ///FUCK There's gotta be a better way to do this in GameMaker
shadowProjectBegin(j);
for( var i = 0, n = array_length(objects); i < n; i++ ) {
var _prev = objects[i];
if(_prev == noone) continue;
_prev.submit(scene, shadow_mapper);
}
objects.submit(scene, shadow_mapper);
shadowProjectEnd();
}

View file

@ -92,7 +92,6 @@ function __3dScene(camera, name = "New scene") constructor {
static submitUI = function(object, shader = noone) { D3DSCENE_PRESUBMIT object.submitUI (self, shader); D3DSCENE_POSTSUBMIT }
static submitSel = function(object, shader = noone) { D3DSCENE_PRESUBMIT object.submitSel (self, shader); D3DSCENE_POSTSUBMIT }
static submitShader = function(object, shader = noone) { D3DSCENE_PRESUBMIT object.submitShader (self, shader); D3DSCENE_POSTSUBMIT }
static submitShadow = function(object) { D3DSCENE_PRESUBMIT object.submitShadow (self, object); D3DSCENE_POSTSUBMIT }
static deferPass = function(object, w, h, deferData = noone) { #region
if(deferData == noone) deferData = {

View file

@ -2,6 +2,7 @@ function __transform() constructor {
parent = noone;
position = new __vec3(0);
anchor = new __vec3(0);
rotation = new BBMOD_Quaternion();
scale = new __vec3(1);
@ -15,15 +16,20 @@ function __transform() constructor {
var sca = matrix_build(0, 0, 0,
0, 0, 0,
scale.x, scale.y, scale.z);
var anc = matrix_build(-anchor.x, -anchor.y, -anchor.z,
0, 0, 0,
1, 1, 1);
matrix_stack_push(pos);
matrix_stack_push(rot);
matrix_stack_push(sca);
matrix_stack_push(anc);
}
static clearMatrix = function() {
matrix_stack_pop();
matrix_stack_pop();
matrix_stack_pop();
matrix_stack_pop();
}
}

View file

@ -273,7 +273,7 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
#region submit
var _bgSurf = _dbg? scene.renderBackground(_dim[0], _dim[1]) : noone;
scene.submitShadow(_sobj);
_sobj.submitShadow(scene, _sobj);
deferData = scene.deferPass(_sobj, _dim[0], _dim[1], deferData);
var _render = outputs[| 0].getValue();

View file

@ -105,15 +105,15 @@ function Node_3D_Mesh_Obj(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group)
obj_read_time = get_timer();
obj_read_file = file_text_open_read(current_path);
use_display_list = false;
}
} #endregion
static updateObjProcess = function() {
static updateObjProcess = function() { #region
switch(obj_read_progress) {
case 0 : readObj_file(); break;
case 1 : readObj_cent(); break;
case 2 : readObj_buff(); break;
}
}
} #endregion
static updateObjComplete = function() { #region
use_display_list = true;
@ -227,5 +227,5 @@ function Node_3D_Mesh_Obj(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group)
draw_set_color(COLORS._main_icon);
//draw_arc(cx, cy, rr, 90, 90 - 360 * (obj_read_progress + obj_read_prog_sub) / obj_read_prog_tot, 4 * _s, 180);
draw_arc(cx, cy, rr, current_time / 5, current_time / 5 + 90, 4 * _s, 90);
}
} #endregion
}

View file

@ -29,24 +29,30 @@ function Node_3D_Repeat(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
inputs[| 8] = nodeValue("Shift Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ] )
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 9] = nodeValue("Positions", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [] )
.setArrayDepth(2);
inputs[| 10] = nodeValue("Rotations", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [] )
.setArrayDepth(2);
inputs[| 11] = nodeValue("Scales", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [] )
.setArrayDepth(2);
outputs[| 0] = nodeValue("Scene", self, JUNCTION_CONNECT.output, VALUE_TYPE.d3Scene, noone);
input_display_list = [
["Objects", false], 0, 3, 4, 5,
["Repeat", false], 1, 2, 6, 7, 8,
["Repeat", false], 1, 2,
["Transforms", false], 9, 10, 11,
["Shift", false], 6, 7, 8,
]
static step = function() { #region
var _mode = array_safe_get(current_data, 1, 0);
//var _tran = array_safe_get(current_data, 9, 0);
var _mode = getSingleValue(1);
inputs[| 0].setArrayDepth(_mode == 1);
inputs[| 2].setVisible(_mode == 0);
//inputs[| 6].setVisible(_tran == 0);
//inputs[| 7].setVisible(_tran == 0);
//inputs[| 8].setVisible(_tran == 0);
} #endregion
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
@ -59,6 +65,10 @@ function Node_3D_Repeat(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
var _Rrot = _data[7];
var _Rsca = _data[8];
var _Apos = _data[ 9];
var _Arot = _data[10];
var _Asca = _data[11];
if(_mode == 1 && !is_array(_object)) return noone;
var _amo = _mode == 1? array_length(_object) : _data[2];
@ -68,24 +78,34 @@ function Node_3D_Repeat(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
var _obj = _mode == 1? _object[i] : _object;
if(_obj == noone) continue;
var _apos = array_safe_get(_Apos, i);
var _arot = array_safe_get(_Arot, i);
var _asca = array_safe_get(_Asca, i);
if(!is_array(_apos) || array_length(_apos) != 3) _apos = [ 0, 0, 0 ];
if(!is_array(_arot) || array_length(_arot) != 4) _arot = [ 0, 0, 0, 1 ];
if(!is_array(_asca) || array_length(_asca) != 3) _asca = [ 0, 0, 0 ];
var _subScene = new __3dGroup();
var _sPos = [ _Spos[0] + _Rpos[0] * i,
_Spos[1] + _Rpos[1] * i,
_Spos[2] + _Rpos[2] * i ];
var _sSca = [ _Ssca[0] + _Rsca[0] * i,
_Ssca[1] + _Rsca[1] * i,
_Ssca[2] + _Rsca[2] * i ];
var _sPos = [ _Spos[0] + _apos[0] + _Rpos[0] * i,
_Spos[1] + _apos[1] + _Rpos[1] * i,
_Spos[2] + _apos[2] + _Rpos[2] * i ];
var _sSca = [ _Ssca[0] + _asca[0] + _Rsca[0] * i,
_Ssca[1] + _asca[1] + _Rsca[1] * i,
_Ssca[2] + _asca[2] + _Rsca[2] * i ];
var _sRot = new BBMOD_Quaternion(_Srot[0], _Srot[1], _Srot[2], _Srot[3]);
var _aRot = new BBMOD_Quaternion(_arot[0], _arot[1], _arot[2], _arot[3]);
var _rRot = new BBMOD_Quaternion(_Rrot[0], _Rrot[1], _Rrot[2], _Rrot[3]);
var _sRotE = _sRot.ToEuler();
var _aRotE = _aRot.ToEuler();
var _rRotE = _rRot.ToEuler();
var _fRotE = [ _sRotE.x + _rRotE.x * i,
_sRotE.y + _rRotE.y * i,
_sRotE.z + _rRotE.z * i ];
var _fRotE = [ _sRotE.x + _aRotE.x + _rRotE.x * i,
_sRotE.y + _aRotE.y + _rRotE.y * i,
_sRotE.z + _aRotE.z + _rRotE.z * i ];
var _fRot = new BBMOD_Quaternion().FromEuler(_fRotE[0], _fRotE[1], _fRotE[2]);
@ -93,8 +113,8 @@ function Node_3D_Repeat(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
_subScene.transform.rotation.set(_fRot.X, _fRot.Y, _fRot.Z, _fRot.W);
_subScene.transform.scale.set(_sSca);
array_push(_subScene.objects, _obj);
array_push(_scene.objects, _subScene);
_subScene.addObject(_obj);
_scene.addObject(_subScene);
}
return _scene;

View file

@ -46,7 +46,7 @@ function Node_3D_Scene(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constru
var _obj = _data[i];
if(_obj == noone) continue;
array_push(_scene.objects, _obj);
_scene.addObject(_obj);
}
return _scene;