/// <summary> /// Convert unity Mesh to a g3.DMesh3. Ignores UV's. /// </summary> public static DMesh3 UnityMeshToDMesh(Mesh mesh) { Vector3[] mesh_vertices = mesh.vertices; Vector3f[] dmesh_vertices = new Vector3f[mesh_vertices.Length]; for (int i = 0; i < mesh.vertexCount; ++i) { dmesh_vertices[i] = mesh_vertices[i]; } Vector3[] mesh_normals = mesh.normals; if (mesh_normals != null) { Vector3f[] dmesh_normals = new Vector3f[mesh_vertices.Length]; for (int i = 0; i < mesh.vertexCount; ++i) { dmesh_normals[i] = mesh_normals[i]; } return(DMesh3Builder.Build(dmesh_vertices, mesh.triangles, dmesh_normals)); } else { return(DMesh3Builder.Build <Vector3f, int, Vector3f>(dmesh_vertices, mesh.triangles, null, null)); } }
string WriteOFF() { IEnumerable <float> coords = mesh.vertices.ToFloats(); DMesh3 dmesh3 = DMesh3Builder.Build <float, int, float>(coords.ToArray(), mesh.triangles); WriteMesh writeMesh = new WriteMesh { Mesh = dmesh3, Name = meshHash }; OFFWriter OFFwriter = new OFFWriter(); string OFF = Application.dataPath + "/VolumetricMeshes/" + meshHash + "/" + meshHash + ".off"; Directory.CreateDirectory(Application.dataPath + "/VolumetricMeshes/" + meshHash + "/"); FileStream OFFfile = File.OpenWrite(OFF); TextWriter textWriter = new StreamWriter(OFFfile); WriteOptions options = new WriteOptions() { RealPrecisionDigits = 7 }; OFFwriter.Write(textWriter, new List <WriteMesh>() { writeMesh }, options); textWriter.Flush(); textWriter.Close(); return(OFF); }
//convert a MeshGeometry3D object into a DMesh object private static DMesh3 MeshGeometryToDMesh(MeshGeometry3D mesh) { List <Vector3d> vertices = new List <Vector3d>(); foreach (Point3D point in mesh.Positions) { vertices.Add(new Vector3d(point.X, point.Y, point.Z)); } List <Vector3f> normals = new List <Vector3f>(); foreach (Point3D normal in mesh.Normals) { normals.Add(new Vector3f(normal.X, normal.Y, normal.Z)); } if (normals.Count() == 0) { normals = null; } List <Index3i> triangles = new List <Index3i>(); for (int i = 0; i < mesh.TriangleIndices.Count; i += 3) { triangles.Add(new Index3i(mesh.TriangleIndices[i], mesh.TriangleIndices[i + 1], mesh.TriangleIndices[i + 2])); } //converting the meshes to use Implicit Surface Modeling return(DMesh3Builder.Build(vertices, triangles, normals)); }
public static void test_mesh_builders() { // test mesh builder DMesh3 origMesh = TestUtil.LoadTestMesh(Program.TEST_FILES_PATH + "bunny_open_base.obj"); float[] Vf = new float[origMesh.VertexCount * 3]; List <Vector3f> Vl = new List <Vector3f>(); int k = 0; foreach (Vector3d v in origMesh.Vertices()) { Vf[k++] = (float)v.x; Vf[k++] = (float)v.y; Vf[k++] = (float)v.z; Vl.Add((Vector3f)v); } double[] Nd = origMesh.NormalsBuffer.GetBufferCast <double>(); Vector3d[] Nl = new Vector3d[origMesh.VertexCount]; foreach (int vid in origMesh.VertexIndices()) { Nl[vid] = origMesh.GetVertexNormal(vid); } int[] Ti = origMesh.TrianglesBuffer.GetBuffer(); Index3i[] Tl = new Index3i[origMesh.TriangleCount]; foreach (int tid in origMesh.TriangleIndices()) { Tl[tid] = origMesh.GetTriangle(tid); } DMesh3 m1 = DMesh3Builder.Build(Vf, Ti, Nd); DMesh3 m2 = DMesh3Builder.Build(Vl, Tl, Nl); Util.gDevAssert(origMesh.IsSameMesh(m1, true)); Util.gDevAssert(origMesh.IsSameMesh(m2, true)); }
public static DMesh3 ToDMesh3(this Rhino.Geometry.Mesh ms) { int numV = ms.Vertices.Count; int numF = ms.Faces.Count; int numC = ms.VertexColors.Count; List <Vector3f> Vertices = new List <Vector3f>(numV); List <Vector3i> Triangles = new List <Vector3i>(numF); for (int i = 0; i < numV; i++) { Vertices.Add(ms.Vertices[i].ToVec3f()); } for (int i = 0; i < numF; i++) { Triangles.Add(ms.Faces[i].ToVec3i()); } DMesh3 dMs = DMesh3Builder.Build <Vector3f, Vector3i, Vector3f>(Vertices, Triangles); if (numV == numC) { dMs.EnableVertexColors(new Vector3f(0.5, 0.5, 0.5)); for (int i = 0; i < numV; i++) { dMs.SetVertexColor(i, new Vector3f((float)ms.VertexColors[i].R / 255, (float)ms.VertexColors[i].G / 255, (float)ms.VertexColors[i].B / 255)); } } return(dMs); }
public DMesh3 getMesh() { BpcData pc = GetBakedPointCloud(); ulong size; byte[] data = GetPackedMesh(out size); Console.WriteLine($"Rawmesh size: {size}"); List <int> tris = new List <int>(); if (size > 0) { for (int position = 0; position < (int)size; position += 12) { tris.Add((int)BitConverter.ToUInt32(data, position)); tris.Add((int)BitConverter.ToUInt32(data, position + 4)); tris.Add((int)BitConverter.ToUInt32(data, position + 8)); } } DMesh3 dmesh = DMesh3Builder.Build <Vector3d, int, int>(pc.positions, tris); if (pc.colors.Count() > 0) { dmesh.EnableVertexColors(new Vector3f()); foreach (int idx in dmesh.VertexIndices()) { dmesh.SetVertexColor(idx, pc.colors.ElementAt(idx)); } } return(dmesh); }
/// <summary> /// Generates a mesh for the ground that we can work with. /// </summary> private void LoadGroundMesh() { var vertices = _data.Vertices.Select(a => new Vector3f(a.X, a.Z, a.Y)); var triangles = _data.Triangles.Select(a => new Index3i(a.Indices[0], a.Indices[1], a.Indices[2])); _mesh = DMesh3Builder.Build <Vector3f, Index3i, Vector3f>(vertices, triangles, null, null); _spatial = new DMeshAABBTree3(_mesh); _spatial.Build(); }
private DMesh3 LoadGLB(ModelRoot inputModel) { var glbMesh = inputModel.LogicalMeshes.First().Primitives.First(); var vertices = glbMesh.GetVertices("POSITION").AsVector3Array(); var indices = glbMesh.GetIndices(); var normals = glbMesh.GetVertices("NORMAL").AsVector3Array(); var mesh = DMesh3Builder.Build(vertices, indices, normals); return(mesh); }
public static void test_mesh_builder_104() { var vertices = new List <Vector3f> { new Vector3f(0, 0, 0), // 0 new Vector3f(1000, 0, 0), // 1 new Vector3f(1000, 200, 0), // 2 new Vector3f(0, 200, 0), // 3 new Vector3f(1000, 0, 200), // 4 new Vector3f(0, 0, 200), // 5 new Vector3f(1000, 0, -200), // 6 new Vector3f(0, 0, -200), // 7 new Vector3f(1000, -200, 0), // 8 new Vector3f(0, -200, 0) // 9 }; var triangles = new List <Index3i> { new Index3i(0, 1, 2), new Index3i(0, 2, 3), new Index3i(0, 4, 1), new Index3i(0, 5, 4), new Index3i(0, 1, 6), // Does not show new Index3i(0, 6, 7), new Index3i(0, 8, 1), // Does not show new Index3i(0, 9, 8) }; var mesh = DMesh3Builder.Build <Vector3f, Index3i, Vector3f>(vertices, triangles); Console.WriteLine($"Number of triangles: {mesh.TriangleCount}"); // Outputs 6, because mesh is not manifold Console.WriteLine($"Vertex Issues: {mesh.FindMetadata("AppendVertexIssues")}"); Console.WriteLine($"Triangle Issues: {mesh.FindMetadata("AppendTriangleIssues")}"); // for greater control of the meshing process use DMesh3Builder class Console.WriteLine("Trying again with DMesh3Builder instance"); DMesh3Builder builder = new DMesh3Builder(); builder.NonManifoldTriBehavior = DMesh3Builder.AddTriangleFailBehaviors.DuplicateAllVertices; mesh = builder.AppendMesh <Vector3f, Index3i, Vector3f>(vertices, triangles); Console.WriteLine($"Number of triangles: {mesh.TriangleCount}"); // Outputs 8, because non manifold is allowed Console.WriteLine($"Triangle Issues: {mesh.FindMetadata("AppendTriangleIssues")}"); Console.WriteLine($"Normals: {mesh.FindMetadata("Normals")}"); Console.WriteLine($"TriGroups: {mesh.FindMetadata("TriGroups")}"); var outF = TestUtil.WriteTestOutputMesh(mesh, "Issue104.obj"); Console.WriteLine($"Written to: {outF}"); }
public MeshData Simplify(MeshData meshData, int numCells = 128, int targetVerticesCount = 10000) { var vertices = meshData.Vertices.Select(v => new Vector3f(v.x, v.y, v.z)); var normals = meshData.Normals?.Select(v => new Vector3f(v.x, v.y, v.z)); var mesh = DMesh3Builder.Build(vertices, meshData.Triangles, normals); mesh = VoxelizeMesh(numCells, mesh); mesh = ReduceVertexCount(targetVerticesCount, mesh); mesh = CreateCompactMesh(mesh); return(new MeshData( mesh.Vertices().Select(v => new Vector3((float)v.x, (float)v.y, (float)v.z)).ToArray(), mesh.Triangles().SelectMany(i3 => i3.array).ToArray() )); }
public Task BuildTreeAsync(Vector3[] positions, Vector3[] normals, int[] indices) { return(Task.Run(() => { var norm = ConvertToVector3f(normals); DMeshLocal = DMesh3Builder.Build(ConvertToVector3f(positions), indices, norm); TreeLocal = new DMeshAABBTree3(DMeshLocal); TreeLocal.Build(); box = new BoundingBox(DMeshLocal.GetBounds()); IsBuilt = true; return this; })); }
void MeshReplace() { Mesh newMesh = new Mesh(); //The triangles tend to come out reversed, so we need to fix them DMesh3 dmesh3 = DMesh3Builder.Build <float, int, float>(verticies, faces); MeshNormals.QuickCompute(dmesh3); dmesh3.ReverseOrientation(false); newMesh.vertices = verticies.ToVectors().ToArray(); newMesh.triangles = dmesh3.TrianglesBuffer.ToArray(); for (int i = 0; i < mesh.uv.Length; i++) { newMesh.uv[i] = mesh.uv[i]; } newMesh.MarkDynamic(); GetComponent <MeshFilter>().mesh = newMesh; }
internal static DMesh3 MakeTetra(Vector3d SquareCornerPosition, double size) { var vertices = new List <Vector3d> { SquareCornerPosition, new Vector3d(SquareCornerPosition.x + size, SquareCornerPosition.y, SquareCornerPosition.z), new Vector3d(SquareCornerPosition.x, SquareCornerPosition.y + size, SquareCornerPosition.z), new Vector3d(SquareCornerPosition.x, SquareCornerPosition.y, SquareCornerPosition.z + size), }; var triangles = new List <Index3i> { new Index3i(0, 2, 1), new Index3i(2, 3, 1), new Index3i(0, 3, 2), new Index3i(1, 3, 0), }; return(DMesh3Builder.Build(vertices, triangles)); }
public Task BuildTreeAsync(IGeometryComponent geo) { if (!geo.IsValid) { return(Task.FromResult(0)); } return(Task.Run(() => { var norm = geo.Normals.IsDefaultOrEmpty ? null : ConvertToVector3f(geo.Normals); DMeshLocal = DMesh3Builder.Build(ConvertToVector3f(geo.Positions), geo.Indices, norm); //var sm = new LaplacianMeshSmoother(DMesh); //sm.Initialize(); //sm.SolveAndUpdateMesh(); //DMesh = sm.Mesh; TreeLocal = new DMeshAABBTree3(DMeshLocal); TreeLocal.Build(); box = new BoundingBox(DMeshLocal.GetBounds()); IsBuilt = true; return this; })); }
protected VirgisFeature _drawFeature(Geometry tin, Feature feature = null) { //Create the GameObjects GameObject dataTIN = Instantiate(MeshPrefab, transform); EditableMesh mesh = dataTIN.GetComponent <EditableMesh>(); if (feature != null) { mesh.feature = feature; } List <Geometry> trigeos = new List <Geometry>(); List <Vector3d> trivects = new List <Vector3d>(); List <int> tris = new List <int>(); for (int i = 0; i < tin.GetGeometryCount(); i++) { trigeos.Add(tin.GetGeometryRef(i)); } HashSet <Vector3d> vertexhash = new HashSet <Vector3d>(); for (int i = 0; i < trigeos.Count; i++) { Geometry tri = trigeos[i]; Geometry linearring = tri.GetGeometryRef(0); for (int j = 0; j < 3; j++) { double[] argout = new double[3]; linearring.GetPoint(j, argout); Vector3d vertex = new Vector3d(argout); vertexhash.Add(vertex); trivects.Add(vertex); } tri.Dispose(); linearring.Dispose(); } List <Vector3d> vertexes = vertexhash.ToList(); foreach (Vector3d vertex in trivects) { tris.Add(vertexes.IndexOf(vertex)); } DMesh3 dmesh = DMesh3Builder.Build <Vector3d, int, int>(vertexes, tris); string crs; tin.GetSpatialReference().ExportToWkt(out crs, null); dmesh.AttachMetadata("CRS", crs); mesh.Draw(dmesh, bodyMain, WireframeMaterial, true); //if (symbology.ContainsKey("body") && symbology["body"].ContainsKey("Label") && symbology["body"].Label != null && (feature?.ContainsKey(symbology["body"].Label) ?? false)) { // //Set the label // GameObject labelObject = Instantiate(LabelPrefab, dataPoly.transform, false); // labelObject.transform.Translate(dataPoly.transform.TransformVector(Vector3.up) * symbology["point"].Transform.Scale.magnitude, Space.Self); // Text labelText = labelObject.GetComponentInChildren<Text>(); // labelText.text = (string) feature.Get(symbology["body"].Label); //} return(mesh); }
public void fpMeshPoints() { List <Vector3d> points = new List <Vector3d>(); List <int> tris = new List <int>(); List <Vector3d> normals = new List <Vector3d>(); float normal = .01f; //string toPull = ReadString(); //string[] linesInFile = toPull.Split('\n'); foreach (var pointCloud in ARpoints.trackables) { //Debug.Log ("Lit" +pointCloud.transform.localPosition); int counter = 0; var visualize = GameObject.FindWithTag("allPoints").GetComponent <UnityEngine.XR.ARFoundation.ARAllPointCloudPointsParticleVisualizer>(); foreach (var kvp in visualize.m_Points) { counter++; points.Add(kvp.Value); tris.Add(counter); tris.Add(counter); tris.Add(counter); normals.Add(new Vector3d(normal, normal, normal)); } } DMesh3 pointSet = DMesh3Builder.Build(points, tris, normals); PointAABBTree3 bvtree = new PointAABBTree3(pointSet, true); bvtree.FastWindingNumber(Vector3d.Zero); // estimate point area based on nearest-neighbour distance double[] areas = new double[pointSet.MaxVertexID]; foreach (int vid in pointSet.VertexIndices()) { bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid! int near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid)); double dist = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid)); areas[vid] = Circle2d.RadiusArea(dist); } bvtree.FWNAreaEstimateF = (vid) => { return(areas[vid]); }; MarchingCubes mc = new MarchingCubes(); mc.Implicit = new PWNImplicit() { Spatial = bvtree }; mc.IsoValue = 0.0; mc.CubeSize = bvtree.Bounds.MaxDim / 10; mc.Bounds = bvtree.Bounds.Expanded(mc.CubeSize * 3); mc.RootMode = MarchingCubes.RootfindingModes.Bisection; mc.Generate(); DMesh3 resultMesh = mc.Mesh; g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh); /* MarchingCubes mc = new MarchingCubes(); * mc.Implicit = new PWNImplicit() { Spatial = bvtree }; * mc.IsoValue = 0.0; * mc.CubeSize = bvtree.Bounds.MaxDim / 10; * mc.Bounds = bvtree.Bounds.Expanded(mc.CubeSize * 3); * mc.RootMode = MarchingCubes.RootfindingModes.Bisection; * mc.Generate(); * DMesh3 resultMesh = mc.Mesh; * g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh); */ }
public void takePointsinandAddtoMesh(List <Vector3d> pointers) { List <int> tris = new List <int>(); List <Vector3d> normals = new List <Vector3d>(); float normal = .01f; if (currentMesh == null) { //ok so first mesh is not been created yet so create it from the first frame int counter = 0; foreach (Vector3d line in pointers) { counter++; //Debug.Log(line); tris.Add(counter); tris.Add(counter); tris.Add(counter); normals.Add(new Vector3d(normal, normal, normal)); } DMesh3 pointSet = DMesh3Builder.Build(pointers, tris, normals); PointAABBTree3 bvtree = new PointAABBTree3(pointSet, true); bvtree.FastWindingNumber(Vector3d.Zero); // estimate point area based on nearest-neighbour distance double[] areas = new double[pointSet.MaxVertexID]; foreach (int vid in pointSet.VertexIndices()) { bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid! int near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid)); double dist = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid)); areas[vid] = Circle2d.RadiusArea(dist); } bvtree.FWNAreaEstimateF = (vid) => { return(areas[vid]); }; MarchingCubes mc = new MarchingCubes(); mc.Implicit = new PWNImplicit() { Spatial = bvtree }; mc.IsoValue = 0.0; mc.CubeSize = bvtree.Bounds.MaxDim / 10; mc.Bounds = bvtree.Bounds.Expanded(mc.CubeSize * 3); mc.RootMode = MarchingCubes.RootfindingModes.Bisection; mc.Generate(); DMesh3 resultMesh = mc.Mesh; // g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh); currentMesh = resultMesh; } else { //ok so this is where we are proscessing second mesh int counter = 0; foreach (Vector3d line in pointers) { counter++; //Debug.Log(line); tris.Add(counter); tris.Add(counter); tris.Add(counter); normals.Add(new Vector3d(normal, normal, normal)); } DMesh3 pointSet = DMesh3Builder.Build(pointers, tris, normals); PointAABBTree3 bvtree = new PointAABBTree3(pointSet, true); bvtree.FastWindingNumber(Vector3d.Zero); // estimate point area based on nearest-neighbour distance double[] areas = new double[pointSet.MaxVertexID]; foreach (int vid in pointSet.VertexIndices()) { bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid! int near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid)); double dist = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid)); areas[vid] = Circle2d.RadiusArea(dist); } bvtree.FWNAreaEstimateF = (vid) => { return(areas[vid]); }; MarchingCubes mc = new MarchingCubes(); mc.Implicit = new PWNImplicit() { Spatial = bvtree }; mc.IsoValue = 0.0; mc.CubeSize = bvtree.Bounds.MaxDim / 10; mc.Bounds = bvtree.Bounds.Expanded(mc.CubeSize * 3); mc.RootMode = MarchingCubes.RootfindingModes.Bisection; mc.Generate(); DMesh3 resultMesh = mc.Mesh; MeshEditor editor = new MeshEditor(currentMesh); editor.AppendMesh(resultMesh, currentMesh.AllocateTriangleGroup()); //suspected its crashing after mesh is over 64000 faces, faceLog.text = "Vertex Count = " + transform.gameObject.GetComponent <MeshFilter>().mesh.triangles.Length; g3UnityUtils.SetGOMesh(transform.gameObject, currentMesh); } }
public void fpMeshPointsfromTextFileWithaSecondPoints() { //this is used in the fast points winding scene to optimize algorithm and make sure its working well //it reads points via text files and then meshes them List <Vector3d> points = new List <Vector3d>(); List <int> tris = new List <int>(); List <Vector3d> normals = new List <Vector3d>(); float normal = .01f; string toPull = ReadString(); string[] linesInFile = toPull.Split('\n'); int counter = 0; foreach (string line in linesInFile) { counter++; //Debug.Log(line); if (!string.IsNullOrEmpty(line)) { points.Add(StringToVector3(line)); tris.Add(counter); tris.Add(counter); tris.Add(counter); normals.Add(new Vector3d(normal, normal, normal)); } } DMesh3 pointSet = DMesh3Builder.Build(points, tris, normals); PointAABBTree3 bvtree = new PointAABBTree3(pointSet, true); bvtree.FastWindingNumber(Vector3d.Zero); // estimate point area based on nearest-neighbour distance double[] areas = new double[pointSet.MaxVertexID]; foreach (int vid in pointSet.VertexIndices()) { bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid! int near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid)); double dist = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid)); areas[vid] = Circle2d.RadiusArea(dist); } bvtree.FWNAreaEstimateF = (vid) => { return(areas[vid]); }; MarchingCubes mc = new MarchingCubes(); mc.Implicit = new PWNImplicit() { Spatial = bvtree }; mc.IsoValue = 0.0; mc.CubeSize = bvtree.Bounds.MaxDim / 50; mc.Bounds = bvtree.Bounds.Expanded(mc.CubeSize * 3); mc.RootMode = MarchingCubes.RootfindingModes.Bisection; mc.Generate(); DMesh3 resultMesh = mc.Mesh; g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh); /* MarchingCubes mc = new MarchingCubes(); * mc.Implicit = new PWNImplicit() { Spatial = bvtree }; * mc.IsoValue = 0.0; * mc.CubeSize = bvtree.Bounds.MaxDim / 10; * mc.Bounds = bvtree.Bounds.Expanded(mc.CubeSize * 3); * mc.RootMode = MarchingCubes.RootfindingModes.Bisection; * mc.Generate(); * DMesh3 resultMesh = mc.Mesh; * g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh); */ //ok now that we meshed the first point set, lets try to take in a second frame of points and then add to orginal dmesh points = new List <Vector3d>(); tris = new List <int>(); normals = new List <Vector3d>(); toPull = ReadString1(); linesInFile = toPull.Split('\n'); counter = 0; foreach (string line in linesInFile) { counter++; Debug.Log(line); if (!string.IsNullOrEmpty(line)) { points.Add(StringToVector3(line)); tris.Add(counter); tris.Add(counter); tris.Add(counter); normals.Add(new Vector3d(normal, normal, normal)); } } pointSet = DMesh3Builder.Build(points, tris, normals); bvtree = new PointAABBTree3(pointSet, true); bvtree.FastWindingNumber(Vector3d.Zero); // estimate point area based on nearest-neighbour distance areas = new double[pointSet.MaxVertexID]; foreach (int vid in pointSet.VertexIndices()) { bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid! int near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid)); double dist = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid)); areas[vid] = Circle2d.RadiusArea(dist); } bvtree.FWNAreaEstimateF = (vid) => { return(areas[vid]); }; mc = new MarchingCubes(); mc.Implicit = new PWNImplicit() { Spatial = bvtree }; mc.IsoValue = 0.0; mc.CubeSize = bvtree.Bounds.MaxDim / 50; mc.Bounds = bvtree.Bounds.Expanded(mc.CubeSize * 3); mc.RootMode = MarchingCubes.RootfindingModes.Bisection; mc.Generate(); DMesh3 resultMesh1 = mc.Mesh; MeshEditor editor = new MeshEditor(resultMesh); editor.AppendMesh(resultMesh1, resultMesh.AllocateTriangleGroup()); g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh1); // g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh); }
private static DMesh3 GenerateDynamicMesh(IEnumerable <Vector3> vertices, IEnumerable <int> triangles, IEnumerable <Vector3> normals) { return(DMesh3Builder.Build(vertices.Select(vertex => new Vector3f(vertex.x, vertex.y, vertex.z)), triangles, normals.Select(vector => new Vector3f(vector.x, vector.y, vector.z)))); }
public static DMesh3 CreaMesh(List <Vector3f> vertices, int[] triangles, List <Vector3f> normals) { return(DMesh3Builder.Build(vertices, triangles, normals)); }
private DMesh3 LoadTriangulation(Triangulation triangulation) { var mesh = DMesh3Builder.Build <Vector3d, int, Vector3d>(triangulation.Positions.Select(p => p.AsVector3()).Select(v => new Vector3d(v.X, v.Y, v.Z)), triangulation.Indices); return(mesh); }