override protected void UpdateGeometry_internal() { // generate mesh tube TubeGenerator meshGen = new TubeGenerator() { Vertices = new List <Vector3d>(curve.Vertices), Capped = true, Polygon = polygon, Frame = new Frame3f(Vector3f.Zero, Vector3f.AxisY) }; meshGen.Generate(); Mesh newMesh = meshGen.MakeUnityMesh(false); meshGO.SetMesh(newMesh); // apparently this is expensive? if (DeferRebuild == false) { meshGO.GetComponent <MeshCollider>().sharedMesh = meshGO.GetComponent <MeshFilter>().sharedMesh; } // expand local bounds add_to_bounds(newMesh.bounds.min); add_to_bounds(newMesh.bounds.max); }
void update_geometry() { if (bUpdatePending == false && curve_timestamp == curve.Timestamp) { return; } if (curve.VertexCount < 2) { return; } // generate mesh tube TubeGenerator meshGen = new TubeGenerator() { Vertices = new List <Vector3d>(curve.Vertices), Capped = true, Polygon = polygon //, Frame = new Frame3f(Vector3f.Zero, Vector3f.AxisY) }; meshGen.Generate(); meshObject.SetMesh(meshGen.MakeUnityMesh(false)); bUpdatePending = false; curve_timestamp = curve.Timestamp; }
void validate_tube_meshes() { Polygon2d circle = Polygon2d.MakeCircle(Radius, Slices); for (int i = 0; i < CurveSet.Length; ++i) { TubeGenerator gen = new TubeGenerator(CurveSet[i].curve, circle) { NoSharedVertices = false }; gen.Generate(); CurveSet[i].tubeMeshGO = GameObjectFactory.CreateMeshGO("tube_" + i.ToString(), gen.MakeUnityMesh(), false, true); CurveSet[i].tubeMeshGO.SetMaterial(curveMaterial, true); parentGO.AddChild(CurveSet[i].tubeMeshGO, false); } }
void append_path_mesh(PolyLine3d pathLine) { TubeGenerator tubegen = new TubeGenerator() { Vertices = new List <Vector3d>(pathLine.Vertices), Polygon = TubeProfile, ClosedLoop = false, Capped = true, NoSharedVertices = true }; DMesh3 tubeMesh = tubegen.Generate().MakeDMesh(); List <DMesh3> layerList; if (LayerMeshes.TryGetValue(ActivePath[0].z, out layerList) == false) { layerList = new List <DMesh3>(); LayerMeshes[ActivePath[0].z] = layerList; } layerList.Add(tubeMesh); }
override protected void Create_internal(fMaterial useMaterial) { if (polygon == null) { polygon = Polygon2d.MakeCircle(0.3f, 8); } // generate mesh tube TubeGenerator meshGen = new TubeGenerator() { Vertices = new List <Vector3d>(curve.Vertices), Capped = true, Polygon = polygon, Frame = new Frame3f(Vector3f.Zero, Vector3f.AxisY) }; meshGen.Generate(); Mesh m = meshGen.MakeUnityMesh(false); meshGO = UnityUtil.CreateMeshGO("tube_mesh", m, useMaterial, true); AppendNewGO(meshGO, RootGameObject, false); }
public DMesh3 MakeElementsMesh(Polygon2d spanProfile, Polygon2d loopProfile) { var result = new DMesh3(); validate_topology(); foreach (EdgeSpan span in Spans) { DCurve3 curve = span.ToCurve(Mesh); var tubegen = new TubeGenerator(curve, spanProfile); MeshEditor.Append(result, tubegen.Generate().MakeDMesh()); } foreach (EdgeLoop loop in Loops) { DCurve3 curve = loop.ToCurve(Mesh); var tubegen = new TubeGenerator(curve, loopProfile); MeshEditor.Append(result, tubegen.Generate().MakeDMesh()); } return(result); }
public DMesh3 Make3DTubes(Interval1i layer_range, double merge_tol, double tube_radius) { Polygon2d tube_profile = Polygon2d.MakeCircle(tube_radius, 8); Frame3f frame = Frame3f.Identity; DMesh3 full_mesh = new DMesh3(); foreach (int layer_i in layer_range) { PlanarSlice slice = Slices[layer_i]; frame.Origin = new Vector3f(0, 0, slice.Z); foreach (GeneralPolygon2d gpoly in slice.Solids) { List <Polygon2d> polys = new List <Polygon2d>() { gpoly.Outer }; polys.AddRange(gpoly.Holes); foreach (Polygon2d poly in polys) { Polygon2d simpPoly = new Polygon2d(poly); simpPoly.Simplify(merge_tol, 0.01, true); if (simpPoly.VertexCount < 3) { Util.gBreakToDebugger(); } TubeGenerator tubegen = new TubeGenerator(simpPoly, frame, tube_profile) { NoSharedVertices = true }; DMesh3 tubeMesh = tubegen.Generate().MakeDMesh(); MeshEditor.Append(full_mesh, tubeMesh); } } } return(full_mesh); }
public static void test_tube_generator() { Polygon2d circle_path = Polygon2d.MakeCircle(50, 64); PolyLine2d arc_path = new PolyLine2d(circle_path.Vertices.Take(circle_path.VertexCount / 2)); Polygon2d irreg_path = new Polygon2d(); for (int k = 0; k < circle_path.VertexCount; ++k) { irreg_path.AppendVertex(circle_path[k]); k += k / 2; } PolyLine2d irreg_arc_path = new PolyLine2d(irreg_path.Vertices.Take(circle_path.VertexCount - 1)); Polygon2d square_profile = Polygon2d.MakeCircle(7, 32); square_profile.Translate(4 * Vector2d.One); //square_profile[0] = 20 * square_profile[0].Normalized; bool no_shared = true; WriteGeneratedMesh( new TubeGenerator(circle_path, Frame3f.Identity, square_profile) { WantUVs = true, NoSharedVertices = no_shared }, "tubegen_loop_standarduv.obj"); WriteGeneratedMesh( new TubeGenerator(irreg_path, Frame3f.Identity, square_profile) { WantUVs = true, NoSharedVertices = no_shared }, "tubegen_irregloop_standarduv.obj"); WriteGeneratedMesh( new TubeGenerator(arc_path, Frame3f.Identity, square_profile) { WantUVs = true, NoSharedVertices = no_shared }, "tubegen_arc_standarduv.obj"); WriteGeneratedMesh( new TubeGenerator(irreg_arc_path, Frame3f.Identity, square_profile) { WantUVs = true, NoSharedVertices = no_shared }, "tubegen_irregarc_standarduv.obj"); // append tube border around each hole of input mesh DMesh3 inMesh = TestUtil.LoadTestInputMesh("n_holed_bunny.obj"); Polygon2d bdrycirc = Polygon2d.MakeCircle(0.25, 6); MeshBoundaryLoops loops = new MeshBoundaryLoops(inMesh); foreach (EdgeLoop loop in loops) { DCurve3 curve = loop.ToCurve().ResampleSharpTurns(); TubeGenerator gen = new TubeGenerator(curve, bdrycirc) { NoSharedVertices = false }; MeshEditor.Append(inMesh, gen.Generate().MakeDMesh()); } TestUtil.WriteTestOutputMesh(inMesh, "boundary_tubes.obj"); }
public static void test_basic_generators() { TrivialDiscGenerator disc_gen = new TrivialDiscGenerator(); disc_gen.Generate(); WriteGeneratedMesh(disc_gen, "meshgen_Disc.obj"); TrivialRectGenerator rect_gen = new TrivialRectGenerator(); rect_gen.Generate(); WriteGeneratedMesh(rect_gen, "meshgen_Rect.obj"); GriddedRectGenerator gridrect_gen = new GriddedRectGenerator(); gridrect_gen.Generate(); WriteGeneratedMesh(gridrect_gen, "meshgen_GriddedRect.obj"); PuncturedDiscGenerator punc_disc_gen = new PuncturedDiscGenerator(); punc_disc_gen.Generate(); WriteGeneratedMesh(punc_disc_gen, "meshgen_PuncturedDisc.obj"); TrivialBox3Generator box_gen = new TrivialBox3Generator(); Frame3f f = Frame3f.Identity; f.Rotate(Quaternionf.AxisAngleD(Vector3f.AxisY, 45.0f)); f.Rotate(Quaternionf.AxisAngleD(Vector3f.AxisZ, 45.0f)); box_gen.Box = new Box3d(f.Origin, f.X, f.Y, f.Z, new Vector3d(3, 2, 1)); box_gen.Generate(); WriteGeneratedMesh(box_gen, "meshgen_TrivialBox_shared.obj"); box_gen.NoSharedVertices = true; box_gen.Generate(); WriteGeneratedMesh(box_gen, "meshgen_TrivialBox_noshared.obj"); RoundRectGenerator roundrect_gen = new RoundRectGenerator(); roundrect_gen.Width = 2; roundrect_gen.Generate(); WriteGeneratedMesh(roundrect_gen, "meshgen_RoundRect.obj"); GridBox3Generator gridbox_gen = new GridBox3Generator(); gridbox_gen.Generate(); WriteGeneratedMesh(gridbox_gen, "meshgen_GridBox_shared.obj"); gridbox_gen.NoSharedVertices = true; gridbox_gen.Generate(); WriteGeneratedMesh(gridbox_gen, "meshgen_GridBox_noshared.obj"); Sphere3Generator_NormalizedCube normcube_gen = new Sphere3Generator_NormalizedCube(); normcube_gen.Generate(); WriteGeneratedMesh(normcube_gen, "meshgen_Sphere_NormalizedCube_shared.obj"); normcube_gen.NoSharedVertices = true; normcube_gen.Box = new Box3d(new Frame3f(Vector3f.One, Vector3f.One), Vector3d.One * 1.3); normcube_gen.Generate(); WriteGeneratedMesh(normcube_gen, "meshgen_Sphere_NormalizedCube_noshared.obj"); TubeGenerator tube_gen = new TubeGenerator() { Vertices = new List <Vector3d>() { Vector3d.Zero, Vector3d.AxisX, 2 * Vector3d.AxisX, 3 * Vector3d.AxisX }, Polygon = Polygon2d.MakeCircle(1, 16) }; tube_gen.Generate(); WriteGeneratedMesh(tube_gen, "meshgen_TubeGenerator.obj"); tube_gen.Polygon.Translate(Vector2d.One); tube_gen.CapCenter = Vector2d.One; tube_gen.Generate(); WriteGeneratedMesh(tube_gen, "meshgen_TubeGenerator_shifted.obj"); }
public static void quick_test() { DMesh3 mesh = StandardMeshReader.ReadMesh("c:\\scratch\\block.obj"); DMeshAABBTree3 spatial = new DMeshAABBTree3(mesh, true); Vector3d rayCenter = new Vector3d(0, 0, 1); Frame3f rayFrame = new Frame3f(rayCenter, Vector3d.AxisZ); List <Frame3f> frames = new List <Frame3f>(); // how far into surface we will inset float SurfaceOffset = 0.01f; double step = 2.5f; for (double angle = 0; angle < 360; angle += step) { double dx = Math.Cos(angle * MathUtil.Deg2Rad), dy = Math.Sin(angle * MathUtil.Deg2Rad); Vector3d dir = dx * (Vector3d)rayFrame.X + dy * (Vector3d)rayFrame.Y; Ray3d ray = new Ray3d(rayFrame.Origin, dir.Normalized); Frame3f hitFrame; if (MeshQueries.RayHitPointFrame(mesh, spatial, ray, out hitFrame)) { frames.Add(hitFrame); } } int N = frames.Count; for (int k = 0; k < N; ++k) { Frame3f f = frames[k]; int prev = (k == 0) ? N - 1 : k - 1; int next = (k + 1) % N; //Vector3f dv = frames[(k + 1) % frames.Count].Origin - f.Origin; Vector3f dv = frames[next].Origin - frames[prev].Origin; dv.Normalize(); f.ConstrainedAlignAxis(0, dv, f.Z); f.Origin = f.Origin + SurfaceOffset * f.Z; frames[k] = f; } //Frame3f f = frames[0]; //Vector3f dv = (frames[1].Origin - frames[0].Origin).Normalized; //f.ConstrainedAlignAxis(1, dv, f.Z); //for (int k = 1; k < frames.Count; ++k) { // f.Origin = frames[k].Origin; // f.AlignAxis(2, frames[k].Z); // frames[k] = f; //} List <Vector3d> vertices = frames.ConvertAll((ff) => { return((Vector3d)ff.Origin); }); TubeGenerator tubegen = new TubeGenerator() { Vertices = vertices, Polygon = Polygon2d.MakeCircle(0.05, 16), NoSharedVertices = false }; DMesh3 tubeMesh = tubegen.Generate().MakeDMesh(); TestUtil.WriteTestOutputMeshes(new List <IMesh>() { mesh, tubeMesh }, "curve_tube.obj"); SimpleQuadMesh stripMeshY = new SimpleQuadMesh(); double w = 0.1; int preva = -1, prevb = -1; for (int k = 0; k < N; ++k) { Vector3d pa = frames[k].Origin + w * (Vector3d)frames[k].Y; Vector3d pb = frames[k].Origin - w * (Vector3d)frames[k].Y; int a = stripMeshY.AppendVertex(pa); int b = stripMeshY.AppendVertex(pb); if (preva != -1) { stripMeshY.AppendQuad(preva, prevb, b, a); } preva = a; prevb = b; } stripMeshY.AppendQuad(preva, prevb, 1, 0); SimpleQuadMesh.WriteOBJ(stripMeshY, TEST_OUTPUT_PATH + "quadstripy.obj", WriteOptions.Defaults); SimpleQuadMesh stripMeshZ = new SimpleQuadMesh(); preva = -1; prevb = -1; double wz = 0.1; for (int k = 0; k < N; ++k) { Vector3d pa = frames[k].Origin + wz * (Vector3d)frames[k].Z; Vector3d pb = frames[k].Origin - wz * (Vector3d)frames[k].Z; int a = stripMeshZ.AppendVertex(pa); int b = stripMeshZ.AppendVertex(pb); if (preva != -1) { stripMeshZ.AppendQuad(preva, prevb, b, a); } preva = a; prevb = b; } stripMeshZ.AppendQuad(preva, prevb, 1, 0); SimpleQuadMesh.WriteOBJ(stripMeshZ, TEST_OUTPUT_PATH + "quadstripz.obj", WriteOptions.Defaults); }