diff --git a/code/Importer.cpp b/code/Importer.cpp index 3ab4fc4f8..2dbe85fc3 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -44,7 +44,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include "../include/assimp.hpp" +#include "../include/aiAssert.h" #include "../include/aiScene.h" +#include "../include/aiPostProcess.h" #include "BaseImporter.h" #include "BaseProcess.h" #include "DefaultIOStream.h" @@ -177,11 +179,27 @@ void Importer::SetIOHandler( IOSystem* pIOHandler) } return; } +// ------------------------------------------------------------------------------------------------ +// Validate post process step flags +bool ValidateFlags(unsigned int pFlags) +{ + if (pFlags & aiProcess_GenSmoothNormals && + pFlags & aiProcess_GenNormals) + { + DefaultLogger::get()->error("aiProcess_GenSmoothNormals and aiProcess_GenNormals " + "may not be specified together"); + return false; + } + return true; +} // ------------------------------------------------------------------------------------------------ // Reads the given file and returns its contents if successful. const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags) { + // validate the flags + ai_assert(ValidateFlags(pFlags)); + // first check if the file is accessable at all if( !mIOHandler->Exists( pFile)) { diff --git a/code/SplitLargeMeshes.h b/code/SplitLargeMeshes.h index 6e4ba19b0..dea9fd3e0 100644 --- a/code/SplitLargeMeshes.h +++ b/code/SplitLargeMeshes.h @@ -54,6 +54,15 @@ namespace Assimp class SplitLargeMeshesProcess_Triangle; class SplitLargeMeshesProcess_Vertex; +// NOTE: If you change these limits, don't forget to also change the +// corresponding values in the Assimp ports + +// ********************************************************** +// Java: PostProcessStep.java, +// PostProcessStep.DEFAULT_VERTEX_SPLIT_LIMIT +// PostProcessStep.DEFAULT_TRIANGLE_SPLIT_LIMIT +// ********************************************************** + // default limit for vertices #define AI_SLM_DEFAULT_MAX_VERTICES 1000000 diff --git a/code/jAssimp/BuildHeader.bat b/code/jAssimp/BuildHeader.bat new file mode 100644 index 000000000..5c595057a --- /dev/null +++ b/code/jAssimp/BuildHeader.bat @@ -0,0 +1,6 @@ +javah -classpath ".\..\..\port\jAssimp\classes" -d "." "assimp.Importer" +javah -classpath ".\..\..\port\jAssimp\classes" -d "." "assimp.Material" +javah -classpath ".\..\..\port\jAssimp\classes" -d "." "assimp.Node" +javah -classpath ".\..\..\port\jAssimp\classes" -d "." "assimp.Scene" +javah -classpath ".\..\..\port\jAssimp\classes" -d "." "assimp.Mesh" +javah -classpath ".\..\..\port\jAssimp\classes" -d "." "assimp.Texture" diff --git a/code/JNICalls.cpp b/code/jAssimp/JNICalls.cpp similarity index 100% rename from code/JNICalls.cpp rename to code/jAssimp/JNICalls.cpp diff --git a/code/jAssimp/assimp_Importer.h b/code/jAssimp/assimp_Importer.h new file mode 100644 index 000000000..47f2010d7 --- /dev/null +++ b/code/jAssimp/assimp_Importer.h @@ -0,0 +1,37 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class assimp_Importer */ + +#ifndef _Included_assimp_Importer +#define _Included_assimp_Importer +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: assimp_Importer + * Method: _NativeInitContext + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_assimp_Importer__1NativeInitContext + (JNIEnv *, jobject); + +/* + * Class: assimp_Importer + * Method: _NativeFreeContext + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_assimp_Importer__1NativeFreeContext + (JNIEnv *, jobject, jint); + +/* + * Class: assimp_Importer + * Method: _NativeLoad + * Signature: (Ljava/lang/String;II)I + */ +JNIEXPORT jint JNICALL Java_assimp_Importer__1NativeLoad + (JNIEnv *, jobject, jstring, jint, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/code/jAssimp/assimp_Material.h b/code/jAssimp/assimp_Material.h new file mode 100644 index 000000000..0aa75e6c5 --- /dev/null +++ b/code/jAssimp/assimp_Material.h @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class assimp_Material */ + +#ifndef _Included_assimp_Material +#define _Included_assimp_Material +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/code/jAssimp/assimp_Mesh.h b/code/jAssimp/assimp_Mesh.h new file mode 100644 index 000000000..a243a05c6 --- /dev/null +++ b/code/jAssimp/assimp_Mesh.h @@ -0,0 +1,17 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class assimp_Mesh */ + +#ifndef _Included_assimp_Mesh +#define _Included_assimp_Mesh +#ifdef __cplusplus +extern "C" { +#endif +#undef assimp_Mesh_MAX_NUMBER_OF_TEXTURECOORDS +#define assimp_Mesh_MAX_NUMBER_OF_TEXTURECOORDS 4L +#undef assimp_Mesh_MAX_NUMBER_OF_COLOR_SETS +#define assimp_Mesh_MAX_NUMBER_OF_COLOR_SETS 4L +#ifdef __cplusplus +} +#endif +#endif diff --git a/code/jAssimp/assimp_Node.h b/code/jAssimp/assimp_Node.h new file mode 100644 index 000000000..593d7037a --- /dev/null +++ b/code/jAssimp/assimp_Node.h @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class assimp_Node */ + +#ifndef _Included_assimp_Node +#define _Included_assimp_Node +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/code/jAssimp/assimp_Scene.h b/code/jAssimp/assimp_Scene.h new file mode 100644 index 000000000..f17fe16b4 --- /dev/null +++ b/code/jAssimp/assimp_Scene.h @@ -0,0 +1,45 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class assimp_Scene */ + +#ifndef _Included_assimp_Scene +#define _Included_assimp_Scene +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: assimp_Scene + * Method: _NativeGetNumMeshes + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumMeshes + (JNIEnv *, jobject, jint); + +/* + * Class: assimp_Scene + * Method: _NativeGetNumAnimations + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumAnimations + (JNIEnv *, jobject, jint); + +/* + * Class: assimp_Scene + * Method: _NativeGetNumTextures + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumTextures + (JNIEnv *, jobject, jint); + +/* + * Class: assimp_Scene + * Method: _NativeGetNumMaterials + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_assimp_Scene__1NativeGetNumMaterials + (JNIEnv *, jobject, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/code/jAssimp/assimp_Texture.h b/code/jAssimp/assimp_Texture.h new file mode 100644 index 000000000..0f08500be --- /dev/null +++ b/code/jAssimp/assimp_Texture.h @@ -0,0 +1,21 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class assimp_Texture */ + +#ifndef _Included_assimp_Texture +#define _Included_assimp_Texture +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: assimp_Texture + * Method: _NativeMapColorData + * Signature: ([B)I + */ +JNIEXPORT jint JNICALL Java_assimp_Texture__1NativeMapColorData + (JNIEnv *, jobject, jbyteArray); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/aiMesh.h b/include/aiMesh.h index c561ff870..bd1d88aba 100644 --- a/include/aiMesh.h +++ b/include/aiMesh.h @@ -218,6 +218,15 @@ struct aiBone */ #define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x4 +// NOTE (Aramis): If you change these values, make sure that you also +// change the corresponding values in all Assimp ports. + +// ********************************************************** +// Java: Mesh.java, +// Mesh.MAX_NUMBER_OF_TEXTURECOORDS +// Mesh.MAX_NUMBER_OF_COLOR_SETS +// ********************************************************** + #endif // !! AI_MAX_NUMBER_OF_TEXTURECOORDS // --------------------------------------------------------------------------- diff --git a/include/aiPostProcess.h b/include/aiPostProcess.h index 359b43f08..052e67da3 100644 --- a/include/aiPostProcess.h +++ b/include/aiPostProcess.h @@ -68,8 +68,8 @@ enum aiPostProcessSteps * the DirectX coordinate system. By default the data is returned in a right-handed * coordinate space which for example OpenGL prefers. In this space, +X points to the * right, +Y points towards the viewer and and +Z points upwards. In the DirectX - * coordinate space +X points to the right, +Y points upwards and +Z points - * away from the viewer. + * coordinate space +X points to the right, +Y points upwards and +Z points + * away from the viewer. */ aiProcess_ConvertToLeftHanded = 4, diff --git a/port/jAssimp/assimp.iml b/port/jAssimp/assimp.iml index d079e1581..72a09f34b 100644 --- a/port/jAssimp/assimp.iml +++ b/port/jAssimp/assimp.iml @@ -1,5 +1,11 @@ + + + + + + diff --git a/port/jAssimp/src/assimp/Animation.java b/port/jAssimp/src/assimp/Animation.java index 7858ff1a6..b932c62e5 100644 --- a/port/jAssimp/src/assimp/Animation.java +++ b/port/jAssimp/src/assimp/Animation.java @@ -1,11 +1,67 @@ +/* +--------------------------------------------------------------------------- +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. +--------------------------------------------------------------------------- +*/ + + package assimp; + /** - * Created by IntelliJ IDEA. - * User: Alex - * Date: 22.05.2008 - * Time: 13:05:35 - * To change this template use File | Settings | File Templates. + * An animation consists of keyframe data for a number of bones. For each + * bone affected by the animation a separate series of data is given. + * + * @author Aramis (Alexander Gessler) + * @version 1.0 */ -public class Animation { +public class Animation extends IMappable { + /** + * Construction from a given object and array index + * + * @param parent Must be valid, null is not allowed + * @param index Valied index in the parent's list + */ + public Animation(Object parent, int index) { + super(parent, index); + } + + protected void OnMap() throws NativeError { + + } } diff --git a/port/jAssimp/src/assimp/IMappable.java b/port/jAssimp/src/assimp/IMappable.java new file mode 100644 index 000000000..0aa423c31 --- /dev/null +++ b/port/jAssimp/src/assimp/IMappable.java @@ -0,0 +1,100 @@ +/* +--------------------------------------------------------------------------- +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. +--------------------------------------------------------------------------- +*/ + + +package assimp; + + +/** + * Defines base behaviour for all sub objects of Mesh. + * + * @author Aramis (Alexander Gessler) + * @version 1.0 + */ +public abstract class IMappable { + + /** + * Index of the mapped object in the parent Mesh + */ + private int m_iArrayIndex = 0; + + /** + * Reference to the parent of the object + */ + private Object m_parent = null; + + + /** + * Construction from a given parent object and array index + * @param parent Must be valid, null is not allowed + * @param index Valied index in the parent's list + */ + public IMappable(Object parent, int index) { + m_parent = parent; + m_iArrayIndex = index; + } + + /** + * Called as a request to the object to map all of its + * data into the address space of the Java virtual machine. + * After this method has been called the class instance must + * be ready to be used without an underyling native aiScene + * @throws NativeError + */ + protected abstract void OnMap() throws NativeError; + + + /** + * Retrieve the index ofthe mappable object in the parent mesh + * @return Value between 0 and n-1 + */ + public int getArrayIndex() { + return m_iArrayIndex; + } + + /** + * Provide access to the parent + * @return Never null ... + */ + public Object getParent() { + return m_parent; + } +} diff --git a/port/jAssimp/src/assimp/Importer.java b/port/jAssimp/src/assimp/Importer.java index da5ff8b41..7bd259937 100644 --- a/port/jAssimp/src/assimp/Importer.java +++ b/port/jAssimp/src/assimp/Importer.java @@ -67,7 +67,8 @@ public class Importer { /** * Unique number representing the address of the internal - * Assimp::Importer object. + * Assimp::Importer object. For 64 bit platforms it is something else .. + * at least it is guaranted to be unique ;-) */ private int m_iNativeHandle = 0xffffffff; @@ -191,11 +192,28 @@ public class Importer { // we need to build a path that is valid for the current OS char sep = System.getProperty("file.separator").charAt(0); - if(sep != '\\') this.path.replace('\\',sep); - if(sep != '/') this.path.replace('/',sep); + if(sep != '\\') this.path = this.path.replace('\\',sep); + if(sep != '/') this.path = this.path.replace('/',sep); + + // need to build a list of postprocess step as bitflag combination + // Of course, this could have been implemented directly. However, + // I've used the PostProcessStep enumeration to make debugging easier. + int flags = 0; + + for (PostProcessStep step : m_vPPSteps) { + if (step.equals(PostProcessStep.CalcTangentSpace)) flags |= 0x1; + else if (step.equals(PostProcessStep.JoinIdenticalVertices)) flags |= 0x2; + else if (step.equals(PostProcessStep.ConvertToLeftHanded)) flags |= 0x4; + else if (step.equals(PostProcessStep.Triangulate)) flags |= 0x8; + else if (step.equals(PostProcessStep.KillNormals)) flags |= 0x10; + else if (step.equals(PostProcessStep.GenFaceNormals)) flags |= 0x20; + else if (step.equals(PostProcessStep.GenSmoothNormals)) flags |= 0x40; + else if (step.equals(PostProcessStep.SplitLargeMeshes)) flags |= 0x80; + } // now load the mesh - if(0xffffffff == this._NativeLoad(this.path,this.m_vPPSteps) || ! this.scene.construct()) { + if(0xffffffff == this._NativeLoad(this.path,flags,this.m_iNativeHandle) || + ! this.scene.construct()) { this.scene = null; this.path = null; return null; @@ -234,7 +252,7 @@ public class Importer { super.finalize(); // be sure that native resources are deallocated properly - if (0xffffffff == _NativeFreeContext()) { + if (0xffffffff == _NativeFreeContext(this.m_iNativeHandle)) { throw new NativeError("Unable to destroy the native library context"); } return; @@ -272,14 +290,14 @@ public class Importer { * to assimp will be successful after this method has been called. * @return 0xffffffff if an error occured */ - private native int _NativeFreeContext(); + private native int _NativeFreeContext(int iContext); /** * JNI bridge call. For internal use only * The method loads the model into memory, but does not map it into the VM * @param path Path (valid separators for the OS) to the model to be loaded - * @param steps List of postprocess steps to be executed + * @param flags List of postprocess steps to be executed * @return 0xffffffff if an error occured */ - private native int _NativeLoad(String path,Vector< PostProcessStep > steps); + private native int _NativeLoad(String path,int flags, int iContext); } diff --git a/port/jAssimp/src/assimp/Material.java b/port/jAssimp/src/assimp/Material.java index c87aadea5..a783ec9fe 100644 --- a/port/jAssimp/src/assimp/Material.java +++ b/port/jAssimp/src/assimp/Material.java @@ -1,11 +1,68 @@ +/* +--------------------------------------------------------------------------- +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. +--------------------------------------------------------------------------- +*/ + + package assimp; + /** - * Created by IntelliJ IDEA. - * User: Alex - * Date: 22.05.2008 - * Time: 13:05:05 - * To change this template use File | Settings | File Templates. + * Class to wrap materials. Materials are represented in ASSIMP as a list of + * key/value pairs, the key being a String and the value being + * a binary buffer. + * + * @author Aramis (Alexander Gessler) + * @version 1.0 */ -public class Material { +public class Material extends IMappable { + /** + * Construction from a given parent object and array index + * + * @param parent Must be valid, null is not allowed + * @param index Valied index in the parent's list + */ + public Material(Object parent, int index) { + super(parent, index); + } + + protected void OnMap() throws NativeError { + + } } diff --git a/port/jAssimp/src/assimp/Mesh.java b/port/jAssimp/src/assimp/Mesh.java index 354b6d36b..ddbd7051f 100644 --- a/port/jAssimp/src/assimp/Mesh.java +++ b/port/jAssimp/src/assimp/Mesh.java @@ -1,11 +1,91 @@ +/* +--------------------------------------------------------------------------- +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. +--------------------------------------------------------------------------- +*/ + + package assimp; + /** - * Created by IntelliJ IDEA. - * User: Alex - * Date: 22.05.2008 - * Time: 13:04:42 - * To change this template use File | Settings | File Templates. + * A mesh represents a geometry or model with a single material. + *

