Пример #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()));
        }
Пример #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()));
        }
Пример #3
0
        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()));
        }
Пример #4
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));
        }
Пример #5
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));
        }
Пример #6
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()));
        }