Ejemplo n.º 1
0
        void initialize_cut_op()
        {
            if (MeshSourceOp != null)
            {
                return;
            }

            MeshSourceOp = new WrapDMeshSourceOp()
            {
                MeshSourceF    = () => { return(InputMeshSO.Mesh); },
                SpatialSourceF = () => { return(InputMeshSO.Spatial); }
            };
            CutOp = new CutPolygonHoleOp()
            {
                MeshSource = MeshSourceOp
            };
            ComputeOp = new ThreadedMeshComputeOp()
            {
                MeshSource = CutOp
            };

            if (CutPreviewMaterial == null)
            {
                CutPreviewMaterial = SOMaterial.CreateFlatShaded("add_hole_cut", Colorf.DimGrey);
            }

            CutPreviewSO = new DMeshSO()
            {
                EnableSpatial = false
            };
            CutPreviewSO.Create(new DMesh3(), CutPreviewMaterial);
            Scene.AddSceneObject(CutPreviewSO);
            CutPreviewSO.SetLocalFrame(InputMeshSO.GetLocalFrame(CoordSpace.ObjectCoords), CoordSpace.ObjectCoords);
            CutPreviewSO.SetLocalScale(InputMeshSO.GetLocalScale());
        }
Ejemplo n.º 2
0
        public static void SetBasePoint(FScene scene, DMeshSO so, Frame3f baseFrameS, bool bInteractive)
        {
            Frame3f curFrameS = so.GetLocalFrame(CoordSpace.SceneCoords);
            Frame3f relFrameS = baseFrameS.ToFrame(curFrameS);

            baseFrameS.AlignAxis(2, -Vector3f.AxisY);
            baseFrameS.Translate(-baseFrameS.Origin);

            Frame3f           newFrameS = baseFrameS.FromFrame(relFrameS);
            TransformSOChange change    = new TransformSOChange(so, curFrameS, newFrameS, CoordSpace.SceneCoords);

            change.Tags.Add("SetBasePoint");
            scene.History.PushChange(change, false);

            Frame3f pivotS = Frame3f.Identity;
            // WHAT why is it the scene pivot ?!
            //Frame3f pivotL = SceneTransforms.SceneToObject(so, pivotS);
            RepositionPivotChangeOp pivotChange = new RepositionPivotChangeOp(pivotS, so);

            scene.History.PushChange(pivotChange, false);

            if (bInteractive)
            {
                scene.History.PushInteractionCheckpoint();
            }
        }
Ejemplo n.º 3
0
        void begin_capture(InputState input, CaptureSide eSide)
        {
            Frame3f handFrameW = (eSide == CaptureSide.Left) ? input.LeftHandFrame : input.RightHandFrame;

            lastPosS          = SceneTransforms.WorldToScene(context.Scene, handFrameW);
            startPosS         = lastPosS;
            startSocketFrameS = legSO.GetLocalFrame(CoordSpace.SceneCoords);
            startAxisS        = new Line3f(startSocketFrameS.Origin, startSocketFrameS.Y);


            if (op is EnclosedRegionOffsetOp)
            {
                EnclosedRegionOffsetOp deformOp = op as EnclosedRegionOffsetOp;
                startParam0 = deformOp.PushPullDistance;
            }
            else if (op is EnclosedRegionSmoothOp)
            {
                EnclosedRegionSmoothOp deformOp = op as EnclosedRegionSmoothOp;
                startParam0 = deformOp.OffsetDistance;
                startParam1 = deformOp.SmoothAlpha;
            }
            else if (op is PlaneBandExpansionOp)
            {
                PlaneBandExpansionOp deformOp = op as PlaneBandExpansionOp;
                startParam0 = deformOp.PushPullDistance;
                startParam1 = deformOp.BandDistance;
            }
        }
Ejemplo n.º 4
0
        static PrintMeshSO emit_new_print_mesh(DMesh3 mesh, DMeshSO fromParent)
        {
            PrintMeshSO newSO = new PrintMeshSO();

            newSO.Create(mesh, CCMaterials.PrintMeshMaterial);
            CCActions.AddNewPrintMesh(newSO);
            if (fromParent != null)
            {
                newSO.SetLocalScale(fromParent.GetLocalScale());
                newSO.SetLocalFrame(fromParent.GetLocalFrame(CoordSpace.SceneCoords), CoordSpace.SceneCoords);
            }
            else
            {
                throw new NotImplementedException("have not implemented this path yet...");
                // estimate frame??
            }

            return(newSO);
        }
