예제 #1
0
        private Urho3DBone[] BuildBones(SkinnedMeshRenderer skinnedMeshRenderer)
        {
            if (skinnedMeshRenderer == null || skinnedMeshRenderer.bones.Length == 0)
            {
                return(new Urho3DBone[0]);
            }
            var unityBones = skinnedMeshRenderer.bones;
            var bones      = new Urho3DBone[unityBones.Length];

            for (var index = 0; index < bones.Length; index++)
            {
                var bone      = new Urho3DBone();
                var unityBone = unityBones[index];
                for (var pIndex = 0; pIndex < bones.Length; ++pIndex)
                {
                    if (unityBones[pIndex] == unityBone.parent)
                    {
                        bone.parent = pIndex;
                        break;
                    }
                }

                bone.name = unityBone.name ?? "bone" + index;
                //if (bone.parent != 0)
                //{
                bone.actualPos   = unityBone.localPosition;
                bone.actualRot   = unityBone.localRotation;
                bone.actualScale = unityBone.localScale;
                //}
                //else
                //{
                //    bone.actualPos = unityBone.position;
                //    bone.actualRot = unityBone.rotation;
                //    bone.actualScale = unityBone.lossyScale;
                //}

                bone.binding = skinnedMeshRenderer.sharedMesh.bindposes[index];
                bones[index] = bone;
            }

            return(bones);
        }
예제 #2
0
        private Urho3DBone[] BuildBones(IMeshSource skinnedMeshRenderer)
        {
            if (skinnedMeshRenderer == null || skinnedMeshRenderer.BonesCount == 0)
            {
                return(new Urho3DBone[0]);
            }
            //var unityBones = skinnedMeshRenderer.bones;
            var bones = new Urho3DBone[skinnedMeshRenderer.BonesCount];

            for (var index = 0; index < bones.Length; index++)
            {
                var bone        = new Urho3DBone();
                var unityBone   = skinnedMeshRenderer.GetBoneTransform(index);
                var parentIndex = skinnedMeshRenderer.GetBoneParent(index);
                if (parentIndex.HasValue)
                {
                    bone.parent = parentIndex.Value;
                }

                bone.name = unityBone.name ?? "bone" + index;
                //if (bone.parent != 0)
                //{
                bone.actualPos   = unityBone.localPosition;
                bone.actualRot   = unityBone.localRotation;
                bone.actualScale = unityBone.localScale;
                //}
                //else
                //{
                //    bone.actualPos = unityBone.position;
                //    bone.actualRot = unityBone.rotation;
                //    bone.actualScale = unityBone.lossyScale;
                //}

                bone.binding = skinnedMeshRenderer.GetBoneBindPose(index);
                bones[index] = bone;
            }

            return(bones);
        }