Пример #1
0
        private void LoadRotation(Array input, Array output, AnimationClip clip, string relativePath)
        {
            var curveX = new AnimationCurve();
            var curveY = new AnimationCurve();
            var curveZ = new AnimationCurve();
            var curveW = new AnimationCurve();

            var times     = (float[])input;
            var rotations = (Vector4[])output;

            CoordinateSystemConverter.Convert(rotations);

            for (int i = 0; i < times.Length; i++)
            {
                var time     = times[i];
                var rotation = rotations[i];

                curveX.AddKey(time, rotation.x);
                curveY.AddKey(time, rotation.y);
                curveZ.AddKey(time, rotation.z);
                curveW.AddKey(time, rotation.w);
            }

            clip.SetCurve(relativePath, typeof(Transform), "localRotation.x", curveX);
            clip.SetCurve(relativePath, typeof(Transform), "localRotation.y", curveY);
            clip.SetCurve(relativePath, typeof(Transform), "localRotation.z", curveZ);
            clip.SetCurve(relativePath, typeof(Transform), "localRotation.w", curveW);
        }
Пример #2
0
		public static Matrix4x4 ConvertMatrix4x4(float[] arr, bool convertCoordinateSystem = true)
		{
			var mat = new Matrix4x4();
			for (int i = 0; i < arr.Length; i++)
				mat[i] = arr[i];

			if (convertCoordinateSystem)
				CoordinateSystemConverter.Convert(ref mat);

			return mat;
		}
Пример #3
0
		public static Quaternion ConvertQuaternion(float[] arr, bool convertCoordinateSystem = true)
		{
			var quat = new Quaternion();
			for (int i = 0; i < arr.Length; i++)
				quat[i] = arr[i];

			if (convertCoordinateSystem)
				CoordinateSystemConverter.Convert(ref quat);

			return quat;
		}
Пример #4
0
		public static Vector4 ConvertVector4(float[] arr, bool convertCoordinateSystem = true)
		{
			var vec = new Vector4();
			for (int i = 0; i < arr.Length; i++)
				vec[i] = arr[i];

			if (convertCoordinateSystem)
				CoordinateSystemConverter.Convert(ref vec);

			return vec;
		}
Пример #5
0
        public static Vector3 ConvertVector3(float[] arr, bool convertCoordinateSystem = true)
        {
            var vec = new Vector3();

            for (int i = 0; i < arr.Length; i++)
            {
                vec[i] = arr[i];
            }

            if (convertCoordinateSystem)
            {
                CoordinateSystemConverter.Convert(ref vec);
            }

            return(vec);
        }
Пример #6
0
        private void LoadBones(glTFLoader.Schema.Skin skin, SkinnedMeshRenderer renderer, Mesh unityMesh)
        {
            var inverseBindMatrices = (Matrix4x4[])accessorLoader.LoadAccessor(skin.InverseBindMatrices.Value);

            CoordinateSystemConverter.Convert(inverseBindMatrices);

            var boneCount = skin.Joints.Length;
            var bones     = new Transform[boneCount];
            var bindPoses = new Matrix4x4[boneCount];

            for (int i = 0; i < boneCount; i++)
            {
                bones[i]     = data.cache.nodes[skin.Joints[i]].transform;
                bindPoses[i] = inverseBindMatrices[i];
            }

            renderer.rootBone   = data.cache.nodes[skin.Skeleton.Value].transform;
            renderer.bones      = bones;
            unityMesh.bindposes = bindPoses;
        }
Пример #7
0
        private void LoadMeshAttribute(GltfMesh mesh, string attributeName, int accessorIndex)
        {
            var arr = accessorLoader.LoadAccessor(accessorIndex);

            switch (attributeName)
            {
            case "POSITION":
            {
                var vertices = (Vector3[])arr;
                CoordinateSystemConverter.Convert(vertices);
                mesh.vertices = vertices;
                break;
            }

            case "NORMAL":
            {
                var normals = (Vector3[])arr;
                CoordinateSystemConverter.Convert(normals);
                mesh.normals = normals;
                break;
            }

            case "TANGENT":
            {
                var tangents = (Vector4[])arr;
                CoordinateSystemConverter.Convert(tangents);
                mesh.tangents = tangents;
                break;
            }

            case "TEXCOORD_0":
            {
                var texCoords = (Vector2[])arr;
                CoordinateSystemConverter.FlipTexCoords(texCoords);
                mesh.texCoords = texCoords;
                break;
            }

            case "COLOR_0":
            {
                var colors = (Vector4[])arr;
                mesh.colors = TypeConverter.ConvertColors(colors);
                break;
            }

            case "INDEX":
            {
                var indices = new int[arr.Length];
                for (int i = 0; i < arr.Length; i++)
                {
                    indices[i] = Convert.ToInt32(arr.GetValue(i));
                }

                CoordinateSystemConverter.FlipIndices(indices);
                mesh.indices = indices;
                break;
            }

            case "JOINTS_0":
                mesh.joints = (Vector4[])arr;
                break;

            case "WEIGHTS_0":
                mesh.weights = (Vector4[])arr;
                break;

            default:
                Debug.LogWarning($"Invalid accessor name ({attributeName})");
                break;
            }
        }