Exemple #1
0
        public bool BuildMeshMaterials(Wm3Texture[] textures, float ambient, bool isOverlay, out Material[] materials)
        {
            bool             ret         = true;
            LevelTextureType textureType = LevelTextureType.STANDARD;

            if (isOverlay)
            {
                textureType = LevelTextureType.OVERLAY;
            }
            int count = textures.Length;

            materials = new Material[count];
            for (int j = 0; j < count; j++)
            {
                Material material;
                Sprite   sprite;
                if (BuildMaterial(textures[j], ambient, textureType, out material, out sprite))
                {
                    materials[j] = material;
                }
                else
                {
                    Debug.LogWarning("MaterialManager.BuildMaterials: unable to build all Materials");
                    ret = false;
                }
            }

            return(ret);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
        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);
        }
Exemple #8
0
        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);
        }