Updated jAssimp API. 40% are complete now, some JNI wrappers are ready

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@34 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
This commit is contained in:
aramis_acg
2008-05-23 12:30:52 +00:00
parent 4254fd9fe0
commit aab9376628
13 changed files with 852 additions and 95 deletions
+8
View File
@@ -200,6 +200,14 @@ const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags
// validate the flags
ai_assert(ValidateFlags(pFlags));
// check whether this Importer instance has already loaded
// a scene. In this case we need to delete the old one
if (this->mScene)
{
delete mScene;
this->mScene = NULL;
}
// first check if the file is accessable at all
if( !mIOHandler->Exists( pFile))
{
+1
View File
@@ -4,3 +4,4 @@ javah -classpath ".\..\..\port\jAssimp\classes" -d "." "assimp.Node"
javah -classpath ".\..\..\port\jAssimp\classes" -d "." "assimp.Scene"
javah -classpath ".\..\..\port\jAssimp\classes" -d "." "assimp.Mesh"
javah -classpath ".\..\..\port\jAssimp\classes" -d "." "assimp.Texture"
javah -classpath ".\..\..\port\jAssimp\classes" -d "." "assimp.Animation"
+234 -2
View File
@@ -43,7 +43,239 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if (defined ASSIMP_JNI_EXPORT)
// include the JNI API
#include <jni.h>
// include the header files generated by javah
#include "assimp_Importer.h"
#include "assimp_Animation.h"
#include "assimp_Node.h"
#include "assimp_Texture.h"
#include "assimp_Mesh.h"
#include "assimp_Material.h"
// include assimp
#include "../../include/aiTypes.h"
#include "../../include/aiMesh.h"
#include "../../include/aiAnim.h"
#include "../../include/aiScene.h"
#include "../../include/aiAssert.h"
#include "../../include/aiPostProcess.h"
#include "../../include/assimp.hpp"
#include "../DefaultLogger.h"
using namespace Assimp;
#include <list>
namespace Assimp {
namespace JNIBridge {
// used as error return code
#define AI_JNI_ERROR_RETURN 0xffffffff
// typedef for a jassimp context, used to uniquely identify
// the Importer object which belongs to a java Importer
typedef uint64_t JASSIMP_CONTEXT;
#if (defined _DEBUG)
typedef std::list< JASSIMP_CONTEXT > ImporterContextList;
static ImporterContextList g_listActiveContexts;
// ------------------------------------------------------------------------------------------------
/* Used in debug builds to validate a context
*/
bool jValidateContext (JASSIMP_CONTEXT context)
{
for (ImporterContextList::const_iterator
i = g_listActiveContexts.begin();
i != g_listActiveContexts.end();++i)
{
if (context == *i)return true;
}
DefaultLogger::get()->error("[jnibridge] Invalid context");
return false;
}
// ------------------------------------------------------------------------------------------------
/* Used in debug builds to validate a given scene
*/
bool jValidateScene (const aiScene* scene)
{
if (!scene)
{
DefaultLogger::get()->error("[jnibridge] No asset loaded at the moment");
return false;
}
return true;
}
#endif // ! ASSIMP_DEBUG
// ------------------------------------------------------------------------------------------------
/* Used in debug builds to validate a given scene
*/
Assimp::Importer* jGetValidImporterScenePair (JASSIMP_CONTEXT jvmcontext)
{
#if (defined _DEBUG)
if (!jValidateContext((JASSIMP_CONTEXT)jvmcontext))return NULL;
#endif // ! ASSIMP_DEBUG
// get the importer instance from the context
Assimp::Importer* pcImp = (Assimp::Importer*)jvmcontext;
#if (defined _DEBUG)
if (!jValidateScene(pcImp->GetScene()))return NULL;
#endif // ! ASSIMP_DEBUG
return pcImp;
}
// ------------------------------------------------------------------------------------------------
/*
* Class: assimp_Importer
* Method: _NativeInitContext
* Signature: ()I
*/
JNIEXPORT jlong JNICALL Java_assimp_Importer__1NativeInitContext
(JNIEnv * jvmenv, jobject jvmthis)
{
ai_assert(NULL != jvmenv && NULL != jvmthis);
// 2^64-1 indicates error
JASSIMP_CONTEXT context = 0xffffffffffffffffL;
// create a new Importer instance
Assimp::Importer* pcImp = new Assimp::Importer();
context = (JASSIMP_CONTEXT)(uintptr_t)pcImp;
#if (defined _DEBUG)
g_listActiveContexts.push_back(context);
#endif // ! ASSIMP_DEBUG
return context;
}
// ------------------------------------------------------------------------------------------------
/*
* Class: assimp_Importer
* Method: _NativeFreeContext
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_assimp_Importer__1NativeFreeContext
(JNIEnv * jvmenv, jobject jvmthis, jlong jvmcontext)
{
ai_assert(NULL != jvmenv && NULL != jvmthis);
#if (defined _DEBUG)
if (!jValidateContext((JASSIMP_CONTEXT)jvmcontext))return AI_JNI_ERROR_RETURN;
#endif // ! ASSIMP_DEBUG
// delete the Importer instance
Assimp::Importer* pcImp = (Assimp::Importer*)jvmcontext;
delete pcImp;
#if (defined _DEBUG)
g_listActiveContexts.remove(jvmcontext);
#endif // ! ASSIMP_DEBUG
return 0;
}
// ------------------------------------------------------------------------------------------------
/*
* Class: assimp_Importer
* Method: _NativeLoad
* Signature: (Ljava/lang/String;II)I
*/
JNIEXPORT jint JNICALL Java_assimp_Importer__1NativeLoad
(JNIEnv *jvmenv, jobject jvmthis, jstring jvmpath, jint jvmflags, jlong jvmcontext)
{
ai_assert(NULL != jvmenv && NULL != jvmthis);
jint iRet = 0;
#if (defined _DEBUG)
if (!jValidateContext((JASSIMP_CONTEXT)jvmcontext))return AI_JNI_ERROR_RETURN;
#endif // ! ASSIMP_DEBUG
// get the path from the jstring
const char* szPath = jvmenv->GetStringUTFChars(jvmpath,NULL);
if (!szPath)
{
DefaultLogger::get()->error("[jnibridge] Unable to get path string from the java vm");
return AI_JNI_ERROR_RETURN;
}
// get the importer instance from the context
Assimp::Importer* pcImp = (Assimp::Importer*)jvmcontext;
// and load the file. The aiScene object itself remains accessible
// via Importer.GetScene().
if(NULL == pcImp->ReadFile(std::string(szPath),(unsigned int)jvmflags))
{
DefaultLogger::get()->error("[jnibridge] Unable to load asset");
// release the path again
jvmenv->ReleaseStringUTFChars(jvmpath,szPath);
return AI_JNI_ERROR_RETURN;
}
// release the path again
jvmenv->ReleaseStringUTFChars(jvmpath,szPath);
return iRet;
}
// ------------------------------------------------------------------------------------------------
/*
* Class: assimp_Scene
* Method: _NativeGetNumMeshes
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumMeshes
(JNIEnv *jvmenv, jobject jvmthis, jlong jvmcontext)
{
ai_assert(NULL != jvmenv && NULL != jvmthis);
// we need a valid scene for this
Assimp::Importer* pcImp = jGetValidImporterScenePair(jvmcontext);
if (!pcImp)return AI_JNI_ERROR_RETURN;
return (jint)pcImp->GetScene()->mNumMeshes;
}
// ------------------------------------------------------------------------------------------------
/*
* Class: assimp_Scene
* Method: _NativeGetNumAnimations
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumAnimations
(JNIEnv *jvmenv, jobject jvmthis, jlong jvmcontext)
{
ai_assert(NULL != jvmenv && NULL != jvmthis);
// we need a valid scene for this
Assimp::Importer* pcImp = jGetValidImporterScenePair(jvmcontext);
if (!pcImp)return AI_JNI_ERROR_RETURN;
return (jint)pcImp->GetScene()->mNumAnimations;
}
// ------------------------------------------------------------------------------------------------
/*
* Class: assimp_Scene
* Method: _NativeGetNumTextures
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumTextures
(JNIEnv *jvmenv, jobject jvmthis, jlong jvmcontext)
{
ai_assert(NULL != jvmenv && NULL != jvmthis);
// we need a valid scene for this
Assimp::Importer* pcImp = jGetValidImporterScenePair(jvmcontext);
if (!pcImp)return AI_JNI_ERROR_RETURN;
return (jint)pcImp->GetScene()->mNumTextures;
}
// ------------------------------------------------------------------------------------------------
/*
* Class: assimp_Scene
* Method: _NativeGetNumMaterials
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumMaterials
(JNIEnv *jvmenv, jobject jvmthis, jlong jvmcontext)
{
ai_assert(NULL != jvmenv && NULL != jvmthis);
// we need a valid scene for this
Assimp::Importer* pcImp = jGetValidImporterScenePair(jvmcontext);
if (!pcImp)return AI_JNI_ERROR_RETURN;
return (jint)pcImp->GetScene()->mNumMaterials;
}
}; //! namespace JNIBridge
}; //! namespace Assimp
#endif // !ASSIMP_JNI_EXPORT
+13
View File
@@ -0,0 +1,13 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class assimp_Animation */
#ifndef _Included_assimp_Animation
#define _Included_assimp_Animation
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif
+4 -4
View File
@@ -18,18 +18,18 @@ JNIEXPORT jint JNICALL Java_assimp_Importer__1NativeInitContext
/*
* Class: assimp_Importer
* Method: _NativeFreeContext
* Signature: (I)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_assimp_Importer__1NativeFreeContext
(JNIEnv *, jobject, jint);
(JNIEnv *, jobject, jlong);
/*
* Class: assimp_Importer
* Method: _NativeLoad
* Signature: (Ljava/lang/String;II)I
* Signature: (Ljava/lang/String;IJ)I
*/
JNIEXPORT jint JNICALL Java_assimp_Importer__1NativeLoad
(JNIEnv *, jobject, jstring, jint, jint);
(JNIEnv *, jobject, jstring, jint, jlong);
#ifdef __cplusplus
}
+8 -8
View File
@@ -10,34 +10,34 @@ extern "C" {
/*
* Class: assimp_Scene
* Method: _NativeGetNumMeshes
* Signature: (I)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumMeshes
(JNIEnv *, jobject, jint);
(JNIEnv *, jobject, jlong);
/*
* Class: assimp_Scene
* Method: _NativeGetNumAnimations
* Signature: (I)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumAnimations
(JNIEnv *, jobject, jint);
(JNIEnv *, jobject, jlong);
/*
* Class: assimp_Scene
* Method: _NativeGetNumTextures
* Signature: (I)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumTextures
(JNIEnv *, jobject, jint);
(JNIEnv *, jobject, jlong);
/*
* Class: assimp_Scene
* Method: _NativeGetNumMaterials
* Signature: (I)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumMaterials
(JNIEnv *, jobject, jint);
(JNIEnv *, jobject, jlong);
#ifdef __cplusplus
}