Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }