Beispiel #1
0
        public void Serialize(TextWriter textWriter, bool isGLB = false)
        {
            JsonWriter jsonWriter = new JsonTextWriter(textWriter);

            if (isGLB)
            {
                jsonWriter.Formatting = Formatting.None;
            }
            else
            {
                jsonWriter.Formatting = Formatting.Indented;
            }

            jsonWriter.WriteStartObject();

            if (ExtensionsUsed != null && ExtensionsUsed.Count > 0)
            {
                jsonWriter.WritePropertyName("extensionsUsed");
                jsonWriter.WriteStartArray();
                foreach (var extension in ExtensionsUsed)
                {
                    jsonWriter.WriteValue(extension);
                }
                jsonWriter.WriteEndArray();
            }

            if (ExtensionsRequired != null && ExtensionsRequired.Count > 0)
            {
                jsonWriter.WritePropertyName("extensionsRequired");
                jsonWriter.WriteStartArray();
                foreach (var extension in ExtensionsRequired)
                {
                    jsonWriter.WriteValue(extension);
                }
                jsonWriter.WriteEndArray();
            }

            if (Accessors != null && Accessors.Count > 0)
            {
                jsonWriter.WritePropertyName("accessors");
                jsonWriter.WriteStartArray();
                foreach (var accessor in Accessors)
                {
                    accessor.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Animations != null && Animations.Count > 0)
            {
                jsonWriter.WritePropertyName("animations");
                jsonWriter.WriteStartArray();
                foreach (var animation in Animations)
                {
                    animation.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            jsonWriter.WritePropertyName("asset");
            Asset.Serialize(jsonWriter);

            if (Buffers != null && Buffers.Count > 0)
            {
                jsonWriter.WritePropertyName("buffers");
                jsonWriter.WriteStartArray();
                foreach (var buffer in Buffers)
                {
                    buffer.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (BufferViews != null && BufferViews.Count > 0)
            {
                jsonWriter.WritePropertyName("bufferViews");
                jsonWriter.WriteStartArray();
                foreach (var bufferView in BufferViews)
                {
                    bufferView.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Cameras != null && Cameras.Count > 0)
            {
                jsonWriter.WritePropertyName("cameras");
                jsonWriter.WriteStartArray();
                foreach (var camera in Cameras)
                {
                    camera.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Images != null && Images.Count > 0)
            {
                jsonWriter.WritePropertyName("images");
                jsonWriter.WriteStartArray();
                foreach (var image in Images)
                {
                    image.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Materials != null && Materials.Count > 0)
            {
                jsonWriter.WritePropertyName("materials");
                jsonWriter.WriteStartArray();
                foreach (var material in Materials)
                {
                    material.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Meshes != null && Meshes.Count > 0)
            {
                jsonWriter.WritePropertyName("meshes");
                jsonWriter.WriteStartArray();
                foreach (var mesh in Meshes)
                {
                    mesh.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Nodes != null && Nodes.Count > 0)
            {
                jsonWriter.WritePropertyName("nodes");
                jsonWriter.WriteStartArray();
                foreach (var node in Nodes)
                {
                    node.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Samplers != null && Samplers.Count > 0)
            {
                jsonWriter.WritePropertyName("samplers");
                jsonWriter.WriteStartArray();
                foreach (var sampler in Samplers)
                {
                    sampler.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Scene != null)
            {
                jsonWriter.WritePropertyName("scene");
                Scene.Serialize(jsonWriter);
            }

            if (Scenes != null && Scenes.Count > 0)
            {
                jsonWriter.WritePropertyName("scenes");
                jsonWriter.WriteStartArray();
                foreach (var scene in Scenes)
                {
                    scene.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Skins != null && Skins.Count > 0)
            {
                jsonWriter.WritePropertyName("skins");
                jsonWriter.WriteStartArray();
                foreach (var skin in Skins)
                {
                    skin.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Textures != null && Textures.Count > 0)
            {
                jsonWriter.WritePropertyName("textures");
                jsonWriter.WriteStartArray();
                foreach (var texture in Textures)
                {
                    texture.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            base.Serialize(jsonWriter);

            jsonWriter.WriteEndObject();
        }
Beispiel #2
0
        public void Serialize(TextWriter textWriter, bool isGLB = false)
        {
            JsonWriter jsonWriter = new JsonTextWriter(textWriter);

            if (isGLB)
            {
                jsonWriter.Formatting = Formatting.None;
            }
            else
            {
                jsonWriter.Formatting = Formatting.Indented;
            }

            jsonWriter.WriteStartObject();

            if (ExtensionsUsed != null && ExtensionsUsed.Count > 0)
            {
                jsonWriter.WritePropertyName("extensionsUsed");
                jsonWriter.WriteStartArray();
                foreach (var extension in ExtensionsUsed)
                {
                    jsonWriter.WriteValue(extension);
                }
                jsonWriter.WriteEndArray();
            }

            if (ExtensionsRequired != null && ExtensionsRequired.Count > 0)
            {
                jsonWriter.WritePropertyName("extensionsRequired");
                jsonWriter.WriteStartArray();
                foreach (var extension in ExtensionsRequired)
                {
                    jsonWriter.WriteValue(extension);
                }
                jsonWriter.WriteEndArray();
            }

            if (Accessors != null && Accessors.Count > 0)
            {
                jsonWriter.WritePropertyName("accessors");
                jsonWriter.WriteStartArray();
                foreach (var accessor in Accessors)
                {
                    accessor.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Animations != null && Animations.Count > 0)
            {
                jsonWriter.WritePropertyName("animations");
                jsonWriter.WriteStartArray();
                foreach (var animation in Animations)
                {
                    animation.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            jsonWriter.WritePropertyName("asset");
            Asset.Serialize(jsonWriter);

            if (Buffers != null && Buffers.Count > 0)
            {
                jsonWriter.WritePropertyName("buffers");
                jsonWriter.WriteStartArray();
                foreach (var buffer in Buffers)
                {
                    buffer.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (BufferViews != null && BufferViews.Count > 0)
            {
                jsonWriter.WritePropertyName("bufferViews");
                jsonWriter.WriteStartArray();
                foreach (var bufferView in BufferViews)
                {
                    bufferView.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Cameras != null && Cameras.Count > 0)
            {
                jsonWriter.WritePropertyName("cameras");
                jsonWriter.WriteStartArray();
                foreach (var camera in Cameras)
                {
                    camera.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Images != null && Images.Count > 0)
            {
                jsonWriter.WritePropertyName("images");
                jsonWriter.WriteStartArray();
                foreach (var image in Images)
                {
                    image.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Materials != null && Materials.Count > 0)
            {
                jsonWriter.WritePropertyName("materials");
                jsonWriter.WriteStartArray();
                foreach (var material in Materials)
                {
                    material.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Meshes != null && Meshes.Count > 0)
            {
                jsonWriter.WritePropertyName("meshes");
                jsonWriter.WriteStartArray();
                foreach (var mesh in Meshes)
                {
                    mesh.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Nodes != null && Nodes.Count > 0)
            {
                jsonWriter.WritePropertyName("nodes");
                jsonWriter.WriteStartArray();
                foreach (var node in Nodes)
                {
                    node.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Samplers != null && Samplers.Count > 0)
            {
                jsonWriter.WritePropertyName("samplers");
                jsonWriter.WriteStartArray();
                foreach (var sampler in Samplers)
                {
                    sampler.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Scene != null)
            {
                jsonWriter.WritePropertyName("scene");
                Scene.Serialize(jsonWriter);
            }

            if (Scenes != null && Scenes.Count > 0)
            {
                jsonWriter.WritePropertyName("scenes");
                jsonWriter.WriteStartArray();
                foreach (var scene in Scenes)
                {
                    scene.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Skins != null && Skins.Count > 0)
            {
                jsonWriter.WritePropertyName("skins");
                jsonWriter.WriteStartArray();
                foreach (var skin in Skins)
                {
                    skin.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Textures != null && Textures.Count > 0)
            {
                jsonWriter.WritePropertyName("textures");
                jsonWriter.WriteStartArray();
                foreach (var texture in Textures)
                {
                    texture.Serialize(jsonWriter);
                }
                jsonWriter.WriteEndArray();
            }

            if (Lights != null)
            {
                //TODO this is a terrible hack. should use proper extensions object to add light data array

                //Extensionszzz.Serialize(jsonWriter, Lights);

                //jsonWriter.WriteRaw(",\"extensions\":{\"KHR_lights_punctual\":{");
                //
                jsonWriter.WritePropertyName("extensions");
                jsonWriter.WriteStartObject();
                jsonWriter.WritePropertyName("KHR_lights_punctual");
                jsonWriter.WriteStartObject();
                jsonWriter.WritePropertyName("lights");
                jsonWriter.WriteStartArray();
                foreach (var light in Lights)
                {
                    light.Serialize(jsonWriter);
                    ////	jsonWriter.WriteRaw(",");
                }
                jsonWriter.WriteEndArray();
                jsonWriter.WriteEndObject();
                jsonWriter.WriteEndObject();
                //
                //jsonWriter.WriteRaw("}}");
            }



            base.Serialize(jsonWriter);

            jsonWriter.WriteEndObject();
        }