|
@@ -19,7 +19,7 @@ jMonkeyProjects/MyGame/test/ # You store test classes here (optional)
|
|
|
<div class="paragraph"><p>Here is an example how you load assets using the AssetManager. This lines loads a default Material from the built-in <code>Common/</code> directory:</p></div>
|
|
|
<div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">Material mat = (Material) assetManager.loadAsset(
|
|
|
<span class="keyword">new</span> AssetKey(<span class="string"><span class="delimiter">"</span><span class="content">Common/Materials/RedColor.j3m</span><span class="delimiter">"</span></span>));</code></pre></div></div>
|
|
|
-<div class="paragraph"><p>This Material is “somewhere in the jME3 JAR; the default Asset Manager is configured to handle a <code>Common/…</code> path correctly, so you don’t have to specify the whole path when referring to built-in assets (such as default Materials).</p></div>
|
|
|
+<div class="paragraph"><p>This Material is “somewhere” in the jME3 JAR; the default Asset Manager is configured to handle a <code>Common/…</code> path correctly, so you don’t have to specify the whole path when referring to built-in assets (such as default Materials).</p></div>
|
|
|
<div class="paragraph"><p>Additionally, you can configure the Asset Manager and add any path to its root. This means, you can load assets from any project directory you specify. The next example shows how you load assets from your project’s assets directory.</p></div></div>
|
|
|
<div class="sect2"><h3 id="asset-directory">Asset Directory</h3><div class="paragraph"><p>By default, jME3 searches for models in a directory named <code>assets</code>.</p></div>
|
|
|
<div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="paragraph"><p>In Java projects created with the jMonkeyEngine SDK, an <code>assets</code> folder is created by default in your project directory. If you are using any other IDE, or the command line, you simply create an <code>assets</code> directory manually (see the Codeless Project tip below).</p></div></td></tr></table></div>
|
|
@@ -39,7 +39,7 @@ jMonkeyProjects/MyGame/assets/Textures/ # .jpg, .png; also .mesh.xml+.materia
|
|
|
<div class="paragraph"><p><strong>Examples:</strong> You can rename <code>assets/Sounds</code> to <code>assets/Audio</code>, you can delete <code>assets/MatDefs</code> if you don’t use it, you can create <code>assets/AIscripts</code>, etc. You can rename/move the <code>assets/Textures</code> directory or its subdirectories, but then you have to re-export all models, and re-convert them all to .j3o, so plan ahead!</p></div>
|
|
|
<div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="paragraph"><p>Store textures in <code>assets/Textures/</code> before you work with them in a mesh editor! Export and save 3D model files (.mesh.xml+.material, .mtl+.obj, .blend) into the <code>assets/Textures/</code> (!) before you convert the model to binary format (.j3o)! This ensures that texture paths correctly point to the <code>assets/Textures</code> directory.<br>
|
|
|
After the conversion, you move the .j3o file into the <code>assets/Models/</code> or <code>assets/Scenes/</code> directories. This way, you can reuse textures, your binaries consistently link the correct textures, and the <code>assets/Models</code> and <code>assets/Scenes</code> directories don’t become cluttered.</p></div></td></tr></table></div></div>
|
|
|
-<div class="sect2"><h3 id="example-code-loading-assets">Example Code: Loading Assets</h3><div class="paragraph"><p>Creating a material instance with the definition “Unshaded.j3md:</p></div>
|
|
|
+<div class="sect2"><h3 id="example-code-loading-assets">Example Code: Loading Assets</h3><div class="paragraph"><p>Creating a material instance with the definition “Unshaded.j3md”:</p></div>
|
|
|
<div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">Material mat_brick = <span class="keyword">new</span> Material(
|
|
|
assetManager, <span class="string"><span class="delimiter">"</span><span class="content">Common/MatDefs/Misc/Unshaded.j3md</span><span class="delimiter">"</span></span>);</code></pre></div></div>
|
|
|
<div class="paragraph"><p>Applying a texture to the material:</p></div>
|
|
@@ -60,7 +60,7 @@ rootNode.attachChild(scene);</code></pre></div></div>
|
|
|
Spatial scene = assetManager.loadModel(<span class="string"><span class="delimiter">"</span><span class="content">main.scene</span><span class="delimiter">"</span></span>);
|
|
|
rootNode.attachChild(scene);</code></pre></div></div>
|
|
|
<div class="paragraph"><p>jME3 also offers a ClasspathLocator, ZipLocator, FileLocator, HttpZipLocator, and UrlLocator (see <code>com.jme3.asset.plugins</code>).</p></div>
|
|
|
-<div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="paragraph"><p>The custom build script does not automatically include all ZIP files in the executable build. See “Cannot Locate Resource solution below.</p></div></td></tr></table></div></div>
|
|
|
+<div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="paragraph"><p>The custom build script does not automatically include all ZIP files in the executable build. See “Cannot Locate Resource” solution below.</p></div></td></tr></table></div></div>
|
|
|
<div class="sect2"><h3 id="common-assetmanager-tasks">Common AssetManager Tasks</h3><table class="tableblock frame-all grid-all spread"><colgroup><col style="width: 15%;"><col style="width: 85%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Task?</th><th class="tableblock halign-left valign-top">Solution!</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Load a model with materials</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Use the asset manager’s <code>loadModel()</code> method and attach the Spatial to the rootNode.</p></div>
|
|
|
<div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">Spatial elephant = assetManager.loadModel(<span class="string"><span class="delimiter">"</span><span class="content">Models/Elephant/Elephant.mesh.xml</span><span class="delimiter">"</span></span>);
|
|
|
rootNode.attachChild(elephant);</code></pre></div></div>
|
|
@@ -83,7 +83,7 @@ java.lang.NullPointerException</code></pre></div></div>
|
|
|
<div class="paragraph"><p>If you use the default build script, <strong>original models and scenes (.mesh.xml, .obj, .blend, .zip), are excluded</strong> from the distribution automatically. A stand-alone executable includes converted <strong>.j3o files</strong> (models and scenes) only. The default build script makes sure to bundle existing .j3o files in the distribution, but you need to remember to convert the models (from mesh.xml–>.j3o, or .obj–>.j3o, etc) yourself.</p></div>
|
|
|
<div class="paragraph"><p><strong>Solution</strong></p></div>
|
|
|
<div class="paragraph"><p>Before building the executable, you must use the jMonkeyEngine SDK’s context menu action to <a href="../../sdk/model_loader_and_viewer.html">convert 3D models to .j3o binary format</a>.</p></div>
|
|
|
-<div class="olist arabic"><ol class="arabic"><li><p>Save your original models (.mesh.xml, .scene, .blend, or .obj files, plus textures) into <code>assets/Textures/</code>. (!)</p></li><li><p>Open the jME3 project in the jMonkeyEngine SDK.</p></li><li><p>Browse to the <code>assets</code> directory in the Projects window.</p></li><li><p>Right-click an original model in <code>assets/Textures/</code>, and choose “Convert to JME3 binary.</p></li><li><p>The converted file appears in the same directory as the original file. It has the same name and a <code>.j3o</code> suffix.</p></li><li><p>Move the .j3o file into the <code>assets/Models/</code> or <code>assets/Scenes/</code> directory.</p></li><li><p>Use the assetManager’s <code>load()</code> method to load the <code>.j3o</code> file.</p></li></ol></div>
|
|
|
+<div class="olist arabic"><ol class="arabic"><li><p>Save your original models (.mesh.xml, .scene, .blend, or .obj files, plus textures) into <code>assets/Textures/</code>. (!)</p></li><li><p>Open the jME3 project in the jMonkeyEngine SDK.</p></li><li><p>Browse to the <code>assets</code> directory in the Projects window.</p></li><li><p>Right-click an original model in <code>assets/Textures/</code>, and choose “Convert to JME3 binary”.</p></li><li><p>The converted file appears in the same directory as the original file. It has the same name and a <code>.j3o</code> suffix.</p></li><li><p>Move the .j3o file into the <code>assets/Models/</code> or <code>assets/Scenes/</code> directory.</p></li><li><p>Use the assetManager’s <code>load()</code> method to load the <code>.j3o</code> file.</p></li></ol></div>
|
|
|
<div class="paragraph"><p>This ensures that the model’s Texture paths keep working between your 3D mesh editor and JME3.</p></div>
|
|
|
<div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="paragraph"><p>If you must load custom assets from a non-.j3o ZIP file, you must manually ammend the <a href="../../sdk/default_build_script.html">default build script</a> to copy ZIP files into your distribution. ZIPs are skipped by default.</p></div></td></tr></table></div></div>
|
|
|
<div class="sect2"><h3 id="asset-handling-for-other-ides-codeless-projects">Asset Handling For Other IDEs: Codeless Projects</h3><div class="paragraph"><p><strong>Problem:</strong></p></div>
|
|
@@ -94,7 +94,7 @@ java.lang.NullPointerException</code></pre></div></div>
|
|
|
Store your assets there as described above.</p></li><li><p>Download and install the jMonkeyEngine SDK.</p></li><li><p>In the SDK, go to File → Import Projects → External Project Assets.</p></li><li><p>Select your (Eclipse or whatever) project and your assets folder in the Import Wizard.</p></li><li><p>You can now open this (Eclipse or whatever) project in the jMonkeyEngine SDK.<br>
|
|
|
Convert assets as described above.</p></li></ol></div>
|
|
|
<div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="paragraph"><p>If you don’t use the SDK for some reason, you can still convert models to j3o format: Load any model in Ogre3D or Wavefront format with the AssetManager.loadModel() as a spatial. Then save the spatial as j3o file using <a href="../../jme3/advanced/save_and_load.html">BinaryExporter</a>.</p></div></td></tr></table></div>
|
|
|
-<div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>Use file version control and let team members check out the project. Your developers open the project in Eclipse (etc) as they are used to. Additionally to their graphic tools, ask your graphic designers to install the jMonkeyEngine SDK, and to check out the codeless project that you just prepared. This makes it easy for non-coding team member to browse and preview game assets, to arrange scenes, and to convert files. At the same time, non-coders don’t accidentally mess with code, and developers don’t accidentally mess with assets. :)</p></div></td></tr></table></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2018-04-19 00:24:55 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
|
|
|
+<div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>Use file version control and let team members check out the project. Your developers open the project in Eclipse (etc) as they are used to. Additionally to their graphic tools, ask your graphic designers to install the jMonkeyEngine SDK, and to check out the codeless project that you just prepared. This makes it easy for non-coding team member to browse and preview game assets, to arrange scenes, and to convert files. At the same time, non-coders don’t accidentally mess with code, and developers don’t accidentally mess with assets. :)</p></div></td></tr></table></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2018-04-19 00:54:13 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
|
|
|
apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
|
|
|
indexName: 'jmonkeyengine',
|
|
|
inputSelector: '#doc-search',
|