菜鸟学习OGRE和天龙八部之九: AXP档案的直接载入搞定

来源:互联网 发布:linux新加硬盘不显示 编辑:程序博客网 时间:2024/04/30 07:36

直接载入AXP格式的文件包,高效又方便,纠结了半天,在网友的帮助下得到启发

OGRE默认的2种档案格式一个是文件夹,一个是Zip压缩包.

不过OGRE提供了自定义档案载入的接口,就是说我们可以自己定义任何类型的档案,比如AXP

把AXP档案交给资源管理器管理,管理器定位到所有资源,

资源中的materi之类的脚本文件自动就会分析,

如果是OGRE支持的文件格式,比如dds之类,需要的时候自动载入

如果是OGRE不直接支持的文件格式,比如二进制文件或者xml文件

我们也可以从资源管理器获得文件名字用流自己来载入,

DataStreamPtr mStreamPtr =   ResourceGroupManager::getSingleton().openResource(   
  fileName, TLBB_RESOURCE_GROUP);

 这样文件路径都省去了.由资源管理器定位的时候就已经保存好了文件路径

 

要想让资源管理器帮我们做好所有事情,

必须按照下面这个接口来定义自己的档案

class MyArchive : public Archive

{

    // 在这省略了具体的实现

}

class MyArchiveFactory : public Archive

{

    //在这省略了具体的实现ArchiveFactory的一些方法

 

Archive* createInstance(const String& name){

     return new MyArchive(name, “MyArchiveType”);

}

};

void function()

{

MyArchiveFactory *factory = new MyArchiveFactory;

ArchiveManager::getSingleton().addArchiveFactory(factory);

}

 

关键点就是自己的实现

要现实的东西比较多,几乎要全部重写Archive和ArchiveFactory这2个类

不过幸运的是我们可以照着OGRE源码里面Zip.cpp这个源文件的实现来写

大部分和Zip的实现相同......有心人研究研究就明白了

框架:

 

 

 [Bootstrap]
Zip=../../Data/OgreCore.zip
Zip=../../Data/MaterialTemplates.zip

[AXP]
AxpPack=../../Data/Scene.axp
AxpPack=../../Data/Material.axp
AxpPack=../../Data/Model.axp
AxpPack=../../Data/Brushes.axp

 最后的效果:

07:57:52: ArchiveFactory for archive type AxpPack registered.
07:57:52: Creating resource group AXP
07:57:52: Added resource location '../../Data/Scene.axp' of type 'AxpPack' to resource group 'AXP'
07:57:52: Added resource location '../../Data/Material.axp' of type 'AxpPack' to resource group 'AXP'
07:57:52: Added resource location '../../Data/Model.axp' of type 'AxpPack' to resource group 'AXP'
07:57:52: Added resource location '../../Data/Brushes.axp' of type 'AxpPack' to resource group 'AXP'
07:57:52: Creating resource group Bootstrap
07:57:52: Added resource location '../../Data/OgreCore.zip' of type 'Zip' to resource group 'Bootstrap'
07:57:52: Added resource location '../../Data/MaterialTemplates.zip' of type 'Zip' to resource group 'Bootstrap'

 

07:57:53: Parsing scripts for resource group AXP
07:57:53: Parsing script FairyTerrain.program
07:57:53: Parsing script std_quad.program
07:57:53: Parsing script FairyTerrain.material
07:57:53: Parsing script all.material
07:57:54: Error at line 59378 of : parent material: NPCnMonsterAlphaTemplate not found for new material:boss玄镰刀怪
07:57:54: Error at line 59383 of : parent material: NPCnMonsterNoAlphaTemplate not found for new material:boss缥缈峰普通侠士双刀
07:57:54: Error at line 59388 of : parent material: NPCnMonsterFaceNoAlphaTemplate not found for new material:boss缥缈峰普通侠士头

 

我把含有父材质的MaterialTemplates.zip放前面,却后解析,很囧,导致NPCnMonsterAlphaTemplate not found

 

有了接口框架,自己照着写就行,而关于AXP资源的破解,网上好像有大侠说的更明白,有兴趣的自己去找找,

 

 

 

原创粉丝点击