Ejemplo n.º 5
0
        public static void MoveToPrintBed(FScene scene, DMeshSO so, bool bInteractive)
        {
            TransformSequence seq    = SceneTransforms.ObjectToSceneXForm(so);
            AxisAlignedBox3d  bounds = BoundsUtil.Bounds(so.Mesh.Vertices(), seq);

            Frame3f curFrameS = so.GetLocalFrame(CoordSpace.SceneCoords);
            float   dy        = (float)(bounds.Center.y - bounds.Extents.y);

            if (Math.Abs(dy) > MathUtil.ZeroTolerancef)
            {
                Frame3f newFrameS = curFrameS;
                newFrameS.Origin = curFrameS.Origin - dy * Vector3f.AxisY;
                TransformSOChange change = new TransformSOChange(so, curFrameS, newFrameS, CoordSpace.SceneCoords);
                change.Tags.Add("MoveToPrintBed");
                scene.History.PushChange(change, false);
                if (bInteractive)
                {
                    scene.History.PushInteractionCheckpoint();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This is the action we give to the trim-scan tool, to run on accept
        /// </summary>
        public static void CropScanFromSelection(DMeshSO so, MeshFaceSelection selection, object tool)
        {
            DMesh3 beforeMesh = new DMesh3(so.Mesh);
            DMesh3 mesh       = so.Mesh;

            // [RMS] if we are using the two-point tool, then we can use the user input points to
            // try to figure out an up axis, by assuming the first point is on the base of the scan. Steps are:
            //   1) guess a midpoint. Currently centroid of upper-half of geodesic selection.
            //   2) construct up axis as (midpoint-basepoint). this axis to Y-up.
            Vector3f upAxisS = Vector3f.AxisY;
            TwoPointFaceSelectionTool ptool = tool as TwoPointFaceSelectionTool;

            if (ptool != null)
            {
                var        cache     = ptool.SelectionCache;
                Interval1d range     = new Interval1d(cache.CurrentScalarThreshold / 2, cache.CurrentScalarThreshold);
                List <int> triangles = new List <int>(selection.Count);
                cache.FindTrianglesInScalarInterval(range, triangles);
                Vector3d c        = MeshMeasurements.Centroid(triangles, mesh.GetTriCentroid);
                Vector3d cS       = SceneTransforms.ObjectToSceneP(so, c);
                Vector3d basePosS = ptool.SourcePositionS.Origin;
                upAxisS = (Vector3f)(cS - basePosS).Normalized;
            }

            // crop scan and fill top hole
            List <int> borderTris = selection.FindBorderTris();
            MeshEditor editor     = new MeshEditor(mesh);

            editor.RemoveTriangles((tid) => { return(selection.IsSelected(tid) == false); }, true);
            if (OGActions.FillHoleInScan)
            {
                SmoothedHoleFill fill = new SmoothedHoleFill(mesh)
                {
                    TargetEdgeLength = 2.5f,
                    SmoothAlpha      = 0.5f,
                    BorderHintTris   = borderTris,
                    OffsetDirection  = SceneTransforms.SceneToObjectN(so, upAxisS),
                    OffsetDistance   = (ptool != null) ? 25.0 : 0.0
                };
                fill.Apply();
            }

            so.NotifyMeshEdited();
            DMesh3 afterMesh = new DMesh3(so.Mesh);

            so.GetScene().History.PushChange(new ReplaceEntireMeshChange(so, beforeMesh, afterMesh), true);
            mesh = so.Mesh;

            // Now we auto-align the scan so it points upwards, and then
            // recenter pivot and shift to above ground plane
            if (ptool != null)
            {
                Vector3d    basePosS = ptool.SourcePositionS.Origin;
                Quaternionf alignUp  = Quaternionf.FromTo(upAxisS, Vector3f.AxisY);

                // rotate part so that axis points up
                Frame3f           curF          = so.GetLocalFrame(CoordSpace.SceneCoords);
                Frame3f           newF          = curF.Rotated(alignUp);
                TransformSOChange alignUpChange = new TransformSOChange(so, curF, newF, CoordSpace.SceneCoords);
                basePosS = newF.FromFrameP(curF.ToFrameP(basePosS));   // map to new frame
                so.GetScene().History.PushChange(alignUpChange, false);

                // recenter pivot at bbox center
                // [RMS] previously was using vertex centroid, but this is then affected by mesh density
                //   (maybe tri centroid? but bbox makes more sense...and below we assume box center)
                Vector3d centerL   = mesh.CachedBounds.Center;
                Vector3d centerO   = newF.FromFrameP(centerL);
                Frame3f  newPivotO = new Frame3f(centerO);
                so.GetScene().History.PushChange(new RepositionPivotChangeOp(newPivotO, so), false);

                // position above ground plane
                AxisAlignedBox3d bounds     = so.Mesh.CachedBounds;
                float            h          = (float)bounds.Height;
                Vector3f         o          = newPivotO.Origin;
                Vector3f         translateO = new Vector3f(-o.x, h * 0.5f - o.y + BaseHeightAboveGroundPlaneMM, -o.z);
                //Vector3f translateO = new Vector3f(0, h * 0.5f - o.y + BaseHeightAboveGroundPlaneMM, 0);
                newPivotO.Translate(translateO);
                so.GetScene().History.PushChange(new TransformSOChange(so, newPivotO, CoordSpace.ObjectCoords), false);

                // save base point in frame of scan
                basePosS += translateO;
                Vector3d basePosL = SceneTransforms.SceneToObjectP(so, basePosS);
                OG.Scan.UserBasePoint = basePosL;
            }

            so.GetScene().History.PushInteractionCheckpoint();
        }