public virtual void InteractingUpdate(NVRHand hand)
 {
     if (hand.UseButtonUp == true)
     {
         UseButtonUp();
     }
 }
Beispiel #2
0
    public void InjectHandUpdate(NewtonVR.NVRHand hand, LogData log, float time)
    {
        if (!Ready())
        {
            return;
        }
        ROSBridgeLib.ontology_msgs.HandUpdate msg = new ROSBridgeLib.ontology_msgs.HandUpdate();
        msg.grasp = hand.HoldButtonAxis;
        msg.use   = hand.UseButtonAxis;
        if (hand.CurrentlyInteracting != null)
        {
            msg.obj_inHand = hand.CurrentlyInteracting.gameObject.name;
        }
        else
        {
            msg.obj_inHand = "NONE";
        }
        msg.handState             = new ROSBridgeLib.ontology_msgs.ObjUpdate();
        msg.handState.timestamp   = new ROSBridgeLib.msg_helpers.Time(time);
        msg.handState.position    = hand.transform.position;
        msg.handState.orientation = hand.transform.rotation;
        msg.handState.velocity    = new Vector3(log.velocity[0], log.velocity[1], log.velocity[2]);
        msg.handState.name        = hand.gameObject.name;

        if (msg.handState.name.Contains("left"))
        {
            l_hand_pub.Publish(msg);
        }
        else
        {
            r_hand_pub.Publish(msg);
        }
    }
        public void ForceDetach(NVRHand hand = null)
        {
            if (hand != null)
            {
                hand.EndInteraction(this);
                this.EndInteraction(hand); //hand should call this in most cases, but rarely hand / item gets disconnected on force detach
            }
            else
            {
                for (int handIndex = 0; handIndex < AttachedHands.Count; handIndex++)
                {
                    AttachedHands[handIndex].EndInteraction(this);

                    // Changed by Drew and Zach
                    if (AttachedHands.Count > 0)
                    {
                        this.EndInteraction(AttachedHands[handIndex]);
                    }
                    else
                    {
                        EndInteractionWhenDestroying();
                    }
                }
            }
        }
    /// <summary>
    /// Creates and saves a LogEntry for all currently tracked objects
    /// </summary>
    /// <param name="time">Current time to save with log entry</param>
    void LogObjects(float time)
    {
        LogEntry newEntry = new LogEntry(time);

        foreach (var obj in tracked_objs)
        {
            // hands do not report velocity through their RigidBody
            NewtonVR.NVRHand hand = obj.GetComponent <NewtonVR.NVRHand>();
            if (hand != null)
            {
                newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, hand.GetVelocityEstimation());
                continue;
            }

            // all other objects should have a normal velocity
            Rigidbody rb = obj.GetComponentInChildren <Rigidbody>();
            if (rb != null)
            {
                newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, rb.velocity);
            }
            else
            {
                newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation);
            }
        }
        foreach (var hand in tracked_hands)
        {
            LogEvent(hand.gameObject, "HoldAxis", hand.HoldButtonAxis.ToString());
        }

        AddLogEntry(newEntry);
    }
    void Update()
    {
        //get last hand and store in memory
        if (GetComponent <NewtonVR.NVRInteractable>().AttachedHand != null)
        {
            hand = GetComponent <NewtonVR.NVRInteractable>().AttachedHand;
        }


        //start linerenderer and freeze marker on z axis
        if (transform.position.z >= whiteBoard.transform.position.z)
        {
            transform.position = new Vector3(transform.position.x, transform.position.y, whiteBoard.transform.position.z);
            if (!whiteBoardHit)
            {
                whiteBoardHit = true;
                onWhiteBoardHit();
            }
        }
        else
        {
            if (whiteBoardHit)
            {
                onWhiteBoardExit();
            }
            whiteBoardHit = false;
        }
    }
Beispiel #6
0
    public void OnBeginInteraction(NewtonVR.NVRHand hand)
    {
        Debug.Log("Picked up a toothpick");
        var colliders = transform.GetComponentsInChildren <Collider>();

        SetCollidersEnabled(false);
    }
 public virtual void InteractingUpdate(NVRHand hand)
 {
     if (hand.UseButtonUp == true)
     {
         UseButtonUp();
     }
 }
