Also, when I applied the same stuff to other mirrors, it was coming as inverted or zoomed in Where can I do the trial and error stuff. I tried with different values in the cubeMirrorNormal and reflector but not upto the mark. Any help on this one??
If youâll use a plane as an mirror and replace the normal (-1, 0, 0) in this line cubeMirrorNormal = BABYLON.Vector3.TransformNormal(new BABYLON.Vector3(-1, 0, 0), cubeMirrorMatrix) with the real normal it should work, so: cubeMirrorNormal = BABYLON.Vector3.TransformNormal(cuberMirrorNormal, cubeMirrorMatrix)
In the PG we are getting the normal from the 3 first vertices: let cubeMirrorNormal = new BABYLON.Vector3(cubeMirrorNormals[0], cubeMirrorNormals[1], cubeMirrorNormals[2]);Since we are not using a plane we canât be sure if we get the normal of the mirror surface face or any other face in the mesh. Thatâs why weâre using a hardcoded normal (-1, 0, 0) in the PG. If using a plane we can be sure that we are getting the normal of the mirror surface face. If you get the backface normal just scale it by -1.
Ok, so I applied the plane and working fine. But I have a model which I cannot share here but in that the reflection is coming upside down. Anyway to fix that??
Remove the majotrity of the model and leave there only the mirror part and share the stripped model. Do not remove the parents. Would it work for you this way?
Thank you @everyone, especially @roland for sticking to the end !!!
The solution is given below. It removes the zoom from the reflection, makes the reflection dynamic and reflects everything around the mirror even if its moving.
const cubeMirrorMatrox = cubeMirror.getWorldMatrix();
const cubeMirrorNormals = cubeMirror.getVerticesData(ânormalâ);
let cubeMirrorNormal = new BABYLON.Vector3(cubeMirrorNormals[0], cubeMirrorNormals[1], cubeMirrorNormals[2]);
//Use worldMatrix to transform normal into its current value
cubeMirrorNormal = BABYLON.Vector3.TransformNormal(cubeMirrorNormal, cubeMirrorMatrox)
For future reference: To be more precise @PreciousCord02 sent me his animated glb in a PM. The glb contains a moving mirror with other stuff.
First issue, the mirror was a quite complilcated mesh. I convertd the mirror surface to a single plane with two faces and had to perform a few extra steps:
The mirroring will take effect on the side of the plane which is facing you, so now our object is OK.
The problem that there is a gap in the mirrored image is caused by vertices offset of the object itself. It means that the vertices are not at origin on the X axis.
You can solve this by dragging the vertices in Edit mode above the origin point as seen here. This displays the mirror_A-1 mesh from aside.
The PG without the glb is here (however nothing fancy here):
The primary issue was the glb: offset of the mirror plane from the origin, compound mesh as a mirror surface, the code is quite straightforward for all situations.