Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        //============================================================
        public override void Serialize(IOutput output)
        {
            //output.WriteInt32(CodeNumber);
            //output.WriteInt32(0);
            output.WriteString(Code);
            // 存储属性
            //output.WriteInt8((sbyte)_optionLoaded);
            //output.WriteInt8((sbyte)_optionSelect);
            //output.WriteInt8((sbyte)_optionGround);
            //output.WriteInt8((sbyte)_optionMergeVertex);
            //output.WriteInt8((sbyte)_optionMergeMaterial);
            //output.WriteInt8((sbyte)_optionLightMap);
            ////............................................................
            //// 统计材质次数
            //FDictionary<int> materialsCount = new FDictionary<int>();
            //foreach (FDrTemplateRenderable renderable in  _renderables){
            //   int materialCount = 0;
            //   if(materialsCount.Contains(renderable.MaterialCode)){
            //      materialCount = materialsCount.Get(renderable.MaterialCode);
            //   }
            //   materialCount++;
            //   materialsCount.Set(renderable.MaterialCode, materialCount);
            //}
            //............................................................
            // 存储渲染列表
            int count = _renderables.Count;

            output.WriteInt16((short)count);
            for (int n = 0; n < count; n++)
            {
                FDrTemplateRenderable renderable = _renderables[n];
                //int materialCount = materialsCount.Get(renderable.MaterialCode);
                //if (1 == materialCount) {
                //   renderable.OptionMerge = EDrFlag.No;
                //}
                //renderable.Id = n + 1;
                renderable.Serialize(output);
            }
            ////............................................................
            //// 存储动画列表
            //if(_animation.IsEmpty) {
            //   output.WriteBool(false);
            //} else {
            //   output.WriteBool(true);
            //   _animation.Serialize(output);
            //}
        }
Ejemplo n.º 3
0
        //============================================================
        // <T>存储配置信息。</T>
        //
        // @param config 配置信息
        //============================================================
        public void SaveConfig(FXmlNode xconfig)
        {
            // 设置信息
            xconfig.Set("name", _name);
            xconfig.Set("label", _label);
            xconfig.Set("option_loaded", _optionLoaded);
            xconfig.Set("option_select", _optionSelect);
            xconfig.Set("option_ground", _optionGround);
            xconfig.Set("option_merge_vertex", _optionMergeVertex);
            xconfig.Set("option_merge_material", _optionMergeMaterial);
            xconfig.Set("option_light_map", _optionLightMap);
            //............................................................
            // 存储渲染列表
            if (!_renderables.IsEmpty)
            {
                FXmlNode xrenderables = xconfig.CreateNode("Renderables");
                int      count        = _renderables.Count;
                xrenderables.Set("count", count);
                for (int n = 0; n < count; n++)
                {
                    FDrTemplateRenderable renderable = _renderables[n];
                    if (renderable.Id == 0)
                    {
                        renderable.Id = n + 1;
                    }
                    renderable.SaveConfig(xrenderables.CreateNode("Renderable"));
                }
            }
            //............................................................
            // 存储引用列表
            if (!_references.IsEmpty)
            {
                FXmlNode xreferences = xconfig.CreateNode("References");
                xreferences.Set("count", _references.Count);
                foreach (FDrTemplateReference reference in _references)
                {
                    reference.SaveConfig(xreferences.CreateNode("Renderable"));
                }
            }
            //............................................................
            // 存储引动画列表
            FXmlNode xanimation = xconfig.CreateNode("Animation");

            _animation.SaveConfig(xanimation);
        }
Ejemplo n.º 4
0
        //============================================================
        // <T>根据模块名称和几何体名称,获得渲染对象。</T>
        //
        // @param modelName 模块名称
        // @param geometryName 几何体名称
        // @return 渲染对象
        //============================================================
        public FDrTemplateRenderable SyncRenderable(string modelName, string geometryName)
        {
            // 查询渲染对象
            if (!_renderables.IsEmpty)
            {
                foreach (FDrTemplateRenderable renderable in _renderables)
                {
                    if (renderable.ModelName.Equals(modelName) && renderable.GeometryName.Equals(geometryName))
                    {
                        return(renderable);
                    }
                }
            }
            // 新建渲染对象
            FDrTemplateRenderable newRenderable = new FDrTemplateRenderable();

            newRenderable.ModelName    = modelName;
            newRenderable.GeometryName = geometryName;
            _renderables.Push(newRenderable);
            return(newRenderable);
        }
Ejemplo n.º 5
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);
            }
        }