/// <summary> /// Inits the specified hud label text. /// </summary> /// <param name="hudLabelText">The hud label text.</param> /// <param name="objectBuilder">The object builder.</param> public void Init(string hudLabelText, MyMwcObjectBuilder_StaticAsteroid objectBuilder, Matrix matrix) { MyStaticAsteroidModels models = GetModelsFromType(objectBuilder.AsteroidType); StringBuilder hudLabelTextSb = (hudLabelText == null) ? null : new StringBuilder(hudLabelText); if (objectBuilder.Generated) { Flags &= ~EntityFlags.EditableInEditor; Flags &= ~EntityFlags.NeedsId; } else { Flags |= EntityFlags.EditableInEditor; Flags |= EntityFlags.NeedsId; } CastShadows = !objectBuilder.Generated; if (!objectBuilder.AsteroidMaterial1.HasValue && MySector.Area.HasValue) { var area = MySolarSystemConstants.Areas[MySector.Area.Value]; objectBuilder.AsteroidMaterial1 = area.SecondaryStaticAsteroidMaterial; objectBuilder.FieldDir = MinerWars.AppCode.Game.GUI.MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized(); } NeedsUpdate = false; Init(hudLabelTextSb, models.LOD0, models.LOD1, null, null, objectBuilder, null, models.LOD2); AsteroidType = objectBuilder.AsteroidType; SetWorldMatrix(matrix); FieldDir = objectBuilder.FieldDir; if (objectBuilder.AsteroidMaterial.HasValue) { VoxelMaterial = objectBuilder.AsteroidMaterial.Value; VoxelMaterial1 = objectBuilder.AsteroidMaterial1; m_drawTechnique = MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID; } if (objectBuilder.UseModelTechnique) { m_meshMaterial = MyVoxelMaterials.GetMaterialForMesh(VoxelMaterial); m_drawTechnique = MyMeshDrawTechnique.MESH; } InitDrawTechniques(); InitPhysics(); MyModels.OnContentLoaded += InitDrawTechniques; InitDrawTechniques(); }
/// <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; }
static void Add(MyMwcVoxelMaterialsEnum materialEnum, string assetName, bool isIndestructible, bool useTwoTextures, float specularShininess, float specularPower, bool hasBuilderVersion) { // Check if not yet assigned MyCommonDebugUtils.AssertRelease(m_materials[(int)materialEnum] == null); //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("new MyVoxelMaterial"); // Create and add into array MyVoxelMaterial voxelMaterial = new MyVoxelMaterial(materialEnum, assetName, isIndestructible, useTwoTextures, specularShininess, specularPower, hasBuilderVersion); m_materials[(int)materialEnum] = voxelMaterial; m_meshMaterials[(int)materialEnum] = new MyMeshMaterial("Textures\\Voxels\\" + assetName + "_ForAxisXZ", assetName, voxelMaterial.GetTextures().TextureDiffuseForAxisXZ, voxelMaterial.GetTextures().TextureNormalMapForAxisXZ); }
static void SetupShaderForMaterialAlternative(MyEffectBase shader, MyMeshMaterial material) { switch (material.DrawTechnique) { case MyMeshDrawTechnique.MESH: case MyMeshDrawTechnique.DECAL: case MyMeshDrawTechnique.HOLO: case MyMeshDrawTechnique.ALPHA_MASKED: { if (material != null) { shader.SetTextureDiffuse(material.DiffuseTexture); shader.SetTextureNormal(material.NormalTexture); //Do we need this? Graphicians dont use this //shader.SetDiffuseColor(material.DiffuseColor); shader.SetSpecularIntensity(material.SpecularIntensity); shader.SetSpecularPower(material.SpecularPower); shader.SetDiffuseUVAnim(material.DiffuseUVAnim); shader.SetEmissivityUVAnim(material.EmissiveUVAnim); shader.SetEmissivityOffset(material.EmissivityOffset); if (material.DrawTechnique == MyMeshDrawTechnique.HOLO) { shader.SetEmissivity(material.HoloEmissivity); } // Commented due 856 - graphicians have to reexport white diffuse colors from MAX //shader.SetDiffuseColor(material.DiffuseColor); } else { shader.SetTextureDiffuse(null); shader.SetTextureNormal(null); shader.SetSpecularPower(1); shader.SetSpecularIntensity(1); //this value is set from object if not from material //shader.SetDiffuseColor(material.DiffuseColor); } if (CheckDiffuseTextures) { if (!shader.IsTextureDiffuseSet()) { LazyLoadDebugTextures(); shader.SetTextureDiffuse(m_debugTexture); shader.SetDiffuseColor(Vector3.One); shader.SetEmissivity(1); } else { if (material.DrawTechnique != MyMeshDrawTechnique.HOLO) { shader.SetEmissivity(0); } } } if (CheckNormalTextures) { if (!shader.IsTextureNormalSet()) { LazyLoadDebugTextures(); shader.SetTextureDiffuse(m_debugTexture); shader.SetEmissivity(1); } else { shader.SetTextureDiffuse(material.NormalTexture); //shader.SetTextureDiffuse(m_debugNormalTexture); shader.SetEmissivity(0); } } if (!shader.IsTextureNormalSet()) { LazyLoadDebugTextures(); shader.SetTextureNormal(m_debugTexture); } } break; case MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID: case MyMeshDrawTechnique.VOXELS_DEBRIS: break; default: { throw new MyMwcExceptionApplicationShouldNotGetHere(); } } }
/// <summary> /// SetupShader /// </summary> /// <param name="shader"></param> public static MyEffectBase SetupShaderForMaterial(MyMeshMaterial material, MyVoxelCacheCellRenderBatch voxelBatch) { switch (material.DrawTechnique) { case MyMeshDrawTechnique.MESH: case MyMeshDrawTechnique.DECAL: case MyMeshDrawTechnique.HOLO: case MyMeshDrawTechnique.ALPHA_MASKED: { MyEffectModelsDNS shader = GetEffect(MyEffects.ModelDNS) as MyEffectModelsDNS; if (material != null) { shader.SetTextureDiffuse(material.DiffuseTexture); shader.SetTextureNormal(material.NormalTexture); //Do we need this? Graphicians dont use this //shader.SetDiffuseColor(material.DiffuseColor); shader.SetSpecularIntensity(material.SpecularIntensity); shader.SetSpecularPower(material.SpecularPower); shader.SetDiffuseUVAnim(material.DiffuseUVAnim); shader.SetEmissivityUVAnim(material.EmissiveUVAnim); shader.SetEmissivityOffset(material.EmissivityOffset); if (material.DrawTechnique == MyMeshDrawTechnique.HOLO) { shader.SetEmissivity(material.HoloEmissivity); } // Commented due 856 - graphicians have to reexport white diffuse colors from MAX //shader.SetDiffuseColor(material.DiffuseColor); } else { shader.SetTextureDiffuse(null); shader.SetTextureNormal(null); shader.SetSpecularPower(1); shader.SetSpecularIntensity(1); //this value is set from object if not from material //shader.SetDiffuseColor(material.DiffuseColor); } if (CheckDiffuseTextures) { if (!shader.IsTextureDiffuseSet()) { LazyLoadDebugTextures(); shader.SetTextureDiffuse(m_debugTexture); shader.SetDiffuseColor(Vector3.One); shader.SetEmissivity(1); } else { if (material.DrawTechnique != MyMeshDrawTechnique.HOLO) { shader.SetEmissivity(0); } } } if (CheckNormalTextures) { if (!shader.IsTextureNormalSet()) { LazyLoadDebugTextures(); shader.SetTextureDiffuse(m_debugTexture); shader.SetEmissivity(1); } else { shader.SetTextureDiffuse(material.NormalTexture); //shader.SetTextureDiffuse(m_debugNormalTexture); shader.SetEmissivity(0); } } if (!shader.IsTextureNormalSet()) { LazyLoadDebugTextures(); shader.SetTextureNormal(m_debugTexture); } return shader; } break; case MyMeshDrawTechnique.VOXELS_DEBRIS: { MyEffectVoxelsDebris effectVoxelsDebris = GetEffect(MyEffects.VoxelDebrisMRT) as MyEffectVoxelsDebris; return effectVoxelsDebris; } break; case MyMeshDrawTechnique.VOXEL_MAP: { MyEffectVoxels effectVoxels = MyRender.GetEffect(MyEffects.VoxelsMRT) as MyEffectVoxels; if (voxelBatch.Type == MyVoxelCacheCellRenderBatchType.SINGLE_MATERIAL) { effectVoxels.UpdateVoxelTextures(OverrideVoxelMaterial ?? voxelBatch.Material0); } else if (voxelBatch.Type == MyVoxelCacheCellRenderBatchType.MULTI_MATERIAL) { effectVoxels.UpdateVoxelMultiTextures(OverrideVoxelMaterial ?? voxelBatch.Material0, OverrideVoxelMaterial ?? voxelBatch.Material1, OverrideVoxelMaterial ?? voxelBatch.Material2); } return effectVoxels; } break; case MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID: { MyEffectVoxelsStaticAsteroid effectVoxelsStaticAsteroid = GetEffect(MyEffects.VoxelStaticAsteroidMRT) as MyEffectVoxelsStaticAsteroid; return effectVoxelsStaticAsteroid; } break; default: { throw new MyMwcExceptionApplicationShouldNotGetHere(); } } return null; }