public static string[] Compile(string[] sources, string[] references, string[] defines, string outputFile, bool allowUnsafeCode) { var assembly = new ScriptAssembly { BuildTarget = BuildTarget.StandaloneWindows, Files = sources, References = references, Defines = defines, OutputDirectory = AssetPath.GetDirectoryName(outputFile), Filename = AssetPath.GetFileName(outputFile), CompilerOptions = new Compilation.ScriptCompilerOptions(), ScriptAssemblyReferences = new ScriptAssembly[0] }; assembly.CompilerOptions.AllowUnsafeCode = allowUnsafeCode; assembly.CompilerOptions.ApiCompatibilityLevel = ApiCompatibilityLevel.NET_Standard_2_0; using (var c = new MicrosoftCSharpCompiler(assembly, assembly.OutputDirectory)) { c.BeginCompiling(); while (!c.Poll()) { System.Threading.Thread.Sleep(50); } return(c.GetCompilerMessages().Select(cm => cm.message).ToArray()); } }
private string Preprocess(IFileStore store, string path, string[] defines) { var builder = new StringBuilder(); if (defines != null) { for (int i = 0; i < defines.Length; ++i) { builder.AppendLine("#define " + defines[i] + " 1"); } } Preprocess(builder, store, AssetPath.GetDirectoryName(path), AssetPath.GetFileName(path), 0); return(builder.ToString()); }
public IEnumerable <string> ListFiles(string path) { // Iterate all files, identify those in the given path int count = SteamRemoteStorage.GetFileCount(); for (int i = 0; i < count; ++i) { int size; string file = SteamRemoteStorage.GetFileNameAndSize(i, out size); if (AssetPath.GetDirectoryName(file) == path) { yield return(AssetPath.GetFileName(file)); } } }
public static Texture GetLocalised(string path, Language language, bool filter) { // Try the current language and it's fallbacks bool triedEnglish = false; while (language != null) { var specificPath = AssetPath.Combine( AssetPath.GetDirectoryName(path), AssetPath.GetFileNameWithoutExtension(path) + "_" + language.Code + ".png" ); if (Assets.Assets.Exists <Texture>(specificPath)) { return(Texture.Get(specificPath, filter)); } if (language.Code == "en") { triedEnglish = true; } language = language.Fallback; } if (!triedEnglish) { // Try english var englishPath = AssetPath.Combine( AssetPath.GetDirectoryName(path), AssetPath.GetFileNameWithoutExtension(path) + "_en.png" ); if (Assets.Assets.Exists <Texture>(englishPath)) { return(Texture.Get(englishPath, filter)); } } // Try unlocalised return(Texture.Get(path, filter)); }
private void Load(IFileStore store) { using (var stream = store.OpenFile(m_path)) { var reader = new StreamReader(stream, Encoding.UTF8); string line; string type = null; var options = new KeyValuePairs(); while ((line = reader.ReadLine()) != null) { // Parse each line string[] parts = line.Split(' '); if (parts.Length < 1) { continue; } // Extract type and options type = parts[0]; options.Clear(); for (int i = 1; i < parts.Length; ++i) { string part = parts[i]; int equalsIndex = part.IndexOf('='); if (equalsIndex >= 0) { string key = part.Substring(0, equalsIndex); string value = part.Substring(equalsIndex + 1); int intValue; if (value.StartsWith("\"")) { if (value.EndsWith("\"") && value.Length >= 2) { value = value.Substring(1, value.Length - 2); } else { value = value.Substring(1) + " "; i++; while (!parts[i].EndsWith("\"")) { value += parts[i] + " "; i++; } value += parts[i].Substring(0, parts[i].Length - 1); } options.Set(key, value); } else if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out intValue)) { options.Set(key, intValue); } } } // Interpret switch (type) { case "common": { m_lineHeight = options.GetInteger("lineHeight"); m_base = options.GetInteger("base"); m_scaleW = options.GetInteger("scaleW"); m_scaleH = options.GetInteger("scaleH"); m_pages = new Page[options.GetInteger("pages")]; break; } case "page": { int id = options.GetInteger("id"); if (id >= PageCount) { Array.Resize(ref m_pages, id + 1); } m_pages[id] = new Page(); m_pages[id].Path = AssetPath.Combine(AssetPath.GetDirectoryName(m_path), options.GetString("file")); break; } case "chars": { m_chars = new Dictionary <int, Char>(options.GetInteger("count")); break; } case "char": { var id = options.GetInteger("id"); m_chars[id] = new Char(); m_chars[id].X = options.GetInteger("x"); m_chars[id].Y = options.GetInteger("y"); m_chars[id].Width = options.GetInteger("width"); m_chars[id].Height = options.GetInteger("height"); m_chars[id].XOffset = options.GetInteger("xoffset"); m_chars[id].YOffset = options.GetInteger("yoffset"); m_chars[id].XAdvance = options.GetInteger("xadvance"); m_chars[id].Page = options.GetInteger("page"); if (m_chars[id].Page < 0 || m_chars[id].Page >= PageCount) { m_chars[id].Page = 0; //throw new IOException( "Page count out of range" ); } break; } case "kernings": { m_kernings = new Dictionary <KerningPair, Kerning>(options.GetInteger("count")); break; } case "kerning": { var first = options.GetInteger("first"); var second = options.GetInteger("second"); var pair = new KerningPair(first, second); m_kernings[pair] = new Kerning(); m_kernings[pair].Amount = options.GetInteger("amount"); break; } } } } }
private void Load(IFileStore store) { // Load var objFile = new OBJFile(); using (var reader = store.OpenTextFile(m_path)) { objFile.Parse(reader); } // Interpret var dir = AssetPath.GetDirectoryName(m_path); m_materialFile = AssetPath.Combine(dir, objFile.MTLLib); m_groups = new List <Group>(); m_groupLookup = new Dictionary <string, int>(); foreach (var objGroup in objFile.Groups) { // Skip empty groups if (objGroup.Faces.Count == 0) { continue; } // Load geometry Geometry geometry = new Geometry(Primitive.Triangles); for (int i = 0; i < objGroup.Faces.Count; ++i) { var objFace = objGroup.Faces[i]; if (objFace.VertexCount >= 3) { Vector3 posA, posB, posC; Vector4 colourA, colourB, colourC; Vector3?normA, normB, normC; Vector2 texCoordA, texCoordB, texCoordC; GetVertInfo(objFile, objFace.FirstVertex, out posA, out colourA, out texCoordA, out normA); GetVertInfo(objFile, objFace.FirstVertex + 1, out posB, out colourB, out texCoordB, out normB); GetVertInfo(objFile, objFace.FirstVertex + 2, out posC, out colourC, out texCoordC, out normC); Vector3 faceNormal, faceTangent; MathUtils.GenerateNormalAndTangent( posA, posB, posC, texCoordA, texCoordB, texCoordC, out faceNormal, out faceTangent ); // Add the verts int firstVertIndex = geometry.VertexCount; geometry.AddVertex(posA, normA.HasValue ? normA.Value : faceNormal, faceTangent, texCoordA, colourA); geometry.AddVertex(posB, normB.HasValue ? normB.Value : faceNormal, faceTangent, texCoordB, colourB); geometry.AddVertex(posC, normC.HasValue ? normC.Value : faceNormal, faceTangent, texCoordC, colourC); for (int j = 3; j < objFace.VertexCount; ++j) { Vector3 posN; Vector4 colourN; Vector3?normN; Vector2 texCoordN; GetVertInfo(objFile, objFace.FirstVertex + j, out posN, out colourN, out texCoordN, out normN); geometry.AddVertex(posN, normN.HasValue ? normN.Value : faceNormal, faceTangent, texCoordN, colourN); } // Add the indexes for (int k = 2; k < objFace.VertexCount; ++k) { geometry.AddIndex(firstVertIndex); geometry.AddIndex(firstVertIndex + k - 1); geometry.AddIndex(firstVertIndex + k); } } } geometry.Rebuild(); // Build shadow geometry var shadowGeometry = new Geometry(Primitive.Triangles); shadowGeometry.AddShadowGeometry(geometry, ref Matrix4.Identity); shadowGeometry.Rebuild(); // Prepare the group var group = new Group(); group.Name = objGroup.Name; group.MaterialName = objGroup.MaterialName; group.Geometry = geometry; group.ShadowGeometry = shadowGeometry; m_groupLookup.Add(group.Name, m_groups.Count); m_groups.Add(group); } }
private void Load(IFileStore store) { // Load the material infos var dir = AssetPath.GetDirectoryName(m_path); Material currentMaterial = null; using (var reader = store.OpenTextFile(m_path)) { // For each line: string line; var whitespace = new char[] { ' ', '\t' }; while ((line = reader.ReadLine()) != null) { // Strip comment var commentIdx = line.IndexOf('#'); if (commentIdx >= 0) { line = line.Substring(0, commentIdx); } // Segment var parts = line.Split(whitespace, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 0) { continue; } // Parse var type = parts[0].ToLowerInvariant(); switch (type) { case "newmtl": { var name = parts[1]; currentMaterial = new Material(); m_materials.Add(name, currentMaterial); break; } case "map_ka": { var path = AssetPath.Combine(dir, parts[1]); currentMaterial.EmissiveColour = Vector3.One; currentMaterial.EmissiveTexture = path; break; } case "map_kd": { var path = AssetPath.Combine(dir, parts[1]); currentMaterial.DiffuseColour = Vector4.One; currentMaterial.DiffuseTexture = path; break; } case "map_ks": { var path = AssetPath.Combine(dir, parts[1]); currentMaterial.SpecularColour = Vector3.One; currentMaterial.SpecularTexture = path; break; } case "map_bump": case "bump": { var path = AssetPath.Combine(dir, parts[1]); currentMaterial.NormalTexture = path; break; } } } } // Add missing material paths foreach (var material in m_materials.Values) { if (material.EmissiveTexture == null) { material.EmissiveColour = Vector3.One; material.EmissiveTexture = "black.png"; if (material.DiffuseTexture != null) { var potentialPath = AssetPath.ChangeExtension(material.DiffuseTexture, "emit.png"); if (store.FileExists(potentialPath)) { material.EmissiveTexture = potentialPath; } } } if (material.SpecularTexture == null) { material.SpecularColour = Vector3.One; material.SpecularTexture = "black.png"; if (material.DiffuseTexture != null) { var potentialPath = AssetPath.ChangeExtension(material.DiffuseTexture, "spec.png"); if (store.FileExists(potentialPath)) { material.SpecularTexture = potentialPath; } } } if (material.NormalTexture == null) { material.NormalTexture = "flat.png"; if (material.DiffuseTexture != null) { var potentialPath = AssetPath.ChangeExtension(material.DiffuseTexture, "norm.png"); if (store.FileExists(potentialPath)) { material.NormalTexture = potentialPath; } } } if (material.DiffuseTexture == null) { material.DiffuseColour = Vector4.One; material.DiffuseTexture = "white.png"; } } }