Beispiel #1
0
        public Transform GetBone(int boneIndex)
        {
            if (handSkeleton != null)
            {
                return(handSkeleton.GetBone(boneIndex));
            }

            return(null);
        }
        // Use this for initialization
        void Start()
        {
            poses    = GetComponent <KnucklePoses>();
            skeleton = GetComponent <SteamVR_Behaviour_Skeleton>();
            hand     = skeleton.inputSource;
            GameObject _claws = Instantiate(clawPrefab, skeleton.GetBonePosition(SteamVR_Skeleton_JointIndexes.wrist), skeleton.GetBoneRotation(SteamVR_Skeleton_JointIndexes.wrist));

            _claws.transform.parent = skeleton.GetBone(SteamVR_Skeleton_JointIndexes.wrist);
            if (hand == SteamVR_Input_Sources.LeftHand)
            {
                _claws.transform.localScale = new Vector3(1, 1, 1);
            }
            claws = _claws.GetComponent <KnuckleClawScaler>();
        }
Beispiel #3
0
        protected void SaveHandData(SteamVR_Skeleton_Pose_Hand handData, SteamVR_Behaviour_Skeleton thisSkeleton)
        {
            // handData.position = thisSkeleton.transform.InverseTransformPoint(poser.transform.position);
            handData.position = thisSkeleton.transform.localPosition;
            handData.rotation = thisSkeleton.transform.localRotation;// Quaternion.Inverse(thisSkeleton.transform.localRotation);

            handData.bonePositions = new Vector3[SteamVR_Action_Skeleton.numBones];
            handData.boneRotations = new Quaternion[SteamVR_Action_Skeleton.numBones];

            for (int boneIndex = 0; boneIndex < SteamVR_Action_Skeleton.numBones; boneIndex++)
            {
                Transform bone = thisSkeleton.GetBone(boneIndex);
                handData.bonePositions[boneIndex] = bone.localPosition;
                handData.boneRotations[boneIndex] = bone.localRotation;
            }

            EditorUtility.SetDirty(activePose);
        }
        protected void SaveHandData(SteamVR_Skeleton_Pose_Hand handData, SteamVR_Behaviour_Skeleton hand)
        {
            // handData.position = hand.transform.InverseTransformPoint(baker.transform.position);
            handData.position = hand.transform.localPosition;

            handData.rotation = hand.transform.localRotation;// Quaternion.Inverse(hand.transform.localRotation);

            handData.bonePositions = new Vector3[SteamVR_Action_Skeleton.numBones];
            handData.boneRotations = new Quaternion[SteamVR_Action_Skeleton.numBones];

            for (int i = 0; i < SteamVR_Action_Skeleton.numBones; i++)
            {
                Transform bone = hand.GetBone(i);
                handData.bonePositions[i] = bone.localPosition;
                handData.boneRotations[i] = bone.localRotation;
            }

            // EditorUtility.SetDirty(activePose);
        }
Beispiel #5
0
        // Use this for initialization
        void Start()
        {
            actionSet.ActivateSecondary();
            poses    = GetComponent <KnucklePoses>();
            skeleton = GetComponent <SteamVR_Behaviour_Skeleton>();
            hand     = skeleton.inputSource;
            if (spiritGunPrefab != null)
            {
                GameObject spiritGun = Instantiate(spiritGunPrefab, skeleton.GetBonePosition(SteamVR_Skeleton_JointIndexes.indexTip), skeleton.GetBoneRotation(SteamVR_Skeleton_JointIndexes.indexTip));
                spiritGunEffect = spiritGun.GetComponent <SpiritGunGlow>();
                spiritGunEffect.transform.parent = skeleton.GetBone(SteamVR_Skeleton_JointIndexes.indexTip);
            }
            if (shockPrefab != null)
            {
                shockObjects[0] = Instantiate(shockPrefab, skeleton.GetBonePosition(SteamVR_Skeleton_JointIndexes.indexTip), skeleton.GetBoneRotation(SteamVR_Skeleton_JointIndexes.indexTip));
                shockObjects[0].transform.parent = skeleton.GetBone(SteamVR_Skeleton_JointIndexes.indexTip);
                shockObjects[0].SetActive(false);

                shockObjects[1] = Instantiate(shockPrefab, skeleton.GetBonePosition(SteamVR_Skeleton_JointIndexes.middleTip), skeleton.GetBoneRotation(SteamVR_Skeleton_JointIndexes.middleTip));
                shockObjects[1].transform.parent = skeleton.GetBone(SteamVR_Skeleton_JointIndexes.middleTip);
                shockObjects[1].SetActive(false);

                shockObjects[2] = Instantiate(shockPrefab, skeleton.GetBonePosition(SteamVR_Skeleton_JointIndexes.ringTip), skeleton.GetBoneRotation(SteamVR_Skeleton_JointIndexes.ringTip));
                shockObjects[2].transform.parent = skeleton.GetBone(SteamVR_Skeleton_JointIndexes.ringTip);
                shockObjects[2].SetActive(false);

                shockObjects[3] = Instantiate(shockPrefab, skeleton.GetBonePosition(SteamVR_Skeleton_JointIndexes.pinkyTip), skeleton.GetBoneRotation(SteamVR_Skeleton_JointIndexes.pinkyTip));
                shockObjects[3].transform.parent = skeleton.GetBone(SteamVR_Skeleton_JointIndexes.pinkyTip);
                shockObjects[3].SetActive(false);

                shockObjects[4] = Instantiate(shockPrefab, skeleton.GetBonePosition(SteamVR_Skeleton_JointIndexes.thumbTip), skeleton.GetBoneRotation(SteamVR_Skeleton_JointIndexes.thumbTip));
                shockObjects[4].transform.parent = skeleton.GetBone(SteamVR_Skeleton_JointIndexes.thumbTip);
                shockObjects[4].SetActive(false);

                if (hand == SteamVR_Input_Sources.LeftHand)
                {
                    foreach (GameObject shockObject in shockObjects)
                    {
                        shockObject.transform.localScale = new Vector3(1, 1, 1);
                    }
                }
            }
        }
