//============================================================ // <T>根据材质组合主题名称查找材质。</T> // // @param themeName 主题名称 // @param groupName 材质组名称 // @return 材质 //============================================================ public FDrMaterial Find(string themeName, string groupName) { string groupCode = RDrUtil.FormatPathToCode(groupName); string themeCode = RDrUtil.FormatPathToCode(themeName); FDrMaterialGroup group = _materials.Find(groupCode); if (null != group) { return(group.FindMaterial(themeCode)); } return(null); }
//============================================================ // <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); } }
//============================================================ // <T>扫描所有节点。</T> // // @param folder 文件夹 // @param path 路径 //============================================================ private void ScanNodes(FDrFolder folder, string path) { string fileTag = string.Empty; // 文件夹排序 folder.Folders.Sort(); // 循环取得每个文件 foreach (FDrFolder subfloder in folder.Folders) { // 获得经过处理的名称 string[] items = subfloder.Name.Split('-'); if (items.Length >= 3) { string type = items[0]; string dotPath = path + "\\" + items[1]; if (type == "fd") { subfloder.Type = "folder"; subfloder.Label = items[1] + " [" + items[2] + "]"; } else if (type == "mt") { subfloder.Type = "material"; FDrMaterialGroup materialGroup = new FDrMaterialGroup(); subfloder.Label = items[1] + " [" + items[2] + "]"; materialGroup.Name = dotPath; materialGroup.Label = items[2]; materialGroup.Directory = subfloder.Directory; materialGroup.DirectoryExprot = _exportDirectory; materialGroup.Scan(); // 存储对照表 if (materialGroup.OptionValid) { subfloder.Tag = materialGroup; _materials.Set(materialGroup.Code, materialGroup); _folders.Push(subfloder); } } ScanNodes(subfloder, dotPath); } } }
//============================================================ // <T>序列化内部数据到输出流。</T> // // @param output 输出流 //============================================================ public void LoadGroup(FDrMaterialGroup group) { // 存储属性 _effectName = group.EffectName; _transformName = group.TransformName; // 存储设置 _optionLight = group.OptionLight; _optionMerge = group.OptionMerge; _optionSort = group.OptionSort; _sortLevel = group.SortLevel; _optionAlpha = group.OptionAlpha; _optionDepth = group.OptionDepth; _optionCompare = group.OptionCompare; _optionDouble = group.OptionDouble; _optionShadow = group.OptionShadow; _optionShadowSelf = group.OptionShadowSelf; _optionDynamic = group.OptionDynamic; _optionTransmittance = group.OptionTransmittance; _optionOpacity = group.OptionOpacity; }
//============================================================ // <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); }
//============================================================ // <T>接收材质信息。</T> //============================================================ public void Assign(FDrMaterialGroup material) { _name = material._name; _textures.Append(material._textures); }