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(); } }
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 <NVRPhysicalController>()); GameObject.DestroyImmediate(PhysicalController.GetComponent <NVRHand>()); GameObject.DestroyImmediate(PhysicalController.GetComponent <SteamVR_TrackedObject>()); GameObject.DestroyImmediate(PhysicalController.GetComponent <SteamVR_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; Rigidbody = PhysicalController.GetComponent <Rigidbody>(); Rigidbody.isKinematic = false; Rigidbody.useGravity = false; Rigidbody.angularDrag = 0; Rigidbody.maxAngularVelocity = 100f; string controllerModel = Hand.GetDeviceName(); switch (controllerModel) { case "vr_controller_05_wireless_b": Transform dk1Trackhat = PhysicalController.transform.FindChild("trackhat"); Collider dk1TrackhatCollider = dk1Trackhat.gameObject.GetComponent <BoxCollider>(); if (dk1TrackhatCollider == null) { dk1TrackhatCollider = dk1Trackhat.gameObject.AddComponent <BoxCollider>(); } Transform dk1Body = PhysicalController.transform.FindChild("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 = PhysicalController.transform.FindChild("VivePreColliders"); if (dk2TrackhatColliders == null) { dk2TrackhatColliders = GameObject.Instantiate(Resources.Load <GameObject>("VivePreColliders")).transform; dk2TrackhatColliders.parent = PhysicalController.transform; dk2TrackhatColliders.localPosition = Vector3.zero; dk2TrackhatColliders.localRotation = Quaternion.identity; dk2TrackhatColliders.localScale = Vector3.one; } Colliders = dk2TrackhatColliders.GetComponentsInChildren <Collider>(); break; default: Debug.LogError("Error. Unsupported device type: " + controllerModel); break; } Renderer[] renderers = PhysicalController.GetComponentsInChildren <Renderer>(); for (int index = 0; index < renderers.Length; index++) { NVRHelpers.SetOpaque(renderers[index].material); } if (initialState == false) { Off(); } else { On(); } }
public void Initialize(NVRHand trackingHand, bool initialState) { Hand = trackingHand; Hand.gameObject.SetActive(false); PhysicalController = Instantiate(Hand.gameObject); PhysicalController.name = PhysicalController.name.Replace("(Clone)", " [Physical]"); Hand.gameObject.SetActive(true); Component[] components = PhysicalController.GetComponentsInChildren <Component>(true); foreach (Component component in components) { Type component_type = component.GetType(); if (KeepTypes.Any(keepType => keepType == component_type || component_type.IsSubclassOf(keepType)) == false) { DestroyImmediate(component); } } PhysicalController.transform.parent = Hand.transform.parent; PhysicalController.transform.position = Hand.transform.position; PhysicalController.transform.rotation = Hand.transform.rotation; PhysicalController.transform.localScale = Hand.transform.localScale; PhysicalController.SetActive(true); if (Hand.HasCustomModel) { SetupCustomModel(); } else { Colliders = Hand.SetupDefaultPhysicalColliders(PhysicalController.transform); } if (Colliders == null) { Debug.LogError("[NewtonVR] Error: Physical colliders on hand not setup properly."); } Rigidbody = PhysicalController.GetComponent <Rigidbody>(); Rigidbody.isKinematic = false; Rigidbody.maxAngularVelocity = float.MaxValue; if (trackingHand.Player.AutomaticallySetControllerTransparency) { Renderer[] renderers = PhysicalController.GetComponentsInChildren <Renderer>(); for (int index = 0; index < renderers.Length; index++) { NVRHelpers.SetOpaque(renderers[index].material); } } if (initialState == false) { Off(); } else { On(); } }
public void Initialize(NVRHand trackingHand, bool initialState) { Debug.Log(this.gameObject.name + " PHYSICAL Controller Init"); Hand = trackingHand; // if we don't have custom models to use for collision, copy whatever the hand has if (Hand.CustomModel == null && Hand.CustomPhysicalColliders == null) { // prevent new PhysicalController's components from starting until we're ready Hand.gameObject.SetActive(false); PhysicalController = GameObject.Instantiate(Hand.gameObject); PhysicalController.name = PhysicalController.name.Replace("(Clone)", " [Physical]"); // TODO: This could use some cleanup. Plenty of other scripts could cause problems being duplicated... GameObject.DestroyImmediate(PhysicalController.GetComponent <NVRPhysicalController>()); GameObject.DestroyImmediate(PhysicalController.GetComponent <NVRHand>()); GameObject.DestroyImmediate(PhysicalController.GetComponent <SteamVR_TrackedObject>()); Hand.gameObject.SetActive(true); PhysicalController.gameObject.SetActive(true); } else { PhysicalController = new GameObject(Hand.gameObject.name + " [Physical]", typeof(Rigidbody)); } PhysicalController.transform.parent = Hand.transform.parent; PhysicalController.transform.position = Hand.transform.position; PhysicalController.transform.rotation = Hand.transform.rotation; PhysicalController.transform.localScale = Hand.transform.localScale; if (Hand.CustomPhysicalColliders != null) { GameObject customColliders = GameObject.Instantiate(Hand.CustomPhysicalColliders); customColliders.name = "CustomColliders"; Transform customCollidersTransform = customColliders.transform; customCollidersTransform.parent = PhysicalController.transform; customCollidersTransform.localPosition = Vector3.zero; customCollidersTransform.localRotation = Quaternion.identity; customCollidersTransform.localScale = Vector3.one; Colliders = customCollidersTransform.GetComponentsInChildren <Collider>(); } else if (Hand.CustomModel != null) { GameObject customColliders = GameObject.Instantiate(Hand.CustomModel); customColliders.name = "CustomColliders"; Transform customCollidersTransform = customColliders.transform; customCollidersTransform.parent = PhysicalController.transform; customCollidersTransform.localPosition = Vector3.zero; customCollidersTransform.localRotation = Quaternion.identity; customCollidersTransform.localScale = Vector3.one; Colliders = customCollidersTransform.GetComponentsInChildren <Collider>(); } else { Colliders = PhysicalController.GetComponentsInChildren <Collider>(true); } // in case we picked up trigger colliders from a custom/inherited model, mark them as physical foreach (Collider col in Colliders) { col.isTrigger = false; col.gameObject.SetActive(true); // for some reason this is sometimes deactivated? } 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(); } }
public void Initialize(NVRHand trackingHand, bool initialState) { Hand = trackingHand; PhysicalController = GameObject.Instantiate(Hand.gameObject); PhysicalController.name = PhysicalController.name.Replace("(Clone)", " [Physical]"); Component[] components = PhysicalController.GetComponentsInChildren <Component>(true); for (int componentIndex = 0; componentIndex < components.Length; componentIndex++) { Type componentType = components[componentIndex].GetType(); if (KeepTypes.Any(keepType => keepType == componentType || componentType.IsSubclassOf(keepType)) == false) { DestroyImmediate(components[componentIndex]); } } 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 "Custom": Transform customCollidersTransform = null; if (Hand.CustomPhysicalColliders == null) { GameObject customColliders = GameObject.Instantiate(Hand.CustomModel); customColliders.name = "CustomColliders"; customCollidersTransform = customColliders.transform; customCollidersTransform.parent = PhysicalController.transform; customCollidersTransform.localPosition = Vector3.zero; customCollidersTransform.localRotation = Quaternion.identity; customCollidersTransform.localScale = Vector3.one; foreach (Collider col in customColliders.GetComponentsInChildren <Collider>()) { col.isTrigger = false; } Colliders = customCollidersTransform.GetComponentsInChildren <Collider>(); } else { 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 = Hand.CustomPhysicalColliders.transform.localScale; } Colliders = customCollidersTransform.GetComponentsInChildren <Collider>(); break; default: Colliders = Hand.SetupDefaultPhysicalColliders(PhysicalController.transform); break; } if (Colliders == null) { Debug.LogError("[NewtonVR] Error: Physical colliders on hand not setup properly."); } Rigidbody = PhysicalController.GetComponent <Rigidbody>(); Rigidbody.isKinematic = false; Rigidbody.maxAngularVelocity = float.MaxValue; if (trackingHand.Player.AutomaticallySetControllerTransparency) { Renderer[] renderers = PhysicalController.GetComponentsInChildren <Renderer>(); for (int index = 0; index < renderers.Length; index++) { NVRHelpers.SetOpaque(renderers[index].material); } } if (initialState == false) { Off(); } else { On(); } }