Beispiel #8
0
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            StartingDrag          = Rigidbody.drag;
            StartingAngularDrag   = Rigidbody.angularDrag;
            Rigidbody.drag        = 0;
            Rigidbody.angularDrag = 0.05f;

            if (DisablePhysicalMaterialsOnAttach)
            {
                DisablePhysicalMaterials();
            }

            PickupTransform          = new GameObject(string.Format("[{0}] NVRPickupTransform", gameObject.name)).transform;
            PickupTransform.parent   = hand.transform;
            PickupTransform.position = transform.position;
            PickupTransform.rotation = transform.rotation;

            ResetVelocityHistory();

            if (OnBeginInteraction != null)
            {
                OnBeginInteraction.Invoke();
            }
        }
Beispiel #9
0
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            StartingDrag          = rigidbody.drag;
            StartingAngularDrag   = rigidbody.angularDrag;
            rigidbody.drag        = 0;
            rigidbody.angularDrag = 0.05f;

            DisablePhysicalMaterials();

            Transform pickupTransform = new GameObject(string.Format("[{0}] NVRPickupTransform", this.gameObject.name)).transform;

            pickupTransform.parent   = this.transform;
            pickupTransform.position = hand.transform.position;
            pickupTransform.rotation = hand.transform.rotation;
            PickupTransforms.Add(hand, pickupTransform);

            ResetVelocityHistory();

            if (OnBeginInteraction != null)
            {
                OnBeginInteraction.Invoke();
            }
        }
    /// <summary>
    /// Adds a log entry for the given GameObject mentioning that the given event has happened.
    /// Useful for recording object-specific events, like button presses or collisions.
    /// Intended to be called asynchronously during recording by other classes. Events are not
    /// automatically tracked by the LogManager.
    ///
    /// Should only be called after recording has already started.
    /// </summary>
    /// <param name="obj">The object which received or triggered the event</param>
    /// <param name="eventName">The event name</param>
    /// <param name="property">Any related event parameters</param>
    public void LogEvent(GameObject obj, string eventName, string property)
    {
        if (!recording)
        {
            return;
        }
        LogEntry newEntry = new LogEntry(GetLogTime());

        NewtonVR.NVRHand hand = obj.GetComponent <NewtonVR.NVRHand>();
        Rigidbody        rb   = obj.GetComponentInChildren <Rigidbody>();

        if (hand != null)
        {
            newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, hand.GetVelocityEstimation(), eventName, property);
        }
        else if (rb != null)
        {
            newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, rb.velocity, eventName, property);
        }
        else
        {
            newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, eventName, property);
        }

        AddLogEntry(newEntry);
    }
        protected virtual bool CheckForDrop()
        {
            for (int handIndex = 0; handIndex < AttachedHands.Count; handIndex++)
            {
                float   shortestDistance = float.MaxValue;
                NVRHand hand             = AttachedHands[handIndex];
                for (int index = 0; index < Colliders.Length; index++)
                {
                    //todo: this does not do what I think it does.
                    Vector3 closest  = Colliders[index].ClosestPointOnBounds(hand.transform.position);
                    float   distance = Vector3.Distance(hand.transform.position, closest);

                    if (distance < shortestDistance)
                    {
                        shortestDistance = distance;
                        ClosestHeldPoint = closest;
                    }
                }

                if (DropDistance != -1 && hand.CurrentInteractionStyle != InterationStyle.ByScript && shortestDistance > DropDistance)
                {
                    DroppedBecauseOfDistance(hand);

                    if (IsAttached == false)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
 public virtual void HoveringUpdate(NVRHand hand, float forTime)
 {
     if (OnHovering != null)
     {
         OnHovering.Invoke();
     }
 }
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            Vector3 closestPoint = Vector3.zero;
            float shortestDistance = float.MaxValue;
            for (int index = 0; index < Colliders.Length; index++)
            {
                Vector3 closest = Colliders[index].bounds.ClosestPoint(AttachedHand.transform.position);
                float distance = Vector3.Distance(AttachedHand.transform.position, closest);

                if (distance < shortestDistance)
                {
                    shortestDistance = distance;
                    closestPoint = closest;
                }
            }

            InitialAttachPoint = new GameObject(string.Format("[{0}] InitialAttachPoint", this.gameObject.name)).transform;
            //InitialAttachPoint = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
            InitialAttachPoint.position = hand.transform.position;
            InitialAttachPoint.rotation = hand.transform.rotation;
            InitialAttachPoint.localScale = Vector3.one * 0.25f;
            InitialAttachPoint.parent = this.transform;
        }
Beispiel #14
0
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            Vector3 closestPoint     = Vector3.zero;
            float   shortestDistance = float.MaxValue;

            for (int index = 0; index < Colliders.Length; index++)
            {
                Vector3 closest  = Colliders[index].bounds.ClosestPoint(AttachedHand.transform.position);
                float   distance = Vector3.Distance(AttachedHand.transform.position, closest);

                if (distance < shortestDistance)
                {
                    shortestDistance = distance;
                    closestPoint     = closest;
                }
            }

            InitialAttachPoint = new GameObject("PickupTransform: " + this.gameObject.name).transform;
            //InitialAttachPoint = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
            InitialAttachPoint.position   = hand.transform.position;
            InitialAttachPoint.rotation   = hand.transform.rotation;
            InitialAttachPoint.localScale = Vector3.one * 0.25f;
            InitialAttachPoint.parent     = this.transform;
        }
Beispiel #15
0
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            Vector3 closestPoint     = Vector3.zero;
            float   shortestDistance = float.MaxValue;

            for (int index = 0; index < Colliders.Length; index++)
            {
                Vector3 closest  = Colliders[index].bounds.ClosestPoint(AttachedHand.transform.position);
                float   distance = Vector3.Distance(AttachedHand.transform.position, closest);

                if (distance < shortestDistance)
                {
                    shortestDistance = distance;
                    closestPoint     = closest;
                }
            }

            PickupTransform          = new GameObject(string.Format("[{0}] PickupTransform", this.gameObject.name)).transform;
            PickupTransform.parent   = hand.transform;
            PickupTransform.position = this.transform.position;
            PickupTransform.rotation = this.transform.rotation;

            this.Rigidbody.useGravity = false;
        }
