- [Render Sprite Sheer] Now output flattened atlas array.

This commit is contained in:
Tanasart 2024-06-15 13:33:31 +07:00
parent d4546ee7fe
commit c9f3b8d46e
5 changed files with 289 additions and 18 deletions

View file

@ -360,7 +360,7 @@ function __part(_node) : __particleObject() constructor {
ss = array_safe_get_fast(surf, clamp(_sca, 0, array_length(surf) - 1));
}
var surface = is_instanceof(ss, SurfaceAtlas)? ss.getSurface() : node.surface_cache[$ ss];
var surface = node.surface_cache[$ ss];
var _useS = is_surface(surface);
if(arr_type == 3) {

View file

@ -339,11 +339,12 @@ function Node_VFX_Spawner_Base(_x, _y, _group = noone) : Node(_x, _y, _group) co
if(array_empty(surfs)) return;
if(!is_array(surfs)) surfs = [ surfs ];
surfs = array_spread(surfs);
for( var i = 0, n = array_length(surfs); i < n; i++ ) {
var _s = surfs[i];
if(is_surface(surface_cache[$ _s]))
if(surface_exists(surface_cache[$ _s]))
continue;
if(is_instanceof(_s, SurfaceAtlas))

View file

@ -54,8 +54,7 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
outputs[| 1] = nodeValue("Atlas Data", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, [])
.setArrayDepth(1);
outputs[| 1] = nodeValue("Atlas Data", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, []);
input_display_list = [
["Surfaces", false], 0, 1, 2,
@ -65,6 +64,8 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
["Custom Range", true, 11], 8,
]
atlases = [];
attribute_surface_depth();
static onInspector1Update = function(updateAll = true) { initSurface(true); PROJECT.animator.render(); }
@ -154,7 +155,7 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
var ww = 0;
var hh = 0;
var _atl = [];
atlases = [];
#region surface generate
@ -235,7 +236,7 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
case 2 : _sy = py + (hh - _h); break;
}
array_push(_atl, new SurfaceAtlas(inpt[i], _sx, _sy));
array_push(atlases, new SurfaceAtlas(inpt[i], _sx, _sy));
draw_surface_safe(inpt[i], _sx, _sy);
px += _w + spac;
@ -258,7 +259,7 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
case 2 : _sx = px + (ww - _w); break;
}
array_push(_atl, new SurfaceAtlas(inpt[i], _sx, _sy));
array_push(atlases, new SurfaceAtlas(inpt[i], _sx, _sy));
draw_surface_safe(inpt[i], _sx, _sy);
py += _h + spac;
@ -289,7 +290,7 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
curr_w = curr_w == -1? _w : curr_w; curr_h = curr_h == -1? _h : curr_h;
if(curr_w != _w || curr_h != _h) noti_warning("Spritesheet node does not support different surfaces size. Use Stack, Image grid, or pack sprite.");
array_push(_atl, new SurfaceAtlas(inpt[index], px, py));
array_push(atlases, new SurfaceAtlas(inpt[index], px, py));
draw_surface_safe(inpt[index], px, py);
px += _w + spc2[0];
@ -304,7 +305,7 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
#endregion
outputs[| 0].setValue(_surf);
outputs[| 1].setValue(_atl);
outputs[| 1].setValue(array_spread(atlases));
} #endregion
anim_curr_w = -1;
@ -324,7 +325,6 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
var user = getInputData(11);
var _out = outputs[| 0].getValue();
var _atl = outputs[| 1].getValue();
var cDep = attrDepth();
printIf(log, $"Init animation");
@ -359,7 +359,7 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
var _surfi = inpt[i];
if(!is_surface(_surfi)) continue;
_atl[i] = [];
atlases[i] = [];
var sw = surface_get_width_safe(_surfi);
var sh = surface_get_height_safe(_surfi);
@ -394,7 +394,7 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
if(!arr) _out = array_safe_get_fast(_out, 0);
outputs[| 0].setValue(_out);
outputs[| 1].setValue(_atl);
outputs[| 1].setValue(array_spread(atlases));
printIf(log, $"Surface generated [{ww}, {hh}]");
} #endregion
@ -412,7 +412,6 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
//var ovlp = getInputData(10);
var user = getInputData(11);
var _atl = outputs[| 1].getValue();
var cDep = attrDepth();
printIf(log, $"Rendering animation {name}/{CURRENT_FRAME}");
@ -463,13 +462,13 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
if(!is_surface(_surfi)) {
printIf(log, $" > Skip input not surface");
_atl[i] = noone;
atlases[i] = noone;
break;
}
if(!is_array(array_safe_get_fast(_atl, i)))
_atl[i] = [];
var _atli = _atl[i];
if(!is_array(array_safe_get_fast(atlases, i)))
atlases[i] = [];
var _atli = atlases[i];
var oo = noone;
if(!is_array(oupt)) oo = oupt;
@ -538,6 +537,6 @@ function Node_Render_Sprite_Sheet(_x, _y, _group = noone) : Node(_x, _y, _group)
} #endregion
if(drawn) array_safe_set(anim_drawn, CURRENT_FRAME, true);
outputs[| 1].setValue(_atl);
outputs[| 1].setValue(array_spread(atlases));
} #endregion
}

