//============================================================ // <T>打开资源。</T> //============================================================ public void SelectItem(object item) { // 存储改变 SaveModel(); // 隐藏属性控件 qdrModelGeometryProperty.Visible = false; qdrMaterialProperty.Visible = false; pnlModelProperty.Visible = false; // 显示选中对象 if (item is FDrMaterialGroup) { FDrMaterialGroup material = item as FDrMaterialGroup; qdrMaterialProperty.Dock = DockStyle.Fill; qdrMaterialProperty.Visible = true; qdrMaterialProperty.LoadMaterialGroup(material); } else if (item is FDrGeometry) { FDrGeometry geometry = item as FDrGeometry; qdrModelGeometryProperty.Dock = DockStyle.Fill; qdrModelGeometryProperty.Visible = true; qdrModelGeometryProperty.LoadGeometry(geometry); } else { pnlModelProperty.Visible = true; pnlModelProperty.Dock = DockStyle.Fill; } }
//============================================================ //<T>展现纹理图片<T> //============================================================ private void MaterialImage(FCfgFolder fol) { FDrMaterialGroup material = fol.Tag as FDrMaterialGroup; ListViewGroup group = new ListViewGroup(); int n = 1; material.Open(); foreach (FDrModelMaterialTexture mat in material.Textures) { if (null != mat && mat.Texture != null) { string path = mat.Texture.Directory + "\\icon\\" + mat.SourceType + ".jpg"; if (RFile.Exists(path)) { Bitmap bit = new Bitmap(path); imageList.Images.Add(bit); int count = imageList.Images.Count; imageList.Images.SetKeyName(count - 1, mat.SourceType + ".jpg"); n++; } } } group.Tag = material; group.Name = fol.Label + "-" + n.ToString(); listView1.Groups.Add(group); }
//============================================================ // <T>保存材质信息。</T> // // @param material 材质信息 //============================================================ public void SaveMaterialGroup(FDrMaterialGroup materialGroup = null) { // 修改默认材质 if (null == materialGroup) { materialGroup = _materialGroup; } if (null == materialGroup) { return; } // 存储属性 materialGroup.EffectName = cboEffectName.Text; materialGroup.TransformName = cboTransformName.Text; // 存储配置 materialGroup.OptionLight = qdrOptionLight.DataValue; materialGroup.OptionMerge = qdrOptionMerge.DataValue; materialGroup.OptionSort = qdrOptionSort.DataValue; materialGroup.SortLevel = (int)nudSortLevel.Value; materialGroup.OptionAlpha = qdrOptionAlpha.DataValue; materialGroup.OptionDepth = qdrOptionDepth.DataValue; materialGroup.OptionCompare = cboOptionCompare.Text; materialGroup.OptionDouble = qdrOptionDouble.DataValue; materialGroup.OptionShadow = qdrOptionShadow.DataValue; materialGroup.OptionShadowSelf = qdrOptionShadowSelf.DataValue; materialGroup.OptionDynamic = qdrOptionDynamic.DataValue; materialGroup.OptionTransmittance = qdrOptionTransmittance.DataValue; materialGroup.OptionOpacity = qdrOptionOpacity.DataValue; // 刷新材质 materialGroup.RefreshMaterials(); }
//============================================================ // <T>选中显示项目。</T> // // @param item 显示项目 //============================================================ public void SelectItem(object item) { qdrMaterialProperty.Visible = false; qdrTemplateRenderableProperty.Visible = false; qdrTemplateMovieProperty.Visible = false; // 显示材质 if (item is FDrMaterialGroup) { FDrMaterialGroup material = item as FDrMaterialGroup; qdrMaterialProperty.Dock = DockStyle.Fill; qdrMaterialProperty.LoadMaterialGroup(material); qdrMaterialProperty.Visible = true; } // 显示渲染 if (item is FDrTemplateRenderable) { FDrTemplateRenderable renderable = item as FDrTemplateRenderable; qdrTemplateRenderableProperty.LoadRenderable(renderable); qdrTemplateRenderableProperty.Dock = DockStyle.Fill; qdrTemplateRenderableProperty.Visible = true; } // 显示动画 if (item is FDrTemplateAnimationMovie) { FDrTemplateAnimationMovie movie = item as FDrTemplateAnimationMovie; qdrTemplateMovieProperty.LoadMovie(movie); qdrTemplateMovieProperty.Dock = DockStyle.Fill; qdrTemplateMovieProperty.Visible = true; } }
//============================================================ // <T>加载配置信息。</T> // // @param config 配置信息 //============================================================ public void LoadConfig(FXmlNode xconfig) { // 读取设置 _id = xconfig.GetInteger("id", 0); _name = xconfig.Get("name", _name); _modelName = xconfig.Nvl("model"); _modelName = _modelName.Replace('/', '\\'); _model = RContent3dManager.ModelConsole.Find(_modelName); if (null == _model) { RMoCore.TrackConsole.Write(this, "LoadConfig", "Model is not exists in tempalte. (template={0}, model={1})", _template.Name, _modelName); return; } _geometryName = xconfig.Nvl("geometry"); _geometry = _model.Mesh.Find(_geometryName); if (null == _geometry) { RMoCore.TrackConsole.Write(this, "LoadConfig", "Model geometry is not exists. (template={0}, model={1}, geometry={2})", _template.Name, _modelName, _geometryName); } else { _optionSelect = _geometry.OptionSelect; _optionGround = _geometry.OptionGround; _optionBoneScale = _geometry.OptionBoneScale; _optionInstnaced = _geometry.OptionInstanced; _instanceCount = _geometry.InstanceCount; _outline.min.Assign(_geometry.OutlineMin); _outline.max.Assign(_geometry.OutlineMax); } _materialName = xconfig.Nvl("material"); _materialName = _materialName.Replace('/', '\\'); _material = RContent3dManager.MaterialConsole.FindGroup(_materialName); if (null == _material) { RMoCore.TrackConsole.Write(this, "LoadConfig", "Material is not exists in tempalte. (template={0}, model={1}, material={2})", _template.Name, _modelName, _materialName); } else { if (!_material.Materials.IsEmpty) { FDrMaterial material = _material.Materials.First; _optionDynamic = material.OptionDynamic; _optionMerge = material.OptionMerge; } } _lightMapName = xconfig.Get("light_map", ""); // 读取选项 if (xconfig.Contains("option_visible")) { _optionVisible = xconfig.GetInteger("option_visible"); } // 读取矩阵 FXmlNode xmatrix = xconfig.Find("Matrix"); if (null != xmatrix) { _matrix.LoadSimpleConfig(xmatrix); } }
//============================================================ // <T>存储材质信息。</T> // // @prama material 材质名称 //============================================================ public void SaveMaterial(FDrMaterialGroup materialGroup) { qdrMaterialGroup.SaveMaterialGroup(materialGroup); if (null != _materialGroup) { qdrMaterialInfo.SaveMaterial(); } }
//============================================================ // <T>序列化数据。</T> //============================================================ public void Export() { // 加载高度图 _heightData.LoadFile(_path + "/texture/" + _textureHeight); _colorData.LoadFile(_path + "/texture/" + _textureColor); for (int n = 1; n <= _layerCount; n++) { FBitmap layerBitmap = _layers[n - 1].Bitmap; layerBitmap.LoadFile(_path + "/texture/level-" + n + ".jpg"); } //............................................................ FCompressFile file = new FCompressFile(); // 存储编号 file.WriteUint32((uint)_id); // 存储层数 file.WriteUint16((ushort)_layerCount); // 当前地图的宽度和高度 file.WriteUint16((ushort)_size.Width); file.WriteUint16((ushort)_size.Height); // 当前范围的宽度和高度 file.WriteUint16((ushort)_range.Width); file.WriteUint16((ushort)_range.Height); file.WriteFloat(_deep); // 存储材质列表 file.WriteInt16((short)_layers.Count); foreach (FDrMapLayer layer in _layers) { string materialCode = RDrUtil.FormatPathToCode(layer.MaterialName); file.WriteInt16((short)layer.Index); file.WriteString(materialCode); FDrMaterialGroup material = RContent3dManager.MaterialConsole.FindGroup(layer.MaterialName); material.Serialize(file); } // 输出文件 file.SaveFile(_exportFilePath + "\\config.swf"); //............................................................ // 导出地图块 int cx = _size.Width / _range.Width; int cy = _size.Height / _range.Height; for (int y = 0; y < cy; y++) { for (int x = 0; x < cx; x++) { ExportRange(x, y); } } // RangeIncise(); _logger.Debug(this, "Export", "Export template success. (file_name={0})", _exportFileName); }
//============================================================ // <T>打开资源。</T> //============================================================ public void SelectItem(object item) { if (item is FDrMaterialGroup) { FDrMaterialGroup material = item as FDrMaterialGroup; qdrMaterialProperty.Dock = DockStyle.Fill; qdrMaterialProperty.Visible = true; qdrMaterialProperty.LoadMaterialGroup(material); } else { qdrMaterialProperty.Visible = false; } }
//============================================================ // <T>导入材质信息。</T> //============================================================ public void ImportMaterial() { Open(); // 获得显示列表 FObjects <FDrSceneDisplay> displays = new FObjects <FDrSceneDisplay>(); displays.Append(_sky.Displays); displays.Append(_map.Displays); displays.Append(_space.Displays); // 压缩文件 foreach (FDrSceneDisplay display in displays) { foreach (FDrSceneMaterial sceneMaterial in display.Materials) { // 获得场景 FDrMaterialGroup group = RContent3dManager.MaterialConsole.FindGroup(sceneMaterial.Name); FDrMaterial material = group.SyncMaterial(_themeName); _logger.Debug(this, "ImportMaterial", "Import material. (material={0}, theme={1})", group.Code, _themeName); // 设置颜色 material.ColorMin = sceneMaterial.ColorMin; material.ColorMax = sceneMaterial.ColorMax; material.ColorMerge = sceneMaterial.ColorMerge; material.ColorRate = sceneMaterial.ColorRate; // 设置透明 material.AlphaBase = sceneMaterial.AlphaBase; material.AlphaRate = sceneMaterial.AlphaRate; material.AlphaLevel = sceneMaterial.AlphaLevel; material.AlphaMerge = sceneMaterial.AlphaMerge; // 设置颜色 material.AmbientColor.Assign(sceneMaterial.AmbientColor); material.DiffuseColor.Assign(sceneMaterial.DiffuseColor); material.DiffuseViewColor.Assign(sceneMaterial.DiffuseViewColor); material.SpecularColor.Assign(sceneMaterial.SpecularColor); material.SpecularBase = sceneMaterial.SpecularBase; material.SpecularRate = sceneMaterial.SpecularRate; material.SpecularAverage = sceneMaterial.SpecularAverage; material.SpecularShadow = sceneMaterial.SpecularShadow; material.SpecularViewColor.Assign(sceneMaterial.SpecularViewColor); material.SpecularViewBase = sceneMaterial.SpecularViewBase; material.SpecularViewRate = sceneMaterial.SpecularViewRate; material.SpecularViewAverage = sceneMaterial.SpecularViewAverage; material.SpecularViewShadow = sceneMaterial.SpecularViewShadow; // 存储资源组 group.Store(); } } _logger.Debug(this, "Export", "Export scene success. (file_name={0})", _exportFileName); }
//============================================================ // <T>按照选中保存。</T> //============================================================ public void SaveSelect() { FObjects <TreeNode> checkeds = tvwCatalog.FetchCheckedNodes(); foreach (TreeNode node in checkeds) { FCfgFolder folder = node.Tag as FCfgFolder; if (folder != null) { FDrMaterialGroup material = folder.Tag as FDrMaterialGroup; if (null != material) { material.Store(); } } } }
//============================================================ // <T>加载材质信息。</T> // // @param material 材质信息 //============================================================ public void LoadMaterialGroup(FDrMaterialGroup materialGroup) { _materialGroup = materialGroup; if (null != materialGroup) { // 设置属性 txtName.Text = materialGroup.Name + "(" + materialGroup.Label + ")"; if (RString.IsEmpty(materialGroup.EffectName)) { cboEffectName.Text = cboEffectName.Items[0].ToString(); } else { cboEffectName.Text = materialGroup.EffectName; } if (RString.IsEmpty(materialGroup.TransformName)) { cboTransformName.Text = cboTransformName.Items[0].ToString(); } else { cboTransformName.Text = materialGroup.TransformName; } // 设置配置 qdrOptionLight.DataValue = materialGroup.OptionLight; qdrOptionMerge.DataValue = materialGroup.OptionMerge; qdrOptionSort.DataValue = materialGroup.OptionSort; nudSortLevel.Value = materialGroup.SortLevel; qdrOptionAlpha.DataValue = materialGroup.OptionAlpha; qdrOptionDepth.DataValue = materialGroup.OptionDepth; cboOptionCompare.Text = materialGroup.OptionCompare; qdrOptionDouble.DataValue = materialGroup.OptionDouble; qdrOptionShadow.DataValue = materialGroup.OptionShadow; qdrOptionShadowSelf.DataValue = materialGroup.OptionShadowSelf; qdrOptionDynamic.DataValue = materialGroup.OptionDynamic; qdrOptionTransmittance.DataValue = materialGroup.OptionTransmittance; qdrOptionOpacity.DataValue = materialGroup.OptionOpacity; } }
//============================================================ // <T>加载材质信息。</T> // // @prama material 材质名称 //============================================================ public void LoadMaterialGroup(FDrMaterialGroup materialGroup) { _loading = true; // 打开材质 materialGroup.Open(); _materialGroup = materialGroup; // 建立材质集合 lbxThemes.Items.Clear(); foreach (FDrMaterial material in materialGroup.Materials) { lbxThemes.Items.Add(material.ThemeCode); } lbxThemes.SelectedIndex = 0; // 设置属性 qdrMaterialGroup.LoadMaterialGroup(materialGroup); qdrMaterialInfo.LoadMaterial(materialGroup.Materials.First); // 建立列表 FDrMaterialTexture firstTexture = null; qgvTextures.Rows.Clear(); foreach (FDrMaterialTexture texture in materialGroup.Textures) { // 创建数据行 DataGridViewRow row = new DataGridViewRow(); row.DefaultCellStyle.BackColor = Color.LightGreen; row.Tag = texture; // 创建类型单元格 DataGridViewTextBoxCell cellType = new DataGridViewTextBoxCell(); cellType.Value = texture.TypeName; row.Cells.Add(cellType); // 创建有效性单元格 DataGridViewTextBoxCell cellValid = new DataGridViewTextBoxCell(); cellValid.Value = texture.IsValid; row.Cells.Add(cellValid); // 创建来源单元格 DataGridViewTextBoxCell cellSource = new DataGridViewTextBoxCell(); cellSource.Value = texture.Source; row.Cells.Add(cellSource); // 创建来源类型单元格 DataGridViewTextBoxCell cellSourceType = new DataGridViewTextBoxCell(); cellSourceType.Value = texture.TypeName; row.Cells.Add(cellSourceType); // 创建来源索引单元格 DataGridViewTextBoxCell cellSourceIndex = new DataGridViewTextBoxCell(); cellSourceIndex.Value = texture.SourceIndex; row.Cells.Add(cellSourceIndex); // 创建尺寸单元格 DataGridViewTextBoxCell cellSize = new DataGridViewTextBoxCell(); if (null != texture.Bitmap) { cellSize.Value = texture.Bitmap.Size.Width + "X" + texture.Bitmap.Size.Height; } row.Cells.Add(cellSize); // 创建数据长度单元格 DataGridViewTextBoxCell cellLength = new DataGridViewTextBoxCell(); if (null != texture.Bitmap) { cellLength.Value = texture.Bitmap.Length; } row.Cells.Add(cellLength); qgvTextures.Rows.Add(row); // 设置首行 if (null == firstTexture) { row.Selected = true; firstTexture = texture; } } // 默认显示第一张图片 if (null != firstTexture) { qpbViewer.LoadBitmap(firstTexture.Bitmap.Image.Native); } else { qpbViewer.Clear(); } _loading = false; }
//============================================================ // <T>加载配置信息。</T> // // @param config 配置信息 //============================================================ public void LoadConfig(FXmlNode xconfig) { _optionLoaded = xconfig.GetInteger("option_loaded", EDrFlag.Inherit); _optionSelect = xconfig.GetInteger("option_select", EDrFlag.Inherit); _optionGround = xconfig.GetInteger("option_ground", EDrFlag.Inherit); if (xconfig.Contains("option_merge")) { _optionMergeVertex = xconfig.GetInteger("option_merge"); } if (xconfig.Contains("option_merge_vertex")) { _optionMergeVertex = xconfig.GetInteger("option_merge_vertex"); } _optionMergeMaterial = xconfig.GetInteger("option_merge_material", EDrFlag.Inherit); _optionLightMap = xconfig.GetInteger("option_light_map", EDrFlag.Inherit); //............................................................ // 加载渲染列表 FXmlNode xrenderables = xconfig.Find("Renderables"); if (null != xrenderables) { _outline.InitializeMin(); foreach (FXmlNode xrenderable in xrenderables.Nodes) { if (xrenderable.IsName("Renderable")) { // 建立渲染对象 FDrTemplateRenderable renderable = new FDrTemplateRenderable(); renderable.Template = this; renderable.LoadConfig(xrenderable); if (null == _model) { _model = renderable.Model; } _outline.InnerMax(renderable.Outline); // 设置材质 FDrMaterialGroup material = renderable.Material; if (null == material) { RMoCore.TrackConsole.Write(this, "LoadConfig", "Material is not exists. (template={0}, geometry={1}, material={2})", _name, renderable.GeometryName, renderable.MaterialName); return; } if (!_materials.Contains(material)) { _materials.Push(material); } _renderables.Push(renderable); } } } //............................................................ // 加载引用列表 FXmlNode xreferences = xconfig.Find("References"); if (null != xreferences) { foreach (FXmlNode xreference in xreferences.Nodes) { if (xreference.IsName("Reference")) { FDrTemplateReference reference = new FDrTemplateReference(); reference.LoadConfig(xreference); _references.Push(reference); } } } //............................................................ // 加载动画列表 FXmlNode xanimation = xconfig.Find("Animation"); if (null != xanimation) { _animation.Model = _model; _animation.LoadConfig(xanimation); } //............................................................ // 材质集合排序 if (!_materials.IsEmpty) { _materials.Sort(_materials.First); } }