Add Normal from a mesh to an other mesh

Hi everyone,

I’m trying to create a function that can take an ArrayMesh, add it into dictionaries for storage, and then later generate a “global” ArrayMesh by combining the meshes stored in those dictionaries.

The problem is that the normals of the resulting global ArrayMesh behave strangely:

-Only the regions with negative coordinates are lit correctly, while everything else appears dark.

-In some areas, one end of an object is lit differently compared to the opposite end of a neighboring object.

Does anyone know what could cause this issue or how to fix it?

Thanks in advance!

for (int i = 0; i < vertices.Length; i++)
        {
            vertexDict.Add(idVertex, transform * vertices[i]);
            normalsDict.Add(idVertex, transform * normals[i]);
            uvsDict.Add(idVertex, uvs[i]);
            idVertex++;
        }
array[(int)Mesh.ArrayType.Normal] = normalsDict.Values.ToArray();

Godot Version

4.3

Question

Why are the normals of my global ArrayMesh behaving incorrectly after combining multiple ArrayMesh objects

Hi Aurele.

Issue is likely related to how you’re transforming and storing normals during combination process.

To correctly transform normals, you should only apply the basis of the Transform, and then normalize the result.

normalsDict.Add(idVertex, (transform.basis * normals[i]).normalized());

Hope this resolve the lighting issues you are seeing.

Yes ! It works, thank you !