예제 #1
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();
        }
예제 #2
0
 //============================================================
 // <T>序列化内容到输出流。</T>
 //
 // @param output 输出流
 //============================================================
 public void Serialize(IOutput output)
 {
     if (null != _model)
     {
         _model.Open();
         if (null != _model.Animation)
         {
             _frameCount = _model.Animation.FrameCount;
             _frameStart = _model.Animation.FrameStart;
             _frameEnd   = _model.Animation.FrameEnd;
             _frameTick  = _model.Animation.FrameTick;
         }
     }
     output.WriteInt32(_frameCount);
     output.WriteInt32(_frameTick);
     output.WriteInt32(_movies.Count);
     foreach (FDrTemplateAnimationMovie movie in _movies)
     {
         movie.Serialize(output);
     }
 }
예제 #3
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);
        }