public static List <MCBarycentricUnit> CreatePrecomputedVolumeMesh(DMC.Node Tetrahedron) { DMC.Hexahedron[] rootHexahedra = ExtractHexahedra(Tetrahedron); List <DMC.Hexahedron> subdividedHexahedra = new List <DMC.Hexahedron>(); for (int i = 0; i < 4; i++) { subdividedHexahedra.AddRange(DMC.DebugAlgorithm.GenerateSubdividedHexahedronList(rootHexahedra[i], 2)); } return(ConvertHexahedraToBarycentric(subdividedHexahedra, Tetrahedron)); }
public void MeshifyNode(DMC.Node node) { GameObject clone = Object.Instantiate(MeshPrefab, new Vector3(0, 0, 0), Quaternion.identity); Color c = Utility.SinColor(node.Depth * 3f); clone.GetComponent <MeshRenderer>().material.color = new Color(c.r, c.g, c.b, 0.9f); clone.transform.localScale = Vector3.one * WorldSize; clone.name = "Node " + node.Number + ", Depth " + node.Depth; MeshFilter mf = clone.GetComponent <MeshFilter>(); mf.mesh = DMC.DebugAlgorithm.PolyganiseNode(PrecomputedVolumeMesh, node); clone.GetComponent <Transform>().SetParent(Parent); UnityObjects[node.Number] = clone; }
public static UnityEngine.Mesh PolyganiseNode(List <MCBarycentricUnit> PrecomputedMesh, DMC.Node node) { List <Strucs.GridCell> MCCells = ConvertVolumeMeshToCartesian(PrecomputedMesh, node); List <Vector3> Vertices = new List <Vector3>(); foreach (Strucs.GridCell cell in MCCells) { Polyganiser.Polyganise(cell, Vertices, 0); } int[] triangles = new int[Vertices.Count]; for (int i = 0; i < Vertices.Count; i++) { triangles[i] = i; } UnityEngine.Mesh m = new UnityEngine.Mesh(); m.vertices = Vertices.ToArray(); m.triangles = triangles; m.RecalculateNormals(); return(m); }
public static List <Strucs.GridCell> ConvertVolumeMeshToCartesian(List <MCBarycentricUnit> PrecomputedMesh, DMC.Node Tetrahedron) { List <Strucs.GridCell> Units = new List <Strucs.GridCell>(); for (int i = 0; i < PrecomputedMesh.Count; i++) { Strucs.GridCell unit = new Strucs.GridCell(); unit.Points = new Strucs.Point[8]; for (int j = 0; j < 8; j++) { unit.Points[j] = new Strucs.Point(); unit.Points[j].Position = Math.Tet_BaryToCart(Tetrahedron.Vertices[0], Tetrahedron.Vertices[1], Tetrahedron.Vertices[2], Tetrahedron.Vertices[3], PrecomputedMesh[i].BarycentricCoords[j]); unit.Points[j].Density = Utility.DebugNoise(unit.Points[j].Position); } Units.Add(unit); } return(Units); }
public static List <MCBarycentricUnit> ConvertHexahedraToBarycentric(List <Hexahedron> Hexahedra, DMC.Node Tetrahedron) { List <MCBarycentricUnit> VolumeMesh = new List <MCBarycentricUnit>(); float a = Hexahedra.Count / 4; for (int i = 0; i < Hexahedra.Count; i++) { bool flip = false; MCBarycentricUnit u = new MCBarycentricUnit(); u.BarycentricCoords = new Vector4[8]; for (int j = 0; j < 8; j++) { if (flip) { u.BarycentricCoords[j] = Math.Tet_CartToBary(Tetrahedron.Vertices[0], Tetrahedron.Vertices[1], Tetrahedron.Vertices[2], Tetrahedron.Vertices[3], Hexahedra[i].Vertices[(j + 4) % 8]); } else { u.BarycentricCoords[j] = Math.Tet_CartToBary(Tetrahedron.Vertices[0], Tetrahedron.Vertices[1], Tetrahedron.Vertices[2], Tetrahedron.Vertices[3], Hexahedra[i].Vertices[j]); } } VolumeMesh.Add(u); } return(VolumeMesh); }