# CSG.FromMesh with absolute = true seems make mesh with funny normals

Hi all-

I am working on an architecture app that uses a lot of transformed shapes and csgs. It’s a lot easer to manage the rotations, positions and scalings of the meshes if create CSGs with identity transform.

It this approach mostly works great but occasionally I can’t successfully apply multimaterials based on face normals, though the approach works fine when I use the mesh transforms and not identity.

See in this playground there is an area of the mesh produced by CSG.FromMesh(mesh,true) that has a vertical face normal?

I know that’s a mouthful. Any suggestions or request of me explaining what the hell I’m doing welcome! Happy Monday, y’all, from Trenton New Jersey!

-Flex

In `createSubmeshes` you wrongly assume that each index is unique and that vertices are not reused.

It’s true when `absolute = false` but not true when `absolute = true`:

• `absolute = false`: num vertices=438, num indices=438 (=146 triangles)
• `absolute = true`: num vertices=206, num indices=438 (=146 triangles)
1 Like

Also wanted to add - the normals are correct:

You should reuse as much as you can - especially the textures that you are recreating every time you need them, and the materials as well.

1 Like

Ok. Thank you so much, Evgeni and Raanan for the replies and for helping me understand what’s happening. That’s right on both counts. I did make some assumptions. Given what you have told me I am surprised that the mesh is not even worse looking!

Here’s the same thing using the facet normals. And the issue is resolved! The only thing I was unsure of is if I am indexing normals from facet data I need to multiply by 3 to translate this index into an indices index, correct?

You can do it this way or you could simply loop over the triangles of the mesh (so loop the indices 3 by 3), compute the normal of the triangle (cross product of p1 to p2 and p1 to p3) and do your processing with this normal. You don’t really need facet data to do that (it takes a little time/memory to generate these data).

1 Like

I am updating the playground to fix a bug that prevented the last submesh from being created, in case someone decides to use the code.

1 Like