+ * It usually consists of a number of vertices and a series of primitives/faces + * referencing the vertices. In addition there might be a series of bones, each + * of them addressing a number of vertices with a certain weight. Vertex data + * is presented in channels with each channel containing a single per-vertex + * information such as a set of texture coords or a normal vector. + *

+ * Note that not all mesh data channels must be there. E.g. most models + * don't contain vertex colors, so this data channel is often not filled. + * + * @author Aramis (Alexander Gessler) + * @version 1.0 */ -public class Mesh { +public class Mesh extends IMappable { + + /** + * Defines the maximum number of UV(W) channels that are available + * for a mesh. If a loader finds more channels in a file, some + * will be skipped + */ + private static final int MAX_NUMBER_OF_TEXTURECOORDS = 0x4; + + /** + * Defines the maximum number of vertex color channels that are + * available for a mesh. If a loader finds more channels in a file, + * some will be skipped + */ + private static final int MAX_NUMBER_OF_COLOR_SETS = 0x4; + + /** + * Construction from a given parent object and array index + * + * @param parent Parent object + * @param index Valied index in the parent's list + */ + public Mesh(Object parent, int index) { + super(parent, index); + } + + + protected void OnMap() throws NativeError { + + } } diff --git a/port/jAssimp/src/assimp/Scene.java b/port/jAssimp/src/assimp/Scene.java index ffa5d58d0..2317573af 100644 --- a/port/jAssimp/src/assimp/Scene.java +++ b/port/jAssimp/src/assimp/Scene.java @@ -49,7 +49,7 @@ import java.util.Vector; * multiple meshes, animations, materials and embedded textures. * And it defines the scenegraph of the asset (the hierarchy of all * meshes, ...). - * + *

