MakeVerbose moved to subdirectory

pp step c'tors are protected now
viewer changes
JNI additions - JNI BUILD CURRENTLY NOT WORKING

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@43 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2008-05-26 21:28:19 +00:00
parent 36d120f886
commit 70f155e515
37 changed files with 718 additions and 133 deletions

View File

@ -42,7 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @file Implementation of the 3ds importer class */
#include "3DSLoader.h"
#include "MaterialSystem.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/IOStream.h"
#include "../include/IOSystem.h"

View File

@ -42,7 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @file Implementation of the 3ds importer class */
#include "3DSLoader.h"
#include "MaterialSystem.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/IOStream.h"
#include "../include/IOSystem.h"

View File

@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ASELoader.h"
#include "MaterialSystem.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "fast_atof.h"
#include "../include/IOStream.h"

View File

@ -41,7 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @file Implementation of the few default functions of the base importer class */
#include "BaseImporter.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/aiScene.h"
#include "../include/aiAssert.h"
using namespace Assimp;

View File

@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <vector>
#include <assert.h>
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "CalcTangentsProcess.h"
#include "SpatialSort.h"
#include "../include/aiPostProcess.h"

View File

@ -61,7 +61,7 @@ class CalcTangentsProcess : public BaseProcess
{
friend class Importer;
public:
protected:
/** Constructor to be privately used by Importer */
CalcTangentsProcess();

View File

@ -2,7 +2,7 @@
* to a left-handed coordinate system.
*/
#include "ConvertToLHProcess.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/aiPostProcess.h"
#include "../include/aiMesh.h"
#include "../include/aiAnim.h"

View File

@ -39,7 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/aiAssert.h"
#include "DefaultIOSystem.h"
#include "Win32DebugLogStream.h"

View File

@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* normals for all imported faces.
*/
#include "GenFaceNormalsProcess.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/aiPostProcess.h"
#include "../include/aiMesh.h"
#include "../include/aiScene.h"

View File

@ -55,7 +55,7 @@ class GenFaceNormalsProcess : public BaseProcess
{
friend class Importer;
public:
protected:
/** Constructor to be privately used by Importer */
GenFaceNormalsProcess();

View File

@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "GenVertexNormalsProcess.h"
#include "SpatialSort.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/aiPostProcess.h"
#include "../include/aiMesh.h"
#include "../include/aiScene.h"

View File

@ -54,7 +54,7 @@ class GenVertexNormalsProcess : public BaseProcess
{
friend class Importer;
public:
protected:
/** Constructor to be privately used by Importer */
GenVertexNormalsProcess();

View File

@ -88,7 +88,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "GenVertexNormalsProcess.h"
#include "KillNormalsProcess.h"
#include "SplitLargeMeshes.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
using namespace Assimp;

View File

@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assert.h>
#include "JoinVerticesProcess.h"
#include "SpatialSort.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/aiPostProcess.h"
#include "../include/aiMesh.h"
#include "../include/aiScene.h"

View File

@ -63,7 +63,7 @@ class JoinVerticesProcess : public BaseProcess
{
friend class Importer;
public:
protected:
/** Constructor to be privately used by Importer */
JoinVerticesProcess();

View File

@ -41,7 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @file Implementation of the post processing step tokill mesh normals
*/
#include "KillNormalsProcess.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/aiPostProcess.h"
#include "../include/aiMesh.h"
#include "../include/aiScene.h"

View File

@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "MaterialSystem.h"
#include "MDLLoader.h"
#include "MDLDefaultColorMap.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/IOStream.h"
#include "../include/IOSystem.h"

View File

@ -7,7 +7,7 @@
#include "../include/aiScene.h"
#include "../include/aiAssert.h"
#include "MaterialSystem.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include <boost/scoped_ptr.hpp>
#include <boost/format.hpp>

View File

@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "PLYLoader.h"
#include "MaterialSystem.h"
#include "fast_atof.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "ByteSwap.h"
#include "../include/IOStream.h"

View File

@ -42,7 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @file Implementation of the SplitLargeMeshes postprocessing step
*/
#include "SplitLargeMeshes.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/aiPostProcess.h"
#include "../include/aiMesh.h"
#include "../include/aiScene.h"

View File

@ -1,10 +1,51 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (ASSIMP)
---------------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
/** @file Implementation of the post processing step to split up
* all faces with more than three indices into triangles.
*/
#include <vector>
#include <assert.h>
#include "TriangulateProcess.h"
#include "DefaultLogger.h"
#include "../include/DefaultLogger.h"
#include "../include/aiPostProcess.h"
#include "../include/aiMesh.h"
#include "../include/aiScene.h"

View File

@ -60,7 +60,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../include/aiPostProcess.h"
#include "../../include/assimp.hpp"
#include "../DefaultLogger.h"
#include "../../include/DefaultLogger.h"
#include "JNIEnvironment.h"
#include "JNILogger.h"
using namespace Assimp;
@ -146,6 +149,24 @@ JNIEXPORT jlong JNICALL Java_assimp_Importer__1NativeInitContext
#if (defined _DEBUG)
g_listActiveContexts.push_back(context);
#endif // ! ASSIMP_DEBUG
// need to setup the logger
JNILogDispatcher* pcLogger;
if (DefaultLogger::isNullLogger())
{
pcLogger = new JNILogDispatcher();
DefaultLogger::set (pcLogger);
}
else
{
JNILogDispatcher* pcLogger = ( JNILogDispatcher* )DefaultLogger::get();
pcLogger->AddRef();
}
// setup the JNI environment ...
// simply setup the newest JNIEnv*
JNIEnvironment::Get()->AttachToCurrentThread(jvmenv);
return context;
}
// ------------------------------------------------------------------------------------------------
@ -169,6 +190,8 @@ JNIEXPORT jint JNICALL Java_assimp_Importer__1NativeFreeContext
#if (defined _DEBUG)
g_listActiveContexts.remove(jvmcontext);
#endif // ! ASSIMP_DEBUG
JNIEnvironment::Get()->DetachFromCurrentThread();
return 0;
}
// ------------------------------------------------------------------------------------------------
@ -187,7 +210,7 @@ JNIEXPORT jint JNICALL Java_assimp_Importer__1NativeLoad
#endif // ! ASSIMP_DEBUG
// get the path from the jstring
const char* szPath = jvmenv->GetStringUTFChars(jvmpath,NULL);
const char* szPath = JNU_GetStringNativeChars(jvmenv,jvmpath);
if (!szPath)
{
DefaultLogger::get()->error("[jnibridge] Unable to get path string from the java vm");
@ -203,11 +226,11 @@ JNIEXPORT jint JNICALL Java_assimp_Importer__1NativeLoad
DefaultLogger::get()->error("[jnibridge] Unable to load asset");
// release the path again
jvmenv->ReleaseStringUTFChars(jvmpath,szPath);
free((void*)szPath);
return AI_JNI_ERROR_RETURN;
}
// release the path again
jvmenv->ReleaseStringUTFChars(jvmpath,szPath);
free((void*)szPath);
return iRet;
}

View File

@ -0,0 +1,188 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (ASSIMP)
---------------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
/** @file Implementation of the JNI API for jAssimp */
#if (defined ASSIMP_JNI_EXPORT)
#include "JNIEnvironment.h"
#include "JNILogger.h"
using namespace Assimp;
namespace Assimp {
namespace JNIBridge {
/*static*/ jclass JNIEnvironment::Class_java_lang_String = 0;
/*static*/ jmethodID JNIEnvironment::MID_String_getBytes = 0;
/*static*/ jmethodID JNIEnvironment::MID_String_init = 0;
// ------------------------------------------------------------------------------------------------
bool JNIEnvironment::AttachToCurrentThread (JNIEnv* pcEnv)
{
ai_assert(NULL != pcEnv);
// first initialize some members
if (0 == Class_java_lang_String)
{
if( 0 == (Class_java_lang_String = pcEnv->FindClass("java.lang.String")))
return false;
}
if (0 == MID_String_getBytes)
{
if( 0 == (MID_String_getBytes = pcEnv->GetStaticMethodID(
Class_java_lang_String,"getBytes","()[byte")))
return false;
}
if (0 == MID_String_init)
{
if( 0 == (MID_String_init = pcEnv->GetStaticMethodID(
Class_java_lang_String,"String","([byte)V")))
return false;
}
// now initialize the thread-local storage
if (NULL == this->ptr.get())
{
// attach to the current thread
JavaVM* vm;
pcEnv->GetJavaVM(&vm);
vm->AttachCurrentThread((void **) &pcEnv, NULL);
this->ptr.reset(new JNIThreadData(pcEnv));
}
// increase the reference counter
else this->ptr->m_iNumRef++;
// attach the logger
((JNILogDispatcher*)DefaultLogger::get())->OnAttachToCurrentThread(this->ptr.get());
return true;
}
// ------------------------------------------------------------------------------------------------
bool JNIEnvironment::DetachFromCurrentThread ()
{
ai_assert(NULL != pcEnv);
// detach the logger
((JNILogDispatcher*)DefaultLogger::get())->OnDetachFromCurrentThread(this->ptr.get());
// decrease the reference counter
if (NULL != this->ptr.get())
{
this->ptr->m_iNumRef--;
if (0 == this->ptr->m_iNumRef)
{
JavaVM* vm;
this->ptr->m_pcEnv->GetJavaVM(&vm);
vm->DetachCurrentThread();
}
}
return true;
}
// ------------------------------------------------------------------------------------------------
JNIThreadData* JNIEnvironment::GetThread()
{
ai_assert(NULL != this->ptr.get());
return this->ptr.get();
}
// ------------------------------------------------------------------------------------------------
jstring JNU_NewStringNative(JNIEnv *env, const char *str)
{
jstring result;
jbyteArray bytes = 0;
int len;
if (env->EnsureLocalCapacity( 2) < 0)
{
return NULL; /* out of memory error */
}
len = strlen(str);
bytes = env->NewByteArray(len);
if (bytes != NULL)
{
env->SetByteArrayRegion(bytes, 0, len,
(jbyte *)str);
result = (jstring)env->NewObject(JNIEnvironment::Class_java_lang_String,
JNIEnvironment::MID_String_init, bytes);
env->DeleteLocalRef(bytes);
return result;
} /* else fall through */
return NULL;
}
// ------------------------------------------------------------------------------------------------
char *JNU_GetStringNativeChars(JNIEnv *env, jstring jstr)
{
jbyteArray bytes = 0;
jthrowable exc;
char *result = 0;
if (env->EnsureLocalCapacity(2) < 0)
{
return 0; /* out of memory error */
}
bytes = (jbyteArray)env->CallObjectMethod(jstr,JNIEnvironment::MID_String_getBytes);
exc = env->ExceptionOccurred();
if (!exc)
{
jint len = env->GetArrayLength(bytes);
result = (char *)malloc(len + 1);
if (result == 0)
{
env->DeleteLocalRef(bytes);
return 0;
}
env->GetByteArrayRegion(bytes, 0, len,
(jbyte *)result);
result[len] = 0; /* NULL-terminate */
}
else
{
env->DeleteLocalRef(exc);
}
env->DeleteLocalRef(bytes);
return result;
}
};};
#endif // ! JNI only

View File

@ -0,0 +1,184 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#if (!defined AI_JNIENVIRONMENT_H_INCLUDED)
#define AI_JNIENVIRONMENT_H_INCLUDED
#include <boost/thread/thread.hpp>
#include <boost/thread/tss.hpp>
#include <vector>
#include <jni.h>
#include "../../include/aiAssert.h"
namespace Assimp {
namespace JNIBridge {
// ---------------------------------------------------------------------------
/** @class JNIThreadData
* @brief Manages a list of JNI data structures that are
* private to a thread.
*/
struct JNIThreadData
{
//! Default constructor
JNIThreadData() : m_pcEnv(NULL), m_iNumRef(1) {}
//! Construction from an existing JNIEnv
JNIThreadData(JNIEnv* env) : m_pcEnv(env), m_iNumRef(1) {}
//! JNI environment, is attached to the thread
JNIEnv* m_pcEnv;
//! Number of Importer instances that have been
//! created by this thread
unsigned int m_iNumRef;
};
// ---------------------------------------------------------------------------
/** @class JNIEnvironment
* @brief Helper class to manage the JNI environment for multithreaded
* use of the library.
*/
class JNIEnvironment
{
private:
JNIEnvironment() : m_iRefCnt(1) {}
public:
//! Create the JNI environment class
//! refcnt = 1
static JNIEnvironment* Create()
{
if (NULL == s_pcEnv)
{
s_pcEnv = new JNIEnvironment();
}
else s_pcEnv->AddRef();
return s_pcEnv;
}
//! static getter for the singleton instance
//! doesn't hange the reference counter
static JNIEnvironment* Get()
{
ai_assert(NULL != s_pcEnv);
return s_pcEnv;
}
//! COM-style reference counting mechanism
unsigned int AddRef()
{
return ++this->m_iRefCnt;
}
//! COM-style reference counting mechanism
unsigned int Release()
{
unsigned int iNew = --this->m_iRefCnt;
if (0 == iNew)delete this;
return iNew;
}
//! Attach to the current thread
bool AttachToCurrentThread (JNIEnv* pcEnv);
//! Detach from the current thread
bool DetachFromCurrentThread ();
//! Get the thread local data of the current thread
JNIThreadData* GetThread();
public:
//! Handle to the java.lang.String class
static jclass Class_java_lang_String;
//! Handle to the java.lang.String.getBytes() class
static jmethodID MID_String_getBytes;
//! Handle to the java.lang.String.String(byte[]) c'tor
static jmethodID MID_String_init;
private:
//! Singleton instance
static JNIEnvironment* s_pcEnv;
//! TLS data
boost::thread_specific_ptr<JNIThreadData> ptr;
//! Reference counter of the whole class
unsigned int m_iRefCnt;
};
};};
// ---------------------------------------------------------------------------
/** @brief Helper function to create a java.lang.String from
* a native char*.
*
* This function has been taken from
* http://java.sun.com/docs/books/jni/html/other.html#26021
* I am not sure whether it is really necessary, but I trust the source
*/
jstring JNU_NewStringNative(JNIEnv *env, const char *str);
// ---------------------------------------------------------------------------
/** @brief Helper function to create a char* from
* a managed jstring
*
* This function has been taken from
* http://java.sun.com/docs/books/jni/html/other.html#26021
* I am not sure whether it is really necessary, but I trust the source
*/
char* JNU_GetStringNativeChars(JNIEnv *env, jstring jstr);
#endif //! AI_JNIENVIRONMENT_H_INCLUDED

View File

@ -53,8 +53,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../include/aiPostProcess.h"
#include "../../include/assimp.hpp"
#include "../DefaultLogger.h"
#include "../../include/DefaultLogger.h"
#include "JNIEnvironment.h"
#include "JNILogger.h"
using namespace Assimp;
@ -65,67 +66,98 @@ namespace JNIBridge {
// ------------------------------------------------------------------------------------------------
void JNILogDispatcher::SetJNIEnvironment(JNIEnv* ptr)
bool JNILogDispatcher::OnAttachToCurrentThread(JNIThreadData* pcData)
{
ai_assert(NULL != pcData);
//this->AddRef(); - done at another position
// there is much error handling code in this function.
// However, it is not impossible that the jAssimp package
// loaded by the JVM is incomplete ...
jclass java_lang_Exception = this->GetJNIEnv()->FindClass("java.lang.Exception");
JNIEnv* jvmenv = JNIEnvironment::Get()->GetThread()->m_pcEnv;
// get a handle to the assimp.DefaultLogger class
this->m_pcJNIEnv = ptr;
if( NULL == (this->m_pcClass = this->GetJNIEnv()->FindClass("assimp.DefaultLogger")))
if (NULL == this->m_pcClass)
{
this->GetJNIEnv()->ThrowNew(java_lang_Exception,
"Unable to get class handle to assimp.DefaultLogger");
return;
if( NULL == (this->m_pcClass = jvmenv->FindClass("assimp.DefaultLogger")))
{
return false;
}
}
// get handles to the logging functions
if( NULL == (this->m_pcMethodError = this->GetJNIEnv()->GetStaticMethodID(
this->m_pcClass,"_NativeCallWriteError","(Ljava/lang/String;)V")))
if (NULL == this->m_pcMethodError)
{
this->GetJNIEnv()->ThrowNew(java_lang_Exception,
"Unable to get class handle to assimp.DefaultLogger._NativeCallWriteError()");
return;
if( NULL == (this->m_pcMethodError = jvmenv->GetStaticMethodID(
this->m_pcClass,"_NativeCallWriteError","(Ljava/lang/String;)V")))
{
return false;
}
}
if( NULL == (this->m_pcMethodWarn = this->GetJNIEnv()->GetStaticMethodID(
this->m_pcClass,"_NativeCallWriteWarn","(Ljava/lang/String;)V")))
if (NULL == this->m_pcMethodWarn)
{
this->GetJNIEnv()->ThrowNew(java_lang_Exception,
"Unable to get class handle to assimp.DefaultLogger._NativeCallWriteWarn()");
return;
if( NULL == (this->m_pcMethodWarn = jvmenv->GetStaticMethodID(
this->m_pcClass,"_NativeCallWriteWarn","(Ljava/lang/String;)V")))
{
return false;
}
}
if( NULL == (this->m_pcMethodInfo = this->GetJNIEnv()->GetStaticMethodID(
this->m_pcClass,"_NativeCallWriteInfo","(Ljava/lang/String;)V")))
if (NULL == this->m_pcMethodInfo)
{
this->GetJNIEnv()->ThrowNew(java_lang_Exception,
"Unable to get class handle to assimp.DefaultLogger._NativeCallWriteInfo()");
return;
if( NULL == (this->m_pcMethodInfo = jvmenv->GetStaticMethodID(
this->m_pcClass,"_NativeCallWriteInfo","(Ljava/lang/String;)V")))
{
return false;
}
}
if( NULL == (this->m_pcMethodDebug = this->GetJNIEnv()->GetStaticMethodID(
this->m_pcClass,"_NativeCallWriteDebug","(Ljava/lang/String;)V")))
if (NULL == this->m_pcMethodDebug)
{
this->GetJNIEnv()->ThrowNew(java_lang_Exception,
"Unable to get class handle to assimp.DefaultLogger._NativeCallWriteDebug()");
if( NULL == (this->m_pcMethodDebug = jvmenv->GetStaticMethodID(
this->m_pcClass,"_NativeCallWriteDebug","(Ljava/lang/String;)V")))
{
return false;
}
}
return true;
}
// ------------------------------------------------------------------------------------------------
bool JNILogDispatcher::OnDetachFromCurrentThread(JNIThreadData* pcData)
{
ai_assert(NULL != pcData);
this->Release();
return true;
}
// ------------------------------------------------------------------------------------------------
void JNILogDispatcher::debug(const std::string &message)
{
JNIEnv* jvmenv = JNIEnvironment::Get()->GetThread()->m_pcEnv;
jstring jstr = JNU_NewStringNative(jvmenv,message.c_str());
jvmenv->CallStaticVoidMethod(this->m_pcClass,this->m_pcMethodDebug,jstr);
jvmenv->DeleteLocalRef(jstr);
}
// ------------------------------------------------------------------------------------------------
void JNILogDispatcher::info(const std::string &message)
{
JNIEnv* jvmenv = JNIEnvironment::Get()->GetThread()->m_pcEnv;
jstring jstr = JNU_NewStringNative(jvmenv,message.c_str());
jvmenv->CallStaticVoidMethod(this->m_pcClass,this->m_pcMethodInfo,jstr);
jvmenv->DeleteLocalRef(jstr);
}
// ------------------------------------------------------------------------------------------------
void JNILogDispatcher::warn(const std::string &message)
{
JNIEnv* jvmenv = JNIEnvironment::Get()->GetThread()->m_pcEnv;
jstring jstr = JNU_NewStringNative(jvmenv,message.c_str());
jvmenv->CallStaticVoidMethod(this->m_pcClass,this->m_pcMethodWarn,jstr);
jvmenv->DeleteLocalRef(jstr);
}
// ------------------------------------------------------------------------------------------------
void JNILogDispatcher::error(const std::string &message)
{
JNIEnv* jvmenv = JNIEnvironment::Get()->GetThread()->m_pcEnv;
jstring jstr = JNU_NewStringNative(jvmenv,message.c_str());
jvmenv->CallStaticVoidMethod(this->m_pcClass,this->m_pcMethodError,jstr);
jvmenv->DeleteLocalRef(jstr);
}

View File

@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../include/Logger.h"
#include "../../include/DefaultLogger.h"
#include <vector>
#include <jni.h>
@ -62,7 +63,13 @@ struct LogStreamInfo;
*/
class JNILogDispatcher : public Logger
{
friend class JNIEnvironment;
public:
//! Default constructor
JNILogDispatcher() : m_iRefCnt(1) {}
/** @brief Logs a debug message */
void debug(const std::string &message);
@ -84,22 +91,32 @@ public:
/** @brief Detach a still attached stream from logger */
void detatchStream(LogStream *pStream, unsigned int severity) {}
//! Setup the JNI environment to use
//! (must be attached to the thread)
//! \param ptr Java environment to be used. != 0
void SetJNIEnvironment(JNIEnv* ptr);
//! Get the current JNI environment
inline JNIEnv* GetJNIEnv()
//! COM-style reference counting mechanism
unsigned int AddRef()
{
ai_assert(NULL != m_pcJNIEnv);
return m_pcJNIEnv;
return ++this->m_iRefCnt;
}
//! COM-style reference counting mechanism
unsigned int Release()
{
unsigned int iNew = --this->m_iRefCnt;
if (0 == iNew)
{
delete this;
// don't forget to reset the logger to the default implementation
DefaultLogger::set(NULL);
}
return iNew;
}
private:
//! JNI environment pointer
JNIEnv* m_pcJNIEnv;
//! Called by JNIEnvironment
bool OnAttachToCurrentThread(JNIThreadData* pcData);
bool OnDetachFromCurrentThread(JNIThreadData* pcData);
private:
//! Handle to assimp.DefaultLogger class
jclass m_pcClass;
@ -115,6 +132,9 @@ private:
//! Handle to the static assimp.DefaultLogger._NativeCallWriteWarn() method
jmethodID m_pcMethodWarn;
//! Reference counter of the logger
unsigned int m_iRefCnt;
};
};};