Beispiel #16
0
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            StartingDrag          = Rigidbody.drag;
            StartingAngularDrag   = Rigidbody.angularDrag;
            Rigidbody.drag        = 0;
            Rigidbody.angularDrag = 0.05f;

            PickupTransform          = new GameObject(string.Format("[{0}] NVRPickupTransform", this.gameObject.name)).transform;
            PickupTransform.parent   = hand.transform;
            PickupTransform.position = this.transform.position;
            PickupTransform.rotation = this.transform.rotation;


            if (hand.Player.VelocityHistorySteps > 0)
            {
                VelocityHistory        = new Vector3?[hand.Player.VelocityHistorySteps];
                AngularVelocityHistory = new Vector3?[hand.Player.VelocityHistorySteps];
            }

            if (OnBeginInteraction != null)
            {
                OnBeginInteraction.Invoke();
            }
        }
Beispiel #17
0
        public override void BeginInteraction(NVRHand hand)
        {
            if (GetComponent <PlayerBrain>().enabled)
            {
                GetComponent <PlayerBrain>().enabled = false;
            }

            base.BeginInteraction(hand);

            StartingDrag          = Rigidbody.drag;
            StartingAngularDrag   = Rigidbody.angularDrag;
            Rigidbody.drag        = 0;
            Rigidbody.angularDrag = 0.05f;

            PickupTransform          = new GameObject(string.Format("[{0}] NVRPickupTransform", this.gameObject.name)).transform;
            PickupTransform.parent   = hand.transform;
            PickupTransform.position = this.transform.position;
            PickupTransform.rotation = this.transform.rotation;

            ResetVelocityHistory();

            if (OnBeginInteraction != null)
            {
                OnBeginInteraction.Invoke();
            }
        }
        public override void Initialize(NVRHand hand)
        {
            base.Initialize(hand);

            SetupButtonMapping();

            Controller = OVRInput.Controller.Remote;
        }
