Beispiel #1
0
        public byte[] ToGlbBytes(SerializerTypes serializer = SerializerTypes.Generated)
        {
            string json;

            if (serializer == SerializerTypes.UniJSON)
            {
                // Obsolete
                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()));
        }
Beispiel #2
0
        public static byte[] ToGlbBytes(this glTF self)
        {
            var f = new JsonFormatter();

            GltfSerializer.Serialize(f, self);

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

            self.RemoveUnusedExtensions(json);

            return(Glb.ToBytes(json, self.buffers[0].GetBytes()));
        }
Beispiel #3
0
        /// <summary>
        /// GLBバイト列
        /// </summary>
        /// <returns></returns>
        public byte[] ToGlbBytes()
        {
            var f = new JsonFormatter();

            GltfSerializer.Serialize(f, Gltf);

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

            json = GltfJsonUtil.FindUsedExtensionsAndUpdateJson(json);

            return(Glb.Create(json, BinBytes).ToBytes());
        }
Beispiel #4
0
        /// <summary>
        /// GLBバイト列
        /// </summary>
        /// <returns></returns>
        public byte[] ToGlbBytes()
        {
            var f = new JsonFormatter();

            GltfSerializer.Serialize(f, GLTF);

            // remove unused extenions
            var json = f.ToString().ParseAsJson().ToString("  ");

            RemoveUnusedExtensions(GLTF, json);
            return(Glb.Create(json, BinBytes).ToBytes());
        }
        public byte[] ToGlbBytes(bool UseUniJSONSerializer = false)
        {
            string json;

            if (UseUniJSONSerializer)
            {
                json = JsonSchema.FromType(GetType()).Serialize(this);
            }
            else
            {
                json = ToJson();
            }

            RemoveUnusedExtensions(json);

            return(Glb.ToBytes(json, buffers[0].GetBytes()));
        }
Beispiel #6
0
        public byte[] ToGlbBytes(ArraySegment <Byte> bytes, bool UseUniJSONSerializer = false)
        {
            string json;

            if (UseUniJSONSerializer)
            {
                json = JsonSchema.FromType(GetType()).Serialize(this);
            }
            else
            {
                json = ToJson();
            }

            RemoveUnusedExtensions(json);

            return(Glb.ToBytes(json, bytes));
        }
Beispiel #7
0
        public byte[] ToGlbBytes(ArraySegment <Byte> bytes, bool UseUniJSONSerializer = false)
        {
            string json;

            if (UseUniJSONSerializer)
            {
                var f = new JsonFormatter();
                f.Serialize(this);
                json = Encoding.UTF8.GetString(f.GetStoreBytes().ToArray());
            }
            else
            {
                json = ToJson();
            }

            RemoveUnusedExtensions(json);

            return(Glb.ToBytes(json, bytes));
        }
Beispiel #8
0
        public byte[] ToGlbBytes(bool UseUniJSONSerializer = false)
        {
            string json;

            if (UseUniJSONSerializer)
            {
                var c = new JsonSchemaValidationContext(this)
                {
                    EnableDiagnosisForNotRequiredFields = true,
                };
                json = JsonSchema.FromType(GetType()).Serialize(this, c);
            }
            else
            {
                json = ToJson();
            }

            RemoveUnusedExtensions(json);

            return(Glb.ToBytes(json, buffers[0].GetBytes()));
        }