EDIT: I realized that if I comment out the function call on line 114 to create a mesh impostor from the heightmap mesh, the alignment seems to be fixed
This actually lines up with what I’ve been observing in my project:
the ammojs physics mesh imposter is shifted in someway so that it’s not aligned with the mesh it’s supposed to represent. This causes other objects such as a sphere, to appear to fall through the ground, or the inverse collide with an invisible object.
I’ve just tried with bjs 5.1.0 and with ‘render wireframe over mesh’ or ‘physics’ helpers, I get a perfect alignment with the ground.
I did a fix some days ago, might be related or I missed smth while testing your PG.
‘Render wireframe over mesh’ clones the mesh with a deep copy. Deep copy also copies physics Impostor and with an impostor delta, it breaks things (with more memory allocated).
PR with the fix coming in a few hours.
we publish nightlies. our playground is using these nightlies, so you can test a playground against those changes. Otherwise, it will be included in the next npm release, which will probably happen tomorrow.
You will very quickly see that the actual physics object that is supposed to represented by the height map mesh is either shifted, rotated or both in some way that makes the visual representation not correct.
mesh.physicsImpostor.setDeltaRotation(rootMesh.rotationQuaternion || new Quaternion(0, 0, 0, 1))
setDeltaRotation and setDeltaPosition tell the engine how the physics impostor is compared to the rendered mesh.
With the value set for rotation, the impostor will be rotated and the display will not be in sync with the physics.
If you want to rotate the terrain, then use mesh.rotation then create the impostor.
delta postion/rotation is for adjusting impostor compared to the mesh.
Easy example is when you have a box mesh with its center at the base of the mesh, not at the center.
Then, you need a delta because the box impostor always assume origin to be at the center.