| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><title>How to Build the jNavigation Recast Bindings</title><link rel="stylesheet" href="./asciidoctor.css">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
- <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"><link rel="stylesheet" href="/home/travis/build/jMonkeyEngine/wiki/build/asciidoc/html5/jme3/advanced/twemoji-awesome.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/advanced/building_recast.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/advanced/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>How to Build the jNavigation Recast Bindings</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#updating-methods">Updating methods</a><ul class="sectlevel2"><li><a href="#adding-new-methods-from-native-side">Adding new methods from native side</a></li></ul></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="paragraph"><p>jNavigation is Java jME port for Recast Navigation written in C++. The project has two parts:</p></div>
- <div class="olist arabic"><ol class="arabic"><li><p><a href="https://github.com/QuietOne/jNavigation-native">jNavigationNative</a> contains Recast Navigation library and C++ wrapper for java</p></li><li><p><a href="https://github.com/QuietOne/jNavigation">jNavigation</a> is Java project that uses jNavigationNative and is the project that the end user will use</p></li></ol></div>
- <div class="paragraph"><p>If there is need for updating Recast Navigation from native side, there are two kinds of updating bindings:</p></div>
- <div class="olist arabic"><ol class="arabic"><li><p>only updating methods as the Recast made more efficient or more precise</p></li><li><p>adding new methods for Recast use</p></li></ol></div></div></div>
- <div class="sect2"><h3 id="updating-methods">Updating methods</h3><div class="paragraph"><p>Only updating methods are easy. The requirements needed:</p></div>
- <div class="ulist"><ul><li><p>C++ compiler</p></li></ul></div>
- <div class="paragraph"><p>The jNavigationNative that has following folders and files (it has more, but these are the most important for now):</p></div>
- <div class="ulist"><ul><li><p>Recast</p><div class="ulist"><ul><li><p>Include</p></li><li><p>Source</p></li></ul></div></li><li><p>README.md</p></li><li><p>Recast_wrap.cxx - Java - C++ wrapper</p></li></ul></div>
- <div class="paragraph"><p>Updating the methods is only the matter of putting all headers from Recast Navigation to Include folder, source to Source folders, and then building the project.</p></div>
- <div class="paragraph"><p>As author of this project used the NetBeans 7.4 for building the project, the following instruction is included, if the building from terminal doesn’t work.</p></div>
- <div class="olist arabic"><ol class="arabic"><li><p>Setting <a href="https://netbeans.org/kb/docs/cnd/beginning-jni-linux.html"> parameters for NetBeans compiler</a></p></li><li><p>Remove all headers from Header Files</p></li><li><p>Remove all source files <strong>EXCEPT Recast_wrap.cxx</strong> from Source Files</p></li><li><p>Right click on Header files, select <code>Add Existing Item…</code> or <code>Add Existing Items from Folders…</code> and select needed headers</p></li><li><p>Right click on Source files, select <code>Add Existing Item…</code> or <code>Add Existing Items from Folders…</code> and select needed source files</p></li><li><p>Build</p></li><li><p>Add built project to jNavigation project</p></li><li><p>Build jNavigation project</p></li></ol></div>
- <div class="sect2"><h3 id="adding-new-methods-from-native-side">Adding new methods from native side</h3><div class="paragraph"><p>This is more complicated process and it includes the all work done in NetBeans mentioned in previous section. After that, there are two ways to add new function:</p></div>
- <div class="ulist"><ul><li><p>manually adding code to wrapper</p></li><li><p>creating new wrapper with <a href="http://swig.org/">SWIG</a></p></li></ul></div>
- <div class="sect3"><h4 id="manually-adding-code-to-wrapper">Manually adding code to wrapper</h4><div class="paragraph"><p>Example of method in wrapper:</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">SWIGEXPORT jint JNICALL Java_com_jme3_ai_navigation_utils_RecastJNI_rcIntArray_1size(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
- ...
- }</code></pre></div></div>
- <div class="paragraph"><p>The Recast_wrap.cxx uses SWIG wrapper so for declaring method in wrapper you must first use the keyword <code>SWIGEXPORT</code> then returning type (for more information on returning types see <a href="http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/types.html">link</a>), then again keyword <code>JNICALL</code> and then as the name of method <code>Java_com_jme3_ai_navigation_utils_RecastJNI_</code> + <code>name of class</code> + <code>name of method</code>, after that, there goes list of parameters needed for the function (for more information see <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html">link</a>). In body of method write how the function should be used.</p></div>
- <div class="paragraph"><p>After adding method to wrapper, compile project and add it to jNavigation.
- In jNavigation project in class <code>com.jme3.ai.navigation.utils.RecastJNI.java</code> add native method, and after that add in class from which you would like to use this method to call this native method. It seems a little bit more complicated than it should be, but this also for support for updating native side with SWIG.</p></div></div>
- <div class="sect3"><h4 id="creating-new-wrapper-with-swig">Creating new wrapper with SWIG</h4><div class="paragraph"><p>In some temporary folder add all headers. It shouldn’t contain any subfolders.</p></div>
- <div class="paragraph"><p>The following script was used for generating wrapper:</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>%module Recast
- %include "carrays.i"
- %array_class(double, DoubleArray);
- %array_class(float, FloatArray);
- %array_class(int, IntArray);
- %array_class(unsigned char, UCharArray);
- %array_class(unsigned short, UShortArray);
- %array_class(unsigned int, UIntArray);
- %array_class(long, LongArray);
- %array_class(bool, BooleanArray)
- %{
- #include "DetourAlloc.h"
- #include "DetourAssert.h"
- #include "DetourCommon.h"
- #include "DetourCrowd.h"
- #include "DetourLocalBoundary.h"
- #include "DetourMath.h"
- #include "DetourNavMesh.h"
- #include "DetourNavMeshBuilder.h"
- #include "DetourNavMeshQuery.h"
- #include "DetourNode.h"
- #include "DetourObstacleAvoidance.h"
- #include "DetourPathCorridor.h"
- #include "DetourPathQueue.h"
- #include "DetourProximityGrid.h"
- #include "DetourStatus.h"
- #include "DetourTileCache.h"
- #include "DetourTileCacheBuilder.h"
- #include "Recast.h"
- #include "RecastAlloc.h"
- #include "RecastAssert.h"
- %}
- /* Let's just grab the original header file here */
- %include "DetourAlloc.h"
- %include "DetourAssert.h"
- %include "DetourCommon.h"
- %include "DetourCrowd.h"
- %include "DetourLocalBoundary.h"
- %include "DetourMath.h"
- %include "DetourNavMesh.h"
- %include "DetourNavMeshBuilder.h"
- %include "DetourNavMeshQuery.h"
- %include "DetourNode.h"
- %include "DetourObstacleAvoidance.h"
- %include "DetourPathCorridor.h"
- %include "DetourPathQueue.h"
- %include "DetourProximityGrid.h"
- %include "DetourStatus.h"
- %include "DetourTileCache.h"
- %include "DetourTileCacheBuilder.h"
- %include "Recast.h"
- %include "RecastAlloc.h"
- %include "RecastAssert.h"
- %pragma(java) jniclasscode=%{
- static {
- System.load("Recast");
- }
- %}</code></pre></div></div>
- <div class="paragraph"><p>If there are more headers at some moment, include them in both places.</p></div>
- <div class="olist arabic"><ol class="arabic"><li><p>Save script as Recast.i into temp folder with rest of the headers</p></li><li><p>Install SWIG if not already</p></li><li><p>Open terminal and go to folder where the script is</p></li><li><p>Execute command <code>swig -c++ -java Recast.i</code></p></li><li><p>Now SWIG will generate Java classes and new Recast_wrap.cxx</p></li><li><p>Recast_wrap.cxx put in jNavigationNative with new headers and source files, as previously mentioned</p></li><li><p>Build that project</p></li><li><p>For jNavigation side, put only new methods in RecastJNI, and use where they are being used. For that you can see in Java class that are build with SWIG.</p></li><li><p>If method uses some explicit SWIG type, try to use some method for converting it into jME type, or similar. You can probably find something in package <code>com.jme3.ai.navigation.utils</code></p></li></ol></div></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-20 23:30:51 +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',
- debug: false // Set debug to true if you want to inspect the dropdown
- });</script></body></html>
|