public static GLTFAnimationChannelTarget Deserialize(GLTFRoot root, JsonReader reader)
        {
            var animationChannelTarget = new GLTFAnimationChannelTarget();

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

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

                switch (curProp)
                {
                case "node":
                    animationChannelTarget.Node = GLTFNodeId.Deserialize(root, reader);
                    break;

                case "path":
                    animationChannelTarget.Path = reader.ReadStringEnum <GLTFAnimationChannelPath>();
                    break;

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

            return(animationChannelTarget);
        }
Example #2
0
        public static GLTFSkin Deserialize(GLTFRoot root, JsonReader reader)
        {
            var skin = new GLTFSkin();

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

                switch (curProp)
                {
                case "inverseBindMatrices":
                    skin.InverseBindMatrices = GLTFAccessorId.Deserialize(root, reader);
                    break;

                case "skeleton":
                    skin.Skeleton = GLTFNodeId.Deserialize(root, reader);
                    break;

                case "joints":
                    skin.Joints = reader.ReadList(() => GLTFNodeId.Deserialize(root, reader));
                    break;

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

            return(skin);
        }
Example #3
0
        public static GLTFScene Deserialize(GLTFRoot root, JsonReader reader)
        {
            var scene = new GLTFScene();

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

                switch (curProp)
                {
                case "nodes":
                    scene.Nodes = GLTFNodeId.ReadList(root, reader);
                    break;

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

            return(scene);
        }
Example #4
0
        public static List <GLTFNodeId> ReadList(GLTFRoot root, JsonReader reader)
        {
            if (reader.Read() && reader.TokenType != JsonToken.StartArray)
            {
                throw new Exception("Invalid array.");
            }

            var list = new List <GLTFNodeId>();

            while (reader.Read() && reader.TokenType != JsonToken.EndArray)
            {
                var node = new GLTFNodeId
                {
                    Id   = int.Parse(reader.Value.ToString()),
                    Root = root
                };

                list.Add(node);
            }

            return(list);
        }
Example #5
0
        public static GLTFNode Deserialize(GLTFRoot root, JsonReader reader)
        {
            var node = new GLTFNode();

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

                switch (curProp)
                {
                case "camera":
                    node.Camera = GLTFCameraId.Deserialize(root, reader);
                    break;

                case "children":
                    node.Children = GLTFNodeId.ReadList(root, reader);
                    break;

                case "skin":
                    node.Skin = GLTFSkinId.Deserialize(root, reader);
                    break;

                case "matrix":
                    var list = reader.ReadDoubleList();
                    var mat  = new Matrix4x4();
                    for (var i = 0; i < 16; i++)
                    {
                        mat[i] = (float)list[i];
                    }
                    node.Matrix = mat;
                    break;

                case "mesh":
                    node.Mesh = GLTFMeshId.Deserialize(root, reader);
                    break;

                case "rotation":
                    node._useTRS  = true;
                    node.Rotation = reader.ReadAsQuaternion();
                    break;

                case "scale":
                    node._useTRS = true;
                    node.Scale   = reader.ReadAsVector3();
                    break;

                case "translation":
                    node._useTRS     = true;
                    node.Translation = reader.ReadAsVector3();
                    break;

                case "weights":
                    node.Weights = reader.ReadDoubleList();
                    break;

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

            return(node);
        }