private bool BuildMaterial(Wm3Texture texture, float ambient, LevelTextureType textureType, out Material material, out Sprite sprite) { bool ret = true; LevelTexture levelTexture = m_levelTextures.Find(x => x.Has(texture, ambient, textureType)); //no material was found - create new one if (levelTexture == null) { ret = Construct(texture, ambient, textureType, out levelTexture); } if (ret) { material = levelTexture.Material; sprite = levelTexture.Sprite; } else { material = null; sprite = null; Debug.LogWarning("MaterialManager.BuildMaterial: unable to build Material"); } return(ret); }
private bool BuildMaterial(Wm3Texture texture, float ambient) { if (TemplateMaterials.IsInitialized) { float alpha = 1.0f; float albedo = texture.Albedo; m_ambient = CalculateAmbient(texture, ambient, m_textureType); if (m_textureType == LevelTextureType.SPRITE) { if (texture.Flags.IsSet(Wm3Flags.Ghost) || texture.Flags.IsSet(Wm3Flags.Diaphanous)) { alpha = 0.7f; } m_material = new Material(TemplateMaterials.GetSprite()); } else { if (texture.Flags.IsSet(Wm3Flags.Ghost) || texture.Flags.IsSet(Wm3Flags.Diaphanous)) { m_material = new Material(TemplateMaterials.GetOverlay()); alpha = 0.7f; } else if (texture.Flags.IsSet(Wm3Flags.Sky)) { m_material = new Material(TemplateMaterials.GetSky()); albedo = 0; } else if (m_textureType == LevelTextureType.OVERLAY) { m_material = new Material(TemplateMaterials.GetOverlay()); } else { m_material = new Material(TemplateMaterials.GetSolid()); } } m_material.renderQueue = -1; //force shader render queue in case template material was setup the wrong way m_material.mainTexture = m_sprite.texture; m_material.name = texture.Name + " A" + m_ambient.ToString("0.00"); if (m_textureType == LevelTextureType.SPRITE) { m_material.name += "S"; } Color col = new Color(m_ambient, m_ambient, m_ambient, alpha); m_material.color = col; m_material.SetFloat("_Diffuse", albedo * 0.01f); return(true); } else { Debug.LogError("LevelTexture.BuildMaterial: BaseMaterial not configured"); m_material = null; return(false); } }
private float CalculateAmbient(Wm3Texture texture, float ambient, LevelTextureType textureType) { float ambient_sum; switch (textureType) { case LevelTextureType.SPRITE: { //WM3 format already merges texture and object ambient (special treatment for A8 engine) //--> only use object ambient and drop any texture ambient ambient_sum = (ambient * 0.01f) + 0.5f; break; } case LevelTextureType.SKY: { //sky does not receive mesh specific ambient ambient_sum = (texture.Ambient * 0.01f) + 0.5f; break; } default: { //add mesh specific ambient to texture ambient ambient_sum = ((texture.Ambient + ambient) * 0.01f) + 0.5f; break; } } return(ambient_sum); }
private bool Construct(Wm3Texture texture, float ambient, LevelTextureType textureType, out LevelTexture levelTexture) { bool ret = false; levelTexture = new LevelTexture(m_searchFolder); if (levelTexture.Construct(texture, ambient, textureType)) { m_levelTextures.Add(levelTexture); AssetDatabase.CreateAsset(levelTexture.Material, m_outputFolder + "/" + levelTexture.Material.name + ".mat"); ret = true; } return(ret); }
public bool Has(Wm3Texture texture, float ambient, LevelTextureType textureType) { bool ret = false; ambient = CalculateAmbient(texture, ambient, textureType); if ( (m_textureReference != null) && (m_textureReference == texture) && (Convert.ToInt32((ambient * 100) - (m_ambient * 100)) == 0) && (m_textureType == textureType) ) { ret = true; } return(ret); }
public bool Link(Wm3Texture[] textures) { bool success = false; if (m_loaded) { if (textures.Length > m_textureRef) { m_texture = textures[m_textureRef]; success = true; } } return(success); }
private float CalculateAmbient(Wm3Texture texture, float ambient, LevelTextureType textureType) { float ambient_sum; if (textureType == LevelTextureType.SPRITE) { //WM3 format already merges texture and object ambient (special treatment for A8 engine) //--> only use object ambient and drop any texture ambient ambient_sum = (ambient * 0.01f) + 0.5f; } else { //add mesh specific ambient to texture ambient ambient_sum = ((texture.Ambient + ambient) * 0.01f) + 0.5f; } return(ambient_sum); }
public bool Construct(Wm3Texture texture, float ambient, LevelTextureType textureType) { bool success = true; m_textureReference = texture; m_textureType = textureType; success = (texture != null); if (success) { success = SetupTexture(texture); } if (success) { success = BuildMaterial(texture, ambient); } return(success); }
private bool SetupTexture(Wm3Texture texture) { //A3 models were referenced as texture, but did not have bitmaps assigned. Skip those here //all textures are of Wm3 sprite type. Not to be confused with Unity sprite 3D objects! if (texture.IsSprite()) { //this is a hack. a texture could have multiple bitmaps, so multiple textures should be created not just the first one Wm3Bitmap bitmap = texture.Bitmaps[0]; bool sky = false; if (texture.Flags.IsSet(Wm3Flags.Sky)) { sky = true; } SpriteLocator locator = new SpriteLocator(m_searchFolder); m_sprite = locator.LocateAndConfigure(bitmap.FileName, sky); return(true); } else { //A3 MDL format currently not handled return(false); } }
public bool Has(Wm3Texture texture, float ambient, LevelTextureType textureType) { bool ret = false; //sky requires special ambient treatment if (texture.Flags.IsSet(Wm3Flags.Sky)) { ambient = CalculateAmbient(texture, ambient, LevelTextureType.SKY); } else { ambient = CalculateAmbient(texture, ambient, textureType); } if ( (m_textureReference != null) && (m_textureReference == texture) && (Convert.ToInt32((ambient * 100) - (m_ambient * 100)) == 0) && (m_textureType == textureType) ) { ret = true; } return(ret); }
public bool BuildObjectMaterial(Wm3Texture texture, float ambient, out Material material, out Sprite sprite) { return(BuildMaterial(texture, ambient, LevelTextureType.SPRITE, out material, out sprite)); }