コード例 #1
0
        public void ApplyMaterial(Utl.MaterialInformation info)
        {
            bool isChanged = false;

            var previous_selfSummary = selfSummary;
            var previous_selfDetail  = selfDetail;

            if (info.Names.ContainsKey(Core.Language))
            {
                selfSummary = info.Names[Core.Language];
            }
            else
            {
                selfSummary = "";
            }


            if (info.Descriptions.ContainsKey(Core.Language))
            {
                selfDetail = info.Descriptions[Core.Language];
            }
            else
            {
                selfDetail = "";
            }

            if (previous_selfSummary != selfSummary)
            {
                isChanged = true;
            }
            if (previous_selfDetail != selfDetail)
            {
                isChanged = true;
            }

            HashSet <ValueStatus> usedValueStatuses = new HashSet <ValueStatus>();
            HashSet <object>      finished          = new HashSet <object>();

            foreach (var withNameFlag in new[] { false, true })
            {
                foreach (var texture in info.Textures)
                {
                    if (finished.Contains(texture))
                    {
                        continue;
                    }

                    var key = StatusKey.From(texture);

                    Func <string> getName = () =>
                    {
                        var ret = "";
                        if (texture.Summaries.ContainsKey(Core.Language))
                        {
                            ret = texture.Summaries[Core.Language];
                        }

                        if (string.IsNullOrEmpty(ret))
                        {
                            ret = texture.Name;
                        }

                        if (string.IsNullOrEmpty(ret))
                        {
                            ret = texture.UniformName;
                        }

                        return(ret);
                    };

                    Func <string> getDesc = () =>
                    {
                        var ret = "";
                        if (texture.Descriptions.ContainsKey(Core.Language))
                        {
                            ret = texture.Descriptions[Core.Language];
                        }

                        return(ret);
                    };

                    ValueStatus status      = null;
                    string      defaultPath = Utils.Misc.GetAbsolutePath(Path.AbsolutePath, texture.DefaultPath);

                    var foundValue = FindValue(key.ToString(), usedValueStatuses, withNameFlag);
                    if (foundValue != null)
                    {
                        status = foundValue;
                        if (status.IsShown != texture.IsParam)
                        {
                            status.IsShown = texture.IsParam;
                            isChanged      = true;
                        }

                        // update default path
                        if (texture.IsParam)
                        {
                            if ((foundValue.Value as Value.PathForImage).AbsolutePath == string.Empty)
                            {
                                (foundValue.Value as Value.PathForImage).SetAbsolutePathDirectly(defaultPath);
                                isChanged = true;
                            }

                            (foundValue.Value as Value.PathForImage).SetDefaultAbsolutePath(defaultPath);
                        }
                        else
                        {
                            if ((foundValue.Value as Value.PathForImage).AbsolutePath != defaultPath)
                            {
                                (foundValue.Value as Value.PathForImage).SetAbsolutePathDirectly(defaultPath);
                                isChanged = true;
                            }

                            (foundValue.Value as Value.PathForImage).SetDefaultAbsolutePath(defaultPath);
                        }
                    }
                    else
                    {
                        // create only when value is not found even if withName flag is true
                        if (!withNameFlag)
                        {
                            continue;
                        }

                        status = new ValueStatus();
                        var value = new Value.PathForImage(rcValues.BasePath, Resources.GetString("ImageFilter"), true, texture.DefaultPath);
                        status.Value    = value;
                        status.IsShown  = texture.IsParam;
                        status.Priority = texture.Priority;
                        valueStatuses.Add(status);

                        if (!string.IsNullOrEmpty(defaultPath))
                        {
                            value.SetAbsolutePathDirectly(defaultPath);
                        }

                        isChanged = true;
                    }

                    if (status.Name != getName())
                    {
                        isChanged = true;
                    }
                    if (status.Description != getDesc())
                    {
                        isChanged = true;
                    }

                    status.Key         = key;
                    status.Name        = getName();
                    status.Description = getDesc();
                    usedValueStatuses.Add(status);
                    finished.Add(texture);
                }

                foreach (var uniform in info.Uniforms)
                {
                    if (finished.Contains(uniform))
                    {
                        continue;
                    }

                    var key = StatusKey.From(uniform);

                    Func <string> getName = () =>
                    {
                        var ret = "";
                        if (uniform.Summaries.ContainsKey(Core.Language))
                        {
                            ret = uniform.Summaries[Core.Language];
                        }

                        if (string.IsNullOrEmpty(ret))
                        {
                            ret = uniform.Name;
                        }

                        if (string.IsNullOrEmpty(ret))
                        {
                            ret = uniform.UniformName;
                        }

                        return(ret);
                    };

                    Func <string> getDesc = () =>
                    {
                        var ret = "";
                        if (uniform.Descriptions.ContainsKey(Core.Language))
                        {
                            ret = uniform.Descriptions[Core.Language];
                        }

                        return(ret);
                    };

                    ValueStatus status = null;

                    var foundValue = FindValue(key.ToString(), usedValueStatuses, withNameFlag);
                    if (foundValue != null)
                    {
                        status = foundValue;

                        status.IsShown = true;
                        isChanged      = true;

                        if (uniform.Type == 0)
                        {
                            (status.Value as Value.Float).ChangeDefaultValue(uniform.DefaultValues[0]);
                        }
                        else if (uniform.Type == 1)
                        {
                            (status.Value as Value.Vector2D).ChangeDefaultValue(uniform.DefaultValues[0], uniform.DefaultValues[1]);
                        }
                        else if (uniform.Type == 2)
                        {
                            (status.Value as Value.Vector3D).ChangeDefaultValue(uniform.DefaultValues[0], uniform.DefaultValues[1], uniform.DefaultValues[2]);
                        }
                        else
                        {
                            (status.Value as Value.Vector4D).ChangeDefaultValue(uniform.DefaultValues[0], uniform.DefaultValues[1], uniform.DefaultValues[2], uniform.DefaultValues[3]);
                        }
                    }
                    else
                    {
                        // create only when value is not found even if withName flag is true
                        if (!withNameFlag)
                        {
                            continue;
                        }

                        if (uniform.Type == 0)
                        {
                            status = new ValueStatus();
                            var value = new Value.Float(uniform.DefaultValues[0]);
                            value.SetValueDirectly(uniform.DefaultValues[0]);
                            status.Value    = value;
                            status.IsShown  = true;
                            status.Priority = uniform.Priority;
                            valueStatuses.Add(status);
                            isChanged = true;
                        }
                        else if (uniform.Type == 1)
                        {
                            status = new ValueStatus();
                            var value = new Value.Vector2D(uniform.DefaultValues[0], uniform.DefaultValues[1]);
                            value.X.SetValueDirectly(uniform.DefaultValues[0]);
                            value.Y.SetValueDirectly(uniform.DefaultValues[1]);
                            status.Value    = value;
                            status.IsShown  = true;
                            status.Priority = uniform.Priority;
                            valueStatuses.Add(status);
                            isChanged = true;
                        }
                        else if (uniform.Type == 2)
                        {
                            status = new ValueStatus();
                            var value = new Value.Vector3D(uniform.DefaultValues[0], uniform.DefaultValues[1], uniform.DefaultValues[2]);
                            value.X.SetValueDirectly(uniform.DefaultValues[0]);
                            value.Y.SetValueDirectly(uniform.DefaultValues[1]);
                            value.Z.SetValueDirectly(uniform.DefaultValues[2]);
                            status.Value    = value;
                            status.IsShown  = true;
                            status.Priority = uniform.Priority;
                            valueStatuses.Add(status);
                            isChanged = true;
                        }
                        else
                        {
                            status = new ValueStatus();
                            var value = new Value.Vector4D(uniform.DefaultValues[0], uniform.DefaultValues[1], uniform.DefaultValues[2], uniform.DefaultValues[3]);
                            value.X.SetValueDirectly(uniform.DefaultValues[0]);
                            value.Y.SetValueDirectly(uniform.DefaultValues[1]);
                            value.Z.SetValueDirectly(uniform.DefaultValues[2]);
                            value.W.SetValueDirectly(uniform.DefaultValues[3]);
                            status.Value    = value;
                            status.IsShown  = true;
                            status.Priority = uniform.Priority;
                            valueStatuses.Add(status);
                            isChanged = true;
                        }
                    }

                    if (status.Name != getName())
                    {
                        isChanged = true;
                    }
                    if (status.Description != getDesc())
                    {
                        isChanged = true;
                    }

                    status.Key         = key;
                    status.Name        = getName();
                    status.Description = getDesc();
                    usedValueStatuses.Add(status);
                    finished.Add(uniform);
                }
            }

            foreach (var kts in valueStatuses)
            {
                if (!usedValueStatuses.Contains(kts))
                {
                    var status = kts;
                    if (status.IsShown)
                    {
                        status.IsShown = false;
                        isChanged      = true;
                    }
                }
            }

            if (info.CustomData.Count() > 0)
            {
                rcValues.CustomData1.Fixed4.ChangeDefaultValue(
                    info.CustomData[0].DefaultValues[0],
                    info.CustomData[0].DefaultValues[1],
                    info.CustomData[0].DefaultValues[2],
                    info.CustomData[0].DefaultValues[3]);
            }

            if (info.CustomData.Count() > 1)
            {
                rcValues.CustomData2.Fixed4.ChangeDefaultValue(
                    info.CustomData[1].DefaultValues[0],
                    info.CustomData[1].DefaultValues[1],
                    info.CustomData[1].DefaultValues[2],
                    info.CustomData[1].DefaultValues[3]);
            }

            if (isChanged && OnChanged != null)
            {
                OnChanged(this, null);
            }
        }