View file

@ -172,7 +172,237 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con
environ = new RM_Environment();
object = new RM_Shape();
tool_pos = new NodeTool( "Transform", THEME.tools_3d_transform, "Node_3D_Object" );
tools = [ tool_pos ];
#region ---- overlay ----
drag_axis = noone;
drag_sv = 0;
drag_delta = 0;
drag_prev = 0;
drag_dist = 0;
drag_val = 0;
drag_mx = 0;
drag_my = 0;
drag_px = 0;
drag_py = 0;
drag_cx = 0;
drag_cy = 0;
drag_rot_axis = new BBMOD_Quaternion();
drag_original = 0;
axis_hover = noone;
#endregion
static drawGizmoPosition = function(index, _vpos, active, params, _mx, _my, _snx, _sny, _panel) { #region
#region ---- main ----
var _pos = inputs[| index].getValue(,,, true);
var _qinv = new BBMOD_Quaternion().FromAxisAngle(new BBMOD_Vec3(1, 0, 0), 90);
var _camera = params.camera;
var _qview = new BBMOD_Quaternion().FromEuler(_camera.focus_angle_y, -_camera.focus_angle_x, 0);
var _hover = noone;
var _hoverDist = 10;
var th;
var _posView = _camera.worldPointToViewPoint(_vpos);
var cx = _posView.x;
var cy = _posView.y;
var ga = [];
var size = 64;
var hs = size / 2;
var sq = 8;
#endregion
#region display
ga[0] = new BBMOD_Vec3(-size, 0, 0);
ga[1] = new BBMOD_Vec3(0, 0, size);
ga[2] = new BBMOD_Vec3(0, -size, 0);
ga[3] = [ new BBMOD_Vec3(-hs + sq, 0, hs - sq),
new BBMOD_Vec3(-hs - sq, 0, hs - sq),
new BBMOD_Vec3(-hs - sq, 0, hs + sq),
new BBMOD_Vec3(-hs + sq, 0, hs + sq), ];
ga[4] = [ new BBMOD_Vec3( 0, -hs + sq, hs - sq),
new BBMOD_Vec3( 0, -hs - sq, hs - sq),
new BBMOD_Vec3( 0, -hs - sq, hs + sq),
new BBMOD_Vec3( 0, -hs + sq, hs + sq), ];
ga[5] = [ new BBMOD_Vec3(-hs + sq, -hs - sq, 0),
new BBMOD_Vec3(-hs - sq, -hs - sq, 0),
new BBMOD_Vec3(-hs - sq, -hs + sq, 0),
new BBMOD_Vec3(-hs + sq, -hs + sq, 0), ];
ga[0] = new BBMOD_Vec3(-size, 0, 0);
ga[1] = new BBMOD_Vec3(0, -size, 0);
ga[2] = new BBMOD_Vec3(0, 0, -size);
ga[3] = [ new BBMOD_Vec3(-hs + sq, -hs - sq, 0),
new BBMOD_Vec3(-hs - sq, -hs - sq, 0),
new BBMOD_Vec3(-hs - sq, -hs + sq, 0),
new BBMOD_Vec3(-hs + sq, -hs + sq, 0), ];
ga[4] = [ new BBMOD_Vec3( 0, -hs + sq, -hs - sq),
new BBMOD_Vec3( 0, -hs - sq, -hs - sq),
new BBMOD_Vec3( 0, -hs - sq, -hs + sq),
new BBMOD_Vec3( 0, -hs + sq, -hs + sq), ];
ga[5] = [ new BBMOD_Vec3(-hs + sq, 0, -hs - sq),
new BBMOD_Vec3(-hs - sq, 0, -hs - sq),
new BBMOD_Vec3(-hs - sq, 0, -hs + sq),
new BBMOD_Vec3(-hs + sq, 0, -hs + sq), ];
for( var i = 0; i < 3; i++ ) {
ga[i] = _qview.Rotate(_qinv.Rotate(ga[i]));
th = 2 + (axis_hover == i || drag_axis == i);
if(drag_axis != noone && drag_axis != i)
continue;
draw_set_color(COLORS.axis[i]);
if(point_distance(cx, cy, cx + ga[i].X, cy + ga[i].Y) < 5)
draw_line_round(cx, cy, cx + ga[i].X, cy + ga[i].Y, th);
else
draw_line_round_arrow(cx, cy, cx + ga[i].X, cy + ga[i].Y, th, 3);
var _d = distance_to_line(_mx, _my, cx, cy, cx + ga[i].X, cy + ga[i].Y);
if(_d < _hoverDist) {
_hover = i;
_hoverDist = _d;
}
}
for( var i = 3; i < 6; i++ ) {
for( var j = 0; j < 4; j++ )
ga[i][j] = _qview.Rotate(_qinv.Rotate(ga[i][j]));
th = 1;
var p0x = cx + ga[i][0].X, p0y = cy + ga[i][0].Y;
var p1x = cx + ga[i][1].X, p1y = cy + ga[i][1].Y;
var p2x = cx + ga[i][2].X, p2y = cy + ga[i][2].Y;
var p3x = cx + ga[i][3].X, p3y = cy + ga[i][3].Y;
var _pax = (p0x + p1x + p2x + p3x) / 4;
var _pay = (p0y + p1y + p2y + p3y) / 4;
if((abs(p0x - _pax) + abs(p1x - _pax) + abs(p2x - _pax) + abs(p3x - _pax)) / 4 < 1)
continue;
if((abs(p0y - _pay) + abs(p1y - _pay) + abs(p2y - _pay) + abs(p3y - _pay)) / 4 < 1)
continue;
draw_set_color(COLORS.axis[(i - 3 - 1 + 3) % 3]);
if(axis_hover == i || drag_axis == i) {
draw_primitive_begin(pr_trianglestrip);
draw_vertex(p0x, p0y);
draw_vertex(p1x, p1y);
draw_vertex(p3x, p3y);
draw_vertex(p2x, p2y);
draw_primitive_end();
} else if (drag_axis == noone) {
draw_line(p0x, p0y, p1x, p1y);
draw_line(p1x, p1y, p2x, p2y);
draw_line(p2x, p2y, p3x, p3y);
draw_line(p3x, p3y, p0x, p0y);
} else
continue;
if(point_in_rectangle_points(_mx, _my, p0x, p0y, p1x, p1y, p3x, p3y, p2x, p2y))
_hover = i;
}
axis_hover = _hover;
#endregion display
if(drag_axis != noone) { #region editing
if(!MOUSE_WRAPPING) {
drag_mx += _mx - drag_px;
drag_my += _my - drag_py;
var mAdj, nor, prj;
var ray = _camera.viewPointToWorldRay(drag_mx, drag_my);
var val = [ drag_val[0], drag_val[1], drag_val[2] ];
if(drag_axis < 3) {
switch(drag_axis) {
case 0 : nor = new __vec3(0, 1, 0); prj = new __vec3(1, 0, 0); break;
case 1 : nor = new __vec3(0, 0, 1); prj = new __vec3(0, 1, 0); break;
case 2 : nor = new __vec3(1, 0, 0); prj = new __vec3(0, 0, 1); break;
}
var pln = new __plane(drag_original, nor);
mAdj = d3d_intersect_ray_plane(ray, pln);
if(drag_prev != undefined) {
var _diff = mAdj.subtract(drag_prev);
var _dist = _diff.dot(prj);
for( var i = 0; i < 3; i++ )
val[i] += prj.getIndex(i) * _dist;
if(inputs[| index].setValue(value_snap(val, _snx)))
UNDO_HOLDING = true;
}
} else {
switch(drag_axis) {
case 3 : nor = new __vec3(0, 0, 1); break;
case 4 : nor = new __vec3(1, 0, 0); break;
case 5 : nor = new __vec3(0, 1, 0); break;
}
var pln = new __plane(drag_original, nor);
mAdj = d3d_intersect_ray_plane(ray, pln);
if(drag_prev != undefined) {
var _diff = mAdj.subtract(drag_prev);
for( var i = 0; i < 3; i++ )
val[i] += _diff.getIndex(i);
if(inputs[| index].setValue(value_snap(val, _snx)))
UNDO_HOLDING = true;
}
}
drag_val = [ val[0], val[1], val[2] ];
drag_prev = mAdj;
}
setMouseWrap();
drag_px = _mx;
drag_py = _my;
} #endregion
if(_hover != noone && mouse_press(mb_left, active)) { #region
drag_axis = _hover;
drag_prev = undefined;
drag_mx = _mx;
drag_my = _my;
drag_px = _mx;
drag_py = _my;
drag_cx = cx;
drag_cy = cy;
drag_val = _pos;
drag_original = new __vec3(_pos);
} #endregion
} #endregion
static drawOverlay3D = function(active, params, _mx, _my, _snx, _sny, _panel) {
var _pos = getSingleValue(2);
var _vpos = new __vec3( _pos[0], _pos[1], _pos[2] );
if(isUsingTool("Transform")) drawGizmoPosition(2, _vpos, active, params, _mx, _my, _snx, _sny, _panel);
if(drag_axis != noone && mouse_release(mb_left)) {
drag_axis = noone;
UNDO_HOLDING = false;
}
}