View File

@ -41,11 +41,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @file Implementation of the post processing step "MakeVerboseFormat"
*/
#include "MakeVerboseFormat.h"
#include "DefaultLogger.h"
#include "../../include/DefaultLogger.h"
#include "../include/aiMesh.h"
#include "../include/aiScene.h"
#include "../include/aiAssert.h"
#include "../../include/aiMesh.h"
#include "../../include/aiScene.h"
#include "../../include/aiAssert.h"
using namespace Assimp;

View File

@ -44,8 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_MAKEVERBOSEFORMAT_H_INC
#define AI_MAKEVERBOSEFORMAT_H_INC
#include "BaseProcess.h"
#include "../include/aiMesh.h"
#include "../BaseProcess.h"
#include "../../include/aiMesh.h"
namespace Assimp
{
@ -66,7 +66,7 @@ class MakeVerboseFormatProcess : public BaseProcess
{
friend class Importer;
public:
protected:
/** Constructor to be privately used by Importer, or by applications
which know what they are doing if they modify the aiScene object */
MakeVerboseFormatProcess();

View File

@ -61,7 +61,7 @@ public class Animation extends Mappable {
super(parent, index);
}
protected void OnMap() throws NativeError {
protected void onMap() throws NativeError {
}
}

View File

@ -58,8 +58,6 @@ import java.awt.*;
public class CompressedTexture extends Texture {
private String m_format = "";
private byte[] m_data;
private int m_length = 0;
/**
@ -70,6 +68,12 @@ public class CompressedTexture extends Texture {
*/
public CompressedTexture(Object parent, int index) throws NativeError {
super(parent, index);
// need to get the format of the texture via the JNI
if ((m_format = this._NativeGetCTextureFormat(((Scene) this.getParent()).
getImporter().getContext(), this.getArrayIndex())).equals("")) {
throw new NativeError("Unable to get the format of the compressed texture");
}
}
/**
@ -83,53 +87,89 @@ public class CompressedTexture extends Texture {
return m_format;
}
/**
* Get a pointer to the data of the compressed texture
* @return Data poiner
*/
public byte[] getData() {
return m_data;
if (null == data) {
try {
this.onMap();
} catch (NativeError nativeError) {
DefaultLogger.get().error(nativeError.getMessage());
return null;
}
}
return (byte[])data;
}
/**
* Retrieve the height of the texture image
*
* @return Height, in pixels
* Get the length of the data of the compressed texture
* @return Data poiner
*/
public int getHeight() {
DefaultLogger.get()
return height;
}
/**
* Retrieve the width of the texture image
*
* @return Width, in pixels
*/
public int getWidth() {
public int getLength() {
return width;
}
/**
* Returns 0 for compressed textures
* @return n/a
*/
@Override
public int getHeight() {
return 0;
}
/**
* Returns 0 for compressed textures
* @return n/a
*/
@Override
public int getWidth() {
return 0;
}
/**
* Returns null for compressed textures
* @return n/a
*/
@Override
public Color getPixel(int x, int y) {
return null;
}
/**
* Returns null for compressed textures
* @return n/a
*/
@Override
public Color[] getColorArray() {
return null;
}
/**
* Internal helper function to map the native texture data into
* a <code>byte</code> array in the memory of the JVM
*/
@Override
protected void OnMap() throws NativeError {
protected void onMap() throws NativeError {
// first allocate the output array
data = new Color[iNumPixels];
data = new byte[this.width];
// now allocate a temporary output array
byte[] temp = new byte[(iNumPixels) << 2];
byte[] temp = new byte[this.width];
// and copy the native color data to it
if (0xffffffff == this._NativeMapColorData(((Scene)this.getParent()).getImporter().getContext(),
if (0xffffffff == this._NativeMapColorData(
((Scene)this.getParent()).getImporter().getContext(),
this.getArrayIndex(),temp)) {
throw new NativeError("Unable to map aiTexture into the Java-VM");
throw new NativeError("Unable to map compressed aiTexture into the Java-VM");
}
DefaultLogger.get().debug("CompressedTexture.onMap successful");
// now convert the temporary representation to a Color array
// (data is given in BGRA order, we need RGBA)
for (int i = 0, iBase = 0; i < iNumPixels; ++i, iBase += 4) {
data[i] = new Color(temp[iBase + 2], temp[iBase + 1], temp[iBase], temp[iBase + 3]);
}
return;
}
private native String _NativeGetCTextureFormat(long context, int arrayIndex);
}

View File

@ -79,7 +79,7 @@ public abstract class Mappable {
* be ready to be used without an underyling native aiScene
* @throws NativeError
*/
protected abstract void OnMap() throws NativeError;
protected abstract void onMap() throws NativeError;
/**

View File

@ -62,7 +62,7 @@ public class Material extends Mappable {
super(parent, index);
}
protected void OnMap() throws NativeError {
protected void onMap() throws NativeError {
}
}

View File

@ -713,7 +713,7 @@ public class Mesh extends Mappable {
}
protected void OnMap() throws NativeError {
protected void onMap() throws NativeError {
// map all vertex component arrays into JVM memory
if (this.hasPositions()) this.mapVertices();
if (this.hasNormals()) this.mapNormals();
@ -727,7 +727,7 @@ public class Mesh extends Mappable {
for (int i = 0; i < MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
if (this.hasUVCoords(i)) this.mapUVs(i);
}
// LOG
DefaultLogger.get().debug("Mesh.onMap successful");
}
@ -738,7 +738,7 @@ public class Mesh extends Mappable {
this.m_vVertices)) {
// this should occur rarely. No need to throw an exception,
// simply write to log and let the array at 0.0f
// LOG
DefaultLogger.get().error("Unable to map vertices into JVM memory");
}
}
@ -749,7 +749,7 @@ public class Mesh extends Mappable {
this.m_vNormals)) {
// this should occur rarely. No need to throw an exception,
// simply write to log and let the array at 0.0f
// LOG
DefaultLogger.get().error("Unable to map normals into JVM memory");
}
}
@ -760,7 +760,7 @@ public class Mesh extends Mappable {
this.m_vTangents)) {
// this should occur rarely. No need to throw an exception,
// simply write to log and let the array at 0.0f
// LOG
DefaultLogger.get().error("Unable to map tangents into JVM memory");
}
}
@ -771,7 +771,7 @@ public class Mesh extends Mappable {
this.m_vBitangents)) {
// this should occur rarely. No need to throw an exception,
// simply write to log and let the array at 0.0f
// LOG
DefaultLogger.get().error("Unable to map bitangents into JVM memory");
}
}
@ -782,7 +782,7 @@ public class Mesh extends Mappable {
this.m_vFaces)) {
// this should occur rarely. No need to throw an exception,
// simply write to log and let the array at 0
// LOG
DefaultLogger.get().error("Unable to map faces into JVM memory");
}
}
@ -793,7 +793,7 @@ public class Mesh extends Mappable {
channel, this.m_avUVs[channel])) {
// this should occur rarely. No need to throw an exception,
// simply write to log and let the array at 0.0f
// LOG
DefaultLogger.get().error("Unable to map UV coordinate set " + channel + " into JVM memory");
}
}
@ -804,7 +804,7 @@ public class Mesh extends Mappable {
channel, this.m_avColors[channel])) {
// this should occur rarely. No need to throw an exception,
// simply write to log and let the array at 0.0f
// LOG
DefaultLogger.get().error("Unable to map vertex color channel " + channel + " into JVM memory");
}
}

View File

@ -61,7 +61,7 @@ public class Texture extends Mappable {
protected int width = 0;
protected int height = 0;
protected Color[] data = null;
protected Object data = null;
/**
* Construction from a given parent object and array index
@ -114,12 +114,12 @@ public class Texture extends Mappable {
// map the color data in memory if required ...
if (null == data) {
try {
this.OnMap();
this.onMap();
} catch (NativeError nativeError) {
return Color.black;
}
}
return data[y * width + x];
return ((Color[])data)[y * width + x];
}
/**
@ -131,12 +131,12 @@ public class Texture extends Mappable {
// map the color data in memory if required ...
if (null == data) {
try {
this.OnMap();
this.onMap();
} catch (NativeError nativeError) {
return null;
}
}
return data;
return (Color[])data;
}
/**
@ -144,7 +144,7 @@ public class Texture extends Mappable {
* a <code>java.awt.Color</code> array
*/
@Override
protected void OnMap() throws NativeError {
protected void onMap() throws NativeError {
final int iNumPixels = width * height;
// first allocate the output array
@ -159,10 +159,12 @@ public class Texture extends Mappable {
throw new NativeError("Unable to map aiTexture into the Java-VM");
}
DefaultLogger.get().debug("Texture.onMap successful");
// now convert the temporary representation to a Color array
// (data is given in BGRA order, we need RGBA)
for (int i = 0, iBase = 0; i < iNumPixels; ++i, iBase += 4) {
data[i] = new Color(temp[iBase + 2], temp[iBase + 1], temp[iBase], temp[iBase + 3]);
((Color[])data)[i] = new Color(temp[iBase + 2], temp[iBase + 1], temp[iBase], temp[iBase + 3]);
}
return;
}
@ -177,7 +179,7 @@ public class Texture extends Mappable {
* @param temp Output array. Assumed to be width * height * 4 in size
* @return 0xffffffff if an error occured
*/
private native int _NativeMapColorData(long context, long index, byte[] temp);
protected native int _NativeMapColorData(long context, long index, byte[] temp);
/**
* JNI bridge call. For internal use only

View File

@ -47,11 +47,50 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "GenVertexNormalsProcess.h"
#include "JoinVerticesProcess.h"
#include "CalcTangentsProcess.h"
#include "MakeVerboseFormat.h"
#include "unused/MakeVerboseFormat.h"
namespace AssimpView {
// NOTE: These classes are necessary since the c'tors of all
// postprocess steps are protected. Generally they're not
// intended to be used directly by applications.
//
// However, the viewer is an exception. It does nothing than
// displaxing the aiScene, so it wouldn't make sense to copy
// the data to another data structure.
//
class MyGenFaceNormalsProcess : public Assimp::GenFaceNormalsProcess
{
public:
MyGenFaceNormalsProcess() {}
};
class MyGenVertexNormalsProcess : public Assimp::GenVertexNormalsProcess
{
public:
MyGenVertexNormalsProcess() {}
};
class MyMakeVerboseFormatProcess : public Assimp::MakeVerboseFormatProcess
{
public:
MyMakeVerboseFormatProcess() {}
};
class MyCalcTangentsProcess : public Assimp::CalcTangentsProcess
{
public:
MyCalcTangentsProcess() {}
};
class MyJoinVerticesProcess : public Assimp::JoinVerticesProcess
{
public:
MyJoinVerticesProcess() {}
};
bool g_bWasFlipped = false;
//-------------------------------------------------------------------------------
@ -83,7 +122,7 @@ void AssetHelper::SetNormalSet(unsigned int iSet)
// we need to build an unique set of vertices for this ...
{
Assimp::MakeVerboseFormatProcess* pcProcess = new Assimp::MakeVerboseFormatProcess();
MyMakeVerboseFormatProcess* pcProcess = new MyMakeVerboseFormatProcess();
pcProcess->Execute(this->pcScene);
delete pcProcess;
@ -104,13 +143,13 @@ void AssetHelper::SetNormalSet(unsigned int iSet)
// now we can start to calculate a new set of normals
if (HARD == iSet)
{
Assimp::GenFaceNormalsProcess* pcProcess = new Assimp::GenFaceNormalsProcess();
MyGenFaceNormalsProcess* pcProcess = new MyGenFaceNormalsProcess();
pcProcess->Execute(this->pcScene);
delete pcProcess;
}
else if (SMOOTH == iSet)
{
Assimp::GenVertexNormalsProcess* pcProcess = new Assimp::GenVertexNormalsProcess();
MyGenVertexNormalsProcess* pcProcess = new MyGenVertexNormalsProcess();
pcProcess->Execute(this->pcScene);
delete pcProcess;
}
@ -128,12 +167,12 @@ void AssetHelper::SetNormalSet(unsigned int iSet)
}
// recalculate tangents and bitangents
Assimp::BaseProcess* pcProcess = new Assimp::CalcTangentsProcess();
Assimp::BaseProcess* pcProcess = new MyCalcTangentsProcess();
pcProcess->Execute(this->pcScene);
delete pcProcess;
// join the mesh vertices again
pcProcess = new Assimp::JoinVerticesProcess();
pcProcess = new MyJoinVerticesProcess();
pcProcess->Execute(this->pcScene);
delete pcProcess;

View File

@ -584,10 +584,6 @@
RelativePath="..\..\code\KillNormalsProcess.h"
>
</File>
<File
RelativePath="..\..\code\MakeVerboseFormat.h"
>
</File>
<File
RelativePath="..\..\code\MaterialSystem.h"
>
@ -795,11 +791,23 @@
RelativePath="..\..\code\jAssimp\assimp_Texture.h"
>
</File>
<File
RelativePath="..\..\code\jAssimp\JNIEnvironment.h"
>
</File>
<File
RelativePath="..\..\code\jAssimp\JNILogger.h"
>
</File>
</Filter>
<Filter
Name="extra"
>
<File
RelativePath="..\..\code\unused\MakeVerboseFormat.h"
>
</File>
</Filter>
</Filter>
<Filter
Name="sources"
@ -852,10 +860,6 @@
RelativePath="..\..\code\KillNormalsProcess.cpp"
>
</File>
<File
RelativePath="..\..\code\MakeVerboseFormat.cpp"
>
</File>
<File
RelativePath="..\..\code\MaterialSystem.cpp"
>
@ -991,11 +995,23 @@
RelativePath="..\..\code\jAssimp\JNICalls.cpp"
>
</File>
<File
RelativePath="..\..\code\jAssimp\JNIEnvironment.cpp"
>
</File>
<File
RelativePath="..\..\code\jAssimp\JNILogger.cpp"
>
</File>
</Filter>
<Filter
Name="extra"
>
<File
RelativePath="..\..\code\unused\MakeVerboseFormat.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="doc"