mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-04 23:32:54 +01:00
apply batched mesh to all things
This commit is contained in:
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;
|
||||
}
|
||||
Reference in new issue
Block a user