apply batched mesh to all things

This commit is contained in:
tresabhi committed 2026-11-29 21:57:28 -06:00
1 parent 19fdb087c5
commit 3078dfeb10
21 files changed
+844 -892

No files matched your search

@@ -0,0 +1,31 @@
import { Matrix4, type Object3D } from "three";
export interface FlatNode {
object: Object3D;
// relative to the root's parent, like jsxTree renders it
matrix: Matrix4;
root: Object3D;
}
function allChildren(object: Object3D) {
return object.children;
}
// every object under the roots; children picks which ones to descend into
export function flattenNodes(roots: Object3D[], children = allChildren) {
const flat: FlatNode[] = [];
function walk(object: Object3D, parent: Matrix4, root: Object3D) {
object.updateMatrix();
const matrix = parent.clone().multiply(object.matrix);
flat.push({ object, matrix, root });
for (const child of children(object)) walk(child, matrix, root);
}
for (const root of roots) walk(root, new Matrix4(), root);
return flat;
}