コード例 #2
0
        public void ApplyMaterial(Utl.MaterialInformation info)
        {
            bool isChanged = false;

            var textureKeys = info.Textures.Select(_ => CreateKey(_)).ToList();

            foreach (var kts in keyToValues)
            {
                if (!textureKeys.Contains(kts.Key))
                {
                    var status = valueToStatus[kts.Value];
                    if (status.IsShown)
                    {
                        status.IsShown = false;
                        isChanged      = true;
                    }
                }
            }

            var uniformKeys = info.Uniforms.Select(_ => CreateKey(_)).ToList();

            foreach (var kts in keyToValues)
            {
                if (!uniformKeys.Contains(kts.Key))
                {
                    var status = valueToStatus[kts.Value];
                    if (status.IsShown)
                    {
                        status.IsShown = false;
                        isChanged      = true;
                    }
                }
            }

            foreach (var texture in info.Textures)
            {
                var key = CreateKey(texture);

                if (keyToValues.ContainsKey(key))
                {
                    var value  = keyToValues[key];
                    var status = valueToStatus[value];
                    if (status.IsShown != texture.IsParam)
                    {
                        status.IsShown = texture.IsParam;
                        isChanged      = true;
                    }
                }
                else
                {
                    var status = new ValueStatus();
                    var value  = new Value.PathForImage(".png", false);
                    status.Name        = texture.Name;
                    status.Description = "";
                    status.IsShown     = texture.IsParam;
                    keyToValues.Add(key, value);
                    valueToStatus.Add(value, status);
                    value.SetAbsolutePathDirectly(texture.DefaultPath);
                    TextureValues.Add(value);
                    isChanged = true;
                }
            }

            foreach (var uniform in info.Uniforms)
            {
                var key = CreateKey(uniform);

                if (keyToValues.ContainsKey(key))
                {
                    var value  = keyToValues[key];
                    var status = valueToStatus[value];
                    if (!status.IsShown)
                    {
                        status.IsShown = true;
                        isChanged      = true;
                    }
                }
                else
                {
                    if (uniform.Type == 0)
                    {
                        var status = new ValueStatus();
                        var value  = new Value.Float();
                        status.Name        = uniform.Name;
                        status.Description = "";
                        status.IsShown     = true;
                        keyToValues.Add(key, value);
                        valueToStatus.Add(value, status);
                        UniformValues.Add(value);
                        isChanged = true;
                    }
                    else
                    {
                        var status = new ValueStatus();
                        var value  = new Value.Vector4D();
                        status.Name        = uniform.Name;
                        status.Description = "";
                        status.IsShown     = true;
                        keyToValues.Add(key, value);
                        valueToStatus.Add(value, status);
                        UniformValues.Add(value);
                        isChanged = true;
                    }
                }
            }

            if (isChanged && OnChanged != null)
            {
                OnChanged(this, null);
            }
        }
