Ejemplo n.º 1
0
        public static GLTFAnimation Deserialize(GLTFRoot root, JsonReader reader)
        {
            var animation = new GLTFAnimation();

            while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
            {
                var curProp = reader.Value.ToString();

                switch (curProp)
                {
                case "channels":
                    animation.Channels = reader.ReadList(() => AnimationChannel.Deserialize(root, reader));
                    break;

                case "samplers":
                    animation.Samplers = reader.ReadList(() => AnimationSampler.Deserialize(root, reader));
                    break;

                default:
                    animation.DefaultPropertyDeserializer(root, reader);
                    break;
                }
            }

            return(animation);
        }
Ejemplo n.º 2
0
        private static void MergeAnimationsAndSkins(GLTFRoot mergeToRoot, GLTFRoot mergeFromRoot, PreviousGLTFSizes previousGLTFSizes)
        {
            if (mergeFromRoot.Skins != null)
            {
                if (mergeToRoot.Skins == null)
                {
                    mergeToRoot.Skins = new List <Skin>(mergeFromRoot.Skins.Count);
                }

                mergeToRoot.Skins.AddRange(mergeFromRoot.Skins);
                for (int i = previousGLTFSizes.PreviousSkinCount; i < mergeToRoot.Skins.Count; ++i)
                {
                    Skin skin = mergeToRoot.Skins[i];
                    if (skin.InverseBindMatrices != null)
                    {
                        skin.InverseBindMatrices.Id += previousGLTFSizes.PreviousAccessorCount;
                    }

                    if (skin.Skeleton != null)
                    {
                        skin.Skeleton.Id += previousGLTFSizes.PreviousNodeCount;
                    }

                    if (skin.Joints != null)
                    {
                        foreach (NodeId joint in skin.Joints)
                        {
                            joint.Id += previousGLTFSizes.PreviousNodeCount;
                        }
                    }
                }
            }

            if (mergeFromRoot.Animations != null)
            {
                if (mergeToRoot.Animations == null)
                {
                    mergeToRoot.Animations = new List <GLTFAnimation>(mergeFromRoot.Animations.Count);
                }

                mergeToRoot.Animations.AddRange(mergeFromRoot.Animations);

                for (int i = previousGLTFSizes.PreviousAnimationCount; i < mergeToRoot.Animations.Count; ++i)
                {
                    GLTFAnimation animation = mergeToRoot.Animations[i];
                    foreach (AnimationSampler sampler in animation.Samplers)
                    {
                        AccessorId inputId = sampler.Input;
                        inputId.Id  += previousGLTFSizes.PreviousAccessorCount;
                        inputId.Root = mergeToRoot;

                        AccessorId outputId = sampler.Output;
                        outputId.Id  += previousGLTFSizes.PreviousAccessorCount;
                        outputId.Root = mergeToRoot;
                    }

                    foreach (AnimationChannel channel in animation.Channels)
                    {
                        SamplerId samplerId = channel.Sampler;
                        samplerId.Id  += previousGLTFSizes.PreviousSamplerCount;
                        samplerId.Root = mergeToRoot;

                        NodeId nodeId = channel.Target.Node;
                        nodeId.Id  += previousGLTFSizes.PreviousNodeCount;
                        nodeId.Root = mergeToRoot;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static GLTFRoot Deserialize(JsonReader reader)
        {
            var root = new GLTFRoot();

            if (reader.Read() && reader.TokenType != JsonToken.StartObject)
            {
                throw new Exception("glTF JSON must be an object");
            }

            while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
            {
                var curProp = reader.Value.ToString();

                switch (curProp)
                {
                case "extensionsUsed":
                    root.ExtensionsUsed = reader.ReadStringList();
                    break;

                case "extensionsRequired":
                    root.ExtensionsRequired = reader.ReadStringList();
                    break;

                case "accessors":
                    root.Accessors = reader.ReadList(() => Accessor.Deserialize(root, reader));
                    break;

                case "animations":
                    root.Animations = reader.ReadList(() => GLTFAnimation.Deserialize(root, reader));
                    break;

                case "asset":
                    root.Asset = Asset.Deserialize(root, reader);
                    break;

                case "buffers":
                    root.Buffers = reader.ReadList(() => Buffer.Deserialize(root, reader));
                    break;

                case "bufferViews":
                    root.BufferViews = reader.ReadList(() => BufferView.Deserialize(root, reader));
                    break;

                case "cameras":
                    root.Cameras = reader.ReadList(() => GLTFCamera.Deserialize(root, reader));
                    break;

                case "images":
                    root.Images = reader.ReadList(() => Image.Deserialize(root, reader));
                    break;

                case "materials":
                    root.Materials = reader.ReadList(() => Material.Deserialize(root, reader));
                    break;

                case "meshes":
                    root.Meshes = reader.ReadList(() => Mesh.Deserialize(root, reader));
                    break;

                case "nodes":
                    root.Nodes = reader.ReadList(() => Node.Deserialize(root, reader));
                    break;

                case "samplers":
                    root.Samplers = reader.ReadList(() => Sampler.Deserialize(root, reader));
                    break;

                case "scene":
                    root.Scene = SceneId.Deserialize(root, reader);
                    break;

                case "scenes":
                    root.Scenes = reader.ReadList(() => GLTF.Scene.Deserialize(root, reader));
                    break;

                case "skins":
                    root.Skins = reader.ReadList(() => Skin.Deserialize(root, reader));
                    break;

                case "textures":
                    root.Textures = reader.ReadList(() => Texture.Deserialize(root, reader));
                    break;

                default:
                    root.DefaultPropertyDeserializer(root, reader);
                    break;
                }
            }

            return(root);
        }