virtual public bool EndCapture(InputEvent e) { if (activeWidget != null) { activeWidget.EndCapture(targetWrapper); MaterialUtil.SetMaterial(activeWidget.RootGameObject, activeWidget.StandardMaterial); // tell wrapper we are done with capture, so it should bake transform/etc bool bModified = targetWrapper.DoneTransformation(EmitChanges); if (bModified) { // update gizmo onTransformModified(null); // allow client/subclass to add any other change records OnTransformInteractionEnd(); // gizmos drop change events by default if (EmitChanges) { Scene.History.PushInteractionCheckpoint(); } } activeWidget = null; } return(true); }
public virtual void EndHover(Ray3f ray) { if (hoverWidget != null) { MaterialUtil.SetMaterial(hoverWidget.RootGameObject, hoverWidget.StandardMaterial); hoverWidget = null; } }
protected void update_material() { if (Enabled == false && DisabledMaterial != null) { MaterialUtil.SetMaterial(buttonMesh, DisabledMaterial); } else { MaterialUtil.SetMaterial(buttonMesh, StandardMaterial); } }
public virtual void UpdateHover(Ray3f ray, UIRayHit hit) { if (hoverWidget != null) { EndHover(ray); } if (Widgets.ContainsKey(hit.hitGO)) { hoverWidget = Widgets[hit.hitGO]; MaterialUtil.SetMaterial(hoverWidget.RootGameObject, hoverWidget.HoverMaterial); } }
virtual public bool UpdateCapture(InputEvent e) { // update capture if we have an active widget if (activeWidget != null) { // [TODO] can remove this once we fix test/begin capture MaterialUtil.SetMaterial(activeWidget.RootGameObject, activeWidget.HoverMaterial); activeWidget.UpdateCapture(targetWrapper, e.ray); return(true); } return(false); }
override public bool UpdateCapture(InputEvent e) { GameObject hitGO = FindHitGO(e.ray); // find item we want to higlight MenuItem highlightItem = (hitGO == null) ? null : AllItems.Find((x) => x.GO == hitGO); // update visual higlight foreach (MenuItem item in AllItems) { if (item == highlightItem) { MaterialUtil.SetMaterial(item.GO, highlightMaterial); } else { MaterialUtil.SetMaterial(item.GO, itemMaterial); } } // TODO cannot automatically hide when we miss, or we never expand the submenu. if (highlightItem == null) { return(true); } if (ActiveMenuItem == highlightItem) { return(true); } if (ActiveMenuItem != null) { hide_child_menus(ActiveMenuItem); hide_sub_menu(ActiveMenuItem); ActiveMenuItem = null; } if (highlightItem != null) { show_parent_menus(highlightItem); show_sub_menu(highlightItem); ActiveMenuItem = highlightItem; } return(true); }
virtual public bool BeginCapture(InputEvent e) { activeWidget = null; // if the hit gameobject has a widget attached to it, begin capture & transformation // TODO maybe wrapper class should have Begin/Update/End capture functions, then we do not need BeginTransformation/EndTransformation ? if (Widgets.ContainsKey(e.hit.hitGO)) { Standard3DTransformWidget w = Widgets [e.hit.hitGO]; if (w.BeginCapture(targetWrapper, e.ray, e.hit.toUIHit())) { MaterialUtil.SetMaterial(w.RootGameObject, w.HoverMaterial); targetWrapper.BeginTransformation(); activeWidget = w; OnTransformInteractionStart(); return(true); } } return(false); }
public void Update() { targetGO.transform.position = TargetPoint; float fScaling = VRUtil.GetVRRadiusForVisualAngle(TargetPoint, gameObject.transform.position, 1.0f); targetGO.transform.localScale = new Vector3(fScaling, fScaling, fScaling); if (ShowTarget) { Material setMaterial = hiddenMaterial; // raycast into scene and if we hit ball before we hit anything else, render // it darker red, to give some sense of inside/outside if (this.context != null) { Vector3 camPos = this.context.ActiveCamera.GetPosition(); float fDistSqr = (TargetPoint - camPos).sqrMagnitude; Ray ray_t = new Ray(camPos, (TargetPoint - camPos).normalized); AnyRayHit hit; if (this.context.Scene.FindSceneRayIntersection(ray_t, out hit) == false) { setMaterial = visibleMaterial; } else if (hit.fHitDist * hit.fHitDist * 1.005f > fDistSqr) { setMaterial = visibleMaterial; } } MaterialUtil.SetMaterial(targetGO, setMaterial); targetGO.Show(); } else { targetGO.Hide(); } }
public void Update() { targetGO.transform.position = TargetPoint; float fScaling = VRUtil.GetVRRadiusForVisualAngle(TargetPoint, gameObject.transform.position, SceneGraphConfig.CameraPivotVisualDegrees); targetGO.transform.localScale = fScaling * Vector3f.One; if (ShowTarget && SceneGraphConfig.EnableVisibleCameraPivot) { Material setMaterial = hiddenMaterial; // raycast into scene and if we hit ball before we hit anything else, render // it darker red, to give some sense of inside/outside if (this.context != null) { Vector3f camPos = this.context.ActiveCamera.GetPosition(); float fDistSqr = TargetPoint.DistanceSquared(camPos); Ray3f ray_t = new Ray3f(camPos, (TargetPoint - camPos).Normalized); AnyRayHit hit; if (this.context.Scene.FindSceneRayIntersection(ray_t, out hit) == false) { setMaterial = visibleMaterial; } else if (hit.fHitDist * hit.fHitDist * 1.005f > fDistSqr) { setMaterial = visibleMaterial; } } MaterialUtil.SetMaterial(targetGO, setMaterial); targetGO.Show(); } else { targetGO.Hide(); } }
virtual public bool EndCapture(InputEvent e) { if (activeWidget != null) { MaterialUtil.SetMaterial(activeWidget.RootGameObject, activeWidget.StandardMaterial); // update widget frame in case we want to do something like stay scene-aligned... activeWidget.EndCapture(targetWrapper); // note: e will be null if we call this from Disconnect(), because we were in an // active capture when we were Disconnected. Not sure how to handle this gracefully // in subclasses...could pass e directly to OnEndCapture? pass a flag? if (e != null) { OnEndCapture(e.ray, activeWidget); } // tell wrapper we are done with capture, so it should bake transform/etc bool bModified = targetWrapper.DoneTransformation(EmitChanges); if (bModified) { // update gizmo onTransformModified(null); // allow client/subclass to add any other change records OnTransformInteractionEnd(); // gizmos drop change events by default if (EmitChanges) { Scene.History.PushInteractionCheckpoint(); } } } activeWidget = null; return(true); }
// FixedUpdate is called before any Update public void Update() { if (CheckForSpatialInputActive() == false) { return; } Vector3 rootPos = spatialCamRig.transform.position; SpatialDevice[] hands = { Left, Right }; for (int i = 0; i < 2; ++i) { SpatialDevice h = hands[i]; h.CursorActive = VRPlatform.IsSpatialDeviceTracked(i); if (h.CursorActive) { h.Hand.Show(); h.Cursor.Show(); Vector3 handPos = VRPlatform.GetLocalControllerPosition(i); Quaternion handRot = VRPlatform.GetLocalControllerRotation(i); h.AbsoluteHandFrame = new Frame3f(rootPos + handPos, handRot); float fPositionT = 0.2f; float fRotationT = 0.2f; //float fPositionT = 1.0f; //float fRotationT = 1.0f; if (h.SmoothedHandFrame.Origin != Vector3f.Zero) { Vector3 new_origin = Vector3.Lerp(h.SmoothedHandFrame.Origin, h.AbsoluteHandFrame.Origin, fPositionT); Quaternion new_rotation = Quaternion.Slerp(h.SmoothedHandFrame.Rotation, h.AbsoluteHandFrame.Rotation, fRotationT); h.SmoothedHandFrame = new Frame3f(new_origin, new_rotation); } else { h.SmoothedHandFrame = h.AbsoluteHandFrame; } h.Hand.transform.position = h.SmoothedHandFrame.Origin; h.Hand.transform.rotation = h.SmoothedHandFrame.Rotation * (Quaternionf)handGeomRotation; h.CursorRay = new Ray(h.SmoothedHandFrame.Origin, (h.SmoothedHandFrame.Rotation * Vector3.forward).Normalized); if (Mathf.Abs(h.CursorRay.direction.sqrMagnitude - 1.0f) > 0.001f) { DebugUtil.Log(2, "SpatialInputController.Update - invlaid cursor ray! rotation was {0}", h.SmoothedHandFrame.Rotation); h.CursorRay = new Ray(h.SmoothedHandFrame.Origin, Vector3.up); } // raycast into scene to see if we hit object, UI, bounds, etc. bool bHit = false; if (context != null) { // want to hit-test active gizmo first, because that has hit-priority if (context.TransformManager.HaveActiveGizmo) { UIRayHit uiHit = null; if (context.TransformManager.ActiveGizmo.FindRayIntersection(h.CursorRay, out uiHit)) { h.RayHitPos = uiHit.hitPos; bHit = true; } } // next we tested scene if (bHit == false) { AnyRayHit hit = null; if (context.FindAnyRayIntersection(h.CursorRay, out hit)) { h.RayHitPos = hit.hitPos; bHit = true; } } // finally test worldbounds if (bHit == false) { GameObjectRayHit ghit = null; if (context.GetScene().FindWorldBoundsHit(h.CursorRay, out ghit)) { h.RayHitPos = ghit.hitPos; } } } // if not, plane cursor on view-perp plane centered at last hit pos, // otherwise it will be stuck/disappear if (bHit == false) { Frame3f f = new Frame3f(h.RayHitPos, camera.transform.forward); h.RayHitPos = f.RayPlaneIntersection(h.CursorRay.origin, h.CursorRay.direction, 2); } h.Cursor.transform.position = h.RayHitPos; //if (scene.InCapture) // MaterialUtil.SetMaterial(h.Cursor, h.CursorCapturingMaterial); //else if (bHit) { MaterialUtil.SetMaterial(h.Cursor, h.CursorHitMaterial); } else { MaterialUtil.SetMaterial(h.Cursor, h.CursorDefaultMaterial); } // maintain a consistent visual size for 3D cursor sphere float fScaling = VRUtil.GetVRRadiusForVisualAngle(h.RayHitPos, camera.transform.position, CursorVisualAngleInDegrees); h.Cursor.transform.localScale = fScaling * Vector3.one; // orient cursor so it is tilted like a 2D cursor, but per-hand Vector3 cursor_right = Vector3.Cross(camera.transform.up, h.CursorRay.direction); Vector3 cursor_fw = Vector3.Cross(cursor_right, camera.transform.up); float rotSign = (h == Right) ? 1.0f : -1.0f; Vector3 pointDir = (camera.transform.up + cursor_fw - 0.5f * rotSign * cursor_right).normalized; h.Cursor.transform.localRotation = Quaternion.FromToRotation(Vector3.up, pointDir); // update laser line if (h.Laser != null) { float hDist = (h.RayHitPos - h.CursorRay.origin).magnitude; Vector3 p0 = h.RayHitPos - 0.9f * hDist * h.CursorRay.direction; Vector3 p1 = h.RayHitPos + 100.0f * h.CursorRay.direction; float r0 = VRUtil.GetVRRadiusForVisualAngle(p0, camera.transform.position, 0.5f); h.LaserRen.SetPosition(0, p0); h.LaserRen.SetPosition(1, p1); h.LaserRen.startWidth = h.LaserRen.endWidth = r0; } // udpate cursor Mesh useMesh = context.ToolManager.HasActiveTool(i) ? activeToolCursorMesh : standardCursorMesh; if (h.Cursor.GetSharedMesh() != useMesh) { h.Cursor.SetSharedMesh(useMesh); } } else { h.Hand.Hide(); h.Cursor.Hide(); } } }
public void SetBackgroundMaterial(Material m) { MaterialUtil.SetMaterial(buttonMesh, m); }