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

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

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

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

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

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

            return(skin);
        }
Ejemplo n.º 2
0
        public static Scene Deserialize(GLTFRoot root, JsonReader reader)
        {
            var scene = new Scene();

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

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

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

            return(scene);
        }
Ejemplo n.º 3
0
        public static Node Deserialize(GLTFRoot root, JsonReader reader)
        {
            var node = new Node();

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

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

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

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

                case "matrix":
                    var list = reader.ReadDoubleList();
                    // gltf has column ordered matricies
                    UnityEngine.Vector4 c1 = new UnityEngine.Vector4((float)list[0], (float)list[1], (float)list[2], (float)list[3]);
                    UnityEngine.Vector4 c2 = new UnityEngine.Vector4((float)list[4], (float)list[5], (float)list[6], (float)list[7]);
                    UnityEngine.Vector4 c3 = new UnityEngine.Vector4((float)list[8], (float)list[9], (float)list[10], (float)list[11]);
                    UnityEngine.Vector4 c4 = new UnityEngine.Vector4((float)list[12], (float)list[13], (float)list[14], (float)list[15]);

                    var mat = new Matrix4x4(c1, c2, c3, c4);

                    node.Matrix = mat;
                    break;

                case "mesh":
                    node.Mesh = MeshId.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);
        }