public void createDebugSkeleton(SkeletonDesc skeletonDesc)
        {
            JointDesc jointDesc = skeletonDesc.jointDescs[0];

            root     = new MGJoint();
            skeleton = root.createGameObjectfromDesc(jointDesc, skeletonDesc, gameObject, skeletonJointTag);
        }
        public GameObject createGameObjectfromDesc(JointDesc jointDesc, SkeletonDesc skeletonDesc, GameObject parent, string skeletonJointTag = "SKELETON_JOINT", GameObject prefab = null, float scale = 1.0f)
        {
            name = jointDesc.name;
            GameObject jointObj = new GameObject();

            jointObj.tag = skeletonJointTag;
            var   q           = new Quaternion();
            float magnitude   = 0;
            float prefabScale = 1f;

            if (prefab != null && jointDesc.children.Length > 0)
            {
                var REF_VECTOR = new Vector3(0, 0, 1);
                foreach (var name in jointDesc.children)
                {
                    JointDesc childDesc = findJointDesc(skeletonDesc.jointDescs, name);
                    if (childDesc == null)
                    {
                        continue;
                    }
                    //int idx = Array.IndexOf(skeletonDesc.jointSequence, name);
                    //JointDesc childDesc = skeletonDesc.jointDescs[idx];
                    var offset = new Vector3(childDesc.offset[0], childDesc.offset[1], childDesc.offset[2]);
                    if (offset.magnitude > 0)
                    {
                        q         = Quaternion.FromToRotation(REF_VECTOR, offset.normalized);
                        magnitude = offset.magnitude;
                        float      heightScale = magnitude / 2;
                        GameObject visObject   = GameObject.Instantiate(prefab, new Vector3(0, 0, 0), q);
                        visObject.transform.localScale = new Vector3(prefabScale, prefabScale, heightScale * prefabScale);
                        visObject.transform.parent     = jointObj.transform;
                    }
                }
            }

            jointObj.transform.parent        = parent.transform;
            jointObj.name                    = name;
            jointObj.transform.localPosition = new Vector3(jointDesc.offset[0] * scale, jointDesc.offset[1] * scale, jointDesc.offset[2] * scale);
            if (jointObj != null)
            {
                transform = jointObj.transform;

                foreach (string name in jointDesc.children)
                {
                    JointDesc childDesc = findJointDesc(skeletonDesc.jointDescs, name);
                    if (childDesc == null)
                    {
                        continue;
                    }

                    MGJoint childJoint = new MGJoint();
                    childJoint.createGameObjectfromDesc(childDesc, skeletonDesc, jointObj, skeletonJointTag, prefab, scale);
                    children.Add(childJoint);
                }
            }
            return(jointObj);
        }
示例#3
0
        public GameObject createDebugSkeleton(SkeletonDesc skeletonDesc)
        {
            JointDesc jointDesc = skeletonDesc.jointDescs[0];
            var       root      = new MGJoint();

            GameObject skeleton = root.createGameObjectfromDesc(jointDesc, skeletonDesc, gameObject, skeletonJointTag, jointPrefab, scale);
            string     name     = skeletonDesc.name;

            rootJoints[name] = root;
            return(skeleton);
        }