diff --git a/code/3DSConverter.cpp b/code/3DSConverter.cpp index 1ac58c6ef..8eb4c9eb1 100644 --- a/code/3DSConverter.cpp +++ b/code/3DSConverter.cpp @@ -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" diff --git a/code/3DSLoader.cpp b/code/3DSLoader.cpp index 3c00f9102..554ac3a14 100644 --- a/code/3DSLoader.cpp +++ b/code/3DSLoader.cpp @@ -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" diff --git a/code/ASEParser.cpp b/code/ASEParser.cpp index 4f6dae32a..cf7dcdc55 100644 --- a/code/ASEParser.cpp +++ b/code/ASEParser.cpp @@ -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" diff --git a/code/BaseImporter.cpp b/code/BaseImporter.cpp index 382678675..4ce86322d 100644 --- a/code/BaseImporter.cpp +++ b/code/BaseImporter.cpp @@ -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; diff --git a/code/CalcTangentsProcess.cpp b/code/CalcTangentsProcess.cpp index 4172d9915..01794cedd 100644 --- a/code/CalcTangentsProcess.cpp +++ b/code/CalcTangentsProcess.cpp @@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "DefaultLogger.h" +#include "../include/DefaultLogger.h" #include "CalcTangentsProcess.h" #include "SpatialSort.h" #include "../include/aiPostProcess.h" diff --git a/code/CalcTangentsProcess.h b/code/CalcTangentsProcess.h index bcaf3c026..35c116b45 100644 --- a/code/CalcTangentsProcess.h +++ b/code/CalcTangentsProcess.h @@ -61,7 +61,7 @@ class CalcTangentsProcess : public BaseProcess { friend class Importer; -public: +protected: /** Constructor to be privately used by Importer */ CalcTangentsProcess(); diff --git a/code/ConvertToLHProcess.cpp b/code/ConvertToLHProcess.cpp index a19e279e7..2e8f049da 100644 --- a/code/ConvertToLHProcess.cpp +++ b/code/ConvertToLHProcess.cpp @@ -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" diff --git a/code/DefaultLogger.cpp b/code/DefaultLogger.cpp index 151f213af..554316f23 100644 --- a/code/DefaultLogger.cpp +++ b/code/DefaultLogger.cpp @@ -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" diff --git a/code/GenFaceNormalsProcess.cpp b/code/GenFaceNormalsProcess.cpp index 22f89919a..65af8c1d8 100644 --- a/code/GenFaceNormalsProcess.cpp +++ b/code/GenFaceNormalsProcess.cpp @@ -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" diff --git a/code/GenFaceNormalsProcess.h b/code/GenFaceNormalsProcess.h index 1e4d99af3..1b9351358 100644 --- a/code/GenFaceNormalsProcess.h +++ b/code/GenFaceNormalsProcess.h @@ -55,7 +55,7 @@ class GenFaceNormalsProcess : public BaseProcess { friend class Importer; -public: +protected: /** Constructor to be privately used by Importer */ GenFaceNormalsProcess(); diff --git a/code/GenVertexNormalsProcess.cpp b/code/GenVertexNormalsProcess.cpp index f3d21d557..0cd45ef93 100644 --- a/code/GenVertexNormalsProcess.cpp +++ b/code/GenVertexNormalsProcess.cpp @@ -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" diff --git a/code/GenVertexNormalsProcess.h b/code/GenVertexNormalsProcess.h index 4f04e90f7..913bc1dff 100644 --- a/code/GenVertexNormalsProcess.h +++ b/code/GenVertexNormalsProcess.h @@ -54,7 +54,7 @@ class GenVertexNormalsProcess : public BaseProcess { friend class Importer; -public: +protected: /** Constructor to be privately used by Importer */ GenVertexNormalsProcess(); diff --git a/code/Importer.cpp b/code/Importer.cpp index 94be22acf..7fdda5022 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -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; diff --git a/code/JoinVerticesProcess.cpp b/code/JoinVerticesProcess.cpp index b0348277a..09ea616bd 100644 --- a/code/JoinVerticesProcess.cpp +++ b/code/JoinVerticesProcess.cpp @@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #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" diff --git a/code/JoinVerticesProcess.h b/code/JoinVerticesProcess.h index 9ca1b9a04..24d7651b7 100644 --- a/code/JoinVerticesProcess.h +++ b/code/JoinVerticesProcess.h @@ -63,7 +63,7 @@ class JoinVerticesProcess : public BaseProcess { friend class Importer; -public: +protected: /** Constructor to be privately used by Importer */ JoinVerticesProcess(); diff --git a/code/KillNormalsProcess.cpp b/code/KillNormalsProcess.cpp index d7c40a2dd..5da70cc68 100644 --- a/code/KillNormalsProcess.cpp +++ b/code/KillNormalsProcess.cpp @@ -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" diff --git a/code/MDLLoader.cpp b/code/MDLLoader.cpp index 43f22fd8f..1e7ae54e0 100644 --- a/code/MDLLoader.cpp +++ b/code/MDLLoader.cpp @@ -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" diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index d85a2f79f..6729d018f 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -7,7 +7,7 @@ #include "../include/aiScene.h" #include "../include/aiAssert.h" #include "MaterialSystem.h" -#include "DefaultLogger.h" +#include "../include/DefaultLogger.h" #include #include diff --git a/code/PlyParser.cpp b/code/PlyParser.cpp index c20caacea..98947785b 100644 --- a/code/PlyParser.cpp +++ b/code/PlyParser.cpp @@ -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" diff --git a/code/SplitLargeMeshes.cpp b/code/SplitLargeMeshes.cpp index 042de6c13..1a6047e46 100644 --- a/code/SplitLargeMeshes.cpp +++ b/code/SplitLargeMeshes.cpp @@ -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" diff --git a/code/TriangulateProcess.cpp b/code/TriangulateProcess.cpp index d4a54a5ab..779a9b6a4 100644 --- a/code/TriangulateProcess.cpp +++ b/code/TriangulateProcess.cpp @@ -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 #include #include "TriangulateProcess.h" -#include "DefaultLogger.h" +#include "../include/DefaultLogger.h" #include "../include/aiPostProcess.h" #include "../include/aiMesh.h" #include "../include/aiScene.h" diff --git a/code/jAssimp/JNICalls.cpp b/code/jAssimp/JNICalls.cpp index 9d628735e..5504210c7 100644 --- a/code/jAssimp/JNICalls.cpp +++ b/code/jAssimp/JNICalls.cpp @@ -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; } diff --git a/code/jAssimp/JNIEnvironment.cpp b/code/jAssimp/JNIEnvironment.cpp new file mode 100644 index 000000000..462f0b303 --- /dev/null +++ b/code/jAssimp/JNIEnvironment.cpp @@ -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 diff --git a/code/jAssimp/JNIEnvironment.h b/code/jAssimp/JNIEnvironment.h new file mode 100644 index 000000000..9253e9687 --- /dev/null +++ b/code/jAssimp/JNIEnvironment.h @@ -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 +#include + +#include +#include + +#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 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 + + diff --git a/code/jAssimp/JNILogger.cpp b/code/jAssimp/JNILogger.cpp index d566e2189..04492d707 100644 --- a/code/jAssimp/JNILogger.cpp +++ b/code/jAssimp/JNILogger.cpp @@ -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); } diff --git a/code/jAssimp/JNILogger.h b/code/jAssimp/JNILogger.h index c04e25dc1..7f1f0d4e3 100644 --- a/code/jAssimp/JNILogger.h +++ b/code/jAssimp/JNILogger.h @@ -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 #include @@ -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; }; };}; diff --git a/code/MakeVerboseFormat.cpp b/code/unused/MakeVerboseFormat.cpp similarity index 94% rename from code/MakeVerboseFormat.cpp rename to code/unused/MakeVerboseFormat.cpp index 62473e547..4acde9d55 100644 --- a/code/MakeVerboseFormat.cpp +++ b/code/unused/MakeVerboseFormat.cpp @@ -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; diff --git a/code/MakeVerboseFormat.h b/code/unused/MakeVerboseFormat.h similarity index 94% rename from code/MakeVerboseFormat.h rename to code/unused/MakeVerboseFormat.h index b76a3e602..c73e9ee61 100644 --- a/code/MakeVerboseFormat.h +++ b/code/unused/MakeVerboseFormat.h @@ -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(); diff --git a/code/DefaultLogger.h b/include/DefaultLogger.h similarity index 100% rename from code/DefaultLogger.h rename to include/DefaultLogger.h diff --git a/port/jAssimp/src/assimp/Animation.java b/port/jAssimp/src/assimp/Animation.java index 2328b0da0..cf9b525b0 100644 --- a/port/jAssimp/src/assimp/Animation.java +++ b/port/jAssimp/src/assimp/Animation.java @@ -61,7 +61,7 @@ public class Animation extends Mappable { super(parent, index); } - protected void OnMap() throws NativeError { + protected void onMap() throws NativeError { } } diff --git a/port/jAssimp/src/assimp/CompressedTexture.java b/port/jAssimp/src/assimp/CompressedTexture.java index 36e05779c..af1624a41 100644 --- a/port/jAssimp/src/assimp/CompressedTexture.java +++ b/port/jAssimp/src/assimp/CompressedTexture.java @@ -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 byte 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); } diff --git a/port/jAssimp/src/assimp/Mappable.java b/port/jAssimp/src/assimp/Mappable.java index 0924d1ab1..f10868b1b 100644 --- a/port/jAssimp/src/assimp/Mappable.java +++ b/port/jAssimp/src/assimp/Mappable.java @@ -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; /** diff --git a/port/jAssimp/src/assimp/Material.java b/port/jAssimp/src/assimp/Material.java index 811e2a1f5..04538ee67 100644 --- a/port/jAssimp/src/assimp/Material.java +++ b/port/jAssimp/src/assimp/Material.java @@ -62,7 +62,7 @@ public class Material extends Mappable { super(parent, index); } - protected void OnMap() throws NativeError { + protected void onMap() throws NativeError { } } diff --git a/port/jAssimp/src/assimp/Mesh.java b/port/jAssimp/src/assimp/Mesh.java index 1be19f052..bbc84af16 100644 --- a/port/jAssimp/src/assimp/Mesh.java +++ b/port/jAssimp/src/assimp/Mesh.java @@ -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"); } } diff --git a/port/jAssimp/src/assimp/Texture.java b/port/jAssimp/src/assimp/Texture.java index 015bc68b0..b4ead21f4 100644 --- a/port/jAssimp/src/assimp/Texture.java +++ b/port/jAssimp/src/assimp/Texture.java @@ -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 java.awt.Color 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 diff --git a/tools/assimp_view/Normals.cpp b/tools/assimp_view/Normals.cpp index 7b50aed6f..fc1b1d6ba 100644 --- a/tools/assimp_view/Normals.cpp +++ b/tools/assimp_view/Normals.cpp @@ -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; diff --git a/workspaces/vc8/assimp.vcproj b/workspaces/vc8/assimp.vcproj index 31707e204..8f3042429 100644 --- a/workspaces/vc8/assimp.vcproj +++ b/workspaces/vc8/assimp.vcproj @@ -584,10 +584,6 @@ RelativePath="..\..\code\KillNormalsProcess.h" > - - @@ -795,11 +791,23 @@ RelativePath="..\..\code\jAssimp\assimp_Texture.h" > + + + + + + - - @@ -991,11 +995,23 @@ RelativePath="..\..\code\jAssimp\JNICalls.cpp" > + + + + + +