Esempio n. 1
0
        //============================================================
        // <T>打开处理。</T>
        //============================================================
        public void ScanTextures()
        {
            string rootDirectory = _folder.Directory;

            foreach (INamePair <FDrTexture> pair in RContent3dManager.TextureConsole.Textures)
            {
                FDrTexture       texture       = pair.Value;
                String           name          = texture.Name;
                FDrMaterialGroup materialGroup = FindGroup(name);
                if (materialGroup != null)
                {
                    continue;
                }
                // 创建材质组
                FDrFolder             folder = texture.Folder;
                FObjects <FCfgFolder> stack  = folder.FetchFolderStack(false);
                string materialPath          = folder.FolderPath().Replace("tx-", "mt-");
                string materialDirectory     = rootDirectory + materialPath;
                RDirectory.MakeDirectories(materialDirectory);
                FDrTheme theme = RContent3dManager.ThemeConsole.DefaultTheme;
                // 创建材质组
                materialGroup                = new FDrMaterialGroup();
                materialGroup.Name           = name;
                materialGroup.ConfigFileName = materialDirectory + "/config.xml";
                // 创建材质
                FDrMaterial material = new FDrMaterial();
                material.Theme      = theme;
                material.EffectName = theme.EffectName;
                materialGroup.Materials.Push(material);
                foreach (FDrTextureBitmap bitmap in texture.Bitmaps)
                {
                    FDrMaterialTexture materialTexture = new FDrMaterialTexture();
                    materialTexture.TypeCd       = bitmap.TypeCd;
                    materialTexture.Source       = texture.Name;
                    materialTexture.SourceTypeCd = bitmap.TypeCd;
                    materialTexture.SourceIndex  = bitmap.Index;
                    materialGroup.Textures.Push(materialTexture);
                }
                // 存储材质
                materialGroup.Store();
                _materials.Set(name, materialGroup);
                _logger.Debug(this, "ScanTextures", "Create material. (name={0})", materialDirectory);
            }
        }
Esempio n. 2
0
        //============================================================
        // <T>查找指定主题的材质。</T>
        //============================================================
        public FDrMaterial SyncMaterial(string themeName)
        {
            string themeCode = RDrUtil.FormatPathToCode(themeName);

            foreach (FDrMaterial material in _materials)
            {
                if (material.ThemeCode == themeCode)
                {
                    return(material);
                }
            }
            FDrMaterial createMaterial = new FDrMaterial();

            createMaterial.Group = this;
            createMaterial.Assign(_materials.First);
            createMaterial.ThemeName = themeName;
            _materials.Push(createMaterial);
            _materials.Sort(new FDrMaterial());
            return(createMaterial);
        }
Esempio n. 3
0
        //============================================================
        // <T>根据材质组合主题名称查找材质。</T>
        //
        // @param themeName 主题名称
        // @param groupName 材质组名称
        // @return 材质
        //============================================================
        public FDrMaterial FindDefault(string themeName, string groupName)
        {
            string           groupCode = RDrUtil.FormatPathToCode(groupName);
            string           themeCode = RDrUtil.FormatPathToCode(themeName);
            FDrMaterialGroup group     = _materials.Find(groupCode);
            FDrMaterial      material  = null;

            if (null != group)
            {
                material = group.FindMaterial(themeCode);
            }
            if (null == material)
            {
                if (null != group)
                {
                    if (!group.Materials.IsEmpty)
                    {
                        material = group.Materials.First;
                    }
                }
            }
            return(material);
        }
