예제 #1
0
 protected override void process_new_result(DMeshOutputStatus result)
 {
     if (result.Mesh != null)
     {
         DSubmesh3 submesh = result.Mesh.FindMetadata("removed_submesh") as DSubmesh3;
         if (submesh != null)
         {
             RemovedSO.ReplaceMesh(submesh.SubMesh, true);
             result.Mesh.RemoveMetadata("removed_submesh");
         }
     }
 }
예제 #2
0
        void update_hole_mesh()
        {
            CappedCylinderGenerator cylgen = new CappedCylinderGenerator()
            {
                BaseRadius = 0.5f, TopRadius = 0.5f, Height = 1, Slices = this.subdivisions,
                Clockwise  = true
            };
            DMesh3 mesh = cylgen.Generate().MakeDMesh();

            MeshTransforms.Rotate(mesh, Vector3d.Zero, Quaterniond.AxisAngleD(Vector3d.AxisX, 90));
            CavityPreviewSO.ReplaceMesh(mesh, true);
        }
예제 #3
0
        void update_cut_op()
        {
            List <ModelingOpException> exceptions = null;

            if (cut_parameters_dirty)
            {
                CutOp.HoleSize         = hole_size;
                CutOp.HoleSubdivisions = subdivisions;
                CutOp.ThroughHole      = through_hole;
                CutOp.HoleDepth        = hole_depth;
                cut_parameters_dirty   = false;
            }

            try {
                DMeshOutputStatus result = ComputeOp.CheckForNewMesh();
                is_computing = (result.State == DMeshOutputStatus.States.Computing);
                if (result.State == DMeshOutputStatus.States.Ready)
                {
                    current_result_ok = (result.IsErrorOutput() == false);

                    var setMesh = result.Mesh;
                    if (result.Mesh.CompactMetric < 0.8)
                    {
                        setMesh = new DMesh3(result.Mesh, true);
                    }
                    CutPreviewSO.ReplaceMesh(setMesh, true);
                    CutPreviewSO.AssignSOMaterial((current_result_ok) ? CutPreviewMaterial : ErrorMaterial);

                    exceptions = result.ComputeExceptions;
                }
            } catch (Exception e) {
                DebugUtil.Log(2, Name + "Tool.PreRender: caught exception! " + e.Message);
            }

            if (ComputeOp.HaveBackgroundException)
            {
                Exception e = ComputeOp.ExtractBackgroundException();
                if (VerboseOutput)
                {
                    DebugUtil.Log(2, GetType().ToString() + ".PreRender: exception in background compute: " + e.Message);
                    DebugUtil.Log(2, e.StackTrace);
                }
            }

            if (exceptions != null && VerboseOutput)
            {
                foreach (var mopex in exceptions)
                {
                    DebugUtil.Log(2, GetType().ToString() + ".PreRender: exception in background compute " + mopex.op.GetType().ToString() + " : " + mopex.e.Message);
                    DebugUtil.Log(2, mopex.e.StackTrace);
                }
            }
        }
예제 #4
0
        virtual public void PreRender()
        {
            if (in_shutdown())
            {
                return;
            }

            List <ModelingOpException> exceptions = null;

            try {
                DMeshOutputStatus result = ComputeOp.CheckForNewMesh();
                is_computing = (result.State == DMeshOutputStatus.States.Computing);
                if (result.State == DMeshOutputStatus.States.Ready)
                {
                    process_new_result(result);
                    current_result_ok = (result.IsErrorOutput() == false);

                    var setMesh = result.Mesh;
                    if (result.Mesh.CompactMetric < 0.8)
                    {
                        setMesh = new DMesh3(result.Mesh, true);
                    }
                    PreviewSO.ReplaceMesh(setMesh, true);
                    PreviewSO.AssignSOMaterial((current_result_ok) ? PreviewMaterial : ErrorMaterial);

                    exceptions = result.ComputeExceptions;
                }
            } catch (Exception e) {
                DebugUtil.Log(2, Name + "Tool.PreRender: caught exception! " + e.Message);
            }

            if (ComputeOp.HaveBackgroundException)
            {
                Exception e = ComputeOp.ExtractBackgroundException();
                DebugUtil.Log(2, GetType().ToString() + ".PreRender: exception in background compute: " + e.Message);
                DebugUtil.Log(2, e.StackTrace);
            }

            if (exceptions != null)
            {
                foreach (var mopex in exceptions)
                {
                    DebugUtil.Log(2, GetType().ToString() + ".PreRender: exception in background compute " + mopex.op.GetType().ToString() + " : " + mopex.e.Message);
                    DebugUtil.Log(2, mopex.e.StackTrace);
                }
            }
        }
