Exemplo n.º 1
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            if (!String.IsNullOrEmpty(name))
            {
                f.Key("name"); f.Value(name);
            }
            if (pbrMetallicRoughness != null)
            {
                f.Key("pbrMetallicRoughness"); f.Value(pbrMetallicRoughness);
            }
            if (normalTexture != null)
            {
                f.Key("normalTexture"); f.Value(normalTexture);
            }
            if (occlusionTexture != null)
            {
                f.Key("occlusionTexture"); f.Value(occlusionTexture);
            }
            if (emissiveTexture != null)
            {
                f.Key("emissiveTexture"); f.Value(emissiveTexture);
            }
            if (emissiveFactor != null)
            {
                f.Key("emissiveFactor"); f.Value(emissiveFactor);
            }
            f.EndMap();
            return(f.ToString());
        }
        public static string ToJson(this glTFAttributes self)
        {
            var f = new JsonFormatter();

            GltfSerializer.Serialize_gltf_meshes__primitives__attributes(f, self);
            return(f.ToString());
        }
        public static string ToJson(this glTF self)
        {
            var f = new JsonFormatter();

            GltfSerializer.Serialize(f, self);
            return(f.ToString());
        }
        public static string ToJson(this glTFMaterialBaseColorTextureInfo self)
        {
            var f = new JsonFormatter();

            GltfSerializer.Serialize_gltf_materials__pbrMetallicRoughness_baseColorTexture(f, self);
            return(f.ToString());
        }
        public static string ToJson(this glTFSkin self)
        {
            var f = new JsonFormatter();

            GltfSerializer.Serialize_gltf_skins_ITEM(f, self);
            return(f.ToString());
        }
Exemplo n.º 6
0
        static string RemoveUnusedExtensions(this glTF self, string json)
        {
            var f = new JsonFormatter();

            self.Traverse(JsonParser.Parse(json), f, default(Utf8String));
            return(f.ToString());
        }
Exemplo n.º 7
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.º 8
0
        string RemoveUnusedExtensions(string json)
        {
            var f = new JsonFormatter();

            Traverse(JsonParser.Parse(json), f, default(Utf8String));

            return(f.ToString());
        }
Exemplo n.º 9
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            f.KeyValue(() => name);
            f.Key("primitives"); f.Value(primitives);
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 10
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            f.KeyValue(() => sampler);
            f.KeyValue(() => source);
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 11
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            f.Key("generator"); f.Value(generator);
            f.Key("version"); f.Value(version);
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 12
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            f.KeyValue(() => inverseBindMatrices);
            f.KeyValue(() => joints);
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 13
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();

            SerializeMembers(f);

            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 14
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()));
        }
Exemplo n.º 15
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();

            f.KeyValue(() => node);
            f.KeyValue(() => path);

            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 16
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            f.Key("index"); f.Value(index);
            f.Key("texCoord"); f.Value(texCoord);
            //f.Key("scale"); f.Value(scale);
            //f.Key("strength"); f.Value(strength);
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 17
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            f.Key("magFilter"); f.Value((int)magFilter);
            f.Key("minFilter"); f.Value((int)minFilter);
            f.Key("wrapS"); f.Value((int)wrapS);
            f.Key("wrapT"); f.Value((int)wrapT);
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 18
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());
        }
Exemplo n.º 19
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());
        }
