Is it possible to attach the mirror material to a mesh from a blender file without using glass?

Hi, one last thing, how do I remove that grey line between the cube and reflection of the cube?

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??

Your mirror must be a plane not a box. I set the scaling of Cube.001 mesh to 0.0001 in this example.

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.

Alright, will use a plane. If possible please share the PG of the image you’ve shared…

1 Like

Line #27 added.

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??

Can you DM me the model?

Unfortunately, I can’t as it is of work and cannot share the model publicly.

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?

Maybe: Check for negatives scales on the mesh, it’s parents.

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)

cubeMirror.material = mirrorMaterial;
// scene.debugLayer.show();

let i = 0
cubeMirrorNormal = BABYLON.Vector3.TransformNormal(new BABYLON.Vector3(1, 0, 0), cubeMirrorMatrox)
scene.onBeforeRenderObservable.add(() => {
    const cubeMirrorMatrox = cubeMirror.getWorldMatrix();

    const reflector = BABYLON.Plane.FromPositionAndNormal(cubeMirror.absolutePosition, cubeMirrorNormal.scale(-1));
    mirrorMaterial.reflectionTexture.mirrorPlane = reflector;

})

1 Like

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:

In Blender turn on:

Blue color means it’s normals are facing towards you so the object is “looking at you”. This is what we want. Thid becomes our mirror surface.

Normals and face direction pointing at the right direction (google how to flip face direction in Blender)

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.

If you move your vertices it moves the object itself:

So all you have to do is now move it back to the desired position:


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.

2 Likes