Beispiel #19
0
 private void TriggerDrawHaptic()
 {
     NewtonVR.NVRHand hand = GetGrabbingHand();
     if (hand != null)
     {
         hand.TriggerHapticPulse(hapticTime, NewtonVR.NVRButtons.Touchpad);
     }
 }
        public override void Initialize(NVRHand hand)
        {
            SetupButtonMapping();

            base.Initialize(hand);

            SteamVR_Events.RenderModelLoaded.Listen(RenderModelLoaded);
        }
Beispiel #21
0
        public override void Initialize(NVRHand hand)
        {
            SetupButtonMapping();
            base.Initialize(hand);

            InteractionManager.InteractionSourceDetected += InteractionManager_InteractionSourceDetected;
            InteractionManager.InteractionSourceUpdated  += InteractionManager_InteractionSourceUpdated;
            InteractionManager.InteractionSourceLost     += InteractionManager_InteractionSourceLost;
        }
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            PickupTransform = new GameObject(string.Format("[{0}] NVRPickupTransform", this.gameObject.name)).transform;
            PickupTransform.parent = hand.transform;
            PickupTransform.position = this.transform.position;
            PickupTransform.rotation = this.transform.rotation;
        }
        public virtual void BeginInteraction(NVRHand hand)
        {
            AttachedHand = hand;

            if (DisableKinematicOnAttach == true)
            {
                Rigidbody.isKinematic = false;
            }
        }
Beispiel #24
0
        public virtual void BeginInteraction(NVRHand hand)
        {
            AttachedHand = hand;

            if (DisableKinematicOnAttach == true)
            {
                Rigidbody.isKinematic = false;
            }
        }
Beispiel #25
0
        public override void Initialize(NVRHand hand)
        {
            SetupButtonMapping();

            base.Initialize(hand);

            SteamVR_Utils.Event.Listen("render_model_loaded", RenderModelLoaded);
            SteamVR_Utils.Event.Listen("new_poses_applied", OnNewPosesApplied);
        }
 public override void BeginInteraction(NVRHand hand)
 {
     base.BeginInteraction(hand);
     SendMessage("OnBeginInteraction", hand, SendMessageOptions.DontRequireReceiver);
     PickupTransform          = new GameObject(string.Format("[{0}] NVRPickupTransform", this.gameObject.name)).transform;
     PickupTransform.parent   = hand.transform;
     PickupTransform.position = this.transform.position;
     PickupTransform.rotation = this.transform.rotation;
 }
Beispiel #27
0
        public override void EndInteraction(NVRHand hand)
        {
            base.EndInteraction(hand);

            if (InitialAttachPoint != null)
            {
                Destroy(InitialAttachPoint.gameObject);
            }
        }
