예제 #1
0
        private void LoadChannel(glTFLoader.Schema.AnimationChannel channel, glTFLoader.Schema.AnimationSampler[] samplers, AnimationClip clip)
        {
            var target       = channel.Target;
            var node         = data.cache.nodes[target.Node.Value];
            var relativePath = GetNodeRelativePath(node.transform, root.transform);

            var sampler = samplers[channel.Sampler];
            var input   = accessorLoader.LoadAccessor(sampler.Input);
            var output  = accessorLoader.LoadAccessor(sampler.Output);

            switch (target.Path)
            {
            case glTFLoader.Schema.AnimationChannelTarget.PathEnum.translation:
                LoadTranslation(input, output, clip, relativePath);
                break;

            case glTFLoader.Schema.AnimationChannelTarget.PathEnum.rotation:
                LoadRotation(input, output, clip, relativePath);
                break;

            case glTFLoader.Schema.AnimationChannelTarget.PathEnum.scale:
                LoadScale(input, output, clip, relativePath);
                break;

            case glTFLoader.Schema.AnimationChannelTarget.PathEnum.weights:
                LoadWeights(input, output, clip, relativePath);
                break;

            default:
                break;
            }
        }
예제 #2
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;
            }
        }