public static CubemapWrapper fetchCubeMap(TextureWrapper textureWrapper)
        {
            bool cubemapExists = CubemapList.ContainsKey(textureWrapper.Name);

            if (cubemapExists)
            {
                return(CubemapList[textureWrapper.Name]);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
 private void Cache()
 {
     if (!cached)
     {
         FieldInfo[] fields = this.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
         foreach (FieldInfo field in fields)
         {
             String name = field.Name;
             //texture
             if (field.FieldType == typeof(TextureWrapper))
             {
                 TextureWrapper texture = (TextureWrapper)field.GetValue(this);
                 if (texture != null)
                 {
                     bool isNormal  = Attribute.IsDefined(field, typeof(BumpMap));
                     bool isClamped = Attribute.IsDefined(field, typeof(Clamped));
                     int  index     = Attribute.IsDefined(field, typeof(Index)) ? ((Index)Attribute.GetCustomAttribute(field, typeof(Index))).value: 0;
                     texture.IsNormal  = isNormal;
                     texture.IsClamped = isClamped;
                     texture.Index     = index;
                     cache.Add(name, texture);
                 }
                 else
                 {
                     cache.Add(name, null);
                 }
             }
             else
             {
                 bool isScaled    = Attribute.IsDefined(field, typeof(Scaled));
                 bool isInvScaled = Attribute.IsDefined(field, typeof(InverseScaled));
                 int  id          = Shader.PropertyToID(name);
                 if (isScaled)
                 {
                     cache.Add(id, new ScaledValue(field.GetValue(this)));
                 }
                 else if (isInvScaled)
                 {
                     cache.Add(id, new InverseScaledValue(field.GetValue(this)));
                 }
                 else
                 {
                     cache.Add(id, field.GetValue(this));
                 }
             }
         }
         cached = true;
     }
 }
        public static bool alphaMaskEval(ConfigNode node)
        {
            TextureWrapper test = new TextureWrapper();

            ConfigHelper.LoadObjectFromConfig(test, node);

            if ((test.type & TextureTypeEnum.AlphaMapMask) > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        private void ApplyCache(Material material, float scale = 1.0f)
        {
            foreach (KeyValuePair <object, object> field in cache)
            {
                object obj        = field.Value;
                float  scaleValue = 1f;
                if (obj != null && obj.GetType() == typeof(ScaledValue))
                {
                    obj        = ((ScaledValue)obj).obj;
                    scaleValue = scale;
                }
                else if (obj != null && obj.GetType() == typeof(InverseScaledValue))
                {
                    obj        = ((InverseScaledValue)obj).obj;
                    scaleValue = 1 / scale;
                }

                if (obj.GetType() == typeof(TextureWrapper))
                {
                    TextureWrapper value = (TextureWrapper)obj;
                    value.ApplyTexture(material, (String)field.Key);
                }
                //float
                else if (obj.GetType() == typeof(float))
                {
                    float value = (float)obj;
                    material.SetFloat((int)field.Key, value * scaleValue);
                }
                //Color
                else if (obj.GetType() == typeof(Color))
                {
                    Color value = (Color)obj;
                    material.SetColor((int)field.Key, value / 256f);
                }
                //Color32
                else if (obj.GetType() == typeof(Color32))
                {
                    Color32 value = (Color32)obj;
                    material.SetColor((int)field.Key, value);
                }//Vector2
                else if (obj.GetType() == typeof(Vector2))
                {
                    Vector2 value = (Vector2)obj;
                    material.SetVector((int)field.Key, value * scaleValue);
                }
                //Vector3
                else if (obj.GetType() == typeof(Vector3))
                {
                    Vector3 value = (Vector3)obj;
                    material.SetVector((int)field.Key, value * scaleValue);
                }
                //Vector4
                else if (obj.GetType() == typeof(Vector4))
                {
                    Vector4 value = (Vector4)obj;
                    material.SetVector((int)field.Key, value * scaleValue);
                }
                //Matrix
                else if (obj.GetType() == typeof(Matrix4x4))
                {
                    Matrix4x4 value = (Matrix4x4)obj;
                    material.SetMatrix((int)field.Key, value);
                }
                //bool
                else if (obj.GetType() == typeof(bool))
                {
                    bool value = (bool)obj;
                    if (value)
                    {
                        material.EnableKeyword((String)field.Key);
                    }
                    else
                    {
                        material.DisableKeyword((String)field.Key);
                    }
                }
                //enum
                else if (obj.GetType().IsEnum)
                {
                    String value = Enum.GetName(obj.GetType(), obj);
                    material.EnableKeyword(value);
                }
            }
        }
 public static bool alphaMaskEval(ConfigNode node)
 {
     TextureWrapper test = new TextureWrapper();
     ConfigHelper.LoadObjectFromConfig(test, node);
     
     if ((test.type & TextureTypeEnum.AlphaMapMask) > 0)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
 public static CubemapWrapper fetchCubeMap(TextureWrapper textureWrapper)
 {
     bool cubemapExists = CubemapList.ContainsKey(textureWrapper.Name);
     if (cubemapExists)
     {
         return CubemapList[textureWrapper.Name];
     }
     else
     {
         return null;
     }
 }