Beispiel #28
0
        public override void EndInteraction(NVRHand hand)
        {
            base.EndInteraction(hand);

            if (PickupTransform != null)
            {
                Destroy(PickupTransform.gameObject);
            }
        }
        public override void EndInteraction(NVRHand hand)
        {
            base.EndInteraction(hand);

            if (hand == null)
            {
                var pickupTransformsEnumerator = PickupTransforms.GetEnumerator();
                while (pickupTransformsEnumerator.MoveNext())
                {
                    var pickupTransform = pickupTransformsEnumerator.Current;
                    if (pickupTransform.Value != null)
                    {
                        Destroy(pickupTransform.Value.gameObject);
                    }
                }

                PickupTransforms.Clear();
            }
            else if (PickupTransforms.ContainsKey(hand))
            {
                Destroy(PickupTransforms[hand].gameObject);
                PickupTransforms.Remove(hand);

                // DA addition: reset velocity when one hand releases on a two handed interaction
                // This improves behaviour on object shooting when releasing during hand scaling
                ResetVelocityHistory();
            }

            if (PickupTransforms.Count == 0)
            {
                Rigidbody.drag        = StartingDrag;
                Rigidbody.angularDrag = StartingAngularDrag;

                EnablePhysicalMaterials();

                ApplyVelocityHistory();
                ResetVelocityHistory();

                if (OnEndInteraction != null)
                {
                    OnEndInteraction.Invoke();
                }
            }

            if (AttachedHands.Count > 0 && PickupTransforms.Count > 0)
            {
                // Reset PickupTransform
                NVRHand attachedHand = AttachedHands[0];
                PickupTransforms[attachedHand].position = this.transform.position;
                PickupTransforms[attachedHand].rotation = this.transform.rotation;
                //Debug.Log("Reset the PickupTransform of " + attachedHand.name + " because of EndInteraction of the other hand");

                // DA addition: reset velocity when one hand releases on a two handed interaction
                // This improves behaviour on object shooting when releasing during hand scaling
                ResetVelocityHistory();
            }
        }
        public override void HoveringUpdate(NVRHand hand, float forTime)
        {
            base.HoveringUpdate(hand, forTime);

            if (OnHovering != null)
            {
                OnHovering.Invoke();
            }
        }
Beispiel #31
0
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            PickupTransform          = new GameObject(string.Format("[{0}] PickupTransform", gameObject.name)).transform;
            PickupTransform.parent   = hand.transform;
            PickupTransform.position = transform.position;
            PickupTransform.rotation = transform.rotation;
        }
        public virtual void EndInteraction()
        {
            AttachedHand     = null;
            ClosestHeldPoint = Vector3.zero;

            if (EnableKinematicOnDetach == true)
            {
                Rigidbody.isKinematic = true;
            }
        }
Beispiel #33
0
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            InitialAttachPoint            = new GameObject(string.Format("[{0}] InitialAttachPoint", this.gameObject.name)).transform;
            InitialAttachPoint.position   = hand.transform.position;
            InitialAttachPoint.rotation   = hand.transform.rotation;
            InitialAttachPoint.localScale = Vector3.one * 0.25f;
            InitialAttachPoint.parent     = this.transform;
        }
Beispiel #34
0
        public virtual void EndInteraction(NVRHand hand)
        {
            AttachedHands.Remove(hand);
            ClosestHeldPoint = Vector3.zero;

            if (FreezeOnDetach == true)
            {
                SetFrozen(true);
            }
        }
Beispiel #35
0
    // Use this for initialization
    void Start()
    {
        m_TrackedObj = GetComponent<SteamVR_TrackedObject>();
        m_TrackedCtl = GetComponent<SteamVR_TrackedController>();
        m_Hand       = GetComponent<NewtonVR.NVRHand>();

        m_TrackedCtl.TriggerClicked += TriggerDown;
        m_TrackedCtl.TriggerUnclicked += TriggerUp;

        m_ColliderList = GetComponentsInChildren<Collider>();
    }
Beispiel #36
0
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            InitialAttachPoint = new GameObject(string.Format("[{0}] InitialAttachPoint", this.gameObject.name)).transform;
            InitialAttachPoint.position = hand.transform.position;
            InitialAttachPoint.rotation = hand.transform.rotation;
            InitialAttachPoint.localScale = Vector3.one * 0.25f;
            InitialAttachPoint.parent = this.transform;

            HingeJoint.useMotor = false;
        }
Beispiel #37
0
        public void RegisterHand(NVRHand hand)
        {
            Collider[] colliders = hand.GetComponentsInChildren<Collider>();

            for (int index = 0; index < colliders.Length; index++)
            {
                if (ColliderToHandMapping.ContainsKey(colliders[index]) == false)
                {
                    ColliderToHandMapping.Add(colliders[index], hand);
                }
            }
        }
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            if (FreezeRotationOnAttach)
            {
                Rigidbody.freezeRotation = true;
            }

            PickupTransform = new GameObject(string.Format("[{0}] NVRPickupTransform", this.gameObject.name)).transform;
            PickupTransform.parent = hand.transform;
            PickupTransform.position = this.transform.position;
            PickupTransform.rotation = this.transform.rotation;
            Rigidbody.useGravity = false;
        }
