Updating reflection planes normal based on object world orientation

I am trying to set up a reflection plane for a a reflectionTexture. the issue im having is I need to update the reflection plane normal to face a reference plane’s (or any other target geometry’s) direction. The docs here are a great start:
but the reference geo in this setup has some transforms applied to it from several parents. Whats the best way to get the world normal from the rotated geo and how do I update the reflection plane transform if the reference geo is rotated?

basic setup here.Note the blue plane is the desired reflection plane that needs to match the reference plane.

You have to call referencePlane.computeWorldMatrix(true); to get the right result from referencePlane.getFacetNormal(0):

@Evgeni_Popov awsome. That works. Still trying to figure out how to update the transform of the plane properly if the rotation of the reference plane changes. My attempts so far has not produced results. See code inside onAfterWorldMatrixUpdateObservable. Try rotating node1.

You can use the mesh.lookAt function:

1 Like

@Evgeni_Popov ah This works but only to update the transform of the viz geometry, but what about the Plane itself The ultimate goal is to use the Plane to create a reflection texture. But I want to update the plane if the mesh that the reflection texture is applied to is rotated. I tried a cople of things but found just re-creating the plane is the way to go. (pressing the a key will put down a new plane in the transformed position).

Is there any overhead to re-creating the plane every time? I assume this is just a simple procedural/mathmatical object so there would be no significant overhead?

When you pass sourcePlane to MeshBuilder.CreatePlane, the function is simply doing this at the very end, after the mesh has been created:

        plane.translate(options.sourcePlane.normal, -options.sourcePlane.d);

where plane is the mesh plane. You could simply do the same thing on your side, when your “math” plane changes.

sorry I think the PG link above was wrong. Here is the correct PG link. The main question was how to update the ‘math’ plane not the mesh plane. I think I figured it out… seems there should be no overhead to recreating the math plane as its just … well… math, and we are not actually allocating new geometry.

1 Like