2008-05-25 22:29:05 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
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 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"
|
|
|
|
|
2008-05-26 21:28:19 +00:00
|
|
|
#include "../../include/DefaultLogger.h"
|
2008-05-25 22:29:05 +00:00
|
|
|
|
2008-05-26 21:28:19 +00:00
|
|
|
#include "JNIEnvironment.h"
|
2008-05-25 22:29:05 +00:00
|
|
|
#include "JNILogger.h"
|
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Assimp {
|
|
|
|
namespace JNIBridge {
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-26 21:28:19 +00:00
|
|
|
bool JNILogDispatcher::OnAttachToCurrentThread(JNIThreadData* pcData)
|
2008-05-25 22:29:05 +00:00
|
|
|
{
|
2008-05-26 21:28:19 +00:00
|
|
|
ai_assert(NULL != pcData);
|
|
|
|
//this->AddRef(); - done at another position
|
|
|
|
|
2008-05-25 22:29:05 +00:00
|
|
|
// there is much error handling code in this function.
|
|
|
|
// However, it is not impossible that the jAssimp package
|
|
|
|
// loaded by the JVM is incomplete ...
|
2008-05-26 21:28:19 +00:00
|
|
|
JNIEnv* jvmenv = JNIEnvironment::Get()->GetThread()->m_pcEnv;
|
2008-05-25 22:29:05 +00:00
|
|
|
|
|
|
|
// get a handle to the assimp.DefaultLogger class
|
2008-05-26 21:28:19 +00:00
|
|
|
if (NULL == this->m_pcClass)
|
2008-05-25 22:29:05 +00:00
|
|
|
{
|
2008-05-26 21:28:19 +00:00
|
|
|
if( NULL == (this->m_pcClass = jvmenv->FindClass("assimp.DefaultLogger")))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-05-25 22:29:05 +00:00
|
|
|
}
|
|
|
|
// get handles to the logging functions
|
2008-05-26 21:28:19 +00:00
|
|
|
if (NULL == this->m_pcMethodError)
|
2008-05-25 22:29:05 +00:00
|
|
|
{
|
2008-05-26 21:28:19 +00:00
|
|
|
if( NULL == (this->m_pcMethodError = jvmenv->GetStaticMethodID(
|
|
|
|
this->m_pcClass,"_NativeCallWriteError","(Ljava/lang/String;)V")))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-05-25 22:29:05 +00:00
|
|
|
}
|
2008-05-26 21:28:19 +00:00
|
|
|
if (NULL == this->m_pcMethodWarn)
|
2008-05-25 22:29:05 +00:00
|
|
|
{
|
2008-05-26 21:28:19 +00:00
|
|
|
if( NULL == (this->m_pcMethodWarn = jvmenv->GetStaticMethodID(
|
|
|
|
this->m_pcClass,"_NativeCallWriteWarn","(Ljava/lang/String;)V")))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-05-25 22:29:05 +00:00
|
|
|
}
|
2008-05-26 21:28:19 +00:00
|
|
|
if (NULL == this->m_pcMethodInfo)
|
2008-05-25 22:29:05 +00:00
|
|
|
{
|
2008-05-26 21:28:19 +00:00
|
|
|
if( NULL == (this->m_pcMethodInfo = jvmenv->GetStaticMethodID(
|
|
|
|
this->m_pcClass,"_NativeCallWriteInfo","(Ljava/lang/String;)V")))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-05-25 22:29:05 +00:00
|
|
|
}
|
2008-05-26 21:28:19 +00:00
|
|
|
if (NULL == this->m_pcMethodDebug)
|
2008-05-25 22:29:05 +00:00
|
|
|
{
|
2008-05-26 21:28:19 +00:00
|
|
|
if( NULL == (this->m_pcMethodDebug = jvmenv->GetStaticMethodID(
|
|
|
|
this->m_pcClass,"_NativeCallWriteDebug","(Ljava/lang/String;)V")))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-05-25 22:29:05 +00:00
|
|
|
}
|
2008-05-26 21:28:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool JNILogDispatcher::OnDetachFromCurrentThread(JNIThreadData* pcData)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != pcData);
|
|
|
|
|
|
|
|
this->Release();
|
|
|
|
return true;
|
2008-05-25 22:29:05 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void JNILogDispatcher::debug(const std::string &message)
|
|
|
|
{
|
2008-05-26 21:28:19 +00:00
|
|
|
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);
|
2008-05-25 22:29:05 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void JNILogDispatcher::info(const std::string &message)
|
|
|
|
{
|
2008-05-26 21:28:19 +00:00
|
|
|
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);
|
2008-05-25 22:29:05 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void JNILogDispatcher::warn(const std::string &message)
|
|
|
|
{
|
2008-05-26 21:28:19 +00:00
|
|
|
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);
|
2008-05-25 22:29:05 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void JNILogDispatcher::error(const std::string &message)
|
|
|
|
{
|
2008-05-26 21:28:19 +00:00
|
|
|
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);
|
2008-05-25 22:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};};
|
|
|
|
|
|
|
|
#endif // jni
|