Cannot read properties of undefined (reading ‘copyFrom’)

I would like to change the normal of a plane using FromPositionAndNormalToRef like in this playground

Whatever I do, I get the error:

rendererComponent.tsx:443 TypeError: Cannot read properties of undefined (reading 'copyFrom')     at e.FromPositionAndNormalToRef (math.plane.ts:204:23)     at createScene (<anonymous>:10:19)     at window.initFunction (<anonymous>:36:16)     at async z._compileAndRunAsync (rendererComponent.tsx:373:17) 'Retrying if possible. If this error persists please notify the team.'

What am I missing?

The FromPositionAndNormalToRef method gets in input, as third parameter, an instance of the Plane class (invisible mathematic plane) rather than an instance of the Mesh class (visible visual plane).

So you need to pass the proper plane:

Thanks very much for the quick answer. That explains it!

I just checked and was able to create the mesh from the Plane class also. Is there an easy way of updating the mesh if I update the plane or do I have to create a new mesh every time I change the plane?

1 Like

I’m not sure about that. I’ll leave that one to the experts!

The latter :slight_smile:

1 Like

Thanks again for all the help. For updating the normal of a plane I found out that it is actually as simple as

mesh = BABYLON.MeshBuilder.CreatePlane();
mesh.lookAt(normal);

One possibility is to create a “unit mesh” then calculate the transformation from the desired plane and that unit mesh. If the plane changes, recalculate the transformation and apply the new transformation to the mesh.

This would be further complicated if you are already applying mesh transformations or if you have a parent to the mesh.

Edit: like you have done with “look at.” The broader concept that includes scale and/or translation may not be needed in your case.