using System.Collections.Generic; using System.IO; using System.Linq; namespace IDTF.Net { /// /// The Scene is the root node in the IDTF file, all objects should be aded to the scene, /// and then the scene is exported to a file /// public class IDTFScene { private List _views; /// /// A list of the View nodes in the scene /// public List Views { get { if (_views == null) { _views = new List(); } return _views; } set { _views = value; } } private List _models; /// /// A list of the Model nodes in this scene /// public List Models { get { if (_models == null) { _models = new List(); } return _models; } set { _models = value; } } private List _groups; /// /// A list of the group nodes in this scene /// public List Groups { get { if (_groups == null) { _groups = new List(); } return _groups; } set { _groups = value; } } private List _lights; /// /// A list of lights in this scene /// public List Lights { get { if (_lights == null) { _lights = new List(); } return _lights; } set { _lights = value; } } private Dictionary _lightResources; public Dictionary LightResources { get { if (_lightResources == null) { _lightResources = new Dictionary(); } return _lightResources; } set { _lightResources = value; } } private Dictionary _modelResources; public Dictionary ModelResources { get { if (_modelResources == null) { _modelResources = new Dictionary(); } return _modelResources; } set { _modelResources = value; } } private Dictionary _viewResources; public Dictionary ViewResources { get { if (_viewResources == null) { _viewResources = new Dictionary(); } return _viewResources; } set { _viewResources = value; } } private Dictionary _shaderResources; public Dictionary ShaderResources { get { if (_shaderResources == null) { _shaderResources = new Dictionary(); } return _shaderResources; } set { _shaderResources = value; } } private Dictionary _materialResources; public Dictionary MaterialResources { get { if (_materialResources == null) { _materialResources = new Dictionary(); } return _materialResources; } set { _materialResources = value; } } private Dictionary _textureResources; public Dictionary TextureResources { get { if (_textureResources == null) { _textureResources = new Dictionary(); } return _textureResources; } set { _textureResources = value; } } private Dictionary _motionResources; public Dictionary MotionResources { get { if (_motionResources == null) { _motionResources = new Dictionary(); } return _motionResources; } set { _motionResources = value; } } private List _shadingModifiers; public List ShadingModifiers { get { if (_shadingModifiers == null) { _shadingModifiers = new List(); } return _shadingModifiers; } set { _shadingModifiers = value; } } public bool Export(string toFile) { // The IDTF file contains the following text blocks written in this order // // // // // // // // // // using (var output = new StreamWriter(toFile)) { // output.WriteLine("FILE_FORMAT \"IDTF\""); output.WriteLine("FORMAT_VERSION 100"); output.WriteLine(); // // // NOT YET IMPLEMENTED // - groups foreach (Group g in this.Groups) { g.WriteOutput(output); } // - Views foreach (View v in this.Views) { v.WriteOutput(output); } // - Models foreach (Model m in this.Models) { m.WriteOutput(output); } // - Light if (this.LightResources.Count() > 0) { output.WriteLine("RESOURCE_LIST \"LIGHT\" {"); output.WriteLine("\tRESOURCE_COUNT {0}", this.LightResources.Count().ToString()); for (int i = 0; i < this.LightResources.Count(); i++) { output.WriteLine("\tRESOURCE {0} {{", i.ToString()); this.LightResources.ElementAt(i).Value.Export(output); output.WriteLine("\t}"); } output.WriteLine("}"); output.WriteLine(); } // - Shader if (this.ShaderResources.Count() > 0) { output.WriteLine("RESOURCE_LIST \"SHADER\" {"); output.WriteLine("\tRESOURCE_COUNT {0}", this.ShaderResources.Count().ToString()); for (int i = 0; i < this.ShaderResources.Count(); i++) { output.WriteLine("\tRESOURCE {0} {{", i.ToString()); this.ShaderResources.ElementAt(i).Value.Export(output); output.WriteLine("\t}"); } output.WriteLine("}"); output.WriteLine(); } // - Material if (this.MaterialResources.Count() > 0) { output.WriteLine("RESOURCE_LIST \"MATERIAL\" {"); output.WriteLine("\tRESOURCE_COUNT {0}", this.MaterialResources.Count().ToString()); for (int i = 0; i < this.MaterialResources.Count(); i++) { output.WriteLine("\tRESOURCE {0} {{", i.ToString()); this.MaterialResources.ElementAt(i).Value.Export(output); output.WriteLine("\t}"); } output.WriteLine("}"); output.WriteLine(); } // - Texture if (this.TextureResources.Count() > 0) { output.WriteLine("RESOURCE_LIST \"TEXTURE\" {"); output.WriteLine("\tRESOURCE_COUNT {0}", this.TextureResources.Count().ToString()); for (int i = 0; i < this.TextureResources.Count(); i++) { output.WriteLine("\tRESOURCE {0} {{", i.ToString()); this.TextureResources.ElementAt(i).Value.Export(output); output.WriteLine("\t}"); } output.WriteLine("}"); output.WriteLine(); } // - Model if (this.ModelResources.Count() > 0) { output.WriteLine("RESOURCE_LIST \"MODEL\" {"); output.WriteLine("\tRESOURCE_COUNT {0}", this.ModelResources.Count().ToString()); for (int i = 0; i < this.ModelResources.Count(); i++) { output.WriteLine("\tRESOURCE {0} {{", i.ToString()); this.ModelResources.ElementAt(i).Value.Export(output); output.WriteLine("\t}"); } output.WriteLine("}"); output.WriteLine(); } // - Shading foreach (ShadingModifier s in this.ShadingModifiers) { s.Export(output); } output.Flush(); output.Close(); } return false; } } }