Ejemplo n.º 1
0
        //============================================================
        public void ExportMerge(FDrModel model)
        {
            SIntSize    size   = new SIntSize(_width, _height);
            Form        form   = new Form();
            FDxDevice3D device = RDxCore.Adapter.CreateDevice(form.Handle, size.Width, size.Height);

            device.ModeWireFrame = false;
            // 设置几何体
            FDxRegion region = new FDxRegion();
            // 设置目标
            FDxBufferedTexture texture = new FDxBufferedTexture();

            texture.Device = device;
            texture.Create(size.Width, size.Height);
            device.SetRenderTarget(texture);
            // 渲染几何体
            FDxTechnique technique = RDxCore.TechniqueConsole.Get(device, "light.map");
            int          index     = 0;

            foreach (INamePair <FDrGeometry> pair in model.Mesh.GeometryDictionary)
            {
                FDrLightGeometry geometry = new FDrLightGeometry();
                geometry.Device = device;
                geometry.LoadResource(pair.Value);
                region.Renderables.Clear();
                region.Renderables.Push(geometry);
                // 绘制结果
                technique.Draw(region);
                // 保存内容
                texture.SaveFile(model.Directory + "/" + RInt.Pad(index, 3) + ".png");
                index++;
            }
        }
Ejemplo n.º 2
0
        //============================================================
        // <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);
            }
        }
Ejemplo n.º 3
0
        //============================================================
        // <T>序列化数据。</T>
        //============================================================
        public void Import()
        {
            string       fileName = _directory + "\\model.m3x";
            FXmlDocument xdoc     = new FXmlDocument(fileName);
            FXmlNode     xscene   = xdoc.Root.Find("Scene");

            // 重新导入所有集合体(可以重复)
            _renderables.Clear();
            int      n     = 0;
            FXmlNode xmesh = xscene.Find("Mesh");

            foreach (FXmlNode xgeometry in xmesh.Nodes)
            {
                if (xgeometry.IsName("Geometry"))
                {
                    string   name  = xgeometry.Get("name");
                    string[] items = name.Split('|');
                    if (items.Length >= 2)
                    {
                        // 获得模型和集合体对象
                        string   modelCode    = items[0];
                        string   geometryName = items[1];
                        FDrModel model        = RContent3dManager.ModelConsole.Find(modelCode);
                        if (null == model)
                        {
                            RMoCore.TrackConsole.Write(this, "Import", "Model is not exists. (model={0})", modelCode);
                            continue;
                        }
                        model.Open();
                        FDrGeometry geometry = model.Mesh.Find(geometryName);
                        if (null == geometry)
                        {
                            RMoCore.TrackConsole.Write(this, "Import", "Model geometry is not exists. (model={0}, geometry={1})", modelCode, geometryName);
                            continue;
                        }
                        // 新建渲染对象
                        FDrTemplateRenderable renderable = new FDrTemplateRenderable();
                        renderable.Id           = n++;
                        renderable.Name         = name;
                        renderable.LightMapName = RString.Right(name, "|");
                        renderable.ModelName    = model.Name;
                        renderable.GeometryName = geometry.Name;
                        renderable.MaterialName = geometry.MaterialName;
                        renderable.LoadExportConfig(xgeometry);
                        _renderables.Push(renderable);
                    }
                }
            }
            _logger.Debug(this, "Import", "Import template success. (file_name={0})", fileName);
            Store();
        }
Ejemplo n.º 4
0
        //============================================================
        // <T>导出光照信息。</T>
        //============================================================
        public void ExportLight()
        {
            FDrModel model = new FDrModel();

            model.Directory     = _directory;
            model.ModelFileName = _directory + "/model.m3x";
            model.MeshFileName  = _directory + "/model.msh";
            model.LoadDataFile();
            // 存储模板文件
            FDrLightMap map = new FDrLightMap();

            map.Export3d(model);
            _logger.Debug(this, "Export", "Export template success. (file_name={0})", _exportFileName);
        }
