Exemplo n.º 1
0
        public byte[] ToGlbBytes(SerializerTypes serializer = SerializerTypes.UniJSON)
        {
            string json;

            if (serializer == SerializerTypes.UniJSON)
            {
                var c = new JsonSchemaValidationContext(this)
                {
                    EnableDiagnosisForNotRequiredFields = true,
                };
                json = JsonSchema.FromType(GetType()).Serialize(this, c);
            }
            else if (serializer == SerializerTypes.Generated)
            {
                var f = new JsonFormatter();
                f.GenSerialize(this);
                json = f.ToString().ParseAsJson().ToString("  ");
            }
            else if (serializer == SerializerTypes.JsonSerializable)
            {
                // Obsolete
                json = ToJson();
            }
            else
            {
                throw new Exception("[UniVRM Export Error] unknown serializer type");
            }

            RemoveUnusedExtensions(json);

            return(Glb.ToBytes(json, buffers[0].GetBytes()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// for unit test
        ///
        /// parse exported value
        /// </summary>
        public override glTFExtensionImport Deserialize()
        {
            var f = new JsonFormatter();

            f.GenSerialize(this);
            var b    = f.GetStoreBytes();
            var json = Encoding.UTF8.GetString(b.Array, b.Offset, b.Count);

            return(new glTFExtensionImport(json.ParseAsJson()));
        }
Exemplo n.º 3
0
        public (string, List <glTFBuffer>) ToGltf(string gltfPath)
        {
            var f = new JsonFormatter();

            // fix buffer path
            if (buffers.Count == 1)
            {
                var withoutExt = Path.GetFileNameWithoutExtension(gltfPath);
                buffers[0].uri = $"{withoutExt}.bin";
            }
            else
            {
                throw new NotImplementedException();
            }

            f.GenSerialize(this);
            var json = f.ToString().ParseAsJson().ToString("  ");

            RemoveUnusedExtensions(json);
            return(json, buffers);
        }