40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
import { performance } from "node:perf_hooks";
|
|
import { fileURLToPath } from "node:url";
|
|
import { dirname, resolve } from "node:path";
|
|
import { NodeIO } from "@gltf-transform/core";
|
|
import RAPIER from "@dimforge/rapier3d-compat";
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const collisionPath = resolve(
|
|
here,
|
|
"../src/assets/game/dungeons/wailing-caverns/wailing-caverns-collision.glb",
|
|
);
|
|
|
|
const readStarted = performance.now();
|
|
const document = await new NodeIO().read(collisionPath);
|
|
const primitive = document.getRoot().listMeshes()[0]?.listPrimitives()[0];
|
|
if (!primitive) throw new Error("Collision GLB has no mesh primitive.");
|
|
|
|
const positions = primitive.getAttribute("POSITION")?.getArray();
|
|
const indices = primitive.getIndices()?.getArray();
|
|
if (!positions || !indices) throw new Error("Collision GLB lacks indexed positions.");
|
|
const readFinished = performance.now();
|
|
|
|
const initStarted = performance.now();
|
|
await RAPIER.init();
|
|
const initFinished = performance.now();
|
|
|
|
const buildStarted = performance.now();
|
|
const world = new RAPIER.World({ x: 0, y: -18, z: 0 });
|
|
const body = world.createRigidBody(RAPIER.RigidBodyDesc.fixed());
|
|
world.createCollider(RAPIER.ColliderDesc.trimesh(positions, indices), body);
|
|
const buildFinished = performance.now();
|
|
|
|
console.log(JSON.stringify({
|
|
vertices: positions.length / 3,
|
|
triangles: indices.length / 3,
|
|
glbReadMs: Math.round(readFinished - readStarted),
|
|
rapierInitMs: Math.round(initFinished - initStarted),
|
|
trimeshBuildMs: Math.round(buildFinished - buildStarted),
|
|
}, null, 2));
|