-
Hi! Thanks for amazing tool :) I am making a multiplayer game using gltf model as a level format. Inside level I have special mesh called PHYSICS_GEOMETRY for suppling it into physics engine. Also, I want to apply meshopt compression for all visible geometry, but not for PHYSICS_GEOMETRY. I didn't find anything in CLI and docs about per-mesh compression (except this pull). Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @upisfree! The compression libraries support this, but currently glTF Transform does not expose a way to customize or disable compression on a per-mesh basis. Could you say more about the reasons for excluding physics-related geometry? Does the physics library not support geometry that has been quantized to integer vertex attributes? Or you need to keep the full precision of the original data? Depending on the game engine and loading process, it might also be possible to dequantize the geometry at loading time, though I understand that's probably not as ideal. :) |
Beta Was this translation helpful? Give feedback.
-
@donmccurdy thanks for the answer, and sorry for a little late reply!
Yes, exactly it! For anyone with the same problem, I found a solution that supports per-file meshopt compression. I am using Rapier physics v0.14.0. To make it work with meshopt you just need to prepare vertices before passing to Rapier. You can do it like here: https://github.com/dimforge/rapier.js/blob/262c307271f350ce8a5379c39cc0b33999d434ee/testbed3d/src/demos/glbToTrimesh.ts#L32-L48 const mesh = child as Mesh;
const geometry = mesh.geometry as BufferGeometry;
const vertices: number[] = [];
const indices = new Uint32Array(geometry.index!.array); // assume index is non-null
const positionAttribute = geometry.getAttribute(
"position",
) as BufferAttribute;
mesh.updateWorldMatrix(true, true);
const v = new Vector3();
for (let i = 0, l = positionAttribute.count; i < l; i++) {
v.fromBufferAttribute(positionAttribute, i);
v.applyMatrix4(mesh.matrixWorld);
vertices.push(v.x, v.y, v.z);
}
// most important part is here, because meshopt returns us Int16Array which contains -1 and it leads to Rapier to crash
const verticesArray = new Float32Array(vertices);
const rigidBodyDesc = RAPIER.RigidBodyDesc.fixed();
const rigidBody = world.createRigidBody(rigidBodyDesc);
const colliderDesc = RAPIER.ColliderDesc.trimesh(
verticesArray,
indices,
);
world.createCollider(colliderDesc, rigidBody); Hope it helps to someone :) |
Beta Was this translation helpful? Give feedback.
@donmccurdy thanks for the answer, and sorry for a little late reply!
Yes, exactly it!
For anyone with the same problem, I found a solution that supports per-file meshopt compression. I am using Rapier physics v0.14.0. To make it work with meshopt you just need to prepare vertices before passing to Rapier. You can do it like here: https://github.com/dimforge/rapier.js/blob/262c307271f350ce8a5379c39cc0b33999d434ee/testbed3d/src/demos/glbToTrimesh.ts#L32-L48