public virtual bool Extrude(int group_id = -1) { // duplicate loop vertices int NV = Loop.Vertices.Length; NewLoop = new EdgeLoop(Mesh); NewLoop.Vertices = new int[NV]; for (int i = 0; i < NV; ++i) { int vid = Loop.Vertices[i]; NewLoop.Vertices[i] = Mesh.AppendVertex(Mesh, vid); } // move to offset positions for (int i = 0; i < NV; ++i) { Vector3D v = Mesh.GetVertex(Loop.Vertices[i]); Vector3F n = Mesh.GetVertexNormal(Loop.Vertices[i]); Vector3D new_v = PositionF(v, n, i); Mesh.SetVertex(NewLoop.Vertices[i], new_v); } // stitch interior MeshEditor edit = new MeshEditor(Mesh); NewTriangles = edit.StitchLoop(Loop.Vertices, NewLoop.Vertices, group_id); return(true); }
public virtual bool Fill(int group_id = -1) { if (Loop.Vertices.Length < 3) { return(false); } // this just needs one triangle if (Loop.Vertices.Length == 3) { Index3i tri = new Index3i(Loop.Vertices[0], Loop.Vertices[2], Loop.Vertices[1]); int new_tid = Mesh.AppendTriangle(tri, group_id); if (new_tid == NGonsCore.geometry3Sharp.mesh.DMesh3.InvalidID) { return(false); } NewTriangles = new int[1] { new_tid }; NewVertex = NGonsCore.geometry3Sharp.mesh.DMesh3.InvalidID; return(true); } // [TODO] 4-case? could check nbr normals to figure out best internal edge... // compute centroid Vector3D c = Vector3D.Zero; for (int i = 0; i < Loop.Vertices.Length; ++i) { c += Mesh.GetVertex(Loop.Vertices[i]); } c *= 1.0 / Loop.Vertices.Length; // add centroid vtx NewVertex = Mesh.AppendVertex(c); // stitch triangles MeshEditor editor = new MeshEditor(Mesh); try { NewTriangles = editor.AddTriangleFan_OrderedVertexLoop(NewVertex, Loop.Vertices, group_id); } catch { NewTriangles = null; } // if fill failed, back out vertex-add if (NewTriangles == null) { Mesh.RemoveVertex(NewVertex); NewVertex = NGonsCore.geometry3Sharp.mesh.DMesh3.InvalidID; } return(true); }
public void Generate() { Append_mesh(); AxisAlignedBox3i bounds = Voxels.GridBounds; bounds.Max -= Vector3i.One; int[] vertices = new int[4]; foreach (Vector3i nz in Voxels.NonZeros()) { Check_counts_or_append(6, 2); Box3d cube = Box3d.UnitZeroCentered; cube.Center = (Vector3D)nz; for (int fi = 0; fi < 6; ++fi) { // checks dependent on neighbours Index3i nbr = nz + gIndices.GridOffsets6[fi]; if (bounds.Contains(nbr)) { if (SkipInteriorFaces && Voxels.Get(nbr)) { continue; } } else if (CapAtBoundary == false) { continue; } int ni = gIndices.BoxFaceNormals[fi]; Vector3F n = (Vector3F)(Math.Sign(ni) * cube.Axis(Math.Abs(ni) - 1)); NewVertexInfo vi = new NewVertexInfo(Vector3D.Zero, n); if (ColorSourceF != null) { vi.c = ColorSourceF(nz); vi.bHaveC = true; } for (int j = 0; j < 4; ++j) { vi.v = cube.Corner(gIndices.BoxFaces[fi, j]); vertices[j] = cur_mesh.AppendVertex(vi); } Index3i t0 = new Index3i(vertices[0], vertices[1], vertices[2], Clockwise); Index3i t1 = new Index3i(vertices[0], vertices[2], vertices[3], Clockwise); cur_mesh.AppendTriangle(t0); cur_mesh.AppendTriangle(t1); } } }
public void MakeMesh(NGonsCore.geometry3Sharp.mesh.DMesh3 m) { int nV = vertices.Count; for (int i = 0; i < nV; ++i) { NewVertexInfo ni = new NewVertexInfo() { v = vertices[i] }; if (WantNormals) { ni.bHaveN = true; ni.n = normals[i]; } if (WantUVs) { ni.bHaveUV = true; ni.uv = uv[i]; } int vID = m.AppendVertex(ni); Util.gDevAssert(vID == i); } int nT = triangles.Count; if (WantGroups && groups != null && groups.Length == nT) { for (int i = 0; i < nT; ++i) { m.AppendTriangle(triangles[i], groups[i]); } } else { for (int i = 0; i < nT; ++i) { m.AppendTriangle(triangles[i]); } } }