/// <summary> /// c-tor - generic way for collecting resources /// </summary> /// <param name="meshInfo"></param> /// assetName - just for debug output public MyMesh(MyMeshPartInfo meshInfo, string assetName) { MyMaterialDescriptor matDesc = meshInfo.m_MaterialDesc; if (matDesc != null) { string texName; matDesc.Textures.TryGetValue("DiffuseTexture", out texName); var material = new MyMeshMaterial(); material.Name = meshInfo.m_MaterialDesc.MaterialName; material.Textures = matDesc.Textures; material.DrawTechnique = meshInfo.Technique; material.GlassCW = meshInfo.m_MaterialDesc.GlassCW; material.GlassCCW = meshInfo.m_MaterialDesc.GlassCCW; material.GlassSmooth = meshInfo.m_MaterialDesc.GlassSmoothNormals; Material = material; } else { //It is OK because ie. collision meshes dont have materials Material = new MyMeshMaterial(); } AssetName = assetName; }
internal static MyMeshMaterialId GetMaterialId(MyMaterialDescriptor importDesc, string contentPath, string assetFile = null) { MyMeshMaterialInfo desc; if (importDesc != null) { desc = new MyMeshMaterialInfo { Name = X.TEXT(importDesc.MaterialName), ContentPath = contentPath, ColorMetal_Texture = X.TEXT(importDesc.Textures.Get("ColorMetalTexture", "")), NormalGloss_Texture = X.TEXT(importDesc.Textures.Get("NormalGlossTexture", "")), Extensions_Texture = X.TEXT(importDesc.Textures.Get("AddMapsTexture", "")), Alphamask_Texture = X.TEXT(importDesc.Textures.Get("AlphamaskTexture", null)), Technique = importDesc.Technique, Facing = importDesc.Facing, WindScaleAndFreq = importDesc.WindScaleAndFreq }; } else { return(NullMaterialId); } return(GetMaterialId(ref desc, assetFile)); }
public void ApplyTo(MyMaterialDescriptor mtl) { var technique = mtl.TechniqueEnum; var isDecal = technique == MyMeshDrawTechnique.HOLO || technique == MyMeshDrawTechnique.DECAL || technique == MyMeshDrawTechnique.FOLIAGE || technique == MyMeshDrawTechnique.DECAL_CUTOUT || technique == MyMeshDrawTechnique.DECAL_NOPREMULT; switch (Mode) { case ModeEnum.Texture: if (Key == "AddMapsTexture" && isDecal) { MyLog.Default.Warning($"Edit to material {mtl.MaterialName} with a decal type technique can not have an ADD texture"); break; } mtl.Textures[Key] = Value; break; case ModeEnum.UserData: mtl.UserData[Key] = Value; break; case ModeEnum.FieldKey: if (Key == TechniqueKey) { mtl.Technique = Value; } break; } }
private void SetMaterialTextures(MyMaterialDescriptor matDesc, Material material) { TextureSlot texture; material.GetMaterialTexture(TextureType.Diffuse, 0, out texture); string filePath = texture.FilePath; if (filePath.Length < MyMeshPartSolver.ColorMetalSuffix.Length) { return; } string str = filePath.Substring(0, filePath.Length - MyMeshPartSolver.ColorMetalSuffix.Length); try { string path2 = MyModelProcessor.GetResourcePathInContent(str + MyMeshPartSolver.ColorMetalSuffix).TrimStart('\\', '/'); if (File.Exists(Path.Combine(ProgramContext.OutputDir, path2))) { matDesc.Textures.Add("ColorMetalTexture", path2); } } catch { } try { string path2 = MyModelProcessor.GetResourcePathInContent(str + MyMeshPartSolver.NormalGlossSuffix).TrimStart('\\', '/'); if (File.Exists(Path.Combine(ProgramContext.OutputDir, path2))) { matDesc.Textures.Add("NormalGlossTexture", path2); } } catch { } try { string path2 = MyModelProcessor.GetResourcePathInContent(str + MyMeshPartSolver.AddMapsSuffix).TrimStart('\\', '/'); if (File.Exists(Path.Combine(ProgramContext.OutputDir, path2))) { matDesc.Textures.Add("AddMapsTexture", path2); } } catch { } try { string path2 = MyModelProcessor.GetResourcePathInContent(str + MyMeshPartSolver.AlphamaskSuffix).TrimStart('\\', '/'); if (!File.Exists(Path.Combine(ProgramContext.OutputDir, path2))) { return; } matDesc.Textures.Add("AlphamaskTexture", path2); } catch { } }
private void SetMaterialTextures(MyMaterialDescriptor matDesc, Material material) { TextureSlot texture; material.GetMaterialTexture(TextureType.Diffuse, 0, out texture); //Custom Change Nr 1. //Always set the path to this instead of filepath of textures. //This fixes the problem that assimp can't read pbr materials from max properly string filePath = material.Name + "_cm.dds"; //string filePath = texture.FilePath; <-- original if (filePath.Length < MyMeshPartSolver.ColorMetalSuffix.Length) { return; } string str = filePath.Substring(0, filePath.Length - MyMeshPartSolver.ColorMetalSuffix.Length); try { string path2 = MyModelProcessor.GetResourcePathInContent(str + MyMeshPartSolver.ColorMetalSuffix).TrimStart('\\', '/'); // if (File.Exists(Path.Combine(ProgramContext.OutputDir, path2))) matDesc.Textures.Add("ColorMetalTexture", path2); } catch { } try { string path2 = MyModelProcessor.GetResourcePathInContent(str + MyMeshPartSolver.NormalGlossSuffix).TrimStart('\\', '/'); // if (File.Exists(Path.Combine(ProgramContext.OutputDir, path2))) matDesc.Textures.Add("NormalGlossTexture", path2); } catch { } try { string path2 = MyModelProcessor.GetResourcePathInContent(str + MyMeshPartSolver.AddMapsSuffix).TrimStart('\\', '/'); //if (File.Exists(Path.Combine(ProgramContext.OutputDir, path2))) matDesc.Textures.Add("AddMapsTexture", path2); } catch { } try { string path2 = MyModelProcessor.GetResourcePathInContent(str + MyMeshPartSolver.AlphamaskSuffix).TrimStart('\\', '/'); // if (!File.Exists(Path.Combine(ProgramContext.OutputDir, path2))) // return; matDesc.Textures.Add("AlphamaskTexture", path2); } catch { } }
internal static MyMeshMaterialId GetMaterialId(MyMaterialDescriptor importDesc, string contentPath, string assetFile = null) { MyMeshMaterialInfo info; if (importDesc != null) { info = ConvertImportDescToMeshMaterialInfo(importDesc, contentPath, assetFile); } else { return(NullMaterialId); } return(GetMaterialId(ref info, assetFile)); }
public Vector4I[] CreateTextureIndices(List <MyMeshPartInfo> partInfos, int verticesNum, string contentPath) { Vector4I[] indices = new Vector4I[verticesNum]; for (int i = 0; i < verticesNum; i++) { indices[i] = new Vector4I(DEFAULT_ARRAY_TEXTURE_INDEX, DEFAULT_ARRAY_TEXTURE_INDEX, DEFAULT_ARRAY_TEXTURE_INDEX, DEFAULT_ARRAY_TEXTURE_INDEX); } if (!MyRender11.Settings.UseGeometryArrayTextures) // system is disabled { return(indices); } foreach (MyMeshPartInfo partInfo in partInfos) { MyMaterialDescriptor materialDesc = partInfo.m_MaterialDesc; if (materialDesc == null) { continue; } string cmTexture, ngTexture, extTexture, alphamaskTexture; if (!materialDesc.Textures.TryGetValue("ColorMetalTexture", out cmTexture)) { continue; } if (!materialDesc.Textures.TryGetValue("NormalGlossTexture", out ngTexture)) { continue; } materialDesc.Textures.TryGetValue("AddMapsTexture", out extTexture); materialDesc.Textures.TryGetValue("AlphamaskTexture", out alphamaskTexture); cmTexture = MyResourceUtils.GetTextureFullPath(cmTexture, contentPath); ngTexture = MyResourceUtils.GetTextureFullPath(ngTexture, contentPath); extTexture = MyResourceUtils.GetTextureFullPath(extTexture, contentPath); alphamaskTexture = MyResourceUtils.GetTextureFullPath(alphamaskTexture, contentPath); Vector4I textureIndices = GetTextureIndices(cmTexture, ngTexture, extTexture, alphamaskTexture); foreach (var offset in partInfo.m_indices) { indices[offset] = textureIndices; } } return(indices); }
public void SetMaterial(Material material) { int hashCode = material.Name.GetHashCode(); if (!this.m_partContainer.ContainsKey(hashCode)) { return; } MyMeshPartInfo myMeshPartInfo = this.m_partContainer[hashCode]; MyMaterialDescriptor matDesc = new MyMaterialDescriptor(material.Name); this.SetMaterialTextures(matDesc, material); if (myMeshPartInfo.m_MaterialDesc != null) { matDesc.Technique = myMeshPartInfo.m_MaterialDesc.Technique; } myMeshPartInfo.m_MaterialDesc = matDesc; }
public static MyMeshMaterialInfo ConvertImportDescToMeshMaterialInfo(MyMaterialDescriptor importDesc, string contentPath, string assetFile = null) { string colorMetalTexture = importDesc.Textures.Get("ColorMetalTexture", ""); string normalGlossTexture = importDesc.Textures.Get("NormalGlossTexture", ""); string extensionTexture = importDesc.Textures.Get("AddMapsTexture", ""); string alphamaskTexture = importDesc.Textures.Get("AlphamaskTexture", null); MyMeshMaterialInfo info = new MyMeshMaterialInfo { Name = X.TEXT_(importDesc.MaterialName), ColorMetal_Texture = MyResourceUtils.GetTextureFullPath(colorMetalTexture, contentPath), NormalGloss_Texture = MyResourceUtils.GetTextureFullPath(normalGlossTexture, contentPath), Extensions_Texture = MyResourceUtils.GetTextureFullPath(extensionTexture, contentPath), Alphamask_Texture = MyResourceUtils.GetTextureFullPath(alphamaskTexture, contentPath), TextureTypes = GetMaterialTextureTypes(colorMetalTexture, normalGlossTexture, extensionTexture, alphamaskTexture), Technique = ConvertToDrawTechnique(importDesc.Technique), Facing = importDesc.Facing, WindScaleAndFreq = importDesc.WindScaleAndFreq }; return(info); }
internal static MyMeshMaterialId GetMaterialId(MyMaterialDescriptor importDesc, string contentPath) { MyMeshMaterialInfo desc; if (importDesc != null) { desc = new MyMeshMaterialInfo { Name = X.TEXT(importDesc.MaterialName), ContentPath = contentPath, ColorMetal_Texture = MyStringId.GetOrCompute(importDesc.Textures.Get("ColorMetalTexture", "")), NormalGloss_Texture = MyStringId.GetOrCompute(importDesc.Textures.Get("NormalGlossTexture", "")), Extensions_Texture = MyStringId.GetOrCompute(importDesc.Textures.Get("AddMapsTexture", "")), Alphamask_Texture = MyStringId.GetOrCompute(importDesc.Textures.Get("AlphamaskTexture", null)), Technique = importDesc.Technique }; } else { return(NullMaterialId); } return(GetMaterialId(ref desc)); }
/// <summary> /// c-tor - generic way for collecting resources /// </summary> /// <param name="meshInfo"></param> /// assetName - just for debug output public MyMesh(MyMeshPartInfo meshInfo, string assetName) { string textureName = null; MyMaterialDescriptor matDesc = meshInfo.m_MaterialDesc; if (matDesc != null) { bool hasNormalTexture = true; string texName = matDesc.m_DiffuseTextureName; if (String.IsNullOrEmpty(texName) == false) { int i = texName.LastIndexOf(C_CONTENT_ID); texName = texName.Substring(i + C_CONTENT_ID.Length, texName.Length - i - C_CONTENT_ID.Length); //@ cut extension int lastIndex = texName.LastIndexOf("."); textureName = texName.Substring(0, texName.Length - (texName.Length - lastIndex)); if (textureName.LastIndexOf(C_POSTFIX_DONT_HAVE_NORMAL) == (textureName.Length - C_POSTFIX_DONT_HAVE_NORMAL.Length)) { hasNormalTexture = false; textureName = textureName.Substring(0, textureName.Length - C_POSTFIX_DONT_HAVE_NORMAL.Length); } //@ if postfix for diffuse is _d -> trim it if (textureName.LastIndexOf(C_POSTFIX_DIFFUSE) == (textureName.Length - 2)) { textureName = textureName.Substring(0, textureName.Length - 2); } if (textureName.LastIndexOf(C_POSTFIX_DIFFUSE_EMISSIVE) == (textureName.Length - 3)) { textureName = textureName.Substring(0, textureName.Length - 3); } } var defaultMaterial = new MyMeshMaterial(matDesc.MaterialName, textureName + C_POSTFIX_DIFFUSE_EMISSIVE, textureName + C_POSTFIX_NORMAL_SPECULAR, matDesc.m_Glossiness, hasNormalTexture, ref matDesc.m_DiffuseColor, ref matDesc.m_SpecularColor); // check for alternative textures and create corresponding materials. if (!textureName.Contains(DEFAULT_DIRECTORY)) { Materials = new MyMeshMaterial[8]; for (int j = 1; j < Materials.Length; j++) { Materials[j] = defaultMaterial; } } else { int materialCount = FindMaterialCount(textureName); Materials = new MyMeshMaterial[materialCount]; // here check if corresponding textures exist in the "v02" or "v03" ... // folder. If not, fall back to default "v01" folder for (int j = 1; j < Materials.Length; j++) { string newFolder = "\\v" + String.Format("{0:00}", j + 1) + "\\"; string newNameDiffuse = textureName.Replace(DEFAULT_DIRECTORY, newFolder) + C_POSTFIX_DIFFUSE_EMISSIVE; string newNameNormal = textureName.Replace(DEFAULT_DIRECTORY, newFolder) + C_POSTFIX_NORMAL_SPECULAR; string diffusepath = Path.Combine(MyMinerGame.Static.RootDirectory, newNameDiffuse) + ".dds"; if (!File.Exists(diffusepath)) { newNameDiffuse = textureName + C_POSTFIX_DIFFUSE_EMISSIVE; } if (!File.Exists(Path.Combine(MyMinerGame.Static.RootDirectory, newNameNormal) + ".dds")) { newNameNormal = textureName + C_POSTFIX_NORMAL_SPECULAR; } Materials[j] = new MyMeshMaterial(matDesc.MaterialName, newNameDiffuse, newNameNormal, matDesc.m_Glossiness, hasNormalTexture, ref matDesc.m_DiffuseColor, ref matDesc.m_SpecularColor); } } Materials[0] = defaultMaterial; } else { //It is OK because ie. collision meshes dont have materials //MyCommonDebugUtils.AssertRelease(false, String.Format("Model {0} has bad material for mesh.", assetName)); Trace.TraceWarning("Model with null material: " + assetName); //We define at least debug material MinerWarsMath.Vector3 color = MinerWarsMath.Color.Pink.ToVector3(); Materials = new MyMeshMaterial[8]; Materials[0] = new MyMeshMaterial("", "Textures2\\Models\\Prefabs\\v01\\v01_cargo_box_de", "Textures2\\Models\\Prefabs\\v01\\v01_cargo_box_ns", 0, true, ref color, ref color); for (int j = 1; j < Materials.Length; j++) { Materials[j] = Materials[0]; } } for (int i = 0; i < Materials.Length; i++) { Materials[i].DrawTechnique = meshInfo.m_MeshRenderTechnique; } m_assetName = assetName; }
protected override string GenerateMaterialName(MyMaterialDescriptor desc) { return(ComputeHash(desc).ToLimitedString(desc.MaterialName.Length)); }
/// <summary> /// c-tor - generic way for collecting resources /// </summary> /// <param name="meshInfo"></param> /// assetName - just for debug output public MyRenderMesh(MyMeshPartInfo meshInfo, string assetName) { string contentDir = ""; if (Path.IsPathRooted(assetName) && assetName.ToLower().Contains("models")) { contentDir = assetName.Substring(0, assetName.ToLower().IndexOf("models")); } MyMaterialDescriptor matDesc = meshInfo.m_MaterialDesc; if (matDesc != null) { bool hasNormalTexture = true; string normalPath = null; string diffusePath; matDesc.Textures.TryGetValue("DiffuseTexture", out diffusePath); matDesc.Textures.TryGetValue("NormalTexture", out normalPath); if (String.IsNullOrEmpty(normalPath) && !String.IsNullOrEmpty(diffusePath)) { if (String.IsNullOrEmpty(diffusePath)) { diffusePath = null; normalPath = null; } else { string ext = Path.GetExtension(diffusePath); string deMatch = C_POSTFIX_DIFFUSE_EMISSIVE + ext; string meMatch = C_POSTFIX_MASK_EMISSIVE + ext; if (diffusePath.EndsWith(deMatch)) { normalPath = diffusePath.Substring(0, diffusePath.Length - deMatch.Length) + C_POSTFIX_NORMAL_SPECULAR + ext; } else if (diffusePath.EndsWith(meMatch)) { normalPath = diffusePath.Substring(0, diffusePath.Length - meMatch.Length) + C_POSTFIX_NORMAL_SPECULAR + ext; } else { normalPath = null; } } } Material = new MyRenderMeshMaterial(matDesc.MaterialName, contentDir, diffusePath, normalPath, matDesc.SpecularPower, matDesc.SpecularIntensity, hasNormalTexture, matDesc.DiffuseColor, matDesc.ExtraData); Material.DrawTechnique = meshInfo.Technique; m_assetName = assetName; } else { //It is OK because ie. collision meshes dont have materials //MyCommonDebugUtils.AssertRelease(false, String.Format("Model {0} has bad material for mesh.", assetName)); Trace.TraceWarning("Model with null material: " + assetName); //We define at least debug material VRageMath.Vector3 color = VRageMath.Color.Pink.ToVector3(); Material = new MyRenderMeshMaterial("", "", @"Textures\Models\Debug\white_de.dds", @"Textures\Models\Debug\white_ns.dds", 0, 0, true, color, color); } }
internal static MyMeshMaterialId GetMaterialId(MyMaterialDescriptor importDesc, string contentPath, string assetFile = null) { MyMeshMaterialInfo desc; if (importDesc != null) { string colorMetalTexture = importDesc.Textures.Get("ColorMetalTexture", ""); string normalGlossTexture = importDesc.Textures.Get("NormalGlossTexture", ""); string extensionTexture = importDesc.Textures.Get("AddMapsTexture", ""); string alphamaskTexture = importDesc.Textures.Get("AlphamaskTexture", null); desc = new MyMeshMaterialInfo { Name = X.TEXT_(importDesc.MaterialName), ContentPath = contentPath, ColorMetal_Texture = X.TEXT_(colorMetalTexture), NormalGloss_Texture = X.TEXT_(normalGlossTexture), Extensions_Texture = X.TEXT_(extensionTexture), Alphamask_Texture = X.TEXT_(alphamaskTexture), TextureTypes = GetMaterialTextureTypes(colorMetalTexture, normalGlossTexture, extensionTexture, alphamaskTexture), Technique = ConvertToDrawTechnique(importDesc.Technique), Facing = importDesc.Facing, WindScaleAndFreq = importDesc.WindScaleAndFreq }; } else { return NullMaterialId; } return GetMaterialId(ref desc, assetFile); }