Reflect a Mesh Function

The function at the top of the following playgrounds will reflect a mesh in a plane passing through the origin.

Use is

const reflectedShape = reflection(mesh, planeNormal, reflectRotation, reflectU, reflectV, dispose)

//mesh, the mesh to be reflected, required
//planeNormal a vector3 normal to the plane of reflection
//reflectU, default true, u of uv values, vertex value remains u, texture will reflect with vertex, when false becomes 1 - u
//reflectV, default true, v of uv values, vertex value remains v, texture will reflect with vertex; when false becomes 1 - v
//dispose, default false, when true original mesh is disposed

PG with defaults non symmetric mesh
PG with Plane, texture affected only by reflection of vertices
PG with Plane, u of uvs not affected by reflection of vertices
PG with Plane, v of uvs not affected by reflection of vertices
PG with Plane, u and v of uvs not affected by reflection of vertices

Please give it a good testing, feel free to edit/improve.

EDIT Original PGs did not work if mesh rotated and plane not XY, XZ, YZ planes. All corrected.

3 Likes

This could be really useful for mirroring objects, without mirroring material. Will definitely update you once I have a chance to try this out. Busy with rendering pipeline a.t.m.

I didn’t check the code logic in details, but it seems if you flip the mesh and uvs, it would be equivalent to scaling<axis> = -1?

Cool! Thanks for sharing!
What is Kerbside Furl anyway? :stuck_out_tongue_closed_eyes:

That looks right, I always like to do things the hard way :blush:

1 Like

Using scaling<axis> = -1by itself only works for reflection in XY, XZ or YZ plane. The hard way works for reflection in any plane through the origin.

In the below PG each run randomizes the plane

https://playground.babylonjs.com/#2RSWF5#9.

A scaling, rotation and transposition may be possible to give a mirror image. Will experiment.

1 Like