* An instance of this class is returned by Importer.readFile(). * * @author Aramis (Alexander Gessler) @@ -57,52 +57,155 @@ import java.util.Vector; */ public class Scene { + // NOTE: use Vector's to be able to use the constructor for initialisation private Vector m_vMeshes; private Vector m_vTextures; private Vector m_vMaterials; private Vector m_vAnimations; - private Node m_rootNode; + private Node m_rootNode = null; + private Importer imp = null; - /** Get the mesh list + private Scene() { + } + + protected Scene(Importer imp) { + this.imp = imp; + } + + public final Importer getImporter() { + return this.imp; + } + + /** + * Get the mesh list * * @return mesh list */ - public Vector getMeshes() { + public final Vector getMeshes() { return m_vMeshes; } - /** Get the texture list + /** + * Get the texture list * * @return Texture list */ - public Vector getTextures() { + public final Vector getTextures() { return m_vTextures; } - /** Get the material list + /** + * Get the material list * * @return Material list */ - public Vector getMaterials() { + public final Vector getMaterials() { return m_vMaterials; } - /** Get the animation list + /** + * Get the animation list * * @return Animation list */ - public Vector getAnimations() { + public final Vector getAnimations() { return m_vAnimations; } - /** Get the root node of the scenegraph + /** + * Get the root node of the scenegraph * * @return Root node */ - public Node getRootNode() { + public final Node getRootNode() { return m_rootNode; } + /** + * Used to initialize the class instance. Called by Importer. Will maybe + * be replaced with a RAII solution ... + * @return true if we're successful + */ protected boolean construct() { + + int i; + + // load all meshes + int iTemp = this._NativeGetNumMeshes(imp.hashCode()); + if (0xffffffff == iTemp) return false; + this.m_vMeshes.setSize(iTemp); + + // Mesh, Animation, Texture, Material and Node constructors + // throw exceptions if they fail + try { + + for (i = 0; i < iTemp; ++i) { + this.m_vMeshes.set(i, new Mesh(this, i)); + } + + // load all animations + iTemp = this._NativeGetNumAnimations(imp.hashCode()); + if (0xffffffff == iTemp) return false; + this.m_vAnimations.setSize(iTemp); + + for (i = 0; i < iTemp; ++i) { + this.m_vAnimations.set(i, new Animation(this, i)); + } + + // load all textures + iTemp = this._NativeGetNumTextures(imp.hashCode()); + if (0xffffffff == iTemp) return false; + this.m_vTextures.setSize(iTemp); + + for (i = 0; i < iTemp; ++i) { + this.m_vTextures.set(i, new Texture(this, i)); + } + + // load all materials + iTemp = this._NativeGetNumMaterials(imp.hashCode()); + if (0xffffffff == iTemp) return false; + this.m_vMaterials.setSize(iTemp); + + for (i = 0; i < iTemp; ++i) { + this.m_vMaterials.set(i, new Material(this, i)); + } + + // now load all nodes + //this.m_rootNode = new Node(this, 0xffffffff); + + } + catch (Exception ex) { + // LOG + return false; + } + return true; } + + /** JNI bridge function - for internal use only + * Retrieve the number of meshes in a scene + * @param context Current importer context (imp.hashCode) + * @return Number of meshes in the scene that belongs to the context + */ + private native int _NativeGetNumMeshes(int context); + + /** JNI bridge function - for internal use only + * Retrieve the number of animations in a scene + * @param context Current importer context (imp.hashCode) + * @return Number of animations in the scene that belongs to the context + */ + private native int _NativeGetNumAnimations(int context); + + /** JNI bridge function - for internal use only + * Retrieve the number of textures in a scene + * @param context Current importer context (imp.hashCode) + * @return Number of textures in the scene that belongs to the context + */ + private native int _NativeGetNumTextures(int context); + + /** JNI bridge function - for internal use only + * Retrieve the number of materials in a scene + * @param context Current importer context (imp.hashCode) + * @return Number of materials in the scene that belongs to the context + */ + private native int _NativeGetNumMaterials(int context); } diff --git a/port/jAssimp/src/assimp/Texture.java b/port/jAssimp/src/assimp/Texture.java index 248b7341c..45e9d6ab2 100644 --- a/port/jAssimp/src/assimp/Texture.java +++ b/port/jAssimp/src/assimp/Texture.java @@ -42,7 +42,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package assimp; -import java.util.Vector; import java.awt.*; /** @@ -57,13 +56,24 @@ import java.awt.*; * @author Aramis (Alexander Gessler) * @version 1.0 */ -public class Texture { +public class Texture extends IMappable { private int width = 0; private int height = 0; private Color[] data = null; + /** + * Construction from a given parent object and array index + * + * @param parent Must be valid, null is not allowed + * @param index Valied index in the parent's list + */ + public Texture(Object parent, int index) { + super(parent, index); + } + + /** * Retrieve the height of the texture image * @@ -96,7 +106,7 @@ public class Texture { // map the color data in memory if required ... if (null == data) { try { - this.MapColorData(); + this.OnMap(); } catch (NativeError nativeError) { return Color.black; } @@ -108,7 +118,8 @@ public class Texture { * Internal helper function to map the native texture data into * a java.awt.Color array */ - private void MapColorData() throws NativeError { + @Override + protected void OnMap() throws NativeError { final int iNumPixels = width * height; // first allocate the output array @@ -119,7 +130,7 @@ public class Texture { // and copy the native color data to it if (0xffffffff == this._NativeMapColorData(temp)) { - throw new NativeError("Unable to map aiTexture into Java-VM"); + throw new NativeError("Unable to map aiTexture into the Java-VM"); } // now convert the temporary representation to a Color array diff --git a/workspaces/jidea5.1/jAssimp.ipr b/workspaces/jidea5.1/jAssimp.ipr index fe4ae4cf4..0fd5cf8bc 100644 --- a/workspaces/jidea5.1/jAssimp.ipr +++ b/workspaces/jidea5.1/jAssimp.ipr @@ -178,10 +178,10 @@ - + - +