public static void DeleteReferencesToObject(Animatable obj) { var deleteKeys = new List <int>(Intersections.Count); for (int i = Intersections.Count - 1; i >= 0; --i) { if (Intersections[i].Item3.GetInstanceID() == obj.GetInstanceID()) { OnIntersectionEnd?.Invoke(Intersections[i]); Intersections.RemoveAt(i); } } }
private static void TrySwitchToEmissionConeGestureMode(ref Animatable selected) { if (selected != null && selected.GetComponent <ParticleEmitter>() != null) { var emitterCenter = selected.SizeProxy.bounds.center; var emissionConeCenter = selected.GetComponent <ParticleEmitter>().RenderedConeMeshFilter.GetComponent <Renderer>().bounds.center; var indexFingerPos = poseManager.GetHandTransform(OvrAvatar.HandType.Right, PoseManager.HandJoint.IndexTip).position; if ((indexFingerPos - emitterCenter).sqrMagnitude > (indexFingerPos - emissionConeCenter).sqrMagnitude) { emitterReceivingConeGestures = selected.GetComponent <ParticleEmitter>(); // stop the gesture which would otherwise have started selected = null; SetRecognitionState(GestureRecognizerState.ReadyForConeGesture); } } }
public static void OnHandObjectCollisionStart(Animatable other, GameObject handPart) { HandType hand; HandJoint joint; GetJointFromGameobjectName(handPart.name, out hand, out joint); if (hand == HandType.Max || other == null) { return; } var tpl = new Tuple <HandType, HandJoint, Animatable>(hand, joint, other); if (!Intersections.Contains(tpl)) { Intersections.Add(tpl); OnIntersectionStart?.Invoke(tpl); } }
private static void _StartTransforming(Animatable obj) { controlledObject = obj; initialObjectPose.transform.SetParent(obj.transform.parent, true); initialObjectPose.transform.SetPositionAndRotation(obj.transform.position, obj.transform.rotation); initialObjectPose.transform.localScale = obj.transform.localScale; NumFrameBeforeGesture = NumFrame; if (IsRecording) { PlayAnimationInScript(); } else { PauseAnimationInScript(); } obj.Selected(); }
private static Animatable GetSmallest(List <Animatable> list, bool overrideGesturalSelection = false) { float minSize = 100.0f; Animatable selected = null; foreach (var obj in list) { var objSize = obj.SizeProxy.bounds.size.sqrMagnitude; if (objSize < minSize) { selected = obj; minSize = objSize; } } TrySwitchToEmissionConeGestureMode(ref selected); return(selected); }
public static void StartRotation(Animatable obj) { _StartTransforming(obj); if (!KeepOldRotationAxis) { rotationAxis = ( Globals.POINTING_FINGER_COORDINATES.x * poseManager.GetHandFrameVector(OvrAvatar.HandType.Right, PoseManager.HandFrame.Fingers) + Globals.POINTING_FINGER_COORDINATES.y * poseManager.GetHandFrameVector(OvrAvatar.HandType.Right, PoseManager.HandFrame.Thumb) + Globals.POINTING_FINGER_COORDINATES.z * poseManager.GetHandFrameVector(OvrAvatar.HandType.Right, PoseManager.HandFrame.Palm) ).normalized; } var handPos = poseManager.GetHandTransform(OvrAvatar.HandType.Left, PoseManager.HandJoint.IndexTip).position; handPos -= initialObjectPose.transform.position; initialHandDirection = (handPos - rotationAxis * Vector3.Dot(handPos, rotationAxis)).normalized; StackRotation(controlledObject.RotationKeys, controlledObject, 0); }
public static void StopTransforming(GestureRecognizerState state) { var opTpl = undoStack.Pop(); undoStack.Push(Tuple.Create(opTpl.Item1, opTpl.Item2, NumFrame - NumFrameBeforeGesture)); switch (state) { case GestureRecognizerState.Translating: var curHandPosition = poseManager.GetHandTransform(OvrAvatar.HandType.Right, PoseManager.HandJoint.IndexTip).position; var addVector = (controlledObject.transform.parent == null) ? (curHandPosition - initialHandPosition) : controlledObject.transform.parent.InverseTransformVector(curHandPosition - initialHandPosition); controlledObject.AddTranslationKey(initialObjectPose.transform.localPosition + addVector, CurFrame); break; case GestureRecognizerState.Scaling: var curInterHandDistance = ( poseManager.GetHandTransform(OvrAvatar.HandType.Right, PoseManager.HandJoint.IndexTip).position - poseManager.GetHandTransform(OvrAvatar.HandType.Left, PoseManager.HandJoint.IndexTip).position ).magnitude; controlledObject.AddScaleKey(initialObjectPose.transform.localScale * (curInterHandDistance / (initialInterHandDistance + float.Epsilon)), CurFrame); break; case GestureRecognizerState.Rotating: var rotation = ComputeCurrentRotation(); rotation = ((initialObjectPose.transform.parent == null) ? Quaternion.identity : Quaternion.Inverse(initialObjectPose.transform.parent.rotation)) * rotation; controlledObject.AddRotationKey(rotation, CurFrame); break; } controlledObject.EvaluateTransform(CurFrame); controlledObject.Deselected(); controlledObject = null; if (IsRecording) { PauseAnimationInScript(); } }
public static void OnHandObjectCollisionEnd(Animatable other, GameObject handPart) { HandType hand; HandJoint joint; GetJointFromGameobjectName(handPart.name, out hand, out joint); if (hand == HandType.Max) { return; } var tpl = new Tuple <HandType, HandJoint, Animatable>(hand, joint, other); if (Intersections.Remove(tpl) == false) { Debug.LogWarning("Collision-end detected on an object without collision-start."); } else { OnIntersectionEnd?.Invoke(tpl); } }
private static Animatable GetSmallest(List <Animatable> list1, List <Animatable> list2) { float minSize = 100.0f; Animatable selected = null; foreach (var obj in list1) { // inefficient, but this list should usually be small if (!list2.Contains(obj)) { continue; } var objSize = obj.SizeProxy.bounds.size.sqrMagnitude; if (objSize < minSize) { selected = obj; minSize = objSize; } } return(selected); }
private static void SetPropertiesFromJsonObject(Animatable sceneObject, SerializableAnimatable obj) { TimeManager.RegisterObject(sceneObject, false); sceneObject.StartFrame = obj.StartFrame; foreach (var pair in obj.TranslationKeys) { sceneObject.AddTranslationKey(pair.Item2, pair.Item1 + obj.StartFrame); } foreach (var pair in obj.RotationKeys) { sceneObject.AddRotationKey(pair.Item2, pair.Item1 + obj.StartFrame); } foreach (var pair in obj.ScaleKeys) { sceneObject.AddScaleKey(pair.Item2, pair.Item1 + obj.StartFrame); } sceneObject.EvaluateTransform(0); // recurse for top-level folks if (obj.IsTopLevel) { var sceneChildren = sceneObject.GetComponentsInChildren <Animatable>(); Debug.Assert(sceneChildren.Length - 1 == obj.Children.Count, "#children in saved file differs from loaded object! " + sceneChildren.Length + " != " + obj.Children.Count); // Since GetComponentsInChildren<T> uses depth-first search, the first // component must be `obj` itself, which we skip for (int i = 1; i < sceneChildren.Length; ++i) { SetPropertiesFromJsonObject(sceneChildren[i], obj.Children[i - 1]); } } }
void Awake() { animScript = GetComponent <Animatable>(); animScript.OnInit += Init; animScript.OnEmissionConeFromUndoStack += SetEmissionConeFromFile; animScript.OnEmissionNoiseFromUndoStack += (amplitude, frequency) => { MaxPositionNoise = amplitude; PositionNoiseFrequency = frequency; MaxRotationNoise = MaxPositionNoise * 360; RotationNoiseFrequency = PositionNoiseFrequency; }; animScript.OnEmissionSpiralFromUndoStack += (frequency) => { SpiralFrequency = frequency; }; RenderedCurve.enabled = false; RenderedCurve.widthMultiplier = Globals.EMISSION_CURVE_RENDER_WIDTH; animScript.SelectUI.Add(RenderedCurve); animScript.SelectUI.Add(RenderedConeMeshFilter.GetComponent <MeshRenderer>()); emissionCone = RenderedConeMeshFilter.GetComponent <EmissionCone>(); emissionCone.GetComponent <Rigidbody>().detectCollisions = false; foreach (var child in GetComponentsInChildren <MeshRenderer>()) { child.enabled = false; animScript.SelectUI.Add(child); if (child.GetInstanceID() != RenderedConeMeshFilter.GetComponent <MeshRenderer>().GetInstanceID()) { animScript.ApproachUI.Add(child); } } animScript.OnSelect += ProcessObjectSelection; animScript.OnDeselect += ProcessObjectDeselection; InitialParticleRotation = Quaternion.identity; // AngleAxis(90, Vector3.right); ParticleScale = new Vector3(0.02f, 0.02f, 0.02f); ps = GetComponent <ParticleSystem>(); ps.Stop(); main = ps.main; main.simulationSpace = ParticleSystemSimulationSpace.Local; main.maxParticles = maxNumParticle; main.startSpeed = Globals.PARTICLE_DEFAULT_START_SPEED; main.startLifetime = 20; main.startSize3D = true; main.startSizeX = ParticleScale.x; main.startSizeY = ParticleScale.y; main.startSizeZ = ParticleScale.z; emission = ps.emission; emission.enabled = true; emitterShape = ps.shape; emitterShape.enabled = true; emitterShape.shapeType = ParticleSystemShapeType.Cone; emitterShape.radius = Globals.PARTICLE_EMITTER_DEFAULT_SIZE; emitterShape.angle = 0; var colourModule = ps.colorOverLifetime; colourModule.color = new ParticleSystem.MinMaxGradient(colourGradient); colourModule.enabled = true; ParticleCustomForceField gravity = new ParticleCustomForceField( ParticleCustomForceField.FieldEffectType.Gravity, x => { return(9.83f * Vector3.down); }, x => { return(Vector3.zero); }, 1 ); forceFields.Add(gravity); }
public static void DeregisterObject(Animatable obj) { objects.Remove(obj); }
public static void StackEmissionSpiral(float s, Animatable obj) { emissionSpiralStack.Push(s); undoStack.Push(Tuple.Create(obj, Operation.SetEmissionSpiral, 0)); }
public static void StackEmissionNoise(Tuple <float, float> n, Animatable obj) { emissionNoiseStack.Push(n); undoStack.Push(Tuple.Create(obj, Operation.SetEmissionNoise, 0)); }
public static void StackScale(List <Tuple <int, Vector3> > s, Animatable obj, int numFramesAdded) { scaleStack.Push(new List <Tuple <int, Vector3> >(s)); undoStack.Push(Tuple.Create(obj, Operation.Scale, numFramesAdded)); }
public static void StackRotation(List <Tuple <int, Quaternion> > r, Animatable obj, int numFramesAdded) { rotationStack.Push(new List <Tuple <int, Quaternion> >(r)); undoStack.Push(Tuple.Create(obj, Operation.Rotate, numFramesAdded)); }
public static void StackTranslation(List <Tuple <int, Vector3> > t, Animatable obj, int numFramesAdded) { translationStack.Push(new List <Tuple <int, Vector3> >(t)); undoStack.Push(Tuple.Create(obj, Operation.Translate, numFramesAdded)); }