using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Drawing; namespace IDTF.Net { /* This file contains data descriptions for the resource_lists. */ internal interface IResourceData { void Export(StreamWriter toStream); } /* Resource data for the "MODEL RESOURCE_LIST" */ public class ShadingDescription { public ShadingDescription(int id = 0) { ShaderID = id; } public int ShaderID { get; set; } private List _textureCoordDimList; public List TextureCoordDimensionList { get { if (_textureCoordDimList == null) { _textureCoordDimList = new List(); } return _textureCoordDimList; } set { _textureCoordDimList = value; } } internal void Export(StreamWriter toStream) { toStream.WriteLine(string.Format("\t\t\t\t\tTEXTURE_LAYER_COUNT {0}", TextureCoordDimensionList.Count())); if (_textureCoordDimList != null) { ListExtensions.ExportTextureCoordListToStream(_textureCoordDimList, toStream); } toStream.WriteLine(string.Format("\t\t\t\t\tSHADER_ID {0}", ShaderID)); } } public class FaceTextureCoord { private List _textureCoordDimList; public List TextureCoordDimensionList { get { if (_textureCoordDimList == null) { _textureCoordDimList = new List(); } return _textureCoordDimList; } set { _textureCoordDimList = value; } } internal void Export(StreamWriter toStream) { if (_textureCoordDimList != null) { ListExtensions.ExportTextureCoordListToStream(_textureCoordDimList, toStream); } } } public class LineTextureCoord { private List _textureCoordDimList; public List TextureCoordDimensionList { get { if (_textureCoordDimList == null) { _textureCoordDimList = new List(); } return _textureCoordDimList; } set { _textureCoordDimList = value; } } internal void Export(StreamWriter toStream) { if (_textureCoordDimList != null) { ListExtensions.ExportTextureCoordListToStream(_textureCoordDimList, toStream); } } } public class MeshData { private List _shadingDescriptionList; private List _meshFacePositionList; private List _meshFaceNormalList; private List _meshFaceShadingList; private List _meshFaceTextureCoordinateList; private List _meshFaceDiffuseColorList; private List _meshFaceSpecularColorList; private List _modelPositionList; private List _modelNormalList; private List _modelDiffuseColorList; private List _modelSpecularColorList; private List _modelTextureCoordList; private List _meshBasePositionList; public List ShadingDescriptionList { get { if (_shadingDescriptionList == null) _shadingDescriptionList = new List(); return _shadingDescriptionList; } set { _shadingDescriptionList = value; } } public List MeshFacePositionList { get { if (_meshFacePositionList == null) _meshFacePositionList = new List(); return _meshFacePositionList; } set { _meshFacePositionList = value; } } public List MeshFaceNormalList { get { if (_meshFaceNormalList == null) _meshFaceNormalList = new List(); return _meshFaceNormalList; } set { _meshFaceNormalList = value; } } public List MeshFaceShadingList { get { if (_meshFaceShadingList == null) _meshFaceShadingList = new List(); return _meshFaceShadingList; } set { _meshFaceShadingList = value; } } public List MeshFaceTextureCoordinateList { get { if (_meshFaceTextureCoordinateList == null) _meshFaceTextureCoordinateList = new List(); return _meshFaceTextureCoordinateList; } set { _meshFaceTextureCoordinateList = value; } } public List MeshFaceDiffuseColorList { get { if (_meshFaceDiffuseColorList == null) _meshFaceDiffuseColorList = new List(); return _meshFaceDiffuseColorList; } set { _meshFaceDiffuseColorList = value; } } public List MeshFaceSpecularColorList { get { if (_meshFaceSpecularColorList == null) _meshFaceSpecularColorList = new List(); return _meshFaceSpecularColorList; } set { _meshFaceSpecularColorList = value; } } public List ModelPositionList { get { if (_modelPositionList == null) _modelPositionList = new List(); return _modelPositionList; } set { _modelPositionList = value; } } public List ModelNormalList { get { if (_modelNormalList == null) _modelNormalList = new List(); return _modelNormalList; } set { _modelNormalList = value; } } public List ModelDiffuseColorList { get { if (_modelDiffuseColorList == null) _modelDiffuseColorList = new List(); return _modelDiffuseColorList; } set { _modelDiffuseColorList = value; } } public List ModelSpecularColorList { get { if (_modelSpecularColorList == null) _modelSpecularColorList = new List(); return _modelSpecularColorList; } set { _modelSpecularColorList = value; } } public List ModelTextureCoordList { get { if (_modelTextureCoordList == null) _modelTextureCoordList = new List(); return _modelTextureCoordList; } set { _modelTextureCoordList = value; } } public List MeshBasePositionList { get { if (_meshBasePositionList == null) _meshBasePositionList = new List(); return _meshBasePositionList; } set { _meshBasePositionList = value; } } public void Export(StreamWriter toStream) { toStream.WriteLine(string.Format("\t\tMESH {{")); toStream.WriteLine(string.Format("\t\t\tFACE_COUNT {0}", MeshFacePositionList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_POSITION_COUNT {0}", ModelPositionList.Count().ToString())); // toStream.WriteLine(String.Format("\t\t\tMODEL_BASE_POSITION_COUNT {0} {{", this.MeshBasePositionList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_NORMAL_COUNT {0}", ModelNormalList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_DIFFUSE_COLOR_COUNT {0}", ModelDiffuseColorList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_SPECULAR_COLOR_COUNT {0}", ModelSpecularColorList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_TEXTURE_COORD_COUNT {0}", ModelTextureCoordList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_BONE_COUNT {0}", 0)); //What does this count??? toStream.WriteLine(string.Format("\t\t\tMODEL_SHADING_COUNT {0}", ShadingDescriptionList.Count().ToString())); ListExtensions.ExportShadingListToStream(ShadingDescriptionList, toStream); ListExtensions.ExportInt3ListToStream(MeshFacePositionList, toStream, "MESH_FACE_POSITION_LIST"); ListExtensions.ExportInt3ListToStream(MeshFaceNormalList, toStream, "MESH_FACE_NORMAL_LIST"); ListExtensions.ExportIntListToStream(MeshFaceShadingList, toStream, "MESH_FACE_SHADING_LIST"); ListExtensions.ExportMeshFaceTextureCoordListToStream(MeshFaceTextureCoordinateList, toStream); ListExtensions.ExportInt3ListToStream(MeshFaceDiffuseColorList, toStream, "MESH_FACE_DIFFUSE_COLOR_LIST"); ListExtensions.ExportInt3ListToStream(MeshFaceSpecularColorList, toStream, "MESH_FACE_SPECULAR_COLOR_LIST"); ListExtensions.ExportPoint3ListToStream(ModelPositionList, toStream, "MODEL_POSITION_LIST"); ListExtensions.ExportPoint3ListToStream(ModelNormalList, toStream, "MODEL_NORMAL_LIST"); ListExtensions.ExportColor4ListToStream(ModelDiffuseColorList, toStream, "MODEL_DIFFUSE_COLOR_LIST"); ListExtensions.ExportColor4ListToStream(ModelSpecularColorList, toStream, "MODEL_NORMAL_LIST"); ListExtensions.ExportVector4ListToStream(ModelTextureCoordList, toStream, "MODEL_TEXTURE_COORD_LIST"); ListExtensions.ExportIntListToStream(MeshBasePositionList, toStream, "MESH_BASE_POSITION_LIST"); toStream.WriteLine(string.Format("\t\t}}")); } } public class LineSetData { private List _shadingDescriptionList; private List _linePositionList; private List _lineNormalList; private List _lineShadingList; private List _lineTextureCoordinateList; private List _lineDiffuseColorList; private List _lineSpecularColorList; private List _modelPositionList; private List _modelNormalList; private List _modelDiffuseColorList; private List _modelSpecularColorList; private List _modelTextureCoordList; public List ShadingDescriptionList { get { if (_shadingDescriptionList == null) _shadingDescriptionList = new List(); return _shadingDescriptionList; } set { _shadingDescriptionList = value; } } public List LinePositionList { get { if (_linePositionList == null) _linePositionList = new List(); return _linePositionList; } set { _linePositionList = value; } } public List LineNormalList { get { if (_lineNormalList == null) _lineNormalList = new List(); return _lineNormalList; } set { _lineNormalList = value; } } public List LineShadingList { get { if (_lineShadingList == null) _lineShadingList = new List(); return _lineShadingList; } set { _lineShadingList = value; } } public List LineTextureCoordinateList { get { if (_lineTextureCoordinateList == null) _lineTextureCoordinateList = new List(); return _lineTextureCoordinateList; } set { _lineTextureCoordinateList = value; } } public List LineDiffuseColorList { get { if (_lineDiffuseColorList == null) _lineDiffuseColorList = new List(); return _lineDiffuseColorList; } set { _lineDiffuseColorList = value; } } public List LineSpecularColorList { get { if (_lineSpecularColorList == null) _lineSpecularColorList = new List(); return _lineSpecularColorList; } set { _lineSpecularColorList = value; } } public List ModelPositionList { get { if (_modelPositionList == null) _modelPositionList = new List(); return _modelPositionList; } set { _modelPositionList = value; } } public List ModelNormalList { get { if (_modelNormalList == null) _modelNormalList = new List(); return _modelNormalList; } set { _modelNormalList = value; } } public List ModelDiffuseColorList { get { if (_modelDiffuseColorList == null) _modelDiffuseColorList = new List(); return _modelDiffuseColorList; } set { _modelDiffuseColorList = value; } } public List ModelSpecularColorList { get { if (_modelSpecularColorList == null) _modelSpecularColorList = new List(); return _modelSpecularColorList; } set { _modelSpecularColorList = value; } } public List ModelTextureCoordList { get { if (_modelTextureCoordList == null) _modelTextureCoordList = new List(); return _modelTextureCoordList; } set { _modelTextureCoordList = value; } } public void Export(StreamWriter toStream) { toStream.WriteLine(string.Format("\t\tLINE_SET {{")); toStream.WriteLine(string.Format("\t\t\tLINE_COUNT {0}", LinePositionList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_POSITION_COUNT {0}", ModelPositionList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_NORMAL_COUNT {0}", ModelNormalList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_DIFFUSE_COLOR_COUNT {0}", ModelDiffuseColorList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_SPECULAR_COLOR_COUNT {0}", ModelSpecularColorList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_TEXTURE_COORD_COUNT {0}", ModelTextureCoordList.Count().ToString())); toStream.WriteLine(string.Format("\t\t\tMODEL_SHADING_COUNT {0}", ShadingDescriptionList.Count().ToString())); ListExtensions.ExportShadingListToStream(ShadingDescriptionList, toStream); ListExtensions.ExportInt2ListToStream(LinePositionList, toStream, "LINE_POSITION_LIST"); ListExtensions.ExportInt2ListToStream(LineNormalList, toStream, "LINE_NORMAL_LIST"); ListExtensions.ExportIntListToStream(LineShadingList, toStream, "LINE_SHADING_LIST"); ListExtensions.ExportLineTextureCoordListToStream(LineTextureCoordinateList, toStream); ListExtensions.ExportInt2ListToStream(LineDiffuseColorList, toStream, "LINE_DIFFUSE_COLOR_LIST"); ListExtensions.ExportInt2ListToStream(LineSpecularColorList, toStream, "LINE_SPECULAR_COLOR_LIST"); ListExtensions.ExportPoint3ListToStream(ModelPositionList, toStream, "MODEL_POSITION_LIST"); ListExtensions.ExportPoint3ListToStream(ModelNormalList, toStream, "MODEL_NORMAL_LIST"); ListExtensions.ExportColor4ListToStream(ModelDiffuseColorList, toStream, "MODEL_DIFFUSE_COLOR_LIST"); ListExtensions.ExportColor4ListToStream(ModelSpecularColorList, toStream, "MODEL_NORMAL_LIST"); ListExtensions.ExportVector4ListToStream(ModelTextureCoordList, toStream, "MODEL_TEXTURE_COORD_LIST"); toStream.WriteLine(string.Format("\t\t}}")); } } public class PointSetData { public void Export(StreamWriter toStream) { } } /* Resource data for the "SHADER RESOURCE_LIST" */ public class TextureLayer : IResourceData { public string TextureName { get; set; } public float? TextureLayerIntensity { get; set; } //optional public TextureLayerBlendFunctionType? TextureLayerBlendFunction { get; set; } //optional public TextureLayerBlendSourceType? TextureLayerBlendSource { get; set; } //optional public float? TextureLayerBlendConstant { get; set; } //optional public string TextureLayerMode { get; set; } //optional public bool? TextureLayerAlphaEnabled { get; set; } //optional public void Export(StreamWriter toStream) { if (TextureLayerIntensity != null) toStream.WriteLine(string.Format("\t\t\t\tTEXTURE_LAYER_INTENSITY {0}", ((float)TextureLayerIntensity).ToString(Format.SixDecPlFormat))); if (TextureLayerBlendFunction != null) toStream.WriteLine(string.Format("\t\t\t\tTEXTURE_LAYER_BLEND_FUNCTION \"{0}\"", TextureLayerBlendFunction.ToString())); if (TextureLayerBlendSource != null) toStream.WriteLine(string.Format("\t\t\t\tTEXTURE_LAYER_BLEND_SOURCE \"{0}\"", TextureLayerBlendSource.ToString())); if (TextureLayerBlendConstant != null) toStream.WriteLine(string.Format("\t\t\t\tTEXTURE_LAYER_BLEND_CONSTANT {0}", ((float)TextureLayerBlendConstant).ToString(Format.SixDecPlFormat))); if (TextureLayerMode != null) toStream.WriteLine(string.Format("\t\t\t\tTEXTURE_LAYER_MODE {0}", TextureLayerMode)); if (TextureLayerAlphaEnabled != null) toStream.WriteLine(string.Format("\t\t\t\tTEXTURE_LAYER_ALPHA_ENABLED \"{0}\"", TextureLayerAlphaEnabled.ToString().ToUpper())); toStream.WriteLine(string.Format("\t\t\t\tTEXTURE_NAME \"{0}\"", TextureName)); } } /* Resource data for the "TEXTURE RESOURCE_LIST" */ public class TextureImageFormat : IResourceData { public CompressionType? Type { get; set; } public bool? AlphaChannel { get; set; } public bool? BlueChannel { get; set; } public bool? GreenChannel { get; set; } public bool? RedChannel { get; set; } public bool? Luminance { get; set; } public bool? ExternalReference { get; set; } private List _urlList; //optional public List UrltList { get { if (_urlList == null) _urlList = new List(); return _urlList; } set { _urlList = value; } } //optional public void Export(StreamWriter toStream) { if (Type != null) toStream.WriteLine(string.Format("\t\t\t\tCOMPRESSION_TYPE \"{0}\"", Type.ToString())); if (AlphaChannel != null) toStream.WriteLine(string.Format("\t\t\t\tALPHA_CHANNEL \"{0}\"", AlphaChannel.ToString().ToUpper())); if (BlueChannel != null) toStream.WriteLine(string.Format("\t\t\t\tBLUE_CHANNEL \"{0}\"", BlueChannel.ToString().ToUpper())); if (GreenChannel != null) toStream.WriteLine(string.Format("\t\t\t\tGREEN_CHANNEL \"{0}\"", GreenChannel.ToString().ToUpper())); if (RedChannel != null) toStream.WriteLine(string.Format("\t\t\t\tRED_CHANNEL \"{0}\"", RedChannel.ToString().ToUpper())); if (Luminance != null) toStream.WriteLine(string.Format("\t\t\t\tLUMINANCE \"{0}\"", Luminance.ToString().ToUpper())); if (ExternalReference != null) toStream.WriteLine(string.Format("\t\t\t\tEXERNAL_REFERENCE \"{0}\"", ExternalReference.ToString().ToUpper())); ListExtensions.ExportUrlListToStream(UrltList, toStream); } } public class Url : IResourceData { public string UrlPath { get; set; } public void Export(StreamWriter toStream) { } } }