Beispiel #6
0
        protected void UpdatePreviewHand(ref GameObject preview, ref bool showPreview, string assetName, SteamVR_Skeleton_Pose_Hand handData, SteamVR_Skeleton_Pose sourcePose, bool forceUpdate)
        {
            if (showPreview)
            {
                if (forceUpdate && preview != null)
                {
                    DestroyImmediate(preview);
                }

                if (preview == null)
                {
                    GameObject prefabProperty = null;
                    string[]   defPaths       = AssetDatabase.FindAssets(string.Format("t:Prefab {0}", assetName));
                    if (defPaths != null && defPaths.Length > 0)
                    {
                        string guid = defPaths[0];
                        string path = AssetDatabase.GUIDToAssetPath(guid);
                        prefabProperty = AssetDatabase.LoadAssetAtPath <GameObject>(path);

                        if (prefabProperty == null)
                        {
                            Debug.LogError("[SteamVR] Could not load prefab: " + assetName + ". Found path: " + path);
                        }
                    }
                    else
                    {
                        Debug.LogError("[SteamVR] Could not load prefab: " + assetName);
                    }

                    preview = GameObject.Instantiate(prefabProperty);
                    preview.transform.localScale    = Vector3.one * poserScale;//.floatValue;
                    preview.transform.parent        = poser.transform;
                    preview.transform.localPosition = Vector3.zero;
                    preview.transform.localRotation = Quaternion.identity;

                    SteamVR_Behaviour_Skeleton previewSkeleton = null;

                    if (preview != null)
                    {
                        previewSkeleton = preview.GetComponent <SteamVR_Behaviour_Skeleton>();
                    }

                    if (previewSkeleton != null)
                    {
                        if (handData.bonePositions == null || handData.bonePositions.Length == 0)
                        {
                            SteamVR_Skeleton_Pose poseResource = (SteamVR_Skeleton_Pose)Resources.Load("ReferencePose_OpenHand");
                            DeepCopyPose(poseResource, sourcePose);
                            EditorUtility.SetDirty(sourcePose);
                        }

                        preview.transform.localPosition = Vector3.zero;
                        preview.transform.localRotation = Quaternion.identity;
                        preview.transform.parent        = null;
                        preview.transform.localScale    = Vector3.one * poserScale;//.floatValue;
                        preview.transform.parent        = poser.transform;

                        preview.transform.localRotation = handData.rotation;
                        preview.transform.localPosition = handData.position;


                        for (int boneIndex = 0; boneIndex < handData.bonePositions.Length; boneIndex++)
                        {
                            Transform bone = previewSkeleton.GetBone(boneIndex);
                            bone.localPosition = handData.bonePositions[boneIndex];
                            bone.localRotation = handData.boneRotations[boneIndex];
                        }
                    }
                    SceneView.RepaintAll();
                }
            }
            else
            {
                if (preview != null)
                {
                    DestroyImmediate(preview);
                    SceneView.RepaintAll();
                }
            }
        }