View file

@ -1133,6 +1133,47 @@ function Panel_Preview() : PanelContent() constructor {
function draw3DSdf(_node) { #region
_node.previewing = 1;
d3_scene_preview = d3_scene;
d3_scene_preview.camera = d3_view_camera;
#region view
var _pos, targ, _blend = 1;
targ = d3_camTarget;
_pos = d3d_PolarToCart(targ.x, targ.y, targ.z, d3_view_camera.focus_angle_x, d3_view_camera.focus_angle_y, d3_view_camera.focus_dist);
if(d3_active_transition == 1) {
var _up = new __vec3(0, 0, -1);
d3_view_camera.position._lerp_float(_pos, 5, 0.1);
d3_view_camera.focus._lerp_float( targ, 5, 0.1);
d3_view_camera.up._lerp_float( _up, 5, 0.1);
if(d3_view_camera.position.equal(_pos) && d3_view_camera.focus.equal(targ))
d3_active_transition = 0;
} else if(d3_active_transition == -1) {
var _pos = new __vec3(0, 0, 8);
var targ = new __vec3(0, 0, 0);
var _up = new __vec3(0, 1, 0);
d3_view_camera.position._lerp_float(_pos, 5, 0.1);
d3_view_camera.focus._lerp_float( targ, 5, 0.1);
d3_view_camera.up._lerp_float( _up, 5, 0.1);
_blend = d3_view_camera.position.distance(_pos) / 2;
_blend = clamp(_blend, 0, 1);
if(d3_view_camera.position.equal(_pos) && d3_view_camera.focus.equal(targ))
d3_active_transition = 0;
} else {
d3_view_camera.position.set(_pos);
d3_view_camera.focus.set(targ);
}
d3_view_camera.setViewSize(w, h);
d3_view_camera.setMatrix();
#endregion
var _env = _node.environ;
var _obj = _node.object;