Ejemplo n.º 5
0
        //============================================================
        // <T>选中导出。</T>
        //============================================================
        public void ExportSelected()
        {
            FObjects <TreeNode> nodes = tvwCatalog.FetchCheckedNodes();

            foreach (TreeNode node in nodes)
            {
                FCfgFolder folder = node.Tag as FCfgFolder;
                if (null != folder)
                {
                    FDrModel model = folder.Tag as FDrModel;
                    if (null != model)
                    {
                        RContent3dManager.ModelConsole.TaskExport(model);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 //============================================================
 // <T>打开资源。</T>
 //============================================================
 public void SelectItem(object item)
 {
     if (item is FDrModel)
     {
         FDrModel model = item as FDrModel;
         qdrModelProperty.Dock    = DockStyle.Fill;
         qdrModelProperty.Visible = true;
         qdrModelProperty.Enabled = false;
         qdrModelProperty.SaveModel();
         qdrModelProperty.LoadModel(model);
         qdrModelProperty.Enabled = true;
     }
     else
     {
         qdrModelProperty.Visible = false;
     }
 }
Ejemplo n.º 7
0
        //============================================================
        // <T>按照选中保存。</T>
        //============================================================
        public void SaveSelect()
        {
            FObjects <TreeNode> nodes = tvwCatalog.FetchCheckedNodes();

            foreach (TreeNode node in nodes)
            {
                FCfgFolder folder = node.Tag as FCfgFolder;
                if (folder != null)
                {
                    FDrModel model = folder.Tag as FDrModel;
                    if (null != model)
                    {
                        model.Store();
                    }
                }
            }
        }
Ejemplo n.º 8
0
        //============================================================
        // <T>选中对象。</T>
        //============================================================
        private void tvwCatalog_AfterSelect(object sender, TreeViewEventArgs e)
        {
            SelectItem(e.Node.Tag);
            FDrModel model = e.Node.Tag as FDrModel;

            if (e.Node.Text == "材质列表")
            {
                SetModelValue(e.Node, "Material");
            }
            if (e.Node.Text == "网格列表")
            {
                SetModelValue(e.Node, "Geometrie");
            }
            if (e.Node.Text == "动画列表")
            {
                SetModelValue(e.Node, "Animation");
            }
        }
Ejemplo n.º 9
0
 //============================================================
 // <T>构造模型跟踪信息。</T>
 //============================================================
 public FDrJoiner(FDrModel model)
 {
     _model = model;
 }
Ejemplo n.º 10
0
        //============================================================
        // <T>加载模型信息。</T>
        //
        // @param model 模型对象
        //============================================================
        public void LoadModel(FDrModel model)
        {
            model.Open();
            _model = model;
            //............................................................
            txtName.Text      = _model.Name;
            txtLabel.Text     = _model.Label;
            txtBoneCount.Text = _model.Skeleton.Bones.Count.ToString();
            //............................................................
            // 清空节点
            tvwCatalog.Nodes.Clear();
            tvwCatalog.BeginUpdate();
            //............................................................
            TreeNode materialsNode = new TreeNode("材质列表");

            materialsNode.ImageKey         = "Floder";
            materialsNode.SelectedImageKey = "Floder";
            materialsNode.Tag = model;
            dgvMaterials.Rows.Clear();
            // 建立材质集合
            foreach (INamePair <FDrModelMaterial> pair in model.Materials.Names)
            {
                FDrModelMaterial material = pair.Value;
                // 建立树目录节点
                TreeNode materialNode = new TreeNode(material.Name);
                materialNode.ImageKey         = "Material";
                materialNode.SelectedImageKey = "Material";
                materialNode.Tag = pair.Value;
                materialsNode.Nodes.Add(materialNode);
                // 建立数据行对象
                DataGridViewRow         row      = new DataGridViewRow();
                DataGridViewTextBoxCell cellName = new DataGridViewTextBoxCell();
                cellName.Value = material.Name;
                row.Cells.Add(cellName);
                DataGridViewTextBoxCell cellLabel = new DataGridViewTextBoxCell();
                if (null != material.Material)
                {
                    cellLabel.Value = material.Material.Label;
                }
                row.Cells.Add(cellLabel);
                dgvMaterials.Rows.Add(row);
            }
            tvwCatalog.Nodes.Add(materialsNode);
            //............................................................
            FDrMesh  mesh           = model.Mesh;
            TreeNode geometriesNode = new TreeNode("网格列表");

            geometriesNode.ImageKey         = "Floder";
            geometriesNode.SelectedImageKey = "Floder";
            geometriesNode.Tag = model;
            dgvGeometries.Rows.Clear();
            // 建立几何集合
            foreach (INamePair <FDrGeometry> pair in model.Mesh.GeometryDictionary)
            {
                FDrGeometry geometry = pair.Value;
                // 建立树目录节点
                string   displayName  = geometry.Name + " (" + geometry.MaterialName + ")";
                TreeNode geometryNode = new TreeNode(displayName);
                geometryNode.ImageKey         = "Geometry";
                geometryNode.SelectedImageKey = "Geometry";
                geometryNode.Tag = geometry;
                geometriesNode.Nodes.Add(geometryNode);
                // 建立数据行对象
                DataGridViewRow         row      = new DataGridViewRow();
                DataGridViewTextBoxCell cellName = new DataGridViewTextBoxCell();
                cellName.Value = geometry.Name;
                row.Cells.Add(cellName);
                // 实体配置
                DataGridViewCheckBoxCell cellOptionInstanced = new DataGridViewCheckBoxCell();
                cellOptionInstanced.Value = EDrFlag.ToBoolean(geometry.OptionInstanced);
                row.Cells.Add(cellOptionInstanced);
                DataGridViewTextBoxCell cellInstanceCount = new DataGridViewTextBoxCell();
                cellInstanceCount.Value = geometry.InstanceCount;
                row.Cells.Add(cellInstanceCount);
                // 动态配置
                DataGridViewCheckBoxCell cellOptionDynamic = new DataGridViewCheckBoxCell();
                cellOptionDynamic.Value = EDrFlag.ToBoolean(geometry.OptionDynamic);
                row.Cells.Add(cellOptionDynamic);
                // 骨骼缩放
                DataGridViewCheckBoxCell cellOptionBoneScale = new DataGridViewCheckBoxCell();
                cellOptionBoneScale.Value = EDrFlag.ToBoolean(geometry.OptionBoneScale);
                row.Cells.Add(cellOptionBoneScale);
                DataGridViewTextBoxCell cellBoneCount = new DataGridViewTextBoxCell();
                cellBoneCount.Value = geometry.AdjustBones.Count;
                row.Cells.Add(cellBoneCount);
                DataGridViewTextBoxCell cellWeightCount = new DataGridViewTextBoxCell();
                cellWeightCount.Value = geometry.WeightMaxCount.ToString();
                row.Cells.Add(cellWeightCount);
                // 影子配置
                DataGridViewCheckBoxCell cellOptionShadow = new DataGridViewCheckBoxCell();
                cellOptionShadow.Value = EDrFlag.ToBoolean(geometry.OptionShadow);
                row.Cells.Add(cellOptionShadow);
                // 自影子配置
                DataGridViewCheckBoxCell cellOptionSelfShadow = new DataGridViewCheckBoxCell();
                cellOptionSelfShadow.Value = EDrFlag.ToBoolean(geometry.OptionSelfShadow);
                row.Cells.Add(cellOptionSelfShadow);
                // 法线配置
                DataGridViewCheckBoxCell cellOptionNormal = new DataGridViewCheckBoxCell();
                cellOptionNormal.Value = EDrFlag.ToBoolean(geometry.OptionNormalFull);
                row.Cells.Add(cellOptionNormal);
                // 双面配置
                DataGridViewCheckBoxCell cellOptionDouble = new DataGridViewCheckBoxCell();
                cellOptionDouble.Value = EDrFlag.ToBoolean(geometry.OptionDouble);
                row.Cells.Add(cellOptionDouble);
                // 选择配置
                DataGridViewCheckBoxCell cellOptionSelect = new DataGridViewCheckBoxCell();
                cellOptionSelect.Value = EDrFlag.ToBoolean(geometry.OptionSelect);
                row.Cells.Add(cellOptionSelect);
                // 材质名称
                DataGridViewTextBoxCell cellMaterialName = new DataGridViewTextBoxCell();
                cellMaterialName.Value = geometry.MaterialName;
                row.Cells.Add(cellMaterialName);
                // 顶点信息
                DataGridViewTextBoxCell cellVertexCount = new DataGridViewTextBoxCell();
                cellVertexCount.Value = geometry.VertexList.Count + "/" + geometry.AdjustVertexDictionary.Count;
                row.Cells.Add(cellVertexCount);
                // 面信息
                DataGridViewTextBoxCell cellFaceCount = new DataGridViewTextBoxCell();
                cellFaceCount.Value = geometry.FaceList.Count;
                row.Cells.Add(cellFaceCount);
                // 法线信息
                DataGridViewTextBoxCell cellNormalCount = new DataGridViewTextBoxCell();
                cellNormalCount.Value = geometry.NormalList.Count;
                row.Cells.Add(cellNormalCount);
                // 副法线信息
                DataGridViewTextBoxCell cellBinormalCount = new DataGridViewTextBoxCell();
                cellBinormalCount.Value = geometry.BinormalList.Count;
                row.Cells.Add(cellBinormalCount);
                // 切线信息
                DataGridViewTextBoxCell cellTangentCount = new DataGridViewTextBoxCell();
                cellTangentCount.Value = geometry.TangentList.Count;
                row.Cells.Add(cellTangentCount);
                row.Tag = geometry;
                dgvGeometries.Rows.Add(row);
            }
            tvwCatalog.Nodes.Add(geometriesNode);
            //............................................................
            TreeNode animationsNode = new TreeNode("动画列表");

            // 建立动画集合
            foreach (FDrMovie movie in model.Animation.Movies)
            {
                TreeNode animationNode = new TreeNode(movie.Name);
                animationNode.ImageKey         = "Movie";
                animationNode.SelectedImageKey = "Movie";
                animationNode.Tag = movie;
                animationsNode.Nodes.Add(animationNode);
            }
            tvwCatalog.Nodes.Add(animationsNode);
            //............................................................
            tvwCatalog.EndUpdate();
            tvwCatalog.ExpandAll();
            // 选择项目
            SelectItem(null);
        }
Ejemplo n.º 11
0
 //============================================================
 // <T>构造模型骨骼。</T>
 //============================================================
 public FDrSkeleton(FDrModel model)
 {
     _model = model;
 }
Ejemplo n.º 12
0
 //============================================================
 // <T>构造模型跟踪信息。</T>
 //============================================================
 public FDrTrack(FDrModel model)
 {
     _model = model;
 }
Ejemplo n.º 13
0
 //============================================================
 // <T>构造模型动画。</T>
 //============================================================
 public FDrAnimation(FDrModel model)
 {
     _model = model;
 }
Ejemplo n.º 14
0
 //============================================================
 // <T>构造网格。</T>
 //============================================================
 public FDrMesh(FDrModel model)
 {
     _model = model;
 }
Ejemplo n.º 15
0
        //============================================================
        // <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);
            }
        }
Ejemplo n.º 16
0
 //============================================================
 // <T>模型骨头。</T>
 //============================================================
 public FDrBone(FDrModel model)
 {
     _model = model;
 }