forked from LeenkxTeam/LNXSDK
Repe [T3DU] Update - 31f26d171bba0355ce2a77031e3aad4c64dbc7e9
This commit is contained in:
@ -1,12 +1,15 @@
|
||||
package leenkx.logicnode;
|
||||
|
||||
import iron.math.Vec4;
|
||||
import iron.RenderPath;
|
||||
import kha.Image;
|
||||
import kha.Color;
|
||||
import leenkx.renderpath.RenderToTexture;
|
||||
|
||||
class DrawImageRenderNode extends LogicNode {
|
||||
var img: Image;
|
||||
var img2D: Image;
|
||||
var initialized: Bool = false;
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
super(tree);
|
||||
@ -14,8 +17,21 @@ class DrawImageRenderNode extends LogicNode {
|
||||
|
||||
override function run(from: Int) {
|
||||
|
||||
if (from == 1)
|
||||
if (from == 1){
|
||||
if (inputs[16].get()){
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
img = kha.Image.createRenderTarget(iron.App.w(), iron.App.h(),
|
||||
kha.graphics4.TextureFormat.RGBA32,
|
||||
kha.graphics4.DepthStencilFormat.NoDepthAndStencil);
|
||||
if (inputs[15].get() || kha.Image.renderTargetsInvertedY())
|
||||
img2D = kha.Image.createRenderTarget(iron.App.w(), iron.App.h(),
|
||||
kha.graphics4.TextureFormat.RGBA32,
|
||||
kha.graphics4.DepthStencilFormat.NoDepthAndStencil);
|
||||
tree.notifyOnRender(render);
|
||||
}
|
||||
else {
|
||||
|
||||
RenderToTexture.ensure2DContext("DrawImageRenderNode");
|
||||
@ -38,12 +54,14 @@ class DrawImageRenderNode extends LogicNode {
|
||||
|
||||
RenderToTexture.g.rotate(angle, x, y);
|
||||
|
||||
if (img != null){
|
||||
RenderToTexture.g.color = 0xff000000;
|
||||
RenderToTexture.g.fillRect(drawx, drawy, width, height);
|
||||
RenderToTexture.g.color = RenderToTexture.g.color = Color.fromFloats(colorVec.x, colorVec.y, colorVec.z, colorVec.w);
|
||||
RenderToTexture.g.color = 0xff000000;
|
||||
RenderToTexture.g.fillRect(drawx, drawy, width, height);
|
||||
RenderToTexture.g.color = RenderToTexture.g.color = Color.fromFloats(colorVec.x, colorVec.y, colorVec.z, colorVec.w);
|
||||
|
||||
if ((inputs[15].get() || kha.Image.renderTargetsInvertedY()) && img2D != null)
|
||||
RenderToTexture.g.drawScaledSubImage(img2D, sx, sy, swidth, sheight, drawx, drawy, width, height);
|
||||
else if(img != null)
|
||||
RenderToTexture.g.drawScaledSubImage(img, sx, sy, swidth, sheight, drawx, drawy, width, height);
|
||||
}
|
||||
|
||||
RenderToTexture.g.rotate(-angle, x, y);
|
||||
|
||||
@ -54,13 +72,11 @@ class DrawImageRenderNode extends LogicNode {
|
||||
}
|
||||
|
||||
function render(g: kha.graphics4.Graphics) {
|
||||
final rpPaused = RenderPath.active.paused;
|
||||
RenderPath.active.paused = false;
|
||||
|
||||
var camera = inputs[2].get();
|
||||
|
||||
img = kha.Image.createRenderTarget(iron.App.w(), iron.App.h(),
|
||||
kha.graphics4.TextureFormat.RGBA32,
|
||||
kha.graphics4.DepthStencilFormat.NoDepthAndStencil);
|
||||
|
||||
final sceneCam = iron.Scene.active.camera;
|
||||
final oldRT = camera.renderTarget;
|
||||
|
||||
@ -69,38 +85,30 @@ class DrawImageRenderNode extends LogicNode {
|
||||
|
||||
camera.renderFrame(g);
|
||||
|
||||
img = camera.renderTarget;
|
||||
|
||||
if (inputs[15].get() || kha.Image.renderTargetsInvertedY()) {
|
||||
|
||||
img = kha.Image.createRenderTarget(iron.App.w(), iron.App.h(),
|
||||
kha.graphics4.TextureFormat.RGBA32,
|
||||
kha.graphics4.DepthStencilFormat.NoDepthAndStencil);
|
||||
img2D.g2.begin(true, Color.Transparent);
|
||||
img2D.g2.color = Color.White;
|
||||
|
||||
img.g2.begin(true, Color.Transparent);
|
||||
if (kha.Image.renderTargetsInvertedY())
|
||||
img2D.g2.drawScaledImage(camera.renderTarget, 0, iron.App.h(), iron.App.w(), -iron.App.h());
|
||||
else
|
||||
img2D.g2.drawImage(camera.renderTarget, 0, 0);
|
||||
|
||||
img.g2.color = Color.White;
|
||||
|
||||
if (kha.Image.renderTargetsInvertedY()) {
|
||||
img.g2.drawScaledImage(camera.renderTarget, 0, iron.App.h(), iron.App.w(), -iron.App.h());
|
||||
} else {
|
||||
img.g2.drawImage(camera.renderTarget, 0, 0);
|
||||
}
|
||||
|
||||
if (inputs[15].get()) {
|
||||
for (f in @:privateAccess iron.App.traitRenders2D) {
|
||||
f(img.g2);
|
||||
}
|
||||
}
|
||||
|
||||
img.g2.end();
|
||||
if (inputs[15].get())
|
||||
for (f in @:privateAccess iron.App.traitRenders2D)
|
||||
f(img2D.g2);
|
||||
|
||||
img2D.g2.end();
|
||||
}
|
||||
|
||||
camera.renderTarget = oldRT;
|
||||
iron.Scene.active.camera = sceneCam;
|
||||
|
||||
tree.removeRender(render);
|
||||
RenderPath.active.paused = rpPaused;
|
||||
|
||||
if (!inputs[16].get())
|
||||
tree.removeRender(render);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user