In my three JS scene, I have a plane positioned and rotated in a certain way. When I send a raycast towards this plane and project an object onto it, everything works perfectly fine in chromium but gets turned upside down in firefox.
This discrepancy is causing significant issues for me, and it seems to be related to a rounding error when the mesh updates the matrix.
To illustrate the problem, consider the following example:
const test = new THREE.Mesh(new THREE.PlaneGeometry(), new THREE.MeshBasicMaterial());
test.position.copy(new THREE.Vector3(-0.0800582263098657,0,-0.003907569688712309))
test.rotation.copy(new THREE.Euler(-1.5707963267948966,0,0, "XYZ"))
test.updateMatrix()
const asString = `[${test.matrix.elements.join(",")}]`
const chromeString = "[1,0,0,0,0,2.220446049250313e-16,-1,0,0,1,2.220446049250313e-16,0,-0.0800582263098657,0,-0.003907569688712309,1]"
console.log(`
${asString}
${chromeString}
${asString === chromeString ? "equal" : "not equal"}
`)
When running this code, you'll see that the output is equal
for chromium but not for firefox. The difference lies in the sign change of the fifth element, which may seem small due to the 'e-16' value, but it causes the projection to flip in firefox.
I've experimented with manually setting the matrix to match the result in chromium (disabling matrixAutoUpdate), and that resolved the issue in firefox. Therefore, I believe the root cause lies within this calculation.
My question is: Is there a way to ensure consistent calculations across browsers by sacrificing some precision? I'm willing to make adjustments to achieve uniform behavior.