- [3D] Add option to apply anchor point to position.

This commit is contained in:
Tanasart 2024-06-02 11:58:48 +07:00
parent 70bb9cd261
commit 1dace22a61
8 changed files with 63 additions and 8 deletions

View file

@ -405,6 +405,7 @@
{"name":"d3d_cube","order":1,"path":"scripts/d3d_cube/d3d_cube.yy",},
{"name":"d3d_cylinder_nocaps","order":9,"path":"scripts/d3d_cylinder_nocaps/d3d_cylinder_nocaps.yy",},
{"name":"d3d_cylinder","order":2,"path":"scripts/d3d_cylinder/d3d_cylinder.yy",},
{"name":"d3d_gizmo_axis","order":7,"path":"scripts/d3d_gizmo_axis/d3d_gizmo_axis.yy",},
{"name":"d3d_gizmo_circle_z","order":4,"path":"scripts/d3d_gizmo_circle_z/d3d_gizmo_circle_z.yy",},
{"name":"d3d_gizmo_line_dashed","order":3,"path":"scripts/d3d_gizmo_line_dashed/d3d_gizmo_line_dashed.yy",},
{"name":"d3d_gizmo_line","order":1,"path":"scripts/d3d_gizmo_line/d3d_gizmo_line.yy",},

View file

@ -767,6 +767,7 @@
{"id":{"name":"d3d_cube","path":"scripts/d3d_cube/d3d_cube.yy",},},
{"id":{"name":"d3d_cylinder_nocaps","path":"scripts/d3d_cylinder_nocaps/d3d_cylinder_nocaps.yy",},},
{"id":{"name":"d3d_cylinder","path":"scripts/d3d_cylinder/d3d_cylinder.yy",},},
{"id":{"name":"d3d_gizmo_axis","path":"scripts/d3d_gizmo_axis/d3d_gizmo_axis.yy",},},
{"id":{"name":"d3d_gizmo_circle_z","path":"scripts/d3d_gizmo_circle_z/d3d_gizmo_circle_z.yy",},},
{"id":{"name":"d3d_gizmo_line_dashed","path":"scripts/d3d_gizmo_line_dashed/d3d_gizmo_line_dashed.yy",},},
{"id":{"name":"d3d_gizmo_line","path":"scripts/d3d_gizmo_line/d3d_gizmo_line.yy",},},

Binary file not shown.

View file

@ -1,12 +1,15 @@
function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constructor {
name = "3D Object";
gizmo = new __3dGizmoAxis(.2, COLORS._main_accent);
cached_object = [];
object_class = noone;
preview_channel = 0;
apply_anchor = false;
inputs[| 0] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ])
.setDisplay(VALUE_DISPLAY.vector);
.setDisplay(VALUE_DISPLAY.vector, { linkable: false });
inputs[| 1] = nodeValue("Rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0, 1 ])
.setDisplay(VALUE_DISPLAY.d3quarternion);
@ -15,7 +18,12 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 3] = nodeValue("Anchor", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ])
.setDisplay(VALUE_DISPLAY.vector);
.setDisplay(VALUE_DISPLAY.vector, {
linkable: false,
side_button : button(function() { apply_anchor = !apply_anchor; triggerRender(); })
.setIcon(THEME.icon_3d_anchor, [ function() /*=>*/ {return apply_anchor} ], c_white)
.setTooltip("Apply Position")
});
in_d3d = ds_list_size(inputs);
@ -616,6 +624,15 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
var _sca = _data[2];
var _anc = _data[3];
if(apply_anchor)
_pos = [
_pos[0] + _anc[0],
_pos[1] + _anc[1],
_pos[2] + _anc[2],
];
gizmo.transform.position.set( _pos[0], _pos[1], _pos[2]);
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]);
@ -626,6 +643,7 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
static getObject = function(index, class = object_class) { #region
var _obj = array_safe_get_fast(cached_object, index, noone);
if(_obj == noone) {
_obj = new class();
} else if(!is_instanceof(_obj, class)) {
@ -636,4 +654,8 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr
cached_object[index] = _obj;
return _obj;
} #endregion
static getPreviewObjects = function() { return [ getPreviewObject(), gizmo ]; }
static getPreviewObjectOutline = function() { return [ getPreviewObject(), gizmo ]; }
}

View file

@ -0,0 +1,18 @@
function __3dGizmoAxis(_size = .5, color = c_white, alpha = 1) : __3dGizmo() constructor {
vertex = [
[
new __vertex( -_size, 0, 0, color, alpha ),
new __vertex( _size, 0, 0, color, alpha ),
],
[
new __vertex( 0, -_size, 0, color, alpha ),
new __vertex( 0, _size, 0, color, alpha ),
],
[
new __vertex( 0, 0, -_size, color, alpha ),
new __vertex( 0, 0, _size, color, alpha ),
],
];
object_counts = 3;
VB = build();
}

View file

@ -0,0 +1,13 @@
{
"$GMScript":"",
"%Name":"d3d_gizmo_axis",
"isCompatibility":false,
"isDnD":false,
"name":"d3d_gizmo_axis",
"parent":{
"name":"gizmo",
"path":"folders/functions/3d/gizmo.yy",
},
"resourceType":"GMScript",
"resourceVersion":"2.0",
}

View file

@ -121,6 +121,7 @@ function __3dObject() constructor {
_s.show_normal = false;
submitVertex(_s, sh_d3d_silhouette);
} #endregion
static submitShader = function(scene = {}, shader = noone) {}
static submitShadow = function(scene = {}, object = noone) {}

View file

@ -1022,13 +1022,12 @@ function Panel_Preview() : PanelContent() constructor {
d3_scene_preview.apply(d3_deferData);
//print("========= Submit begin =========");
for( var i = 0, n = array_length(_prev_obj); i < n; i++ ) {
var _prev = _prev_obj[i];
if(_prev == noone) continue;
_prev.submitUI(d3_scene_preview); //////////////// SUBMIT ////////////////
_prev.submitUI(d3_scene_preview);
}
//print("========= Submit end =========");
gpu_set_cullmode(cull_noculling);
surface_reset_target();