Beispiel #39
0
        public virtual void EndInteraction()
        {
            AttachedHand = null;
            ClosestHeldPoint = Vector3.zero;

            if (EnableKinematicOnDetach == true)
            {
                Rigidbody.isKinematic = true;
            }

            if (EnableGravityOnDetach == true)
            {
                Rigidbody.useGravity = true;
            }
        }
        public void Initialize(NVRHand trackingHand, bool initialState)
        {
            Hand = trackingHand;

            PhysicalController = GameObject.Instantiate(Hand.gameObject);
            PhysicalController.name = PhysicalController.name.Replace("(Clone)", " [Physical]");
            GameObject.DestroyImmediate(PhysicalController.GetComponent<NVRHand>());
            GameObject.DestroyImmediate(PhysicalController.GetComponent<SteamVR_TrackedObject>());
            GameObject.DestroyImmediate(PhysicalController.GetComponent<SteamVR_RenderModel>());

            Collider[] clonedColliders = PhysicalController.GetComponentsInChildren<Collider>();
            for (int index = 0; index < clonedColliders.Length; index++)
            {
                GameObject.DestroyImmediate(clonedColliders[index]);
            }

            PhysicalController.transform.parent = Hand.transform.parent;
            PhysicalController.transform.position = Hand.transform.position;
            PhysicalController.transform.rotation = Hand.transform.rotation;
            PhysicalController.transform.localScale = Hand.transform.localScale;

            Rigidbody = PhysicalController.GetComponent<Rigidbody>();
            Rigidbody.isKinematic = false;

            Transform trackhat = PhysicalController.transform.FindChild("trackhat");
            Collider trackhatCollider = trackhat.gameObject.AddComponent<BoxCollider>();

            Transform body = PhysicalController.transform.FindChild("body");
            Collider bodyCollider = body.gameObject.AddComponent<BoxCollider>();

            Colliders = new Collider[] { trackhatCollider, bodyCollider };

            Renderer[] renderers = PhysicalController.GetComponentsInChildren<Renderer>();
            for (int index = 0; index < renderers.Length; index++)
            {
                NVRHelpers.SetOpaque(renderers[index].material);
            }

            if (initialState == false)
            {
                Off();
            }
            else
            {
                On();
            }
        }
Beispiel #41
0
        public override void BeginInteraction(NVRHand hand)
        {
            base.BeginInteraction(hand);

            Vector3 closestPoint = Vector3.zero;
            float shortestDistance = float.MaxValue;
            for (int index = 0; index < Colliders.Length; index++)
            {
                Vector3 closest = Colliders[index].bounds.ClosestPoint(AttachedHand.transform.position);
                float distance = Vector3.Distance(AttachedHand.transform.position, closest);

                if (distance < shortestDistance)
                {
                    shortestDistance = distance;
                    closestPoint = closest;
                }
            }

            PickupTransform = new GameObject(string.Format("[{0}] PickupTransform", this.gameObject.name)).transform;
            PickupTransform.parent = hand.transform;
            PickupTransform.position = this.transform.position;
            PickupTransform.rotation = this.transform.rotation;
        }
Beispiel #42
0
 public virtual void BeginInteraction(NVRHand hand)
 {
     AttachedHand = hand;
 }
