Trying to create mesh from code, problem with normals

Hi to whoever is reading. I have a beginners question( yes, sorry I know :frowning: )
On https://playground.babylonjs.com/#H4134L#1 I try to create a custom mesh in code. I think that I already managed to display 2 triangles of a piramid, but I have a problem showing the normals in my mesh.
As far as I understand , each vertex has a normal associated and it should be possible to visualise this normal on screen (for debugging purposes)

I did add normals to my vertices (although not in the 100% correct direction yet) and use the function showNormals (copy pasted from demo code in manual) to show the normals.

Somehow they don’t show at all. Did I do something wrong or did I set up too little data for the engine to handle my request ?

And 1 extra question (for when I get the normals visible). Do you have to normalize the normalvector in BabylonS to be of exactly length 1 or are there functionalities inside the engine for that ?

Kind regards and thank you very much to whoever wants to help me a little. I know how to do this in for example Unity3D but now I want to switch to babylon

So they show up when I launch your playground link. But when I go to rerun, they disappear.

2 Likes

I can take a peak in a little bit.

Alrighty here we go! The fix turned out to be simple. You had all the right code just needed to be one scope up. Enjoy! :slight_smile:

https://playground.babylonjs.com/#H4134L#4

2 Likes

Hi,
@educa, you can use this method
normalize(): Vector3 to normalize the vectors.

Thank you for your help

1 Like

Thank you