예제 #5
0
        virtual public void PreRender()
        {
            if (in_shutdown())
            {
                return;
            }

            if (parameters_dirty)
            {
                DMesh3 new_shape_mesh = null;
                switch (shape_type)
                {
                case ShapeTypes.Box:
                    new_shape_mesh = make_shape_box(); break;

                default:
                case ShapeTypes.Sphere:
                    new_shape_mesh = make_shape_sphere(); break;

                case ShapeTypes.Cylinder:
                    new_shape_mesh = make_shape_cylinder(); break;

                case ShapeTypes.Arrow:
                    new_shape_mesh = make_shape_arrow(); break;

                case ShapeTypes.Bunny:
                    new_shape_mesh = make_bunny(); break;
                }

                if (new_shape_mesh != null)
                {
                    PreviewSO.ReplaceMesh(new_shape_mesh, true);
                }

                PreviewSO.Name = shape_type.ToString();

                parameters_dirty = false;
            }
        }
예제 #6
0
        virtual public void PreRender()
        {
            if (in_shutdown())
            {
                return;
            }

            if (parameters_dirty)
            {
                PolyLine2d spiral = PolyLine2d.MakeBoxSpiral(Vector2d.Zero, length, PathWidth + spacing);

                DMesh3 mesh = new DMesh3();

                List <int> bottom_verts = new List <int>();
                List <int> top_verts    = new List <int>();
                for (int i = 0; i < spiral.VertexCount; ++i)
                {
                    Vector2d x  = spiral[i];
                    Vector3d vb = new Vector3d(x.x, 0, x.y);
                    bottom_verts.Add(mesh.AppendVertex(vb));
                    top_verts.Add(mesh.AppendVertex(vb + Height * Vector3d.AxisY));
                }

                MeshEditor editor = new MeshEditor(mesh);
                editor.StitchSpan(bottom_verts, top_verts);

                PreviewSO.ReplaceMesh(mesh, true);

                Vector3d translate = scene_bounds.Point(1, -1, 1);
                translate.x += spiral.Bounds.Width + PathWidth;
                Frame3f sceneF = Frame3f.Identity.Translated((Vector3f)translate);
                PreviewSO.SetLocalFrame(sceneF, CoordSpace.SceneCoords);

                parameters_dirty = false;
            }
        }
예제 #7
0
        virtual public void PreRender()
        {
            if (in_shutdown())
            {
                return;
            }

            if (parameters_dirty)
            {
                // offset
                List <GeneralPolygon2d> offset = ClipperUtil.RoundOffset(combined_all, offset_distance);
                // aggressively simplify after round offset...
                foreach (var poly in offset)
                {
                    poly.Simplify(path_width);
                }

                // subtract initial and add tiny gap so these don't get merged by slicer
                if (SubtractSolids)
                {
                    offset = ClipperUtil.Difference(offset, combined_solid);
                    offset = ClipperUtil.MiterOffset(offset, -path_width * 0.1);
                }

                offset = CurveUtils2.FilterDegenerate(offset, 0.001);
                foreach (var poly in offset)
                {
                    poly.Simplify(path_width * 0.02);
                }

                DMesh3     mesh   = new DMesh3();
                MeshEditor editor = new MeshEditor(mesh);
                foreach (var poly in offset)
                {
                    TriangulatedPolygonGenerator polygen = new TriangulatedPolygonGenerator()
                    {
                        Polygon = poly
                    };
                    editor.AppendMesh(polygen.Generate().MakeDMesh());
                }
                MeshTransforms.ConvertZUpToYUp(mesh);

                if (mesh.TriangleCount > 0)
                {
                    MeshExtrudeMesh extrude = new MeshExtrudeMesh(mesh);
                    extrude.ExtrudedPositionF = (v, n, vid) => {
                        return(v + Layers * layer_height * Vector3d.AxisY);
                    };
                    extrude.Extrude();
                    MeshTransforms.Translate(mesh, -mesh.CachedBounds.Min.y * Vector3d.AxisY);
                }

                PreviewSO.ReplaceMesh(mesh, true);

                //Vector3d translate = scene_bounds.Point(1, -1, 1);
                //translate.x += spiral.Bounds.Width + PathWidth;
                //Frame3f sceneF = Frame3f.Identity.Translated((Vector3f)translate);
                //PreviewSO.SetLocalFrame(sceneF, CoordSpace.SceneCoords);

                parameters_dirty = false;
            }
        }