public static void copy_performance() { Sphere3Generator_NormalizedCube meshgen = new Sphere3Generator_NormalizedCube() { EdgeVertices = 200 }; meshgen.Generate(); DMesh3 sphereMesh = meshgen.MakeDMesh(); DateTime start = DateTime.Now; for (int k = 0; k < 250; ++k) { if (k % 10 == 0) { System.Console.WriteLine("{0} / 250", k); } DMesh3 m = new DMesh3(sphereMesh); //m.CheckValidity(); //if (!m.IsSameMesh(sphereMesh)) // System.Console.WriteLine("NOT SAME MESH!"); } DateTime end = DateTime.Now; System.Console.WriteLine("Time {0}", (end - start).TotalSeconds); }
virtual protected DMesh3 make_shape_sphere() { Vector3d origin = new Vector3d(0, ShapeHeight / 2, 0); Sphere3Generator_NormalizedCube spheregen = new Sphere3Generator_NormalizedCube() { Box = new Box3d(origin, Vector3d.One), Radius = ShapeHeight / 2, EdgeVertices = Subdivisions }; return(spheregen.Generate().MakeDMesh()); }
public static void test_AABBTree_TriTriDist() { System.Console.WriteLine("test_AABBTree_TriTriDist()"); Sphere3Generator_NormalizedCube gen = new Sphere3Generator_NormalizedCube() { Radius = 1, EdgeVertices = 6 }; DMesh3 sphereMesh = gen.Generate().MakeDMesh(); Reducer reducer = new Reducer(sphereMesh); reducer.ReduceToTriangleCount(77); Random r = new Random(31337); for (int iter = 0; iter < 1000; ++iter) { DMesh3 sphere1 = new DMesh3(sphereMesh), sphere2 = new DMesh3(sphereMesh); Vector3d[] pts = TestUtil.RandomPoints3(3, r, Vector3d.Zero, 100); Vector3d p1 = pts[0], p2 = pts[1]; double r1 = 5, r2 = 10; MeshTransforms.Scale(sphere1, r1); MeshTransforms.Translate(sphere1, p1); MeshTransforms.Scale(sphere2, r2); MeshTransforms.Translate(sphere2, p2); DMeshAABBTree3 tree1 = new DMeshAABBTree3(sphere1, true); DMeshAABBTree3 tree2 = new DMeshAABBTree3(sphere2, true); double sphere_dist = p1.Distance(p2) - (r1 + r2); double distBrute = double.MaxValue; Index2i nearestBrute = MeshQueries.FindNearestTriangles_LinearSearch(sphere1, sphere2, out distBrute); DistTriangle3Triangle3 qBrute = MeshQueries.TrianglesDistance(sphere1, nearestBrute.a, sphere2, nearestBrute.b); double distTree = double.MaxValue; Index2i nearestTree = tree1.FindNearestTriangles(tree2, null, out distTree); DistTriangle3Triangle3 qTree = MeshQueries.TrianglesDistance(sphere1, nearestTree.a, sphere2, nearestTree.b); double distTree2 = double.MaxValue; Index2i nearestTree2 = tree2.FindNearestTriangles(tree1, null, out distTree2); // pairs are unstable if we are on an edge if (qBrute.Triangle0BaryCoords.x < 0.99 && qBrute.Triangle0BaryCoords.y < 0.99 && qBrute.Triangle0BaryCoords.z < 0.99 && qBrute.Triangle1BaryCoords.x < 0.99 && qBrute.Triangle1BaryCoords.y < 0.99 && qBrute.Triangle1BaryCoords.z < 0.99) { Util.gDevAssert(nearestBrute.a == nearestTree.a && nearestBrute.b == nearestTree.b); Util.gDevAssert(nearestBrute.b == nearestTree2.a && nearestBrute.a == nearestTree.b); } Util.gDevAssert(Math.Abs(distBrute - distTree) < MathUtil.Epsilonf && Math.Abs(distBrute - distTree2) < MathUtil.Epsilonf); } }
public static void test_AABBTree_TriTriIntr() { System.Console.WriteLine("test_AABBTree_TriTriIntr()"); Sphere3Generator_NormalizedCube gen = new Sphere3Generator_NormalizedCube() { Radius = 1, EdgeVertices = 25 }; DMesh3 sphereMesh = gen.Generate().MakeDMesh(); Reducer reducer = new Reducer(sphereMesh); reducer.ReduceToTriangleCount(77); int hit_count = 0; Random r = new Random(31337); for (int iter = 0; iter < 5000; ++iter) { DMesh3 sphere1 = new DMesh3(sphereMesh), sphere2 = new DMesh3(sphereMesh); Vector3d[] pts = TestUtil.RandomPoints3(3, r, Vector3d.Zero, 10); // at 10, about half of the spheres intersect Vector3d p1 = pts[0], p2 = pts[1]; double r1 = 5, r2 = 10; double eps = (r1 + r2) * 0.5 * 0.001; MeshTransforms.Scale(sphere1, r1); MeshTransforms.Translate(sphere1, p1); MeshTransforms.Scale(sphere2, r2); MeshTransforms.Translate(sphere2, p2); DMeshAABBTree3 tree1 = new DMeshAABBTree3(sphere1, true); DMeshAABBTree3 tree2 = new DMeshAABBTree3(sphere2, true); bool spheres_intersect = p1.Distance(p2) < (r1 + r2 + 2 * eps); if (spheres_intersect && p1.Distance(p2) + Math.Min(r1, r2) < Math.Max(r1, r2) * 0.9) { spheres_intersect = false; } Index2i hitBrute = MeshQueries.FindIntersectingTriangles_LinearSearch(sphere1, sphere2); bool bHitBrute = hitBrute != Index2i.Max; if (bHitBrute) { hit_count++; } // [RMS] not reliable because of tesselation //Util.gDevAssert(bHitBrute == spheres_intersect); bool bHitTree1 = tree1.TestIntersection(tree2); bool bHitTree2 = tree2.TestIntersection(tree1); Util.gDevAssert(bHitBrute == bHitTree1 && bHitTree1 == bHitTree2); } System.Console.WriteLine(hit_count.ToString()); }
void set_failure_output(DMesh3 lastOKMesh) { if (lastOKMesh == null) { Sphere3Generator_NormalizedCube gen = new Sphere3Generator_NormalizedCube() { Radius = 50 }; ResultMesh = gen.Generate().MakeDMesh(); } else { ResultMesh = new DMesh3(lastOKMesh, false, MeshComponents.None); } ResultMesh.EnableVertexColors(Colorf.VideoRed); last_result_status = ResultStatus.ErrorResult; }
// Use this for initialization void Start() { // find path to sample file string curPath = Application.dataPath; string filePath = Path.Combine(curPath, Path.Combine("..\\sample_files", "bunny_solid.obj")); // load sample file, convert to unity coordinate system, translate and scale to origin Sphere3Generator_NormalizedCube spheregen = new Sphere3Generator_NormalizedCube() { Radius = SphereRadius }; sphereMesh = spheregen.Generate().MakeDMesh(); // load wireframe shader Material wireframeShader = g3UnityUtils.SafeLoadMaterial("wireframe_shader/Wireframe"); // create initial mesh meshGO = g3UnityUtils.CreateMeshGO("sphere", sphereMesh, wireframeShader); }
public static DMesh3 MakeFailureOutput(DMesh3 sourceMesh, bool bCopy = true) { DMesh3 failMesh = null; if (sourceMesh == null) { Sphere3Generator_NormalizedCube gen = new Sphere3Generator_NormalizedCube() { Radius = 25 }; failMesh = gen.Generate().MakeDMesh(); failMesh.EnableVertexColors(Colorf.VideoRed); } else if (bCopy) { failMesh = new DMesh3(sourceMesh, false, MeshComponents.None); failMesh.EnableVertexColors(Colorf.VideoRed); } TagAsFailureMesh(failMesh); return(failMesh); }
public static void performance_grinder() { LocalProfiler p = new LocalProfiler(); DateTime start = DateTime.Now; //p.Start("Meshgen"); //for (int k = 0; k < 100; ++k) { // Sphere3Generator_NormalizedCube tmpgen = new Sphere3Generator_NormalizedCube(); // tmpgen.EdgeVertices = 100; // tmpgen.Generate(); // DMesh3 tmp = tmpgen.MakeDMesh(); //} //p.StopAndAccumulate("Meshgen"); //System.Console.WriteLine("done meshgen"); Sphere3Generator_NormalizedCube meshgen = new Sphere3Generator_NormalizedCube() { EdgeVertices = 100 }; meshgen.Generate(); DMesh3 sphereMesh = meshgen.MakeDMesh(); //p.Start("Spatial"); //for (int k = 0; k < 100; ++k) { // DMeshAABBTree3 tmpspatial = new DMeshAABBTree3(sphereMesh); // tmpspatial.Build(); //} //p.StopAndAccumulate("Spatial"); //System.Console.WriteLine("done spatial"); meshgen.EdgeVertices = 5; meshgen.Generate(); sphereMesh = meshgen.MakeDMesh(); double remesh_len = (2.0 / 5.0) * 0.025; // takes ~220s //double remesh_len = (2.0 / 5.0) * 0.05; long max_mem = 0; Remesher remesher = new Remesher(sphereMesh); for (int k = 0; k < 10; ++k) { System.Console.WriteLine("{0}", k); p.Start("Remesh"); remesher.SetTargetEdgeLength(remesh_len); remesher.SmoothSpeedT = 0.5f; for (int j = 0; j < 20; ++j) { remesher.BasicRemeshPass(); foreach (int vid in sphereMesh.VertexIndices()) { Vector3d v = sphereMesh.GetVertex(vid); v.Normalize(); sphereMesh.SetVertex(vid, v); } } p.StopAndAccumulate("Remesh"); //System.Console.WriteLine(sphereMesh.MeshInfoString()); System.Console.WriteLine(" {0}", k); p.Start("Reduce"); remesher.SetTargetEdgeLength(remesh_len * 10); for (int j = 0; j < 20; ++j) { remesher.BasicRemeshPass(); foreach (int vid in sphereMesh.VertexIndices()) { Vector3d v = sphereMesh.GetVertex(vid); v.Normalize(); sphereMesh.SetVertex(vid, v); } } p.StopAndAccumulate("Reduce"); } DateTime end = DateTime.Now; System.Console.WriteLine("done remesh"); System.Console.WriteLine("Time {0} MaxMem {1}", (end - start).TotalSeconds, max_mem / (1024 * 1024)); System.Console.WriteLine(p.AllAccumulatedTimes("Accumulated: ")); }
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"); }
public static void test_Winding() { Sphere3Generator_NormalizedCube gen = new Sphere3Generator_NormalizedCube() { EdgeVertices = 200 }; DMesh3 mesh = gen.Generate().MakeDMesh(); //DMesh3 mesh = TestUtil.LoadTestInputMesh("bunny_solid.obj"); DMeshAABBTree3 spatial = new DMeshAABBTree3(mesh, true); GC.Collect(); double maxdim = mesh.CachedBounds.MaxDim; Vector3d center = mesh.CachedBounds.Center; var pts = TestUtil.RandomPoints3(100, new Random(31337), center, maxdim * 0.5); int num_inside = 0; foreach (Vector3d pt in pts) { bool inside = spatial.IsInside(pt); double distSqr = MeshQueries.TriDistanceSqr(mesh, spatial.FindNearestTriangle(pt), pt); double ptDist = pt.Length; double winding = mesh.WindingNumber(pt); double winding_2 = spatial.WindingNumber(pt); if (Math.Abs(winding - winding_2) > 0.00001) { System.Diagnostics.Debugger.Break(); } bool winding_inside = Math.Abs(winding) > 0.5; if (inside != winding_inside) { System.Diagnostics.Debugger.Break(); } if (inside) { num_inside++; } } System.Console.WriteLine("inside {0} / {1}", num_inside, pts.Length); // force rebuild for profiling code GC.Collect(); LocalProfiler p = new LocalProfiler(); pts = TestUtil.RandomPoints3(1000, new Random(31337), center, maxdim * 0.5); p.Start("full eval"); double sum = 0; foreach (Vector3d pt in pts) { double winding = mesh.WindingNumber(pt); sum += winding; } p.StopAll(); p.Start("tree build"); spatial = new DMeshAABBTree3(mesh, true); spatial.WindingNumber(Vector3d.Zero); p.StopAll(); GC.Collect(); GC.Collect(); p.Start("tree eval"); sum = 0; foreach (Vector3d pt in pts) { double winding = spatial.WindingNumber(pt); sum += winding; } p.StopAll(); System.Console.WriteLine(p.AllTimes()); }
// Use this for initialization public override void Awake() { VRPlatform.VREnabled = false; // restore any settings SceneGraphConfig.RestorePreferences(); // set up some defaults SceneGraphConfig.DefaultSceneCurveVisualDegrees = 0.5f; SceneGraphConfig.DefaultPivotVisualDegrees = 1.5f; SceneGraphConfig.DefaultAxisGizmoVisualDegrees = 10.0f; SceneOptions options = new SceneOptions(); options.UseSystemMouseCursor = true; options.EnableCockpit = true; options.Use2DCockpit = true; options.ConstantSize2DCockpit = true; // you usually want this options.EnableTransforms = true; options.CockpitInitializer = new SetupObjectsDemoCockpit(); options.MouseCameraControls = new MayaCameraHotkeys(); // very verbose options.LogLevel = 2; context = new FContext(); context.Start(options); // register transformation gizmos //context.TransformManager.RegisterGizmoType(AxisTransformGizmo.DefaultName, new AxisTransformGizmoBuilder()); //context.TransformManager.SetActiveGizmoType(AxisTransformGizmo.DefaultName); // if you had other tools, you would register them here. context.ToolManager.RegisterToolType(DrawPrimitivesTool.Identifier, new DrawPrimitivesToolBuilder()); context.ToolManager.SetActiveToolType(DrawPrimitivesTool.Identifier, ToolSide.Right); // Set up standard scene lighting if requested if (options.EnableDefaultLighting) { GameObject lighting = GameObject.Find("SceneLighting"); if (lighting == null) { lighting = new GameObject("SceneLighting"); } SceneLightingSetup setup = lighting.AddComponent <SceneLightingSetup>(); setup.Context = context; setup.LightDistance = 30.0f; // related to total scene scale... } /* * Import elements of Unity scene that already exist into the FScene */ // set up ground plane geometry (optional) GameObject groundPlane = GameObject.Find("GroundPlane"); context.Scene.AddWorldBoundsObject(groundPlane); Sphere3Generator_NormalizedCube gen = new Sphere3Generator_NormalizedCube() { Radius = 1.0f }; DMeshSO meshSO = new DMeshSO(); meshSO.Create(gen.Generate().MakeDMesh(), Context.Scene.DefaultMeshSOMaterial); Context.Scene.AddSceneObject(meshSO); //SceneObject focusSO = null; // convert a mesh GameObject to our DMeshSO // Note: any child GameObjects will be lost GameObject meshGO = GameObject.Find("bunny_mesh"); if (meshGO != null) { //DMeshSO meshSO = UnitySceneUtil.WrapMeshGameObject(meshGO, context, true) as DMeshSO; UnitySceneUtil.WrapMeshGameObject(meshGO, context, true); } GameObject meshGO2 = GameObject.Find("bunny_mesh2"); if (meshGO2 != null) { //DMeshSO meshSO = UnitySceneUtil.WrapMeshGameObject(meshGO, context, true) as DMeshSO; UnitySceneUtil.WrapMeshGameObject(meshGO2, context, true); } //// center the camera on the capsule assembly //if (focusSO != null) { // Vector3f centerPt = focusSO.GetLocalFrame(CoordSpace.WorldCoords).Origin; // context.ActiveCamera.Manipulator().ScenePanFocus( // context.Scene, context.ActiveCamera, centerPt, true); //} }