Esempio n. 4
0
        //============================================================
        // <T>加载配置信息。</T>
        //
        // @param config 配置信息
        //============================================================
        public void LoadConfig(FXmlNode xconfig)
        {
            // 读取属性
            _effectName          = xconfig.Nvl("effect_name");
            _transformName       = xconfig.Nvl("transform_name");
            _optionLight         = xconfig.GetInteger("option_light", _optionLight);
            _optionMerge         = xconfig.GetInteger("option_merge", _optionMerge);
            _optionSort          = xconfig.GetInteger("option_sort", _optionSort);
            _sortLevel           = xconfig.GetInteger("sort_level", _sortLevel);
            _optionAlpha         = xconfig.GetInteger("option_alpha", _optionAlpha);
            _optionDepth         = xconfig.GetInteger("option_depth", _optionDepth);
            _optionCompare       = xconfig.Get("option_compare", _optionCompare);
            _optionDouble        = xconfig.GetInteger("option_double", _optionDouble);
            _optionShadow        = xconfig.GetInteger("option_shadow", _optionShadow);
            _optionShadowSelf    = xconfig.GetInteger("option_shadow_self", _optionShadowSelf);
            _optionDynamic       = xconfig.GetInteger("option_dynamic", _optionDynamic);
            _optionTransmittance = xconfig.GetInteger("option_transmittance", _optionTransmittance);
            _optionOpacity       = xconfig.GetInteger("option_opacity", _optionOpacity);
            // 查找节点
            FXmlNode xmaterialConfig = null;
            FXmlNode xmaterials      = xconfig.Find("Materials");
            FXmlNode xtextures       = xconfig.Find("Textures");

            // 读取纹理列表
            if (null == xmaterials)
            {
                FXmlNode xmaterial = xconfig.Find("Material");
                if (null != xmaterial)
                {
                    FDrMaterial material = new FDrMaterial();
                    material.Group = this;
                    material.LoadConfig(xmaterial);
                    _materials.Push(material);
                    // 查找纹理节点
                    xtextures       = xmaterial.Find("Textures");
                    xmaterialConfig = xmaterial;
                }
            }
            else
            {
                // 找到默认节点
                FXmlNode xdefault = null;
                foreach (FXmlNode xmaterial in xmaterials.Nodes)
                {
                    if (xmaterial.IsName("Material"))
                    {
                        string themeCode = RDrUtil.FormatPathToCode(xmaterial.Get("theme_name"));
                        xdefault        = xmaterial;
                        xmaterialConfig = xmaterial;
                        if ("shadow" == themeCode)
                        {
                            break;
                        }
                    }
                }
                foreach (FDrTheme theme in RContent3dManager.ThemeConsole.Themes.Values)
                {
                    string code = theme.Code;
                    // 查找加载信息
                    bool finded = false;
                    foreach (FXmlNode xmaterial in xmaterials.Nodes)
                    {
                        if (xmaterial.IsName("Material"))
                        {
                            string themeCode = RDrUtil.FormatPathToCode(xmaterial.Get("theme_name"));
                            if (code == themeCode)
                            {
                                FDrMaterial material = new FDrMaterial();
                                material.Group = this;
                                material.LoadConfig(xmaterial);
                                FDrMaterial findMaterial = FindMaterial(material.ThemeName);
                                if (null == findMaterial)
                                {
                                    _materials.Push(material);
                                }
                                finded = true;
                                break;
                            }
                        }
                    }
                    // 如果不存在,则新建材质
                    if (!finded)
                    {
                        if (null != xdefault)
                        {
                            FDrMaterial material = new FDrMaterial();
                            material.Group = this;
                            material.LoadConfig(xdefault);
                            material.Theme     = theme;
                            material.ThemeName = theme.Name;
                            _materials.Push(material);
                        }
                    }
                }
            }
            // 如果效果名称不存在,则获得首个材质设定
            if (!xconfig.Contains("effect_name") && (null != xmaterialConfig))
            {
                _effectName          = xmaterialConfig.Nvl("effect_name");
                _transformName       = xmaterialConfig.Nvl("transform_name");
                _optionLight         = xmaterialConfig.GetInteger("option_light", _optionLight);
                _optionMerge         = xmaterialConfig.GetInteger("option_merge", _optionMerge);
                _optionSort          = xmaterialConfig.GetInteger("option_sort", _optionSort);
                _sortLevel           = xmaterialConfig.GetInteger("sort_level", _sortLevel);
                _optionAlpha         = xmaterialConfig.GetInteger("option_alpha", _optionAlpha);
                _optionDepth         = xmaterialConfig.GetInteger("option_depth", _optionDepth);
                _optionCompare       = xmaterialConfig.Get("option_compare", _optionCompare);
                _optionDouble        = xmaterialConfig.GetInteger("option_double", _optionDouble);
                _optionShadow        = xmaterialConfig.GetInteger("option_shadow", _optionShadow);
                _optionShadowSelf    = xmaterialConfig.GetInteger("option_shadow_self", _optionShadowSelf);
                _optionDynamic       = xmaterialConfig.GetInteger("option_dynamic", _optionDynamic);
                _optionTransmittance = xmaterialConfig.GetInteger("option_transmittance", _optionTransmittance);
                _optionOpacity       = xmaterialConfig.GetInteger("option_opacity", _optionOpacity);
            }
            foreach (FDrMaterial material in _materials)
            {
                material.LoadGroup(this);
            }
            // 读取纹理列表
            if (null != xtextures)
            {
                foreach (FXmlNode xtexture in xtextures.Nodes)
                {
                    if (xtexture.IsName("Texture"))
                    {
                        FDrMaterialTexture materialTexture = new FDrMaterialTexture();
                        materialTexture.Material = this;
                        materialTexture.LoadConfig(xtexture);
                        FDrTexture texture = RContent3dManager.TextureConsole.Find(materialTexture.Source);
                        if (null != texture)
                        {
                            materialTexture.Texture = texture;
                            materialTexture.IsValid = true;
                        }
                        else
                        {
                            RMoCore.TrackConsole.Write(this, "LoadConfig", "Texture is not exists in material. (texture={0}, file_name={1})", materialTexture.Source, _configFileName);
                            materialTexture.IsValid = false;
                        }
                        _textures.Push(materialTexture);
                    }
                }
            }
        }