public static void PrepareDeployment(InvocationParams config, string filePath, string filterPath, out IFileDeployment outDeployment) { outDeployment = null; // Prepare for what there is to come: var inputFile = new FileInfo(filePath); if (!inputFile.Exists) { throw new FileNotFoundException($"File '{filePath}' does not exist"); } // There are two special filter paths: "assets" and "shaders". // Files under both filter paths are copied to the output directory, but // only those under "shaders" are possibly compiled to SPIR-V (in case // of building against Vulkan) or their GLSL code might be modified (in // case of building against OpenGL) // // All in all, we have the following special cases: // #1: If it is a shader file and we're building for Vulkan => compile to SPIR-V // #2: If it is a shader file and we're building for OpenGL => modify GLSL // #3: If it is an .obj 3D Model file => get its materials file var isExternalDependency = CgbUtils.NormalizePath(inputFile.FullName).Contains(CgbUtils.NormalizePath(config.CgbExternalPath)); var isAsset = RegexIsInAssets.IsMatch(filterPath); var isShader = RegexIsInShaders.IsMatch(filterPath); if (!isAsset && !isShader && !isExternalDependency) { Trace.TraceInformation($"Skipping '{filePath}' since it is neither in 'assets/' nor in 'shaders/' nor is it an external dependency."); return; } // Ensure we have no coding errors for the following cases: Diag.Debug.Assert(isAsset != isShader || isExternalDependency); // Construct the deployment and DO IT... JUST DO IT IFileDeployment deploy = null; Action <IFileDeployment> additionalInitAction = null; if (isShader) { if (config.TargetApi == BuildTargetApi.Vulkan) { // It's a shader and we're building for Vulkan => Special case #1 deploy = new VkShaderDeployment(); } else { Diag.Debug.Assert(config.TargetApi == BuildTargetApi.OpenGL); // It's a shader and we're building for OpenGL => Special case #2 deploy = new GlShaderDeployment(); } } else // is an asset { // Is it a model? try { using (AssimpContext importer = new AssimpContext()) { var model = importer.ImportFile(inputFile.FullName); var allTextures = new HashSet <string>(); foreach (var m in model.Materials) { if (m.HasTextureAmbient) { allTextures.Add(m.TextureAmbient.FilePath); } if (m.HasTextureDiffuse) { allTextures.Add(m.TextureDiffuse.FilePath); } if (m.HasTextureDisplacement) { allTextures.Add(m.TextureDisplacement.FilePath); } if (m.HasTextureEmissive) { allTextures.Add(m.TextureEmissive.FilePath); } if (m.HasTextureHeight) { allTextures.Add(m.TextureHeight.FilePath); } if (m.HasTextureLightMap) { allTextures.Add(m.TextureLightMap.FilePath); } if (m.HasTextureNormal) { allTextures.Add(m.TextureNormal.FilePath); } if (m.HasTextureOpacity) { allTextures.Add(m.TextureOpacity.FilePath); } if (m.HasTextureReflection) { allTextures.Add(m.TextureReflection.FilePath); } if (m.HasTextureSpecular) { allTextures.Add(m.TextureSpecular.FilePath); } } if (inputFile.FullName.Trim().EndsWith(".obj", true, System.Globalization.CultureInfo.InvariantCulture)) { deploy = new ObjModelDeployment(); } else { deploy = new ModelDeployment(); } additionalInitAction = (theDeployment) => { ((ModelDeployment)theDeployment).SetTextures(allTextures); }; } } catch (AssimpException aex) { Trace.TraceWarning(aex.Message); // Maybe it is no model?! } if (null == deploy) { deploy = new CopyFileDeployment(); } } deploy.SetInputParameters( config, filterPath, inputFile, Path.Combine(config.OutputPath, filterPath, inputFile.Name)); additionalInitAction?.Invoke(deploy); // We're done here => return the deployment-instance to the caller outDeployment = deploy; }
private static bool AreFileNamesEqual(string filepath1, string filepath2) { return(CgbUtils.NormalizePath(filepath1) == CgbUtils.NormalizePath(filepath2)); }