Beispiel #43
0
        public override void BeginInteraction(NVRHand hand)
        {
            this.Rigidbody.isKinematic = false;

            base.BeginInteraction(hand);
        }
        public void Initialize(NVRHand trackingHand, bool initialState)
        {
            Hand = trackingHand;

            PhysicalController = GameObject.Instantiate(Hand.gameObject);
            PhysicalController.name = PhysicalController.name.Replace("(Clone)", " [Physical]");

            SteamVR_RenderModel renderModel = PhysicalController.GetComponentInChildren<SteamVR_RenderModel>();
            ModelParent = renderModel.transform;

            GameObject.DestroyImmediate(PhysicalController.GetComponent<NVRPhysicalController>());
            GameObject.DestroyImmediate(PhysicalController.GetComponent<NVRHand>());
            GameObject.DestroyImmediate(PhysicalController.GetComponent<SteamVR_TrackedObject>());
            GameObject.DestroyImmediate(renderModel);
            GameObject.DestroyImmediate(PhysicalController.GetComponent<NVRPhysicalController>());

            Collider[] clonedColliders = PhysicalController.GetComponentsInChildren<Collider>();
            for (int index = 0; index < clonedColliders.Length; index++)
            {
                GameObject.DestroyImmediate(clonedColliders[index]);
            }

            PhysicalController.transform.parent = Hand.transform.parent;
            PhysicalController.transform.position = Hand.transform.position;
            PhysicalController.transform.rotation = Hand.transform.rotation;
            PhysicalController.transform.localScale = Hand.transform.localScale;

            string controllerModel = Hand.GetDeviceName();
            switch (controllerModel)
            {
                case "vr_controller_05_wireless_b":
                    Transform dk1Trackhat = ModelParent.transform.Find("trackhat");
                    Collider dk1TrackhatCollider = dk1Trackhat.gameObject.GetComponent<BoxCollider>();
                    if (dk1TrackhatCollider == null)
                        dk1TrackhatCollider = dk1Trackhat.gameObject.AddComponent<BoxCollider>();

                    Transform dk1Body = ModelParent.transform.Find("body");
                    Collider dk1BodyCollider = dk1Body.gameObject.GetComponent<BoxCollider>();
                    if (dk1BodyCollider == null)
                        dk1BodyCollider = dk1Body.gameObject.AddComponent<BoxCollider>();

                    Colliders = new Collider[] { dk1TrackhatCollider, dk1BodyCollider };
                    break;

                case "vr_controller_vive_1_5":
                    Transform dk2TrackhatColliders = ModelParent.transform.FindChild("VivePreColliders");
                    if (dk2TrackhatColliders == null)
                    {
                        dk2TrackhatColliders = GameObject.Instantiate(Resources.Load<GameObject>("VivePreColliders")).transform;
                        dk2TrackhatColliders.parent = ModelParent.transform;
                        dk2TrackhatColliders.localPosition = Vector3.zero;
                        dk2TrackhatColliders.localRotation = Quaternion.identity;
                        dk2TrackhatColliders.localScale = Vector3.one;
                    }

                    Colliders = dk2TrackhatColliders.GetComponentsInChildren<Collider>();
                    break;

                case "Custom":
                    Transform customCollidersTransform = PhysicalController.transform.FindChild("VivePreColliders");
                    if (customCollidersTransform == null)
                    {
                        GameObject customColliders = GameObject.Instantiate(Hand.CustomPhysicalColliders);
                        customColliders.name = "CustomColliders";
                        customCollidersTransform = customColliders.transform;

                        customCollidersTransform.parent = PhysicalController.transform;
                        customCollidersTransform.localPosition = Vector3.zero;
                        customCollidersTransform.localRotation = Quaternion.identity;
                        customCollidersTransform.localScale = Vector3.one;
                    }

                    Colliders = customCollidersTransform.GetComponentsInChildren<Collider>();
                    break;

                default:
                    Debug.LogError("Error. Unsupported device type: " + controllerModel);
                    break;
            }

            Rigidbody = PhysicalController.GetComponent<Rigidbody>();
            Rigidbody.isKinematic = false;
            Rigidbody.maxAngularVelocity = float.MaxValue;

            Renderer[] renderers = PhysicalController.GetComponentsInChildren<Renderer>();
            for (int index = 0; index < renderers.Length; index++)
            {
                NVRHelpers.SetOpaque(renderers[index].material);
            }

            if (initialState == false)
            {
                Off();
            }
            else
            {
                On();
            }
        }
Beispiel #45
0
 public virtual void EndInteraction()
 {
     AttachedHand = null;
     ClosestHeldPoint = Vector3.zero;
 }