private static void Main(string[] args) { Stopwatch.StartNew(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); string executingAssemblyFolder = Path.GetDirectoryName(executingAssembly.Location); char pathSeparator = Path.DirectorySeparatorChar; string outputFolder = Path.GetFullPath(Path.Combine(executingAssemblyFolder, string.Format(@"..{0}..{0}..{0}..{0}Output", pathSeparator))); string positiveTestsFolder = Path.Combine(outputFolder, "Positive"); string negativeTestsFolder = Path.Combine(outputFolder, "Negative"); var jsonSerializer = new JsonSerializer { Formatting = Formatting.Indented, ContractResolver = new CamelCasePropertyNamesContractResolver() }; // Make an inventory of what images there are. var imageList = FileHelper.FindImageFiles(Path.Combine(executingAssemblyFolder, "Resources")); // Create an ordered list initalizing each model group. var positiveTests = new List <ModelGroup> { new Animation_Node(imageList), new Animation_NodeMisc(imageList), new Animation_Skin(imageList), new Animation_SkinType(imageList), new Buffer_Interleaved(imageList), new Compatibility(imageList), new Material(imageList), new Material_AlphaBlend(imageList), new Material_AlphaMask(imageList), new Material_DoubleSided(imageList), new Material_MetallicRoughness(imageList), new Material_Mixed(imageList), new Material_SpecularGlossiness(imageList), new Mesh_PrimitiveAttribute(imageList), new Mesh_PrimitiveMode(imageList), new Mesh_PrimitiveVertexColor(imageList), new Mesh_Primitives(imageList), new Mesh_PrimitivesUV(imageList), new Node_Attribute(imageList), new Node_NegativeScale(imageList), new Texture_Sampler(imageList), new Animation_SamplerType(imageList), new Instancing(imageList), }; var negativeTests = new List <ModelGroup> { new Mesh_PrimitiveRestart(imageList), new Mesh_NoPosition(imageList), }; // Retains the manifest from each test type for use in updating the main readme table. var mainManifests = new List <List <Manifest> > { ProcessModelGroups(positiveTests, positiveTestsFolder), ProcessModelGroups(negativeTests, negativeTestsFolder), }; ReadmeBuilder.UpdateMainReadme(executingAssembly, mainManifests, Directory.GetParent(outputFolder).ToString(), new string[] { "Positive", "Negative" }); // Writes a readme explaining the different test types. using (var newReadme = new FileStream(Path.Combine(outputFolder, "README.md"), FileMode.Create)) { executingAssembly.GetManifestResourceStream("AssetGenerator.ReadmeTemplates.Page_Output.md").CopyTo(newReadme); } Console.WriteLine("Model Creation Complete!"); Console.WriteLine($"Completed in : {TimeSpan.FromTicks(Stopwatch.GetTimestamp()).ToString()}"); /// <summary> /// Saves each model group to a master manifest as it is created, and writes that manifest to file. /// </summary> /// <returns>Manifest containing all of the model groups and created.</returns> List <Manifest> ProcessModelGroups(List <ModelGroup> modelGroupList, string savePath) { // Generates the models and saves the model group manifest in with the master manifest. var manifests = new List <Manifest>(); foreach (var modelGroup in modelGroupList) { manifests.Add(GenerateModels(modelGroup, savePath)); } // Writes the master manifest to file. using (var writeManifest = new StreamWriter(Path.Combine(savePath, "Manifest.json"))) { jsonSerializer.Serialize(writeManifest, manifests.ToArray()); } return(manifests); } /// <summary> /// Create and write all models contained in a model group. Writes a mini-manifest for just the model group to file. /// Generates a readme describing the models created. Also copies over required textures and figures. /// </summary> /// <returns>Manifest containing the model group's models.</returns> Manifest GenerateModels(ModelGroup modelGroup, string savePath) { var readme = new ReadmeBuilder(); var manifest = new Manifest(modelGroup.Id); string modelGroupFolder = Path.Combine(savePath, modelGroup.Id.ToString()); Directory.CreateDirectory(modelGroupFolder); // Copy all of the images used by the model group into that model group's output directory. FileHelper.CopyImageFiles(executingAssemblyFolder, modelGroupFolder, modelGroup.UsedFigures); FileHelper.CopyImageFiles(executingAssemblyFolder, modelGroupFolder, modelGroup.UsedTextures, useThumbnails: true); readme.SetupHeader(modelGroup); var numCombos = modelGroup.Models.Count; for (var comboIndex = 0; comboIndex < numCombos; comboIndex++) { var model = modelGroup.Models[comboIndex]; var filename = $"{modelGroup.Id}_{comboIndex:00}.gltf"; using (var data = new Data($"{modelGroup.Id}_{comboIndex:00}.bin")) { // Pass the desired properties to the runtime layer, which then coverts that data into // a gltf loader object, ready to create the model. var converter = new Runtime.GLTFConverter { CreateInstanceOverride = model.CreateSchemaInstance }; glTFLoader.Schema.Gltf gltf = converter.ConvertRuntimeToSchema(model.GLTF, data); // Makes last second changes to the model that bypass the runtime layer. model.PostRuntimeChanges?.Invoke(gltf); // Create the .gltf file and writes the model's data to it. string assetFile = Path.Combine(modelGroupFolder, filename); glTFLoader.Interface.SaveModel(gltf, assetFile); // Create the .bin file and writes the model's data to it. string dataFile = Path.Combine(modelGroupFolder, data.Name); File.WriteAllBytes(dataFile, data.ToArray()); } readme.SetupTable(modelGroup, comboIndex, model, Path.GetFileName(savePath)); manifest.Models.Add(new Manifest.Model(filename, modelGroup.Id, modelGroup.NoSampleImages, model.Camera, model.Animated, model.Loadable)); } // Write the readme and manifest specific to this model group. readme.WriteOut(executingAssembly, modelGroup, modelGroupFolder); using (var writeModelGroupManifest = new StreamWriter(Path.Combine(modelGroupFolder, "Manifest.json"))) { jsonSerializer.Serialize(writeModelGroupManifest, manifest); } return(manifest); } }
private static void Main(string[] args) { Stopwatch.StartNew(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); string executingAssemblyFolder = Path.GetDirectoryName(executingAssembly.Location); var pathSeparator = Path.DirectorySeparatorChar; string outputFolder = Path.GetFullPath(Path.Combine(executingAssemblyFolder, string.Format(@"..{0}..{0}..{0}..{0}Output", pathSeparator))); List <Manifest> manifestMaster = new List <Manifest>(); var jsonSerializer = new Newtonsoft.Json.JsonSerializer { Formatting = Newtonsoft.Json.Formatting.Indented, ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() }; // Make an inventory of what images there are var imageList = FileHelper.FindImageFiles(Path.Combine(executingAssemblyFolder, "Resources")); // Create a list containing each model group and their initial values List <ModelGroup> allModelGroups = new List <ModelGroup>() { new Animation_Node(imageList), new Animation_NodeMisc(imageList), new Animation_Skin(imageList), new Animation_SkinType(imageList), new Buffer_Interleaved(imageList), new Compatibility(imageList), new Material(imageList), new Material_AlphaBlend(imageList), new Material_AlphaMask(imageList), new Material_DoubleSided(imageList), new Material_MetallicRoughness(imageList), new Material_Mixed(imageList), new Material_SpecularGlossiness(imageList), new Mesh_PrimitiveAttribute(imageList), new Mesh_PrimitiveMode(imageList), new Mesh_PrimitiveVertexColor(imageList), new Mesh_Primitives(imageList), new Mesh_PrimitivesUV(imageList), new Node_Attribute(imageList), new Node_NegativeScale(imageList), new Texture_Sampler(imageList), }; foreach (var modelGroup in allModelGroups) { ReadmeBuilder readme = new ReadmeBuilder(); Manifest manifest = new Manifest(modelGroup.Id); string modelGroupFolder = Path.Combine(outputFolder, modelGroup.Id.ToString()); Directory.CreateDirectory(modelGroupFolder); // Copy all of the images used by the model group into that model group's output directory FileHelper.CopyImageFiles(executingAssemblyFolder, modelGroupFolder, modelGroup.UsedFigures); FileHelper.CopyImageFiles(executingAssemblyFolder, modelGroupFolder, modelGroup.UsedTextures, useThumbnails: true); readme.SetupHeader(modelGroup); int numCombos = modelGroup.Models.Count; for (int comboIndex = 0; comboIndex < numCombos; comboIndex++) { var model = modelGroup.Models[comboIndex]; var filename = $"{modelGroup.Id}_{comboIndex:00}.gltf"; using (var data = new Data($"{modelGroup.Id}_{comboIndex:00}.bin")) { // Passes the desired properties to the runtime layer, which then coverts that data into // a gltf loader object, ready to create the model var converter = new Runtime.GLTFConverter { CreateInstanceOverride = model.CreateSchemaInstance }; var gltf = converter.ConvertRuntimeToSchema(model.GLTF, data); // Makes last second changes to the model that bypass the runtime layer // in order to add features that don't really exist otherwise model.PostRuntimeChanges(gltf); // Creates the .gltf file and writes the model's data to it var assetFile = Path.Combine(modelGroupFolder, filename); glTFLoader.Interface.SaveModel(gltf, assetFile); // Creates the .bin file and writes the model's data to it var dataFile = Path.Combine(modelGroupFolder, data.Name); File.WriteAllBytes(dataFile, data.ToArray()); } readme.SetupTable(modelGroup, comboIndex, model.Properties); manifest.Models.Add(new Manifest.Model(filename, modelGroup.Id, modelGroup.NoSampleImages, model.Camera)); } readme.WriteOut(executingAssembly, modelGroup, modelGroupFolder); manifestMaster.Add(manifest); // Write out the manifest JSON specific to this model group using (StreamWriter writeModelGroupManifest = new StreamWriter(Path.Combine(modelGroupFolder, "Manifest.json"))) jsonSerializer.Serialize(writeModelGroupManifest, manifest); } // Write out the master manifest JSON containing all of the model groups using (StreamWriter writeManifest = new StreamWriter(Path.Combine(outputFolder, "Manifest.json"))) jsonSerializer.Serialize(writeManifest, manifestMaster.ToArray()); // Update the main readme ReadmeBuilder.UpdateMainReadme(executingAssembly, outputFolder, manifestMaster); Console.WriteLine("Model Creation Complete!"); Console.WriteLine("Completed in : " + TimeSpan.FromTicks(Stopwatch.GetTimestamp()).ToString()); }
private static void Main(string[] args) { Stopwatch.StartNew(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); string executingAssemblyFolder = Path.GetDirectoryName(executingAssembly.Location); string outputFolder = Path.GetFullPath(Path.Combine(executingAssemblyFolder, @"..\..\..\..\Output")); List <Manifest> manifestMaster = new List <Manifest>(); // Make an inventory of what images there are var textures = FileHelper.FindImageFiles(executingAssembly, "Textures"); var figures = FileHelper.FindImageFiles(executingAssembly, "Figures"); // Uses Reflection to create a list containing one instance of each group of models List <dynamic> allModelGroups = new List <dynamic>(); foreach (var type in executingAssembly.GetTypes()) { var modelGroupAttribute = type.GetCustomAttribute <ModelGroupAttribute>(); if (modelGroupAttribute != null) { ConstructorInfo ctor = type.GetConstructor(new Type[] { typeof(List <string>), typeof(List <string>) }); dynamic modelGroup = ctor.Invoke(new dynamic[] { textures, figures }); allModelGroups.Add(modelGroup); } } foreach (var modelGroup in allModelGroups) { List <List <Property> > combos = ComboHelper.AttributeCombos(modelGroup); ReadmeBuilder readme = new ReadmeBuilder(); Manifest manifest = new Manifest(modelGroup.modelGroupName); string assetFolder = Path.Combine(outputFolder, modelGroup.modelGroupName.ToString()); FileHelper.ClearOldFiles(outputFolder, assetFolder); Directory.CreateDirectory(assetFolder); // Copy all of the images used by the model group into that model group's output directory FileHelper.CopyImageFiles(executingAssembly, assetFolder, modelGroup.usedTextures, useThumbnails: true); FileHelper.CopyImageFiles(executingAssembly, assetFolder, modelGroup.usedFigures); readme.SetupHeader(modelGroup); int numCombos = combos.Count; for (int comboIndex = 0; comboIndex < numCombos; comboIndex++) { string[] name = ReadmeStringHelper.GenerateName(combos[comboIndex]); var asset = new Runtime.Asset { Generator = "glTF Asset Generator", Version = "2.0", Extras = new Runtime.Extras { // Inserts a string into the .gltf containing the properties that are set for a given model, for debug. Attributes = String.Join(" - ", name) } }; var gltf = new glTFLoader.Schema.Gltf { Asset = asset.ConvertToSchema() }; var dataList = new List <Data>(); var geometryData = new Data(modelGroup.modelGroupName.ToString() + "_" + comboIndex.ToString("00") + ".bin"); dataList.Add(geometryData); Runtime.GLTF wrapper = Common.SinglePlane(); wrapper.Asset = asset; Runtime.Material mat = new Runtime.Material(); // Takes the current combo and uses it to bundle together the data for the desired properties wrapper = modelGroup.SetModelAttributes(wrapper, mat, combos[comboIndex], ref gltf); // Passes the desired properties to the runtime layer, which then coverts that data into // a gltf loader object, ready to create the model Runtime.GLTFConverter.ConvertRuntimeToSchema(wrapper, ref gltf, geometryData); // Makes last second changes to the model that bypass the runtime layer // in order to add 'features that don't really exist otherwise modelGroup.PostRuntimeChanges(combos[comboIndex], ref gltf); // Creates the .gltf file and writes the model's data to it var filename = modelGroup.modelGroupName.ToString() + "_" + comboIndex.ToString("00") + ".gltf"; var assetFile = Path.Combine(assetFolder, filename); glTFLoader.Interface.SaveModel(gltf, assetFile); // Creates the .bin file and writes the model's data to it foreach (var data in dataList) { data.Writer.Flush(); var dataFile = Path.Combine(assetFolder, data.Name); File.WriteAllBytes(dataFile, ((MemoryStream)data.Writer.BaseStream).ToArray()); } readme.SetupTable(modelGroup, comboIndex, combos); manifest.files.Add(filename); } readme.WriteOut(executingAssembly, modelGroup, assetFolder); manifestMaster.Add(manifest); // Write out the manifest JSON specific to this model group string json = Newtonsoft.Json.JsonConvert.SerializeObject(manifest, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(Path.Combine(assetFolder, "Manifest.json"), json); } // Write out the master manifest JSON containing all of the model groups string jsonMaster = Newtonsoft.Json.JsonConvert.SerializeObject(manifestMaster.ToArray(), Newtonsoft.Json.Formatting.Indented); File.WriteAllText(Path.Combine(outputFolder, "Manifest.json"), jsonMaster); // Update the main readme ReadmeBuilder.UpdateMainReadme(executingAssembly, outputFolder, manifestMaster); // Create reference images ReferenceImages.Create(executingAssembly, outputFolder, manifestMaster); Console.WriteLine("Model Creation Complete!"); Console.WriteLine("Completed in : " + TimeSpan.FromTicks(Stopwatch.GetTimestamp()).ToString()); }