Пример #1
0
        public static GLTFCamera Deserialize(GLTFRoot root, JsonReader reader)
        {
            var camera = new GLTFCamera();

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

                switch (curProp)
                {
                case "orthographic":
                    camera.Orthographic = GLTFCameraOrthographic.Deserialize(root, reader);
                    break;

                case "perspective":
                    camera.Perspective = GLTFCameraPerspective.Deserialize(root, reader);
                    break;

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

            return(camera);
        }
        public static GLTFCameraPerspective Deserialize(GLTFRoot root, JsonReader reader)
        {
            var cameraPerspective = new GLTFCameraPerspective();

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

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

                switch (curProp)
                {
                case "aspectRatio":
                    cameraPerspective.AspectRatio = reader.ReadAsDouble().Value;
                    break;

                case "yfov":
                    cameraPerspective.YFov = reader.ReadAsDouble().Value;
                    break;

                case "zfar":
                    cameraPerspective.ZFar = reader.ReadAsDouble().Value;
                    break;

                case "znear":
                    cameraPerspective.ZNear = reader.ReadAsDouble().Value;
                    break;

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

            return(cameraPerspective);
        }