protected virtual void update_handle_position() { if (handleGO == null) { return; } float t = (float)(snapped_value - 0.5); Frame3f handleF = handleStart; handleF.Translate(SliderWidth * t * handleF.X); float dz = get_handle_offset(handleGO); handleF.Translate(dz * handleF.Z); handleGO.SetLocalFrame(handleF); }
virtual public Frame3f From2DCoords(Vector2f pos, float fNormalOffset) { Frame3f f = new Frame3f(Frame); f.Translate(pos.x * Frame.X + pos.y * Frame.Y + fNormalOffset * Frame.Z); return(f); }
/// <summary> /// Initialize the data model to the new-imported-scan state, with the given mesh (presumably loaded from file?) /// </summary> public static void InitializeScan(DMesh3 mesh) { AxisAlignedBox3d bounds = mesh.CachedBounds; Vector3d translate = -bounds.Center; double dy = 0.5 * bounds.Height; MeshTransforms.Translate(mesh, translate); ScanSO scanSO = new ScanSO(); scanSO.Create(mesh, OrthogenMaterials.ScanMaterial); OG.Scene.AddSceneObject(scanSO); Frame3f f = scanSO.GetLocalFrame(CoordSpace.SceneCoords); f.Translate((float)dy * Vector3f.AxisY); scanSO.SetLocalFrame(f, CoordSpace.SceneCoords); OG.Model.InitializeScan(scanSO); OG.Model.Workflow.SetInitialState(ScanState.Identifier); // reposition camera Vector3f c = scanSO.GetLocalFrame(CoordSpace.WorldCoords).Origin; //OG.Context.ActiveCamera.Animator().PanFocus(c); OG.Context.ActiveCamera.Manipulator().ScenePanFocus( OG.Context.Scene, OG.Context.ActiveCamera, c, false); // [TODO] this should happen via a transition, I think... // set up xforms/etc OG.Context.TransformManager.SetActiveGizmoType(AxisTransformGizmo.DefaultName); }
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(); } }
void add(HUDStandardItem element, LayoutOptions options) { if (element.IsVisible == false) { element.IsVisible = true; } IBoxModelElement elemBoxModel = element as IBoxModelElement; // for 2D view (but doesn't matter if we are doing a layout anyway!) Frame3f viewFrame = Cockpit.GetViewFrame2D(); // with 3D view we should use this... //Frame3f viewFrame = Frame3f.Identity; element.SetObjectFrame(Frame3f.Identity); HUDUtil.PlaceInViewPlane(element, viewFrame); Cockpit.AddUIElement(element); Func <Vector2f> pinSourceF = options.PinSourcePoint2D; if (pinSourceF == null) { pinSourceF = LayoutUtil.BoxPointF(elemBoxModel, BoxPosition.Center); } Func <Vector2f> pinTargetF = options.PinTargetPoint2D; if (pinTargetF == null) { pinTargetF = LayoutUtil.BoxPointF(Solver.Container, BoxPosition.Center); } Solver.AddLayoutItem(element, pinSourceF, pinTargetF, this.StandardDepth + options.DepthShift); // if we want to shift result in its layout frame, do that via a post-transform if (options.FrameAxesShift != Vector3f.Zero) { Solver.AddPostTransform(element, (e) => { Frame3f f = (e as IElementFrame).GetObjectFrame(); f.Translate(options.FrameAxesShift.x * f.X + options.FrameAxesShift.y * f.Y + options.FrameAxesShift.z * f.Z); (e as IElementFrame).SetObjectFrame(f); }); } // auto-show if ((options.Flags & LayoutFlags.AnimatedShow) != 0) { HUDUtil.AnimatedShow(element); } }
void update_current_hole_type() { if (HoleType == HoleTypes.CutHole) { if (CutOp != null) { CutOp.StartPoint = LastUpdateRay.Origin; CutOp.EndPoint = LastUpdateRay.PointAt(LastThroughDepth); } } if (HoleType == HoleTypes.CavityObject || AlwaysShowPreview) { Frame3f holeFrame = new Frame3f(LastUpdateRay.Origin, LastUpdateRay.Direction); holeFrame.Translate((float)(-CurEndOffset) * holeFrame.Z); Frame3f holeFrameS = SceneTransforms.ObjectToScene(InputMeshSO, holeFrame); CavityPreviewSO.SetLocalFrame(holeFrameS, CoordSpace.SceneCoords); CavityPreviewSO.SetLocalScale(new Vector3f(hole_size, hole_size, (float)CurHoleDepth)); } active_hole_type = HoleType; }
/// <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(); }