Mesh normals help

Hello!I am kinda lost :frowning:
I need to merge 2 meshes and then make them have like the same “smoothing group” talking in 3ds max language.

To merge the meshes i am using this script :

@script RequireComponent(MeshFilter)
@script RequireComponent(MeshRenderer)
function Start () {
var meshFilters = GetComponentsInChildren(MeshFilter);
var combine : CombineInstance[] = new CombineInstance[meshFilters.length];
for ( i = 0; i < meshFilters.length; i++){
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.active = false;
}
transform.GetComponent(MeshFilter).mesh = new Mesh();
transform.GetComponent(MeshFilter).mesh.CombineMeshes(combine);
transform.gameObject.active = true;
}

Photo:

RecalculateNormals() wont work :frowning:

Is it a matter of shading or of calculating the normals / tangents?
Please help me :frowning:

The issue is probably that the CombineMeshes function doesn’t actually merge shared points between the faces, so although the points along the seam are in the exact same place they are in fact 2 seperate vertices for each attached face. The calculated normals your seeing are correct if this is the case.

The only way that I can see of getting around this is to manually find and adjust the normals of would-be shared points in your new combined mesh.

Thanks for your reply :slight_smile:

Well,i can’t :frowning: My actual mesh is procedurally generated :\

Is there a way to weld those verts then?

for all vertices in my combined mesh
if vertices overlap
normalize the 2 normals of each overlapping vertices
while you are at it
eliminate the unnecessary vertice and retriangulate

something like the above.

Aham…But is there any easy way to test if the vertices overlap?

if vertexA position == vertexB position
ooor
Distance(vertexA to vertexB) < some very small value here.
oooor
if vertexA and vertexB in same area
then
they overlap.

You should think before you ask.

No,mister.I know that :expressionless:
By easy way i ment something like : Mesh.VertexOverlap :stuck_out_tongue:
Just askin’…I see that everything is possible in Unity and most of the times i start to spend hours on a script and then find out that that script could be translated into a single line of code.
Thanks for yo’ anwser,tho

Sorry, by ‘manually’ I meant writing your own script for it like Aubergine suggested, rather than unity doing it for you. Poor choice of words by me :slight_smile: