public static void test_basic_generators() { TrivialDiscGenerator disc_gen = new TrivialDiscGenerator(); disc_gen.Generate(); WriteGeneratedMesh(disc_gen, "__g3Test_disc.obj"); TrivialRectGenerator rect_gen = new TrivialRectGenerator(); rect_gen.Generate(); WriteGeneratedMesh(rect_gen, "__g3Test_rect.obj"); PuncturedDiscGenerator punc_disc_gen = new PuncturedDiscGenerator(); punc_disc_gen.Generate(); WriteGeneratedMesh(punc_disc_gen, "__g3Test_punctured_disc.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.NoSharedVertices = true; box_gen.Generate(); WriteGeneratedMesh(box_gen, "__g3Test_trivial_box.obj"); RoundRectGenerator roundrect_gen = new RoundRectGenerator(); roundrect_gen.Width = 2; roundrect_gen.Generate(); WriteGeneratedMesh(roundrect_gen, "__g3Test_round_rect.obj"); }
static fMesh MakeBox() { TrivialBox3Generator gen = new TrivialBox3Generator() { Clockwise = false, NoSharedVertices = true }; gen.Generate(); return(new fMesh(gen.MakeUnityMesh())); }
public void AppendBox(Frame3f frame, float size) { TrivialBox3Generator boxgen = new TrivialBox3Generator() { Box = new Box3d(frame, size * 0.5 * Vector3D.One), NoSharedVertices = false }; boxgen.Generate(); NGonsCore.geometry3Sharp.mesh.DMesh3 mesh = new NGonsCore.geometry3Sharp.mesh.DMesh3(); boxgen.MakeMesh(mesh); AppendMesh(mesh, Mesh.AllocateTriangleGroup()); }
protected override fGameObject create_pivot_shape() { mesh_height = CC.Settings.LayerHeightMM; TrivialBox3Generator boxgen = new TrivialBox3Generator() { NoSharedVertices = true, Box = new Box3d(Vector3d.Zero, new Vector3d(2.5, CC.Settings.LayerHeightMM, 2.5)) }; DMesh3 mesh = boxgen.Generate().MakeDMesh(); fMeshGameObject meshGO = GameObjectFactory.CreateMeshGO("pivotMesh", new fMesh(mesh), true, true); meshGO.SetMaterial(MaterialUtil.CreateStandardMaterial(Colorf.Orange)); return(meshGO); }
private GCodeFile CreateGCode() { var boxGenerator = new TrivialBox3Generator(); boxGenerator.Box = new Box3d(new Vector3d(0, 0, 5), new Vector3d(5, 5, 5)); var mesh = boxGenerator.Generate().MakeDMesh(); var parts = new List <Tuple <DMesh3, PrintProfileFFF> >(); parts.Add(new Tuple <DMesh3, PrintProfileFFF>(mesh, null)); var settings = (PrintProfileFFF)engine.SettingsManager.CreateSettingsInstance(); settings.Part.LayerHeightMM = 1; var result = engine.Generator.GenerateGCode(parts, settings); return(result.Value?.File); }
static public fGameObject EmitDebugBox(string name, Box3d box, Colorf color, GameObject parent = null, bool bIsInWorldPos = true) { if (FPlatform.InMainThread() == false) { ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugBox(name, box, color, parent, bIsInWorldPos); }); return(null); } TrivialBox3Generator boxgen = new TrivialBox3Generator() { Box = box, NoSharedVertices = true, Clockwise = true }; boxgen.Generate(); DMesh3 mesh = boxgen.MakeDMesh(); fMeshGameObject fMeshGO = GameObjectFactory.CreateMeshGO(name, new fMesh(mesh), false, true); fMeshGO.SetMaterial(MaterialUtil.CreateStandardMaterialF(color)); if (parent != null) { parent.AddChild(fMeshGO, bIsInWorldPos); } return(fMeshGO); }
public static void test_basic_generators() { TrivialDiscGenerator disc_gen = new TrivialDiscGenerator(); WriteGeneratedMesh(disc_gen, "meshgen_Disc.obj"); TrivialRectGenerator rect_gen = new TrivialRectGenerator(); WriteGeneratedMesh(rect_gen, "meshgen_Rect.obj"); GriddedRectGenerator gridrect_gen = new GriddedRectGenerator(); WriteGeneratedMesh(gridrect_gen, "meshgen_GriddedRect.obj"); PuncturedDiscGenerator punc_disc_gen = new PuncturedDiscGenerator(); 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)); WriteGeneratedMesh(box_gen, "meshgen_TrivialBox_shared.obj"); box_gen.NoSharedVertices = true; WriteGeneratedMesh(box_gen, "meshgen_TrivialBox_noshared.obj"); RoundRectGenerator roundrect_gen = new RoundRectGenerator(); roundrect_gen.Width = 2; WriteGeneratedMesh(roundrect_gen, "meshgen_RoundRect.obj"); GridBox3Generator gridbox_gen = new GridBox3Generator(); WriteGeneratedMesh(gridbox_gen, "meshgen_GridBox_shared.obj"); gridbox_gen.NoSharedVertices = true; WriteGeneratedMesh(gridbox_gen, "meshgen_GridBox_noshared.obj"); Sphere3Generator_NormalizedCube normcube_gen = new Sphere3Generator_NormalizedCube(); 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); 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) }; WriteGeneratedMesh(tube_gen, "meshgen_TubeGenerator.obj"); tube_gen.Polygon.Translate(Vector2d.One); tube_gen.CapCenter = Vector2d.One; WriteGeneratedMesh(tube_gen, "meshgen_TubeGenerator_shifted.obj"); }
// [RMS] this only tests some basic cases... public static void test_RayBoxIntersect() { Random rand = new Random(316136327); // check that box hit works for (int ii = 0; ii < 1000; ++ii) { // generate random triangle Triangle3d t = new Triangle3d(rand.PointInRange(10), rand.PointInRange(10), rand.PointInRange(10)); AxisAlignedBox3d bounds = new AxisAlignedBox3d(t.V0); bounds.Contain(t.V1); bounds.Contain(t.V2); Vector3d c = (t.V0 + t.V1 + t.V2) / 3.0; for (int jj = 0; jj < 1000; ++jj) { Vector3d d = rand.Direction(); Ray3d ray = new Ray3d(c - 100 * d, d); IntrRay3AxisAlignedBox3 bhit = new IntrRay3AxisAlignedBox3(ray, bounds); Debug.Assert(bhit.Find()); IntrRay3Triangle3 thit = new IntrRay3Triangle3(ray, t); Debug.Assert(thit.Find()); Debug.Assert(bhit.RayParam0 < thit.RayParameter); } } int N = 100; for (int ii = 0; ii < N; ++ii) { // generate random boxes Vector3d c = rand.PointInRange(10); Vector3d e = rand.PositivePoint(); AxisAlignedBox3d aabox = new AxisAlignedBox3d(c - e, c + e); Box3d obox = new Box3d(c, Vector3d.AxisX, Vector3d.AxisY, Vector3d.AxisZ, e); double r = aabox.DiagonalLength; // center-out tests for (int jj = 0; jj < N; ++jj) { Ray3d ray = new Ray3d(c, rand.Direction()); assert_same_hit(aabox, obox, ray, true); } // outside-in tests for (int jj = 0; jj < N; ++jj) { Vector3d p = c + 2 * r * rand.Direction(); Ray3d ray = new Ray3d(p, (c - p).Normalized); assert_same_hit(aabox, obox, ray, true); } } // random rays int hits = 0; int InnerN = 1000; for (int ii = 0; ii < N; ++ii) { // generate random boxe Vector3d c = rand.PointInRange(10); Vector3d e = rand.PositivePoint(); // every tenth box, set an axis to degenerate if (ii % 10 == 0) { e[rand.Next() % 3] = 0; } AxisAlignedBox3d aabox = new AxisAlignedBox3d(c - e, c + e); Box3d obox = new Box3d(c, Vector3d.AxisX, Vector3d.AxisY, Vector3d.AxisZ, e); double r = aabox.DiagonalLength; TrivialBox3Generator boxgen = new TrivialBox3Generator() { Box = obox }; boxgen.Generate(); DMesh3 mesh = new DMesh3(); boxgen.MakeMesh(mesh); for (int i = 0; i < InnerN; ++i) { Vector3d target = c + rand.PointInRange(r); Vector3d o = c + rand.PointInRange(10 * r); Ray3d ray = new Ray3d(o, (target - o).Normalized); assert_same_hit(aabox, obox, ray, false); int hitT = MeshQueries.FindHitTriangle_LinearSearch(mesh, ray); bool bMeshHit = (hitT != DMesh3.InvalidID); if (bMeshHit) { ++hits; } IntrRay3AxisAlignedBox3 aabbhit = new IntrRay3AxisAlignedBox3(ray, aabox); Debug.Assert(aabbhit.Find() == bMeshHit); Debug.Assert(aabbhit.Test() == bMeshHit); } } System.Console.WriteLine("hit {0} of {1} rays", hits, N * InnerN); }