Exemplo n.º 20
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            if (!string.IsNullOrEmpty(uri))
            {
                f.KeyValue(() => uri);
            }
            f.KeyValue(() => byteLength);
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 21
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();

            f.KeyValue(() => input);
            f.KeyValue(() => interpolation);
            f.KeyValue(() => output);

            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 22
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            if (!string.IsNullOrEmpty(name))
            {
                f.KeyValue(() => name);
            }
            if (children != null && children.Any())
            {
                f.Key("children"); f.BeginList();
                foreach (var child in children)
                {
                    f.Value(child);
                }
                f.EndList();
            }
            if (matrix != null)
            {
                f.KeyValue(() => matrix);
            }
            if (translation != null)
            {
                f.KeyValue(() => translation);
            }
            if (rotation != null)
            {
                f.KeyValue(() => rotation);
            }
            if (scale != null)
            {
                f.KeyValue(() => scale);
            }

            if (mesh >= 0)
            {
                f.KeyValue(() => mesh);
            }
            if (skin >= 0)
            {
                f.KeyValue(() => skin);
            }
            if (camera >= 0)
            {
                f.KeyValue(() => camera);
            }
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 23
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            f.KeyValue(() => mode);
            f.KeyValue(() => indices);
            f.Key("attributes"); f.Value(attributes);
            f.KeyValue(() => material);
            if (targets != null)
            {
                f.Key("targets"); f.Value(targets);
            }
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 24
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            if (!string.IsNullOrEmpty(uri))
            {
                f.KeyValue(() => uri);
            }
            else
            {
                f.KeyValue(() => bufferView);
                f.KeyValue(() => mimeType);
            }
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 25
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            f.KeyValue(() => buffer);
            f.KeyValue(() => byteOffset);
            f.KeyValue(() => byteLength);
            if (target != glBufferTarget.NONE)
            {
                f.Key("target"); f.Value((int)target);
            }
            if (target == glBufferTarget.ARRAY_BUFFER)
            {
                f.KeyValue(() => byteStride);
            }
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 26
0
        /// <summary>
        /// glTF 形式で出力する?
        /// </summary>
        /// <param name="gltfPath"></param>
        /// <returns></returns>
        public (string, glTFBuffer) ToGltf(string gltfPath)
        {
            // fix buffer path
            if (GLTF.buffers.Count == 1)
            {
                var withoutExt = Path.GetFileNameWithoutExtension(gltfPath);
                GLTF.buffers[0].uri = $"{withoutExt}.bin";
            }
            else
            {
                throw new NotImplementedException();
            }

            var f = new JsonFormatter();

            GltfSerializer.Serialize(f, GLTF);
            var json = f.ToString().ParseAsJson().ToString("  ");

            RemoveUnusedExtensions(GLTF, json);
            return(json, GLTF.buffers[0]);
        }
Exemplo n.º 27
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            f.KeyValue(() => bufferView);
            f.KeyValue(() => byteOffset);
            f.KeyValue(() => type);
            f.Key("componentType"); f.Value((int)componentType);
            f.KeyValue(() => count);
            if (max != null && max.Any())
            {
                f.KeyValue(() => max);
            }
            if (min != null && min.Any())
            {
                f.KeyValue(() => min);
            }
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 28
0
        public static (string, List <glTFBuffer>) ToGltf(this glTF self, string gltfPath)
        {
            var f = new JsonFormatter();

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

            GltfSerializer.Serialize(f, self);
            var json = f.ToString().ParseAsJson().ToString("  ");

            self.RemoveUnusedExtensions(json);
            return(json, self.buffers);
        }
Exemplo n.º 29
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            if (baseColorTexture != null)
            {
                f.KeyValue(() => baseColorTexture);
            }
            if (baseColorFactor != null)
            {
                f.KeyValue(() => baseColorFactor);
            }
            if (metallicRoughnessTexture != null)
            {
                f.KeyValue(() => metallicRoughnessTexture);
            }
            f.KeyValue(() => metallicFactor);
            f.KeyValue(() => roughnessFactor);
            f.EndMap();
            return(f.ToString());
        }
Exemplo n.º 30
0
        public string ToJson()
        {
            var f = new JsonFormatter();

            f.BeginMap();
            if (POSITION >= 0)
            {
                f.KeyValue(() => POSITION);
            }
            if (NORMAL >= 0)
            {
                f.KeyValue(() => NORMAL);
            }
            if (TANGENT >= 0)
            {
                f.KeyValue(() => TANGENT);
            }
            if (TEXCOORD_0 >= 0)
            {
                f.KeyValue(() => TEXCOORD_0);
            }
            if (JOINTS_0 >= 0)
            {
                f.KeyValue(() => JOINTS_0);
            }
            if (WEIGHTS_0 >= 0)
            {
                f.KeyValue(() => WEIGHTS_0);
            }
            if (COLOR_0 >= 0)
            {
                f.KeyValue(() => COLOR_0);
            }
            f.EndMap();
            return(f.ToString());
        }