# [C#] Clipping multiple triangles and vertex ordering

This topic is 3048 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm currently clipping triangles from a mesh to 6 planes in order create a new mesh for a decal. Unfortunately I cannot figure out how to combine the clipped vertices correctly in order create the decal's mesh. The following code: - Detects the triangles that intersect the decal's OBB - Each triangle that the OBB intersects is clipped to the 6 planes of the OBB - The clipped vertices are then added to a list that makes the final decal's mesh vertices
            // Test each triangle that make up the intersecting sufraces
for (int i = 0; i < triangles.Count; ++i)
{
CD_Triangle tri = triangles;

if (Vector3.Dot(normal, tri.Normal) < 0.001f)
{
// Triangle is facing away from decal's normal direction and can be ignored
continue;
}

// Triangle points must be wound CCW
Vector3[] v_ToClip = new Vector3[3];

if (tri.IsWoundCCW())
{
v_ToClip[0] = tri.GetVertex(0);
v_ToClip[1] = tri.GetVertex(1);
v_ToClip[2] = tri.GetVertex(2);
}
else
{
v_ToClip[0] = tri.GetVertex(1);
v_ToClip[1] = tri.GetVertex(0);
v_ToClip[2] = tri.GetVertex(2);
}

// Following array holds all vertices that have been clipped behind each plane tested
Vector3[] v_Clipped = new Vector3[0];

// Clip current triangle vertices to each of the 6 OBB planes
for (int ii = 0; ii < 6; ++ii)
{
v_Clipped = ClipVerticesToPlane(planes[ii], v_ToClip);

// If all vertices lie on the positive side of the plane
if (v_ToClip.Length == 0)
{
break;
}
else
{
// Otherwise set the new vertices to clip using the clipped vertices
v_ToClip = v_Clipped;
}
}

// Add clipped vertices for this triangle to the final decal vertices
}


The list of clipped vertices should represent the final mesh however, some vertices might be duplicated. Also, because each triangle is clipped separately I have no idea how to index the vertices so that the mesh decal is drawn correctly. Can anyone please help? Thank you.

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 28
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631737
• Total Posts
3001945
×