Files
LNXSDK/leenkx/Sources/iron/culling/OccluderProxy.hx
2026-10-15 02:41:03 -07:00

72 lines
2.0 KiB
Haxe

package iron.culling;
class OccluderProxy {
public var positions: kha.arrays.Float32Array;
public var indices: kha.arrays.Uint32Array;
public var triangleCount: Int;
public var meshUid: Int;
var worldPositions: kha.arrays.Float32Array;
var mvp: iron.math.Mat4;
public function new() {
indices = new kha.arrays.Uint32Array(0);
triangleCount = 0;
}
public function setData(pos: kha.arrays.Float32Array, idx: kha.arrays.Uint32Array, uid: Int) {
#if js
if (!Std.isOfType(pos, js.lib.DataView)) {
var srcF: Array<Float> = cast pos;
var dstF = new kha.arrays.Float32Array(srcF.length);
for (i in 0...srcF.length) dstF[i] = srcF[i];
pos = dstF;
}
if (!Std.isOfType(idx, js.lib.DataView)) {
var srcI: Array<Int> = cast idx;
var dstI = new kha.arrays.Uint32Array(srcI.length);
for (i in 0...srcI.length) dstI[i] = srcI[i];
idx = dstI;
}
#end
positions = pos;
indices = idx;
triangleCount = Std.int(idx.length / 3);
meshUid = uid;
}
public function rasterize(
rasterizer: SoftwareOcclusionRasterizer,
world: iron.math.Mat4,
vp: iron.math.Mat4,
screenW: Int, screenH: Int
) {
if (positions == null || indices == null || triangleCount == 0) return;
var vertCount = Std.int(positions.length / 3);
var clipSize = vertCount * 4;
if (worldPositions == null || worldPositions.length < clipSize) {
worldPositions = new kha.arrays.Float32Array(clipSize);
}
if (mvp == null) mvp = iron.math.Mat4.identity();
mvp.multmats(vp, world);
for (i in 0...vertCount) {
var x = positions[i * 3];
var y = positions[i * 3 + 1];
var z = positions[i * 3 + 2];
var off = i * 4;
worldPositions[off] = mvp._00 * x + mvp._10 * y + mvp._20 * z + mvp._30;
worldPositions[off + 1] = mvp._01 * x + mvp._11 * y + mvp._21 * z + mvp._31;
worldPositions[off + 2] = mvp._02 * x + mvp._12 * y + mvp._22 * z + mvp._32;
worldPositions[off + 3] = mvp._03 * x + mvp._13 * y + mvp._23 * z + mvp._33;
}
rasterizer.rasterizeProxyTransformed(worldPositions, indices, screenW, screenH);
}
}