public static void RecenterPivot(FScene scene, DMeshSO so, PivotLocation location, bool bInteractive) { if (so.Parent != scene) { DebugUtil.Log("OrientationChanges.RecenterPivot: tried to recenter pivot on non-scene-child"); return; } Frame3f sceneL = SceneTransforms.SceneToObject(so, Frame3f.Identity); AxisAlignedBox3d sceneBoundsL = AxisAlignedBox3d.Empty; so.SafeMeshRead((mesh) => { sceneBoundsL = MeshMeasurements.BoundsInFrame(mesh, sceneL); return(null); }); Vector3d originL = sceneBoundsL.Center; if (location == PivotLocation.BaseCenter) { originL -= sceneBoundsL.Extents.y * Vector3d.AxisY; } Frame3f newFrameL = new Frame3f(originL); RepositionPivotChangeOp change = new RepositionPivotChangeOp(newFrameL, so); scene.History.PushChange(change, false); if (bInteractive) { scene.History.PushInteractionCheckpoint(); } }
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(); } }
override public void Apply() { float VerticalSpaceFudge = 10.0f; DMeshSO TargetMeshSO = TargetSO as DMeshSO; Frame3f curFrameS = TargetSO.GetLocalFrame(CoordSpace.SceneCoords); TransformSOChange change = new TransformSOChange(TargetSO, curFrameS, lastPreviewFrameS, CoordSpace.SceneCoords); Scene.History.PushChange(change, false); Frame3f newFrameS = new Frame3f(SceneTransforms.ObjectToSceneP(TargetSO, meshBounds.Center)); RepositionPivotChangeOp pivot1 = new RepositionPivotChangeOp(newFrameS, TargetMeshSO); Scene.History.PushChange(pivot1, false); newFrameS = TargetSO.GetLocalFrame(CoordSpace.SceneCoords); AxisAlignedBox3d bounds = TargetMeshSO.Mesh.CachedBounds; float h = (float)bounds.Height; Vector3f o = newFrameS.Origin; Vector3f translate = new Vector3f(-o.x, h * 0.5f - o.y + VerticalSpaceFudge, -o.z); Frame3f centeredFrameS = newFrameS.Translated(translate); TransformSOChange centerChange = new TransformSOChange(TargetSO, newFrameS, centeredFrameS, CoordSpace.SceneCoords); Scene.History.PushChange(centerChange, false); newFrameS = TargetSO.GetLocalFrame(CoordSpace.SceneCoords); o = newFrameS.Origin; o.y = 0; newFrameS.Origin = o; RepositionPivotChangeOp pivot2 = new RepositionPivotChangeOp(newFrameS, TargetMeshSO); Scene.History.PushChange(pivot2, false); Scene.History.PushInteractionCheckpoint(); }
public static void SwapUpDirection(FScene scene, List <PrintMeshSO> objects) { AxisAlignedBox3f sceneBounds = AxisAlignedBox3f.Empty; Vector3f sharedOrigin = Vector3f.Zero; foreach (var meshSO in objects) { sharedOrigin += meshSO.GetLocalFrame(CoordSpace.SceneCoords).Origin; sceneBounds.Contain(meshSO.GetBoundingBox(CoordSpace.SceneCoords).ToAABB()); } sharedOrigin /= objects.Count; foreach (var so in objects) { Frame3f curF = so.GetLocalFrame(CoordSpace.SceneCoords); UpDirection from = so.UpDirection; UpDirection to = (from == UpDirection.YUp) ? UpDirection.ZUp : UpDirection.YUp; Quaternionf rotate = Quaternionf.AxisAngleD(Vector3f.AxisX, (to == UpDirection.YUp) ? -90 : 90); Frame3f newF = curF; newF.RotateAround(sharedOrigin, rotate); TransformSOChange upChange = new TransformSOChange(so, newF, CoordSpace.SceneCoords) { OnApplyF = (x) => { so.UpDirection = to; }, OnRevertF = (x) => { so.UpDirection = from; } }; scene.History.PushChange(upChange, false); } AxisAlignedBox3f newSceneBounds = AxisAlignedBox3f.Empty; foreach (var meshSO in objects) { newSceneBounds.Contain(meshSO.GetBoundingBox(CoordSpace.SceneCoords).ToAABB()); } Vector3f startBase = sceneBounds.Center; startBase.y = 0; Vector3f newBase = newSceneBounds.Center; newBase.y = newSceneBounds.Min.y; Vector3f df = startBase - newBase; foreach (var so in objects) { Frame3f curF = so.GetLocalFrame(CoordSpace.SceneCoords); Frame3f newF = curF.Translated(df); TransformSOChange centerChange = new TransformSOChange(so, newF, CoordSpace.SceneCoords); scene.History.PushChange(centerChange, false); } // reposition pivots at base of List <Frame3f> setF = new List <Frame3f>(); foreach (var so in objects) { Frame3f objF = so.GetLocalFrame(CoordSpace.ObjectCoords); Vector3f center = so.GetBoundingBox(CoordSpace.SceneCoords).Center; center.y = 0; Frame3f sceneF = new Frame3f(center); setF.Add(sceneF); } for (int k = 0; k < objects.Count; ++k) { RepositionPivotChangeOp change = new RepositionPivotChangeOp(setF[k], objects[k], CoordSpace.SceneCoords); scene.History.PushChange(change, false); } }