系列目录:
JME3资源管理之一:核心组件介绍
JME3资源管理之二:AssetLoader和AssetLocator
JME3资源管理之三:资源加载流程
JME3资源管理之四:心得和小节
AssetManager加载资源前,首先要注册各种AssetLoader和AssetLocator,否则AssetManager将不知道怎么去加载资源。
1、注册AssetLoader
AssetLoader保存在一个map中,通过后缀名来匹配。如果2个AssetLoader都注册了同样的后缀名,那么
后注册的AssetLoader会挤掉先定义的AssetLoader。
am.registerLoader(AWTLoader.class, "jpg");
2、注册AssetLocator
AssetLocator保存在一个list中。如果2个资源位置中都有同名的资源,那么
先注册的资源会被找到,后面的就忽略了。
am.registerLocator("res", FileLocator.class);//注册程序相对路径res
am.registerLocator("C:/", FileLocator.class);// 注册绝对路径
am.registerLocator("/", ClasspathLocator.class);
3、默认注册
使用JME3的应用程序时,默认注册了下面这些AssetLoader和AssetLocater。
LOCATOR / com.jme3.asset.plugins.ClasspathLocator
LOADER com.jme3.texture.plugins.AWTLoader : jpg, bmp, gif, png, jpeg
LOADER com.jme3.audio.plugins.WAVLoader : wav
LOADER com.jme3.audio.plugins.OGGLoader : ogg
LOADER com.jme3.cursors.plugins.CursorLoader : ani, cur, ico
LOADER com.jme3.material.plugins.J3MLoader : j3m
LOADER com.jme3.material.plugins.J3MLoader : j3md
LOADER com.jme3.material.plugins.ShaderNodeDefinitionLoader : j3sn
LOADER com.jme3.font.plugins.BitmapFontLoader : fnt
LOADER com.jme3.texture.plugins.DDSLoader : dds
LOADER com.jme3.texture.plugins.PFMLoader : pfm
LOADER com.jme3.texture.plugins.HDRLoader : hdr
LOADER com.jme3.texture.plugins.TGALoader : tga
LOADER com.jme3.export.binary.BinaryImporter : j3o
LOADER com.jme3.export.binary.BinaryImporter : j3f
LOADER com.jme3.scene.plugins.OBJLoader : obj
LOADER com.jme3.scene.plugins.MTLLoader : mtl
LOADER com.jme3.scene.plugins.ogre.MeshLoader : meshxml, mesh.xml
LOADER com.jme3.scene.plugins.ogre.SkeletonLoader : skeletonxml, skeleton.xml
LOADER com.jme3.scene.plugins.ogre.MaterialLoader : material
LOADER com.jme3.scene.plugins.ogre.SceneLoader : scene
LOADER com.jme3.scene.plugins.blender.BlenderModelLoader : blend
LOADER com.jme3.shader.plugins.GLSLLoader : vert, frag, glsl, glsllib
上面的数据来自jme3默认文件:
com/jme3/asset/Desktop.cfg
4、AssetConfig
除了在代码里面直接调用AssetManager的方法来注册,我们还可以利用配置文件来进行注册。
配置文件的格式就和上面的代码一样,AssetConfig类专门用于解析这种配置文件。然而实际上我们在编程的时候几乎不上AssetConfig,只要注意配置的方式就行了。我们这里主要谈谈怎么使用配置文件。
配置文件的使用有3个关键点:
(1)配置文件必须放在工程的classpath之下,否则无法识别。
(2)要在AppSettings中添加参数"AssetConfigURL",指定配置文件的加载路径。
(3)如果使用自定义配置文件,那么jme3默认的配置文件就不会生效了!
你可以直接在src文件夹下面创建一个文本文件,文件名无所谓,只要文件格式正确就行。使用方法如下:
public static void main(String[] args) {
AppSettings settings = new AppSettings();
settings.set("AssetConfigURL", "org/pstale/asset/Assets.cfg");
SimpleApplication app = new YourApplication();
app.setSettings(settings);
app.start();
}
那么,为什么配置文件会有这些限制呢?我们看一看Application类的源代码就知道了。
Application初始化AssetManager的时候,会从AppSettings中读取"AssetConfigURL"这个参数,然后再读取配置文件。
找不到配置文件的话,就会使用默认配置文件。
private void initAssetManager(){
if (settings != null){
String assetCfg = settings.getString("AssetConfigURL");
if (assetCfg != null){
URL url = null;
try {
url = new URL(assetCfg);
} catch (MalformedURLException ex) {
}
if (url == null) {
url = Application.class.getClassLoader().getResource(assetCfg);
if (url == null) {
logger.log(Level.SEVERE, "Unable to access AssetConfigURL in asset config:{0}", assetCfg);
return;
}
}
assetManager = JmeSystem.newAssetManager(url);
}
}
if (assetManager == null){
assetManager = JmeSystem.newAssetManager(
Thread.currentThread().getContextClassLoader()
.getResource("com/jme3/asset/Desktop.cfg"));
}
}
分享到:
相关推荐
com.jme3.animation com.jme3.app com.jme3.app.state com.jme3.asset com.jme3.asset.pack com.jme3.asset.plugins com.jme3.audio com.jme3.audio.joal ...jme3tools.preview
游戏开发引擎JME3中文翻译文档,简单点例子分享
JME3-JFX 用于 JME 的 JFX Gui 桥接器,具有用于常见用例的有用实用程序。 许可证是新的 BSD 许可证(与 JME3 相同) 二进制版本可在以下位置获得: ( ) ( ) 它也可以用作 maven 存储库(请参阅“设置我”按钮)。 ...
JME和Java 3D具有类似的场景结构,开发者必须以树状方式组织自己的场景。JME有一套很好的优化机制,这使得它得运行速度要比Java 3D快很多。JME(java Monkey Engine),一个非常棒的Java 3D游戏引擎。
jme3-clj-aide JMonkeyEngine3 + Clojure-Android + AIDE 示例项目
它还实现了强大的REPL模式,该模式允许您交互使用JME库实现的大多数语言功能,包括CSV,HTML,JSON和XML导入和导出。 可以在以下页面上查阅用户和开发人员文档:...
NULL 博文链接:https://hjk685.iteye.com/blog/767080
NULL 博文链接:https://hjk685.iteye.com/blog/2181913
NULL 博文链接:https://hjk685.iteye.com/blog/2297517
基于jmonkeyengine游戏引擎,纯java开发,单机3d小游戏demo
JME商业游戏进阶二 (地表层的神秘面纱1)源代码
JME教程.rar
JME程序设计实例教程 JME程序设计实例教程 JME程序设计实例教程
JME Molecular Editor结构式在线编辑器
本人翻译水平有限,请大家包含,并希望能够给予指教。 本来就是给大家的资料所以我不喜欢要什么资源分,希望大家也上传时不要资源分
主要内容是介绍如何使用 jMonkeyEngine 进行游戏开发,旨在帮助初学者快速理解 jMonkeyEngine 中的核心概念,自己学习做的一些笔记,有不完美之处,还请见谅
jme3-样板 jMonkeyEngine 3.0 项目的 gradle 样板 桌面+安卓构建 maven 满足 jme3 依赖项 android sdk 必须在local.properties提供 安卓依赖 android sdk 构建工具 21.1.1 android 支持存储库 8 安卓支持库 21.0.1...
jmasters JMasters 是一个简单的应用程序,遵循所有 JMonkeyEngine 3.x 教程。 可以说它是对网站上现有教程的翻译。 使用的平台: JMonkeyEngine 3.x 64 位; Oracle JDK 7; Kubuntu 14.04 LTS。
本文档介绍jme的文件格式及支持的文件格式