コード例 #3
0
        public void ApplyMaterial(Utl.MaterialInformation info)
        {
            bool isChanged = false;

            if (info.Names.ContainsKey(Core.Language))
            {
                selfSummary = info.Names[Core.Language];
            }
            else
            {
                selfSummary = "";
            }


            if (info.Descriptions.ContainsKey(Core.Language))
            {
                selfDetail = info.Descriptions[Core.Language];
            }
            else
            {
                selfDetail = "";
            }


            var textureKeys = info.Textures.Select(_ => CreateKey(_)).ToList();

            foreach (var kts in keyToValues)
            {
                if (!textureKeys.Contains(kts.Key))
                {
                    var status = kts.Value as ValueStatus;
                    if (status.IsShown)
                    {
                        status.IsShown = false;
                        isChanged      = true;
                    }
                }
            }

            var uniformKeys = info.Uniforms.Select(_ => CreateKey(_)).ToList();

            foreach (var kts in keyToValues)
            {
                if (!uniformKeys.Contains(kts.Key))
                {
                    var status = kts.Value as ValueStatus;
                    if (status.IsShown)
                    {
                        status.IsShown = false;
                        isChanged      = true;
                    }
                }
            }

            foreach (var texture in info.Textures)
            {
                var key = CreateKey(texture);

                Func <string> getName = () =>
                {
                    var ret = "";
                    if (texture.Names.ContainsKey(Core.Language))
                    {
                        ret = texture.Names[Core.Language];
                    }

                    if (string.IsNullOrEmpty(ret))
                    {
                        ret = texture.Name;
                    }

                    return(ret);
                };

                Func <string> getDesc = () =>
                {
                    var ret = "";
                    if (texture.Descriptions.ContainsKey(Core.Language))
                    {
                        ret = texture.Descriptions[Core.Language];
                    }

                    return(ret);
                };

                if (keyToValues.ContainsKey(key))
                {
                    var status = keyToValues[key] as ValueStatus;
                    if (status.IsShown != texture.IsParam)
                    {
                        status.IsShown = texture.IsParam;
                        isChanged      = true;
                    }
                }
                else
                {
                    var status = new ValueStatus();
                    var value  = new Value.PathForImage(Resources.GetString("ImageFilter"), true);
                    status.Key         = key;
                    status.Value       = value;
                    status.Name        = getName();
                    status.Description = getDesc();
                    status.IsShown     = texture.IsParam;
                    status.Priority    = texture.Priority;
                    keyToValues.Add(key, status);
                    value.SetAbsolutePathDirectly(texture.DefaultPath);
                    isChanged = true;
                }
            }

            foreach (var uniform in info.Uniforms)
            {
                var key = CreateKey(uniform);

                Func <string> getName = () =>
                {
                    var ret = "";
                    if (uniform.Names.ContainsKey(Core.Language))
                    {
                        ret = uniform.Names[Core.Language];
                    }

                    if (string.IsNullOrEmpty(ret))
                    {
                        ret = uniform.Name;
                    }

                    return(ret);
                };

                Func <string> getDesc = () =>
                {
                    var ret = "";
                    if (uniform.Descriptions.ContainsKey(Core.Language))
                    {
                        ret = uniform.Descriptions[Core.Language];
                    }

                    return(ret);
                };

                if (keyToValues.ContainsKey(key))
                {
                    var status = keyToValues[key] as ValueStatus;
                    if (!status.IsShown)
                    {
                        status.IsShown = true;
                        isChanged      = true;
                    }
                }
                else
                {
                    if (uniform.Type == 0)
                    {
                        var value = new Value.Float();
                        value.SetValueDirectly(uniform.DefaultValues[0]);
                        var status = new ValueStatus();
                        status.Key         = key;
                        status.Value       = value;
                        status.Name        = getName();
                        status.Description = getDesc();
                        status.IsShown     = true;
                        status.Priority    = uniform.Priority;
                        keyToValues.Add(key, status);
                        isChanged = true;
                    }
                    else
                    {
                        var value = new Value.Vector4D();
                        value.X.SetValueDirectly(uniform.DefaultValues[0]);
                        value.Y.SetValueDirectly(uniform.DefaultValues[1]);
                        value.Z.SetValueDirectly(uniform.DefaultValues[2]);
                        value.W.SetValueDirectly(uniform.DefaultValues[3]);
                        var status = new ValueStatus();
                        status.Key         = key;
                        status.Value       = value;
                        status.Name        = getName();
                        status.Description = getDesc();
                        status.IsShown     = true;
                        status.Priority    = uniform.Priority;
                        keyToValues.Add(key, status);
                        isChanged = true;
                    }
                }
            }

            if (isChanged && OnChanged != null)
            {
                OnChanged(this, null);
            }
        }