private void Scene_SelectionChangedEvent(object sender, EventArgs e) { FScene scene = Context.Scene; List <TransformableSO> vSelected = new List <TransformableSO>(); foreach (SceneObject so in scene.Selected) { TransformableSO tso = so as TransformableSO; if (tso != null) { if (SelectionFilterF == null || SelectionFilterF(tso)) { vSelected.Add(tso); } } } if (vSelected.Count == 0 && activeGizmo != null) { // object de-selected, dismiss gizmo DismissActiveGizmo(); return; } if (activeGizmo != null && unordered_lists_equal(vSelected, activeGizmo.Targets) == false) { DismissActiveGizmo(); } if (vSelected.Count > 0) { AddGizmo(vSelected); } }
// restore structs public virtual void RestoreTransform(TransformableSO so, TypedAttribSet attributes) { TypedAttribSet transform = find_struct(attributes, IOStrings.TransformStruct); if (transform == null) { throw new Exception("SOFactory.RestoreTransform: Transform struct not found!"); } Frame3f f = Frame3f.Identity; if (check_key_or_debug_print(transform, IOStrings.APosition)) { Vector3f vPosition = (Vector3f)transform[IOStrings.APosition]; f.Origin = vPosition; } if (check_key_or_debug_print(transform, IOStrings.AOrientation)) { Quaternionf vRotation = (g3.Quaternionf)transform[IOStrings.AOrientation]; f.Rotation = vRotation; } so.SetLocalFrame(f, CoordSpace.ObjectCoords); if (check_key_or_debug_print(transform, IOStrings.AOrientation)) { Vector3f vScale = (Vector3f)transform[IOStrings.AScale]; so.RootGameObject.transform.localScale = vScale; } }
public SOFrameLink(TransformableSO From, TransformableSO To, Frame3f setRelativeF) { Target = To; Source = From; relativeF = setRelativeF; To.OnTransformModified += OnTargetModified; }
public AddToGroupChange(FScene scene, GroupSO group, TransformableSO so) { this.Scene = scene; this.Group = group; this.Objects = new List <TransformableSO>() { so }; }
public override OpStatus Revert() { // [RMS] parentSO may not be GC'd immediately, but GO be null as // soon as Scene.RemoveSeceneObject() is called if (parentSO.IsAlive && (parentSO.Target as SceneObject).RootGameObject != null) { TransformableSO tso = (parentSO.Target as TransformableSO); tso.SetLocalFrame(parentBefore, CoordSpace.SceneCoords); if (tso.SupportsScaling) { tso.SetLocalScale(parentScaleBefore); } } else { for (int i = 0; i < childSOs.Count; ++i) { childSOs[i].SetLocalFrame(before[i], CoordSpace.SceneCoords); if (childSOs[i].SupportsScaling) { childSOs[i].SetLocalScale(scaleBefore[i]); } } } return(OpStatus.Success); }
/// <summary> /// input objectF is in Object (local) coords of so, apply all intermediate /// transforms to get it to Scene coords /// </summary> public static Frame3f ObjectToScene(TransformableSO so, Frame3f objectF) { Frame3f sceneF = objectF; TransformableSO curSO = so; while (curSO != null) { Frame3f curF = curSO.GetLocalFrame(CoordSpace.ObjectCoords); Vector3f scale = curSO.GetLocalScale(); Util.gDevAssert(IsUniformScale(scale)); sceneF.Scale(scale); sceneF = curF.FromFrame(sceneF); SOParent parent = curSO.Parent; if (parent is FScene) { return(sceneF); } curSO = (parent as TransformableSO); } if (curSO == null) { DebugUtil.Error("SceneTransforms.TransformTo: found null parent SO!"); } return(sceneF); }
public static void TranslateInFrame(TransformableSO so, Vector3f translate, CoordSpace eSpace = CoordSpace.ObjectCoords) { Frame3f f = so.GetLocalFrame(eSpace); f.Origin += translate; so.SetLocalFrame(f, eSpace); }
/// <summary> /// Input sceneF is a point in Scene, apply all intermediate inverse /// transforms to get it into local point of a SO /// </summary> public static Vector3f SceneToObject(TransformableSO so, Vector3f scenePt) { Frame3f f = new Frame3f(scenePt); SceneToObject(so, f); return(f.Origin); }
/// <summary> /// Assuming pointIn is in space eFrom of fromSO, transform to eTo /// </summary> public static Vector3f TransformTo(Vector3f pointIn, TransformableSO fromSO, CoordSpace eFrom, CoordSpace eTo) { // this is not the most efficient but we can optimize later! Frame3f tmp = new Frame3f(pointIn); return(TransformTo(tmp, fromSO, eFrom, eTo).Origin); }
/// <summary> /// input objectF is in Object (local) coords of so, apply all intermediate /// transforms to get it to Scene coords /// </summary> public static Vector3f ObjectToScene(TransformableSO so, Vector3f objectPt) { Frame3f f = new Frame3f(objectPt); ObjectToScene(so, f); return(f.Origin); }
public void SetActiveReferenceObject(TransformableSO so) { if (activeGizmo != null && activeGizmo.SupportsReferenceObject) { activeGizmo.SetReferenceObject(so); } }
// configure gizmo - constructs necessary ITransformWrapper to provide // desired gizmo behavior. You can modify behavior in subclasses by // overriding InitializeTransformWrapper (but you must void SetActiveFrame(FrameType eFrame) { // disconect existing wrapper if (targetWrapper != null) { targetWrapper.Target.OnTransformModified -= onTransformModified; } // if we have multiple targets, we construct a transient SO to // act as a parent (stored as internalGroupSO) if (targets.Count > 1 && internalGroupSO == null) { internalGroupSO = new TransientGroupSO(); internalGroupSO.Create(); parentScene.AddSceneObject(internalGroupSO); internalGroupSO.AddChildren(targets); } TransformableSO useSO = (targets.Count == 1) ? targets[0] : internalGroupSO; // construct the wrapper targetWrapper = InitializeTransformWrapper(useSO, eFrame); //connect up to it targetWrapper.Target.OnTransformModified += onTransformModified; onTransformModified(null); // configure gizmo uniform_scale.SetVisible(targetWrapper.SupportsScaling); }
public SOFrameLink(TransformableSO From, TransformableSO To) : base() { Target = To; Source = From; update_source(); To.OnTransformModified += OnTargetModified; }
void update_source() { TransformableSO from = Source as TransformableSO; Frame3f FrameS = from.GetLocalFrame(CoordSpace.SceneCoords); TransformableSO to = Target as TransformableSO; relativeF = SceneTransforms.SceneToObject(to, FrameS); }
void onTransformModified(TransformableSO so) { // keep widget synced with object frame of target Frame3f widgetFrame = targetWrapper.GetLocalFrame(CoordSpace.ObjectCoords); gizmo.transform.localPosition = widgetFrame.Origin; gizmo.transform.localRotation = widgetFrame.Rotation; }
public override OpStatus Apply() { TransformableSO target = Scene.FindByUUID(TargetUUID) as TransformableSO; TransformableSO source = Scene.FindByUUID(SourceUUID) as TransformableSO; SOLink newLink = new SOFrameLink(source, target); Scene.LinkManager.AddLink(newLink); LinkUUID = newLink.UUID; return(OpStatus.Success); }
private void OnTargetModified(TransformableSO so) { if (IsValid) { TransformableSO from = Source as TransformableSO; TransformableSO to = Target as TransformableSO; Frame3f FrameS = SceneTransforms.ObjectToScene(to, relativeF); from.SetLocalFrame(FrameS, CoordSpace.SceneCoords); } }
public static void EmitTransform(this SceneSerializer s, IOutputStream o, TransformableSO so) { o.BeginStruct(IOStrings.TransformStruct); Frame3f f = so.GetLocalFrame(CoordSpace.ObjectCoords); o.AddAttribute(IOStrings.APosition, f.Origin); o.AddAttribute(IOStrings.AOrientation, f.Rotation); o.AddAttribute(IOStrings.AScale, so.RootGameObject.transform.localScale); o.EndStruct(); }
public void AddChild(TransformableSO so) { if (!vChildren.Contains(so)) { vChildren.Add(so); parentScene.AddSceneObjectToParentSO(so, this); update_shared_origin(); increment_timestamp(); //so.OnTransformModified += childTransformModified; } }
/// <summary> /// Input sceneF is a frame in Scene, apply all intermediate inverse /// transforms to get it into local frame of a SO /// </summary> public static Frame3f SceneToObject(TransformableSO so, Frame3f sceneF) { SOParent parent = so.Parent; if (parent is FScene) { return(ApplyInverseTransform(so, sceneF)); } // this will recursively apply all the inverse parent transforms from scene on down return(ApplyInverseTransform(so, SceneToObject(parent as TransformableSO, sceneF))); }
public void RemoveChild(TransformableSO so) { if (vChildren.Contains(so)) { //so.OnTransformModified -= childTransformModified; vChildren.Remove(so); parentScene.RemoveSceneObjectFromParentSO(so); update_shared_origin(); increment_timestamp(); } }
public void Connect(TransformableSO source, TransformableSO target) { //this.source = source; this.target = target; Frame3f sourceW = source.GetLocalFrame(CoordSpace.WorldCoords); this.SetLocalFrame(sourceW, CoordSpace.WorldCoords); target.RootGameObject.transform.SetParent(gameObject.transform, true); increment_timestamp(); }
public TransformGizmoChange change; // [TODO] shouldn't be using gizmo change for this? public GrabInfo(Cockpit cockpit, TransformableSO so, Frame3f handF) { this.cockpit = cockpit; this.so = so; this.startHandF = handF; this.startObjFW = so.GetLocalFrame(CoordSpace.WorldCoords); this.startObjRelF = this.startHandF.ToFrame(this.startObjFW); this.stickDelta = Vector2f.Zero; change = new TransformGizmoChange() { parentSO = new WeakReference(so), parentBefore = so.GetLocalFrame(CoordSpace.SceneCoords), parentScaleBefore = so.GetLocalScale() }; }
public void SetReferenceObject(TransformableSO sourceSO) { if (sourceSO != null && frameSourceSO == sourceSO) { return; // ignore repeats as this is kind of expensive } if (internalXFormSO != null) { internalXFormSO.Disconnect(); parentScene.RemoveSceneObject(internalXFormSO, true); internalXFormSO = null; } frameSourceSO = sourceSO; SetActiveFrame(eCurrentFrameMode); }
public virtual TransformableSO BuildSO(Func <DCurve3, TransformableSO> SOBuilderF, SOMaterial material, float scale = 1.0f) { Vector3d vCenter = curve.GetBoundingBox().Center; DCurve3 shifted = new DCurve3(curve); for (int i = 0; i < shifted.VertexCount; ++i) { shifted[i] -= vCenter; } Frame3f shiftedFrame = new Frame3f((Vector3f)vCenter, Quaternionf.Identity); TransformableSO so = SOBuilderF(shifted); so.SetLocalFrame(shiftedFrame, CoordSpace.WorldCoords); return(so); }
// you can override this to modify behavior. Note that this default // implementation currently uses some internal members for the relative-xform case virtual protected ITransformWrapper InitializeTransformWrapper(TransformableSO useSO, FrameType eFrame) { if (frameSourceSO != null) { internalXFormSO = new TransientXFormSO(); internalXFormSO.Create(); parentScene.AddSceneObject(internalXFormSO); internalXFormSO.Connect(frameSourceSO, useSO); return(new PassThroughWrapper(internalXFormSO)); } else if (eFrame == FrameType.LocalFrame) { return(new PassThroughWrapper(useSO)); } else { return(new SceneFrameWrapper(parentScene, useSO)); } }
public void AddChild(TransformableSO so, bool bMaintainOrigin = false) { Util.gDevAssert(so != this); if (!vChildren.Contains(so)) { vChildren.Add(so); if (parentScene != null) { if (so.Parent == null) { throw new Exception("GroupSO.AddChild: tried to re-parent SO to group that has no parent!"); } parentScene.AddSceneObjectToParentSO(so, this); } if (bMaintainOrigin == false) { update_shared_origin(); } increment_timestamp(); //so.OnTransformModified += childTransformModified; } }
/// <summary> /// Assuming dimensionIn is in space eFrom of fromSO, transform to eTo /// </summary> public static float TransformTo(float dimensionIn, TransformableSO fromSO, CoordSpace eFrom, CoordSpace eTo) { if (eFrom == eTo) { return(dimensionIn); } FScene scene = fromSO.GetScene(); float sceneDim = dimensionIn; if (eFrom == CoordSpace.ObjectCoords) { // if we are in Object coords, we are either going up to Scene or World sceneDim = ObjectToScene(fromSO, dimensionIn); } else if (eFrom == CoordSpace.WorldCoords) { // if we are in World coords, we are going down to Scene or Object sceneDim = scene.ToSceneDimension(dimensionIn); } // (otherwise frameIn is in Scene coords) // going World->Scene or Object->Scene if (eTo == CoordSpace.SceneCoords) { return(sceneDim); } // going Scene->World or Object->World if (eTo == CoordSpace.WorldCoords) { return(scene.ToWorldDimension(sceneDim)); } // only thing left is going from Scene to Object //return SceneToObject(fromSO, sceneDim); throw new NotImplementedException("SceneTransforms.TransformTo: transforming to object coordinates not supported yet"); }
/// <summary> /// input dimension is in Object (local) coords of so, apply all intermediate /// transform scaling to get it to Scene coords /// </summary> public static float ObjectToScene(TransformableSO so, float objectDim) { float sceneDim = objectDim; TransformableSO curSO = so; while (curSO != null) { Vector3f scale = curSO.GetLocalScale(); Util.gDevAssert(IsUniformScale(scale)); sceneDim *= ((scale.x + scale.y + scale.z) / 3.0f); // yikes! SOParent parent = curSO.Parent; if (parent is FScene) { return(sceneDim); } curSO = (parent as TransformableSO); } if (curSO == null) { DebugUtil.Error("SceneTransforms.TransformTo: found null parent SO!"); } return(sceneDim); }
override public bool EndCapture(InputEvent e) { if (eState == CaptureState.ClickType) { return(base.EndCapture(e)); } if (newPrimitive is PrimitiveSO) { SavedSettings.Save("DropPrimButton_scale", fPrimScale); } // store undo/redo record for new primitive TargetScene.History.PushChange( new AddSOChange() { scene = TargetScene, so = newPrimitive, bKeepWorldPosition = true }); TargetScene.History.PushInteractionCheckpoint(); newPrimitive = null; return(true); }