Merge pull request #491 from arris69/Fix_Jassimp_for_Android

pull/502/head^2
Alexander Gessler 2015-03-18 23:06:23 +01:00
commit ee98c80654
2 changed files with 72 additions and 25 deletions

View File

@ -0,0 +1,13 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := jassimp
LOCAL_SRC_FILES := src/jassimp.cpp
LOCAL_CFLAGS += -DJNI_LOG
#LOCAL_STATIC_LIBRARIES := assimp_static
LOCAL_SHARED_LIBRARIES := assimp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)

View File

@ -5,12 +5,16 @@
#ifdef JNI_LOG
#ifdef ANDROID
#include <android/log.h>
#define lprintf(...) __android_log_print(ANDROID_LOG_VERBOSE, __func__, __VA_ARGS__)
#else
#define lprintf(...) printf (__VA_ARGS__)
#endif /* ANDROID */
#else
#define lprintf
#endif
static bool createInstance(JNIEnv *env, const char* className, jobject& newInstance)
{
jclass clazz = env->FindClass(className);
@ -30,6 +34,7 @@ static bool createInstance(JNIEnv *env, const char* className, jobject& newInsta
}
newInstance = env->NewObject(clazz, ctr_id);
env->DeleteLocalRef(clazz);
if (NULL == newInstance)
{
@ -41,7 +46,7 @@ static bool createInstance(JNIEnv *env, const char* className, jobject& newInsta
}
static bool createInstance(JNIEnv *env, const char* className, const char* signature, const jvalue* params, jobject& newInstance)
static bool createInstance(JNIEnv *env, const char* className, const char* signature,/* const*/ jvalue* params, jobject& newInstance)
{
jclass clazz = env->FindClass(className);
@ -60,6 +65,7 @@ static bool createInstance(JNIEnv *env, const char* className, const char* signa
}
newInstance = env->NewObjectA(clazz, ctr_id, params);
env->DeleteLocalRef(clazz);
if (NULL == newInstance)
{
@ -82,6 +88,7 @@ static bool getField(JNIEnv *env, jobject object, const char* fieldName, const c
}
jfieldID fieldId = env->GetFieldID(clazz, fieldName, signature);
env->DeleteLocalRef(clazz);
if (NULL == fieldId)
{
@ -106,6 +113,7 @@ static bool setIntField(JNIEnv *env, jobject object, const char* fieldName, jint
}
jfieldID fieldId = env->GetFieldID(clazz, fieldName, "I");
env->DeleteLocalRef(clazz);
if (NULL == fieldId)
{
@ -130,6 +138,7 @@ static bool setFloatField(JNIEnv *env, jobject object, const char* fieldName, jf
}
jfieldID fieldId = env->GetFieldID(clazz, fieldName, "F");
env->DeleteLocalRef(clazz);
if (NULL == fieldId)
{
@ -154,6 +163,7 @@ static bool setObjectField(JNIEnv *env, jobject object, const char* fieldName, c
}
jfieldID fieldId = env->GetFieldID(clazz, fieldName, signature);
env->DeleteLocalRef(clazz);
if (NULL == fieldId)
{
@ -192,7 +202,7 @@ static bool getStaticField(JNIEnv *env, const char* className, const char* field
static bool call(JNIEnv *env, jobject object, const char* typeName, const char* methodName,
const char* signature, const jvalue* params)
const char* signature,/* const*/ jvalue* params)
{
jclass clazz = env->FindClass(typeName);
@ -203,6 +213,7 @@ static bool call(JNIEnv *env, jobject object, const char* typeName, const char*
}
jmethodID mid = env->GetMethodID(clazz, methodName, signature);
env->DeleteLocalRef(clazz);
if (NULL == mid)
{
@ -210,6 +221,27 @@ static bool call(JNIEnv *env, jobject object, const char* typeName, const char*
return false;
}
jboolean jReturnValue = env->CallBooleanMethod(object, mid, params[0].l);
return (bool)jReturnValue;
}
static bool callv(JNIEnv *env, jobject object, const char* typeName,
const char* methodName, const char* signature,/* const*/ jvalue* params) {
jclass clazz = env->FindClass(typeName);
if (NULL == clazz) {
lprintf("could not find class %s\n", typeName);
return false;
}
jmethodID mid = env->GetMethodID(clazz, methodName, signature);
env->DeleteLocalRef(clazz);
if (NULL == mid) {
lprintf("could not find method %s with signature %s in type %s\n", methodName, signature, typeName);
return false;
}
env->CallVoidMethodA(object, mid, params);
return true;
@ -217,7 +249,7 @@ static bool call(JNIEnv *env, jobject object, const char* typeName, const char*
static bool callStaticObject(JNIEnv *env, const char* typeName, const char* methodName,
const char* signature, const jvalue* params, jobject& returnValue)
const char* signature,/* const*/ jvalue* params, jobject& returnValue)
{
jclass clazz = env->FindClass(typeName);
@ -338,7 +370,7 @@ static bool loadMeshes(JNIEnv *env, const aiScene* cScene, jobject& jScene)
/* set general mesh data in java */
jvalue setTypesParams[1];
setTypesParams[0].i = cMesh->mPrimitiveTypes;
if (!call(env, jMesh, "jassimp/AiMesh", "setPrimitiveTypes", "(I)V", setTypesParams))
if (!callv(env, jMesh, "jassimp/AiMesh", "setPrimitiveTypes", "(I)V", setTypesParams))
{
return false;
}
@ -380,7 +412,7 @@ static bool loadMeshes(JNIEnv *env, const aiScene* cScene, jobject& jScene)
allocateBuffersParams[1].i = cMesh->mNumFaces;
allocateBuffersParams[2].z = isPureTriangle;
allocateBuffersParams[3].i = (jint) faceBufferSize;
if (!call(env, jMesh, "jassimp/AiMesh", "allocateBuffers", "(IIZI)V", allocateBuffersParams))
if (!callv(env, jMesh, "jassimp/AiMesh", "allocateBuffers", "(IIZI)V", allocateBuffersParams))
{
return false;
}
@ -470,7 +502,7 @@ static bool loadMeshes(JNIEnv *env, const aiScene* cScene, jobject& jScene)
jvalue allocateDataChannelParams[2];
allocateDataChannelParams[0].i = 0;
allocateDataChannelParams[1].i = 0;
if (!call(env, jMesh, "jassimp/AiMesh", "allocateDataChannel", "(II)V", allocateDataChannelParams))
if (!callv(env, jMesh, "jassimp/AiMesh", "allocateDataChannel", "(II)V", allocateDataChannelParams))
{
lprintf("could not allocate normal data channel\n");
return false;
@ -491,7 +523,7 @@ static bool loadMeshes(JNIEnv *env, const aiScene* cScene, jobject& jScene)
jvalue allocateDataChannelParams[2];
allocateDataChannelParams[0].i = 1;
allocateDataChannelParams[1].i = 0;
if (!call(env, jMesh, "jassimp/AiMesh", "allocateDataChannel", "(II)V", allocateDataChannelParams))
if (!callv(env, jMesh, "jassimp/AiMesh", "allocateDataChannel", "(II)V", allocateDataChannelParams))
{
lprintf("could not allocate tangents data channel\n");
return false;
@ -512,7 +544,7 @@ static bool loadMeshes(JNIEnv *env, const aiScene* cScene, jobject& jScene)
jvalue allocateDataChannelParams[2];
allocateDataChannelParams[0].i = 2;
allocateDataChannelParams[1].i = 0;
if (!call(env, jMesh, "jassimp/AiMesh", "allocateDataChannel", "(II)V", allocateDataChannelParams))
if (!callv(env, jMesh, "jassimp/AiMesh", "allocateDataChannel", "(II)V", allocateDataChannelParams))
{
lprintf("could not allocate bitangents data channel\n");
return false;
@ -535,7 +567,7 @@ static bool loadMeshes(JNIEnv *env, const aiScene* cScene, jobject& jScene)
jvalue allocateDataChannelParams[2];
allocateDataChannelParams[0].i = 3;
allocateDataChannelParams[1].i = c;
if (!call(env, jMesh, "jassimp/AiMesh", "allocateDataChannel", "(II)V", allocateDataChannelParams))
if (!callv(env, jMesh, "jassimp/AiMesh", "allocateDataChannel", "(II)V", allocateDataChannelParams))
{
lprintf("could not allocate colorset data channel\n");
return false;
@ -574,7 +606,7 @@ static bool loadMeshes(JNIEnv *env, const aiScene* cScene, jobject& jScene)
}
allocateDataChannelParams[1].i = c;
if (!call(env, jMesh, "jassimp/AiMesh", "allocateDataChannel", "(II)V", allocateDataChannelParams))
if (!callv(env, jMesh, "jassimp/AiMesh", "allocateDataChannel", "(II)V", allocateDataChannelParams))
{
lprintf("could not allocate texture coordinates data channel\n");
return false;
@ -671,7 +703,7 @@ static bool loadMeshes(JNIEnv *env, const aiScene* cScene, jobject& jScene)
wrapParams[0].l = jMatrixArr;
jobject jMatrix;
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapMatrix", "([F)Ljava/lang/Object;", wrapParams, jMatrix))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapMatrix", "([F)Ljava/lang/Object;", wrapParams, jMatrix))
{
return false;
}
@ -701,6 +733,8 @@ static bool loadMeshes(JNIEnv *env, const aiScene* cScene, jobject& jScene)
}
}
}
env->DeleteLocalRef(jMeshes);
env->DeleteLocalRef(jMesh);
}
return true;
@ -719,7 +753,7 @@ static bool loadSceneNode(JNIEnv *env, const aiNode *cNode, jobject parent, jobj
wrapMatParams[0].l = jMatrixArr;
jobject jMatrix;
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapMatrix", "([F)Ljava/lang/Object;", wrapMatParams, jMatrix))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapMatrix", "([F)Ljava/lang/Object;", wrapMatParams, jMatrix))
{
return false;
}
@ -749,7 +783,7 @@ static bool loadSceneNode(JNIEnv *env, const aiNode *cNode, jobject parent, jobj
wrapNodeParams[2].l = jMeshrefArr;
wrapNodeParams[3].l = jNodeName;
jobject jNode;
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapSceneNode",
if (!callStaticObject(env, "jassimp/Jassimp", "wrapSceneNode",
"(Ljava/lang/Object;Ljava/lang/Object;[ILjava/lang/String;)Ljava/lang/Object;", wrapNodeParams, jNode))
{
return false;
@ -842,7 +876,7 @@ static bool loadMaterials(JNIEnv *env, const aiScene* cScene, jobject& jScene)
setNumberParams[0].i = ttInd;
setNumberParams[1].i = num;
if (!call(env, jMaterial, "jassimp/AiMaterial", "setTextureNumber", "(II)V", setNumberParams))
if (!callv(env, jMaterial, "jassimp/AiMaterial", "setTextureNumber", "(II)V", setNumberParams))
{
return false;
}
@ -880,7 +914,7 @@ static bool loadMaterials(JNIEnv *env, const aiScene* cScene, jobject& jScene)
wrapColorParams[0].f = ((float*) cProperty->mData)[0];
wrapColorParams[1].f = ((float*) cProperty->mData)[1];
wrapColorParams[2].f = ((float*) cProperty->mData)[2];
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapColor3", "(FFF)Ljava/lang/Object;", wrapColorParams, jData))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapColor3", "(FFF)Ljava/lang/Object;", wrapColorParams, jData))
{
return false;
}
@ -905,7 +939,7 @@ static bool loadMaterials(JNIEnv *env, const aiScene* cScene, jobject& jScene)
wrapColorParams[1].f = ((float*) cProperty->mData)[1];
wrapColorParams[2].f = ((float*) cProperty->mData)[2];
wrapColorParams[3].f = ((float*) cProperty->mData)[3];
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapColor4", "(FFFF)Ljava/lang/Object;", wrapColorParams, jData))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapColor4", "(FFFF)Ljava/lang/Object;", wrapColorParams, jData))
{
return false;
}
@ -1137,7 +1171,7 @@ static bool loadLights(JNIEnv *env, const aiScene* cScene, jobject& jScene)
wrapColorParams[1].f = cLight->mColorDiffuse.g;
wrapColorParams[2].f = cLight->mColorDiffuse.b;
jobject jDiffuse;
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapColor3", "(FFF)Ljava/lang/Object;", wrapColorParams, jDiffuse))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapColor3", "(FFF)Ljava/lang/Object;", wrapColorParams, jDiffuse))
{
return false;
}
@ -1146,7 +1180,7 @@ static bool loadLights(JNIEnv *env, const aiScene* cScene, jobject& jScene)
wrapColorParams[1].f = cLight->mColorSpecular.g;
wrapColorParams[2].f = cLight->mColorSpecular.b;
jobject jSpecular;
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapColor3", "(FFF)Ljava/lang/Object;", wrapColorParams, jSpecular))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapColor3", "(FFF)Ljava/lang/Object;", wrapColorParams, jSpecular))
{
return false;
}
@ -1155,7 +1189,7 @@ static bool loadLights(JNIEnv *env, const aiScene* cScene, jobject& jScene)
wrapColorParams[1].f = cLight->mColorAmbient.g;
wrapColorParams[2].f = cLight->mColorAmbient.b;
jobject jAmbient;
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapColor3", "(FFF)Ljava/lang/Object;", wrapColorParams, jAmbient))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapColor3", "(FFF)Ljava/lang/Object;", wrapColorParams, jAmbient))
{
return false;
}
@ -1167,7 +1201,7 @@ static bool loadLights(JNIEnv *env, const aiScene* cScene, jobject& jScene)
wrapVec3Params[1].f = cLight->mPosition.y;
wrapVec3Params[2].f = cLight->mPosition.z;
jobject jPosition;
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapVec3", "(FFF)Ljava/lang/Object;", wrapVec3Params, jPosition))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapVec3", "(FFF)Ljava/lang/Object;", wrapVec3Params, jPosition))
{
return false;
}
@ -1176,7 +1210,7 @@ static bool loadLights(JNIEnv *env, const aiScene* cScene, jobject& jScene)
wrapVec3Params[1].f = cLight->mPosition.y;
wrapVec3Params[2].f = cLight->mPosition.z;
jobject jDirection;
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapVec3", "(FFF)Ljava/lang/Object;", wrapVec3Params, jDirection))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapVec3", "(FFF)Ljava/lang/Object;", wrapVec3Params, jDirection))
{
return false;
}
@ -1242,7 +1276,7 @@ static bool loadCameras(JNIEnv *env, const aiScene* cScene, jobject& jScene)
wrapPositionParams[1].f = cCamera->mPosition.y;
wrapPositionParams[2].f = cCamera->mPosition.z;
jobject jPosition;
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapVec3", "(FFF)Ljava/lang/Object;", wrapPositionParams, jPosition))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapVec3", "(FFF)Ljava/lang/Object;", wrapPositionParams, jPosition))
{
return false;
}
@ -1251,7 +1285,7 @@ static bool loadCameras(JNIEnv *env, const aiScene* cScene, jobject& jScene)
wrapPositionParams[1].f = cCamera->mUp.y;
wrapPositionParams[2].f = cCamera->mUp.z;
jobject jUp;
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapVec3", "(FFF)Ljava/lang/Object;", wrapPositionParams, jUp))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapVec3", "(FFF)Ljava/lang/Object;", wrapPositionParams, jUp))
{
return false;
}
@ -1260,7 +1294,7 @@ static bool loadCameras(JNIEnv *env, const aiScene* cScene, jobject& jScene)
wrapPositionParams[1].f = cCamera->mLookAt.y;
wrapPositionParams[2].f = cCamera->mLookAt.z;
jobject jLookAt;
if (!callStaticObject(env, "Ljassimp/Jassimp;", "wrapVec3", "(FFF)Ljava/lang/Object;", wrapPositionParams, jLookAt))
if (!callStaticObject(env, "jassimp/Jassimp", "wrapVec3", "(FFF)Ljava/lang/Object;", wrapPositionParams, jLookAt))
{
return false;
}