From f3808c425126c8acd361c72f8c878d3de2b910c0 Mon Sep 17 00:00:00 2001 From: Onek8 Date: Wed, 28 May 2025 22:24:50 +0000 Subject: [PATCH] t3du - New Image nodes: Draw Sub Image and Write Image --- .../leenkx/logicnode/DrawSubImageNode.hx | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 leenkx/Sources/leenkx/logicnode/DrawSubImageNode.hx diff --git a/leenkx/Sources/leenkx/logicnode/DrawSubImageNode.hx b/leenkx/Sources/leenkx/logicnode/DrawSubImageNode.hx new file mode 100644 index 0000000..4318c1c --- /dev/null +++ b/leenkx/Sources/leenkx/logicnode/DrawSubImageNode.hx @@ -0,0 +1,59 @@ +package leenkx.logicnode; + +import iron.math.Vec4; +import kha.Image; +import kha.Color; +import leenkx.renderpath.RenderToTexture; + +class DrawSubImageNode extends LogicNode { + var img: Image; + var lastImgName = ""; + + public function new(tree: LogicTree) { + super(tree); + } + + override function run(from: Int) { + RenderToTexture.ensure2DContext("DrawImageNode"); + + final imgName: String = inputs[1].get(); + final colorVec: Vec4 = inputs[2].get(); + final anchorH: Int = inputs[3].get(); + final anchorV: Int = inputs[4].get(); + final x: Float = inputs[5].get(); + final y: Float = inputs[6].get(); + final width: Float = inputs[7].get(); + final height: Float = inputs[8].get(); + final sx: Float = inputs[9].get(); + final sy: Float = inputs[10].get(); + final swidth: Float = inputs[11].get(); + final sheight: Float = inputs[12].get(); + final angle: Float = inputs[13].get(); + + final drawx = x - 0.5 * width * anchorH; + final drawy = y - 0.5 * height * anchorV; + final sdrawx = sx - 0.5 * swidth * anchorH; + final sdrawy = sy - 0.5 * sheight * anchorV; + + RenderToTexture.g.rotate(angle, x, y); + + if (imgName != lastImgName) { + // Load new image + lastImgName = imgName; + iron.data.Data.getImage(imgName, (image: Image) -> { + img = image; + }); + } + + if (img == null) { + runOutput(0); + return; + } + + RenderToTexture.g.color = Color.fromFloats(colorVec.x, colorVec.y, colorVec.z, colorVec.w); + RenderToTexture.g.drawScaledSubImage(img, sdrawx, sdrawy, swidth, sheight, drawx, drawy, width, height); + RenderToTexture.g.rotate(-angle, x, y); + + runOutput(0); + } +}