public static void SetSOLocalFrame(SceneObject so, CoordSpace eSpace, Frame3f newFrame) { if (eSpace == CoordSpace.SceneCoords) { // scene frames should not be scaled by scene scale, but we want to set as world // coords, so we need to apply it now if (so.GetScene().GetSceneScale() != 1.0f) { newFrame = newFrame.Scaled(so.GetScene().GetSceneScale()); } Frame3f sceneW = UnityUtil.GetGameObjectFrame(so.GetScene().RootGameObject, CoordSpace.WorldCoords); Frame3f objW = sceneW.FromFrame(newFrame); UnityUtil.SetGameObjectFrame(so.RootGameObject, objW, CoordSpace.WorldCoords); } else { UnityUtil.SetGameObjectFrame(so.RootGameObject, newFrame, eSpace); } }
static public GameObject EmitDebugFrame(string name, Frame3f f, float fAxisLength, float diameter = 0.05f, GameObject parent = null) { if (FPlatform.InMainThread() == false) { ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugFrame(name, f, fAxisLength, diameter); }); return(null); } GameObject frameObj = new GameObject(name); GameObject x = EmitDebugLine(name + "_x", f.Origin, f.Origin + fAxisLength * f.X, diameter, Color.red, frameObj, false); GameObject y = EmitDebugLine(name + "_y", f.Origin, f.Origin + fAxisLength * f.Y, diameter, Color.green, frameObj, false); GameObject z = EmitDebugLine(name + "_z", f.Origin, f.Origin + fAxisLength * f.Z, diameter, Color.blue, frameObj, false); if (parent != null) { frameObj.transform.SetParent(parent.transform, false); } return(frameObj); }
public static void SetGameObjectFrame(GameObject go, Frame3f newFrame, CoordSpace eSpace) { if (eSpace == CoordSpace.WorldCoords) { go.transform.position = newFrame.Origin; go.transform.rotation = newFrame.Rotation; } else if (eSpace == CoordSpace.ObjectCoords) { go.transform.localPosition = newFrame.Origin; go.transform.localRotation = newFrame.Rotation; } else { // [RMS] cannot do this w/o handle to scene... Debug.Log("[MathUtil.SetGameObjectFrame] unsupported!\n"); throw new ArgumentException("not possible without refernce to scene!"); } }
void update_position(AnyRayHit hit) { int nNormalAxis = 1; int nUpAxis = 2; // as we drag object we will align Y with hit surface normal, but // we also want to constrain rotation so it is stable. Hence, we are // going to use world or local frame of target object to stabilize // rotation around normal. Frame3f hitF = TargetScene.SceneFrame; Vector3 targetAxis = hitF.GetAxis(1); if (hit.hitSO is SceneObject) { hitF = (hit.hitSO as SceneObject).GetLocalFrame(CoordSpace.WorldCoords); } bool bUseLocal = (TargetScene.Context.TransformManager.ActiveFrameType == FrameType.LocalFrame); if (bUseLocal && hit.hitSO is SceneObject) { hitF = (hit.hitSO as SceneObject).GetLocalFrame(CoordSpace.WorldCoords); targetAxis = hitF.GetAxis(1); } // if normal is parallel to target, this would become unstable, so use another axis if (Vector3.Dot(targetAxis, hit.hitNormal) > 0.99f) { targetAxis = hitF.GetAxis(0); } if (lastHitObject == null || hit.hitSO != lastHitObject) { lastHitF = new Frame3f(hit.hitPos, hit.hitNormal, nNormalAxis); lastHitF.ConstrainedAlignAxis(nUpAxis, targetAxis, lastHitF.GetAxis(nNormalAxis)); } else { lastHitF.Origin = hit.hitPos; lastHitF.AlignAxis(nNormalAxis, hit.hitNormal); lastHitF.ConstrainedAlignAxis(nUpAxis, targetAxis, lastHitF.GetAxis(nNormalAxis)); } lastHitObject = hit.hitSO; }
public static Frame3f GetSOLocalFrame(SceneObject so, CoordSpace eSpace) { if (eSpace == CoordSpace.SceneCoords) { Frame3f sceneW = UnityUtil.GetGameObjectFrame(so.GetScene().RootGameObject, CoordSpace.WorldCoords); Frame3f objW = UnityUtil.GetGameObjectFrame(so.RootGameObject, CoordSpace.WorldCoords); Frame3f result = sceneW.ToFrame(objW); // world coords have scene scale applied, we don't want that in scene coords if (so.GetScene().GetSceneScale() != 1.0f) { result = result.Scaled(1.0f / so.GetScene().GetSceneScale()); } return(result); } else { return(UnityUtil.GetGameObjectFrame(so.RootGameObject, eSpace)); } }
public override bool UpdateCapture(ITransformable target, Ray3f worldRay) { Func <SceneObject, bool> FilterF = (so) => { return(this.ConstraintSurfaces.Contains(so)); }; SORayHit hit; if (Scene.FindSORayIntersection(worldRay, out hit, FilterF)) { CurrentConstraintSO = hit.hitSO; Frame3f f = SourceSO.GetLocalFrame(CoordSpace.WorldCoords); f.Origin = hit.hitPos; f.AlignAxis(2, hit.hitNormal); SourceSO.SetLocalFrame(f, CoordSpace.WorldCoords); } return(true); }
public static PlaneIntersectionCurveSO CreateFromPlane(DMeshSO TargetSO, Frame3f PlaneS, SOMaterial material, FScene scene, double fNormalOffset = 0.0f) { Frame3f PlaneO = SceneTransforms.SceneToObject(TargetSO, PlaneS); PlaneIntersectionCurves curves = new PlaneIntersectionCurves(TargetSO.Mesh, PlaneO, 1) { NormalOffset = fNormalOffset }; curves.Compute(); if (curves.Loops.Length != 1) { throw new Exception("PlaneIntersectionSO.CreateFromPlane: got more than one cut loop?"); } DCurve3 loop = curves.Loops[0]; // map loop back into plane frame for (int i = 0; i < loop.VertexCount; ++i) { loop[i] = PlaneO.ToFrameP(loop[i]); } PlaneIntersectionCurveSO curveSO = new PlaneIntersectionCurveSO() { Curve = loop }; curveSO.Create(material); Frame3f curveFrame = SceneTransforms.ObjectToScene(TargetSO, PlaneO); curveSO.SetLocalFrame(curveFrame, CoordSpace.ObjectCoords); scene.History.PushChange( new AddSOChange() { scene = scene, so = curveSO, bKeepWorldPosition = false }); scene.History.PushInteractionCheckpoint(); return(curveSO); }
protected override void OnPointUpdated(ControlPoint pt, Frame3f prevFrameS, bool isFirst) { Vector3f basePt = GetPointPosition(BasePointID, CoordSpace.SceneCoords).Origin; Vector3f frontPt = GetPointPosition(FrontPointID, CoordSpace.SceneCoords).Origin; Vector3f topPt = GetPointPosition(TopPointID, CoordSpace.SceneCoords).Origin; lastTargetFrameS = TargetSO.GetLocalFrame(CoordSpace.SceneCoords); Frame3f previewFrameS = lastTargetFrameS; // position next to original object previewFrameS = previewFrameS.Translated(1.1f * (float)meshBounds.Width * Vector3f.AxisX); Vector3f upAxis = (topPt - basePt).Normalized; // construct a frame perp to upAxis at midpoint, and project original and current fw points Frame3f upFrame = new Frame3f((topPt + basePt) * 0.5f, upAxis); Vector3f origFW = upFrame.ProjectToPlane(initialFrontPt, 2); origFW = (origFW - upFrame.Origin).Normalized; Vector3f curFW = upFrame.ProjectToPlane(frontPt, 2); curFW = (curFW - upFrame.Origin).Normalized; //float angle = MathUtil.PlaneAngleSignedD(origFW, curFW, upAxis); start_forward_pt_S = upFrame.FromFrameP(origFW); current_forward_pt_S = upFrame.FromFrameP(curFW); // construct rotation that aligns up axis with y-up Quaternionf upRotate = Quaternionf.FromTo(upAxis, Vector3f.AxisY); previewFrameS.Rotate(upRotate); // now rotate so that forward dir points along -Z //Quaternionf fwRotate = Quaternionf.AxisAngleD(Vector3f.AxisY, angle); //curFW = upRotate * curFW; Quaternionf fwRotate = Quaternionf.FromToConstrained(curFW, -Vector3f.AxisZ, Vector3f.AxisY); previewFrameS.Rotate(fwRotate); previewSO.SetLocalFrame(previewFrameS, CoordSpace.SceneCoords); lastPreviewFrameS = previewFrameS; }
override public Capture UpdateCapture(InputState input, CaptureData data) { if (Released(input)) { SORayHit rayHit; if (SceneUtil.FindNearestRayIntersection(tool.Targets, WorldRay(input), out rayHit)) { Frame3f clickW = new Frame3f(rayHit.hitPos, rayHit.hitNormal); tool.Scene.Context.RegisterNextFrameAction(() => { tool.SetPlaneFromSingleClick(clickW, input.bShiftKeyDown); }); } return(Capture.End); } else { return(Capture.Continue); } }
public void Build(Frame3f centerW, float extentW, GameObject parent, Material mat, int nLayer = -1) { lineGO = new GameObject("snap_line"); LineRenderer ren = lineGO.AddComponent <LineRenderer>(); ren.startWidth = ren.endWidth = 0.05f; ren.material = mat; ren.useWorldSpace = false; ren.positionCount = 2; ren.SetPosition(0, centerW.Origin - extentW * centerW.Z); ren.SetPosition(1, centerW.Origin + extentW * centerW.Z); MaterialUtil.DisableShadows(lineGO); UnityUtil.AddChild(parent, lineGO, false); if (nLayer > 0) { lineGO.SetLayer(nLayer); } }
public virtual bool FindNearest(Vector3d point, double maxDist, out SORayHit nearest, CoordSpace eInCoords) { nearest = null; if (enable_spatial == false) { return(false); } if (spatial == null) { spatial = new DMeshAABBTree3(mesh); spatial.Build(); } // convert to local Vector3f local_pt = SceneTransforms.TransformTo((Vector3f)point, this, eInCoords, CoordSpace.ObjectCoords); if (mesh.CachedBounds.Distance(local_pt) > maxDist) { return(false); } int tid = spatial.FindNearestTriangle(local_pt); if (tid != DMesh3.InvalidID) { DistPoint3Triangle3 dist = MeshQueries.TriangleDistance(mesh, tid, local_pt); nearest = new SORayHit(); nearest.fHitDist = (float)Math.Sqrt(dist.DistanceSquared); Frame3f f_local = new Frame3f(dist.TriangleClosest, mesh.GetTriNormal(tid)); Frame3f f = SceneTransforms.TransformTo(f_local, this, CoordSpace.ObjectCoords, eInCoords); nearest.hitPos = f.Origin; nearest.hitNormal = f.Z; nearest.hitGO = RootGameObject; nearest.hitSO = this; return(true); } return(false); }
void update_box() { if (nCurMesh != (int)PrimType.Box) { meshObject.SetMesh(UnityUtil.GetPrimitiveMesh(PrimitiveType.Cube)); nCurMesh = (int)PrimType.Box; } Transform parent = meshObject.transform.parent; meshObject.transform.parent = null; float fHeightSignShift = (Height < 0) ? Height : 0; float fAbsHeight = Math.Abs(Height); float fWidthShift = (Width < 0) ? Width : 0; float fAbsWidth = Math.Abs(Width); float fDepthShift = (Depth < 0) ? Depth : 0; float fAbsDepth = Math.Abs(Depth); Vector3f vShift = Vector3f.Zero; if (Center == CenterModes.Base) { vShift = new Vector3f(0, fHeightSignShift + fAbsHeight * 0.5f, 0); } else if (Center == CenterModes.Corner) { vShift = new Vector3f(fWidthShift + fAbsWidth * 0.5f, fHeightSignShift + fAbsHeight * 0.5f, fDepthShift + fAbsDepth * 0.5f); } meshObject.transform.localPosition = Vector3.zero; meshObject.transform.localRotation = Quaternion.identity; // default unity box is 1x1x1 cube meshObject.transform.localScale = new Vector3f(fAbsWidth, fAbsHeight, fAbsDepth); shiftedFrame = Frame.Translated(Frame.FromFrameV(vShift)); UnityUtil.SetGameObjectFrame(meshObject, shiftedFrame, CoordSpace.WorldCoords); meshObject.transform.SetParent(parent, true); }
/// <summary> /// called on click-down /// </summary> override public void Begin(SceneObject so, Vector2d downPos, Ray3f downRayWorld) { SORayHit hit; if (TargetSO.FindRayIntersection(downRayWorld, out hit) == false) { return; } Vector3d scenePos = SceneTransforms.WorldToSceneP(this.Scene, hit.hitPos); if (have_source == false) { CurrentSourceHitPosS = new Frame3f(scenePos); sourceIndicator = new SphereIndicator() { SceneFrameF = () => { return(CurrentSourceHitPosS); }, Radius = fDimension.Scene(SourceIndicatorSizeScene * 0.5), ColorF = () => { return(Colorf.Orange); } }; indicators.AddIndicator(sourceIndicator); have_source = true; source_modified = true; } else if (have_extent == false) { CurrentExtentHitPosS = new Frame3f(scenePos); extentIndicator = new SphereIndicator() { SceneFrameF = () => { return(CurrentExtentHitPosS); }, Radius = fDimension.Scene(ExtentIndicatorSizeScene * 0.5), ColorF = () => { return(Colorf.CornflowerBlue); } }; indicators.AddIndicator(extentIndicator); have_extent = true; extent_modified = true; } }
/// <summary> /// when the socket is updated, shift the ground plane to be directly below it /// </summary> public static void AddRepositionGroundPlaneOnSocketEdit() { OG.OnSocketUpdated += () => { // compute scene-space bbox of socket mesh Frame3f socketF = OG.Socket.Socket.GetLocalFrame(CoordSpace.ObjectCoords); AxisAlignedBox3d boundsS = MeshMeasurements.Bounds(OG.Socket.Socket.Mesh, socketF.FromFrameP); // vertically translate bounds objects to be at same y // (assumes they are xz planes!!) Vector3d baseS = boundsS.Center - boundsS.Extents[1] * Vector3d.AxisY; Vector3d baseW = OG.Scene.ToWorldP(baseS); foreach (var go in OG.Scene.BoundsObjects) { Vector3f pos = go.GetPosition(); pos.y = (float)baseW.y; go.SetPosition(pos); } }; }
void add_curve_widget(PolyCurveSO curve, bool bFirst, Func <Vector3> localPositionF) { GameObject go = AppendMeshGO("curve_endpoint", UnityUtil.GetPrimitiveMesh(PrimitiveType.Cube), stdMaterial, gizmo); go.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f); Frame3f sourceFrame = new Frame3f(localPositionF()); UnityUtil.SetGameObjectFrame(go, sourceFrame, CoordSpace.ObjectCoords); WidgetParameterUpdates.Add(() => { UnityUtil.SetGameObjectFrame(go, new Frame3f(localPositionF()), CoordSpace.ObjectCoords); }); Widgets[go] = new CurveHandleEditWidget(this, curve, this.parentScene) { RootGameObject = go, StandardMaterial = stdMaterial, HoverMaterial = stdHoverMaterial, VertexIndex = (bFirst) ? 0 : CurveHandleEditWidget.LastIndex }; }
/// <summary> /// Cache the transform sequence from SO up to scene coordinates /// </summary> public static TransformSequence ObjectToSceneXForm(SceneObject so) { TransformSequence seq = new TransformSequence(); SceneObject curSO = so; while (curSO != null) { Frame3f curF = curSO.GetLocalFrame(CoordSpace.ObjectCoords); Vector3f scale = curSO.GetLocalScale(); seq.AppendScale(scale); seq.AppendFromFrame(curF); SOParent parent = curSO.Parent; if (parent is FScene) { break; } curSO = (parent as SceneObject); } return(seq); }
public void Create(SOMaterial useMaterial, fGameObject parent, int nLayer = -1) { if (curve == null) { curve = new DCurve3(); } axis = Frame3f.Identity; meshObject = GameObjectFactory.CreateMeshGO("revolve_preview"); meshObject.SetMaterial(MaterialUtil.ToMaterialf(useMaterial), true); if (nLayer != -1) { meshObject.SetLayer(nLayer); } bUpdatePending = true; meshObject.SetParent(parent, false); meshObject.SetLocalScale(1.001f * Vector3f.One); }
void update_pos(Vector3f pos, double time) { Frame3f f = PrintHeadSO.GetLocalFrame(CoordSpace.SceneCoords); f.Origin = pos + PrintHeadOffset * Vector3f.AxisY; PrintHeadSO.SetLocalFrame(f, CoordSpace.SceneCoords); Vector3f worldNozzlePt = PrintHeadSO.GetScene().ToWorldP(f.Origin); Vector3f worldPathPt = PrintHeadSO.GetScene().ToWorldP(pos); LaserGO.SetStart(worldNozzlePt); LaserGO.SetEnd(worldPathPt); if (emitting) { CC.SetLayerFromZ(pos.y); } update_heat_display(pos, time); }
public virtual bool FindNearest(Vector3d point, double maxDist, out SORayHit nearest, CoordSpace eInCoords) { nearest = null; Frame3f f = this.GetLocalFrame(eInCoords); double dist = (f.Origin - point).Length; if (dist > maxDist) { return(false); } nearest = new SORayHit(); nearest.fHitDist = (float)dist; nearest.hitPos = f.Origin; nearest.hitNormal = Vector3f.Zero; nearest.hitGO = RootGameObject; nearest.hitSO = this; return(true); }
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(); }
DMesh3 compute_through_hole(Vector3d start, Vector3d end, double tol) { DMesh3 origMesh = MeshSource.GetDMeshUnsafe(); DMeshAABBTree3 origSpatial = MeshSource.GetSpatial() as DMeshAABBTree3; DMesh3 cutMesh = new DMesh3(origMesh); Polygon2d polygon = Polygon2d.MakeCircle(hole_size / 2, hole_subdivisions); Vector3f axis = (Vector3f)(start - end).Normalized; int start_tid = origSpatial.FindNearestTriangle(start); Frame3f start_frame = origMesh.GetTriFrame(start_tid); start_frame.Origin = (Vector3f)start; start_frame.AlignAxis(2, axis); int end_tid = origSpatial.FindNearestTriangle(end); //Frame3f end_frame = origMesh.GetTriFrame(end_tid); end_frame.Origin = (Vector3f)end; Frame3f end_frame = start_frame; end_frame.Origin = (Vector3f)end; MeshInsertProjectedPolygon start_insert = new MeshInsertProjectedPolygon(cutMesh, polygon, start_frame, start_tid); bool start_ok = start_insert.Insert(); MeshInsertProjectedPolygon end_insert = new MeshInsertProjectedPolygon(cutMesh, polygon, end_frame, end_tid); bool end_ok = end_insert.Insert(); if (start_ok == false || end_ok == false) { throw new Exception("CutPolygonHoleOp.compute_through_hole: start or end insertion failed!"); } MeshEditor editor = new MeshEditor(cutMesh); EdgeLoop l0 = start_insert.InsertedLoop; EdgeLoop l1 = end_insert.InsertedLoop; l1.Reverse(); editor.StitchLoop(l0.Vertices, l1.Vertices); return(cutMesh); }
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); // auto-show if ((options.Flags & LayoutFlags.AnimatedShow) != 0) { HUDUtil.AnimatedShow(element); } }
private void AddCapBeforeJoint(Vector3d segmentDirection, TPrintVertex printVertex, ToolpathPreviewJoint joint, ToolpathPreviewMesh mesh) { var frame = new Frame3f(printVertex.Position); frame.AlignAxis(1, ToVector3f(segmentDirection)); joint.InTop = mesh.AddVertex(vertexFactory(printVertex, frame.FromFrameP(DiamondCrossSection.Top(printVertex.Dimensions)), brightnessMax)); joint.InRight = mesh.AddVertex(vertexFactory(printVertex, frame.FromFrameP(DiamondCrossSection.Right(printVertex.Dimensions)), brightnessMin)); joint.InBottom = mesh.AddVertex(vertexFactory(printVertex, frame.FromFrameP(DiamondCrossSection.Bottom(printVertex.Dimensions)), brightnessMax)); joint.InLeft = mesh.AddVertex(vertexFactory(printVertex, frame.FromFrameP(DiamondCrossSection.Left(printVertex.Dimensions)), brightnessMin)); mesh.AddTriangle(joint.InBottom, joint.InLeft, joint.InTop); mesh.AddTriangle(joint.InBottom, joint.InTop, joint.InRight); }
public bool BeginCapture(MMDModel target, HitResult hit) { // save local and world frames translateFrameL = target.GetGameObjectFrame(CoordSpace.ObjectCoords); translateFrameW = target.GetGameObjectFrame(CoordSpace.WorldCoords); translateAxisW = translateFrameW.GetAxis(nTranslationAxis); // save t-value of closest point on translation axis, so we can find delta-t Vector3 vWorldHitPos = hit.HitPosition; fTranslateStartT = ClosestPointOnLineT( translateFrameW.Origin, translateAxisW, vWorldHitPos); // construct plane we will ray-intersect with in UpdateCapture() Vector3 makeUp = Vector3.Cross(Platform.Program.Camera.Forward, translateAxisW).GetNormalized( ); Vector3 vPlaneNormal = Vector3.Cross(makeUp, translateAxisW).GetNormalized( ); raycastFrame = new Frame3f(vWorldHitPos, vPlaneNormal); return(true); }
public override bool UpdateCapture(ITransformable target, Ray3f worldRay) { // ray-hit with plane that contains translation axis Vector3f planeHit = raycastFrame.RayPlaneIntersection(worldRay.Origin, worldRay.Direction, 2); // figure out new T-value along axis, then our translation update is delta-t float fNewT = Distance.ClosestPointOnLineT(translateFrameW.Origin, translateAxisW, planeHit); float fDeltaT = (fNewT - fTranslateStartT); fDeltaT *= TranslationScaleF(); // construct new frame translated along axis (in local space) Frame3f newFrame = translateFrameL; newFrame.Origin += fDeltaT * translateFrameL.GetAxis(nTranslationAxis); // update target target.SetLocalFrame(newFrame, CoordSpace.ObjectCoords); return(true); }
float fTranslateStartT; // start T-value along translateAxisW public override bool BeginCapture(ITransformable target, Ray3f worldRay, UIRayHit hit) { // save local and world frames translateFrameL = target.GetLocalFrame(CoordSpace.ObjectCoords); translateFrameW = target.GetLocalFrame(CoordSpace.WorldCoords); translateAxisW = translateFrameW.GetAxis(nTranslationAxis); // save t-value of closest point on translation axis, so we can find delta-t Vector3f vWorldHitPos = hit.hitPos; fTranslateStartT = Distance.ClosestPointOnLineT( translateFrameW.Origin, translateAxisW, vWorldHitPos); // construct plane we will ray-intersect with in UpdateCapture() Vector3f makeUp = Vector3f.Cross(Camera.main.transform.forward, translateAxisW).Normalized; Vector3f vPlaneNormal = Vector3f.Cross(makeUp, translateAxisW).Normalized; raycastFrame = new Frame3f(vWorldHitPos, vPlaneNormal); return(true); }
public static void ToFrame(IDeformableMesh mesh, Frame3f f) { int NV = mesh.MaxVertexID; bool bHasNormals = mesh.HasVertexNormals; for (int vid = 0; vid < NV; ++vid) { if (mesh.IsVertex(vid)) { Vector3D v = mesh.GetVertex(vid); Vector3D vf = f.ToFrameP((Vector3F)v); mesh.SetVertex(vid, vf); if (bHasNormals) { Vector3F n = mesh.GetVertexNormal(vid); Vector3F nf = f.ToFrameV(n); mesh.SetVertexNormal(vid, nf); } } } }
void add_axis_widget(PrimitiveSO primitive, Vector3 frameAxisV, float deltaMult, string paramName, Func <Vector3> localPositionF) { GameObject go = AppendMeshGO(paramName, UnityUtil.GetPrimitiveMesh(PrimitiveType.Cube), stdMaterial, gizmo); go.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); Frame3f sourceFrame = new Frame3f(localPositionF()); UnityUtil.SetGameObjectFrame(go, sourceFrame, CoordSpace.ObjectCoords); WidgetParameterUpdates.Add(() => { UnityUtil.SetGameObjectFrame(go, new Frame3f(localPositionF()), CoordSpace.ObjectCoords); }); Widgets[go] = new AxisParameterEditWidget(this, primitive, this.parentScene) { RootGameObject = go, StandardMaterial = stdMaterial, HoverMaterial = stdHoverMaterial, AxisParamName = paramName, AxisVectorInFrame = frameAxisV, DeltaScalingF = () => { return(deltaMult / parentScene.GetSceneScale()); } }; }
override public void SetLocalFrame(Frame3f newFrame, CoordSpace eSpace) { if (Parent != GetScene()) { throw new Exception("SlicePlaneHeightSO.SetLocalFrame: unsupported"); } Frame3f newSceneFrame = newFrame; if (eSpace == CoordSpace.WorldCoords) { newSceneFrame = SceneTransforms.WorldToScene(GetScene(), newFrame); } Line3d axis = new Line3d(ConstraintFrameS.Origin, Vector3d.AxisY); Segment3d seg = new Segment3d(axis.ClosestPoint(MinPosS), axis.ClosestPoint(MaxPosS)); Vector3d cp = seg.NearestPoint(newSceneFrame.Origin); newSceneFrame.Origin = (Vector3f)cp; base.SetLocalFrame(newSceneFrame, CoordSpace.SceneCoords); }
public DMeshSO BuildSO(FScene scene, SOMaterial material) { DMesh3 revolveMesh = UnityUtil.UnityMeshToDMesh(meshObject.GetSharedMesh(), false); // move axis frame to center of bbox of mesh, measured in axis frame Frame3f useF = OutputFrame; AxisAlignedBox3f boundsInFrame = (AxisAlignedBox3f)BoundsUtil.BoundsInFrame(revolveMesh.Vertices(), useF); useF.Origin = useF.FromFrameP(boundsInFrame.Center); // transform mesh into this frame MeshTransforms.ToFrame(revolveMesh, useF); // create new so DMeshSO meshSO = new DMeshSO(); meshSO.Create(revolveMesh, material); meshSO.SetLocalFrame(useF, CoordSpace.ObjectCoords); return(meshSO); }