Open CaseyHofland opened 3 years ago
Martin had a quick look and it seems like it will need dedicated time to fix rather than be included in a bug blitz
We could consider to upgrade the Ammo version, and use btScaledBvhTriangleMeshShape API which allows to use btBvhTriangleMeshShape with different scale without having to have separate btBvhTriangleMeshShape instance. This was added in Sept 2008 it seems .. not sure why its not in our Ammo version yet. https://github.com/kripken/ammo.js/pull/240
Otherwise we can implement the system using the duplication.
Does it still need to be uniformly scaled?
Random thought, I wonder if instead of using the mesh.id, we can construct a string of the mesh.id and scale here (eg '' + mesh.id + sx + sy + sz
: https://github.com/playcanvas/engine/blob/a596c8b7881acbb318bca3f8b1b727aad62c3ecc/src/framework/components/collision/system.js#L318
That would allow different sized meshes to be built and cached using the same model data. It would mean an extra cost of calling _getNodeScaling
to get the final scale on each look up though 🤔
That's what we did in Solar Tools by patching the engine. And in addition we provided an option to round the scale to the nearest value set by the user. So for example he could group various rock objects to 0.75, 1.0, 1.25 scale variants and produce just 3 cached mesh shapes.
@yaustar Yeah, something like that. Or create a hash from the scale.
I've implemented something similar.
export const getScaleUniqueMeshId = (meshId: number, scale: Vec3): number => {
// Removes scale values from meshId if present
const rawMeshId = Math.floor(meshId);
const { x, y, z } = scale.clone().abs().round();
return Number(`${rawMeshId}.${x}${y}${z}`);
};
When using differently scaled mesh colliders of the same mesh, only 1 instance of the collider will be used on all entities.
As LeXXik put it (forum username): "Placing a mesh into the physics world is a computationally expensive operation - the engine generates an Ammo compound shape from a number of bvh triangle meshes, one for each mesh instance. Once generated the trimeshes then get cached for future re-use. As a result, when you use the same mesh for another collider, the trimeshes are taken from the cache, instead of generating new ones."
Provide as much information as possible. Include (where applicable): The forum discussion
Example:
Steps to Reproduce
Result: all colliders have the same scale. Desired: all colliders have their own scale.