protected virtual void BuildMesh_NoMerge(STLSolid solid, IMeshBuilder builder) { /*int meshID = */ builder.AppendNewMesh(false, false, false, false); DVectorArray3f vertices = solid.Vertices; int nTris = vertices.Count / 3; for (int ti = 0; ti < nTris; ++ti) { Vector3F va = vertices[3 * ti]; int a = builder.AppendVertex(va.x, va.y, va.z); Vector3F vb = vertices[3 * ti + 1]; int b = builder.AppendVertex(vb.x, vb.y, vb.z); Vector3F vc = vertices[3 * ti + 2]; int c = builder.AppendVertex(vc.x, vc.y, vc.z); builder.AppendTriangle(a, b, c); } }
// [TODO] is there any way we could use a HashSet<Vector3f> here, instead of Dictionary? protected virtual void BuildMesh_IdenticalWeld(STLSolid solid, IMeshBuilder builder) { /*int meshID = */ builder.AppendNewMesh(false, false, false, false); DVectorArray3f vertices = solid.Vertices; int N = vertices.Count; int[] mapV = new int[N]; Dictionary <Vector3F, int> uniqueV = new Dictionary <Vector3F, int>(); for (int vi = 0; vi < N; ++vi) { Vector3F v = vertices[vi]; int existing_idx; if (uniqueV.TryGetValue(v, out existing_idx)) { mapV[vi] = existing_idx; } else { int vid = builder.AppendVertex(v.x, v.y, v.z); uniqueV[v] = vid; mapV[vi] = vid; } } int nTris = N / 3; for (int ti = 0; ti < nTris; ++ti) { int a = mapV[3 * ti]; int b = mapV[3 * ti + 1]; int c = mapV[3 * ti + 2]; builder.AppendTriangle(a, b, c); } }