Merge pull request #9 from assimp/master

Update fork
pull/1350/head
Madrich 2015-10-24 14:01:02 +02:00
commit 6bbec8d96e
21 changed files with 251 additions and 92 deletions

View File

@ -27,6 +27,7 @@ execute_process(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
# Get the latest abbreviated commit hash of the working branch
@ -35,6 +36,7 @@ execute_process(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT GIT_COMMIT_HASH)
@ -63,7 +65,9 @@ if( CMAKE_COMPILER_IS_MINGW )
endif()
if((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT CMAKE_COMPILER_IS_MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") # this is a very important switch and some libraries seem now to have it....
if (BUILD_SHARED_LIBS AND CMAKE_SIZEOF_VOID_P EQUAL 8) # -fPIC is only required for shared libs on 64 bit
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
# hide all not-exported symbols
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -Wall" )
elseif(MSVC)
@ -119,7 +123,9 @@ IF ( ASSIMP_ENABLE_BOOST_WORKAROUND )
MESSAGE( STATUS "Building a non-boost version of Assimp." )
ELSE ( ASSIMP_ENABLE_BOOST_WORKAROUND )
SET( Boost_DETAILED_FAILURE_MSG ON )
SET( Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0" "1.48.0" "1.48" "1.49" "1.49.0" "1.50" "1.50.0" "1.51" "1.51.0" "1.52.0" "1.53.0" "1.54.0" "1.55" "1.55.0" "1.56" "1.56.0" "1.57" "1.57.0" "1.58" "1.58.0" )
IF ( NOT Boost_ADDITIONAL_VERSIONS )
SET( Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0" "1.48.0" "1.48" "1.49" "1.49.0" "1.50" "1.50.0" "1.51" "1.51.0" "1.52.0" "1.53.0" "1.54.0" "1.55" "1.55.0" "1.56" "1.56.0" "1.57" "1.57.0" "1.58" "1.58.0" "1.59" "1.59.0")
ENDIF ( NOT Boost_ADDITIONAL_VERSIONS )
FIND_PACKAGE( Boost )
IF ( NOT Boost_FOUND )
MESSAGE( FATAL_ERROR

View File

@ -113,6 +113,9 @@ If the docs don't solve your problem, ask on [StackOverflow](http://stackoverflo
For development discussions, there is also a (very low-volume) mailing list, _assimp-discussions_
[(subscribe here)]( https://lists.sourceforge.net/lists/listinfo/assimp-discussions)
And we also have an IRC-channel at freenode: #assetimporterlib . You can easily join us via: [KiwiIRC/freenote](https://kiwiirc.com/client/irc.freenode.net), choose your nickname and type
> /join #assetimporterlib
### Contributing ###
Contributions to assimp are highly appreciated. The easiest way to get involved is to submit
@ -125,4 +128,3 @@ Our license is based on the modified, __3-clause BSD__-License.
An _informal_ summary is: do whatever you want, but include Assimp's license text with your product -
and don't sue us if our code doesn't work. Note that, unlike LGPLed code, you may link statically to Assimp.
For the legal details, see the `LICENSE` file.

View File

@ -1,9 +1,6 @@
# AppVeyor file
# http://www.appveyor.com/docs/appveyor-yml
# Operating system (build VM template)
os: Previous Windows Server 2012 R2 # using previous worker images since default worker has problem installing DART-Prerequisites.msi
# clone directory
clone_folder: c:\projects\assimp

View File

@ -35,6 +35,7 @@ if(WIN32) # The only platform it makes sense to check for DirectX SDK
"C:/Program Files (x86)/Microsoft DirectX SDK*"
"C:/apps/Microsoft DirectX SDK*"
"C:/Program Files/Microsoft DirectX SDK*"
"C:/Program Files (x86)/Windows Kits/8.1"
"$ENV{ProgramFiles}/Microsoft DirectX SDK*"
)
create_search_paths(DirectX)

View File

@ -63,7 +63,7 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
BaseImporter::BaseImporter()
: progress()
: m_progress()
{
// nothing to do here
}
@ -79,8 +79,8 @@ BaseImporter::~BaseImporter()
// Imports the given file and returns the imported data.
aiScene* BaseImporter::ReadFile(const Importer* pImp, const std::string& pFile, IOSystem* pIOHandler)
{
progress = pImp->GetProgressHandler();
ai_assert(progress);
m_progress = pImp->GetProgressHandler();
ai_assert(m_progress);
// Gather configuration properties for this run
SetupProperties( pImp );
@ -98,8 +98,8 @@ aiScene* BaseImporter::ReadFile(const Importer* pImp, const std::string& pFile,
} catch( const std::exception& err ) {
// extract error description
mErrorText = err.what();
DefaultLogger::get()->error(mErrorText);
m_ErrorText = err.what();
DefaultLogger::get()->error(m_ErrorText);
return NULL;
}
@ -274,7 +274,7 @@ void BaseImporter::GetExtensionList(std::set<std::string>& extensions)
for (unsigned int i = 0; i < num; ++i) {
// also check against big endian versions of tokens with size 2,4
// that's just for convinience, the chance that we cause conflicts
// that's just for convenience, the chance that we cause conflicts
// is quite low and it can save some lines and prevent nasty bugs
if (2 == size) {
uint16_t rev = *magic_u16;

View File

@ -181,7 +181,7 @@ public:
* string if there was no error.
*/
const std::string& GetErrorText() const {
return mErrorText;
return m_ErrorText;
}
// -------------------------------------------------------------------
@ -362,10 +362,10 @@ public: // static utilities
protected:
/** Error description in case there was one. */
std::string mErrorText;
std::string m_ErrorText;
/** Currently set progress handler */
ProgressHandler* progress;
ProgressHandler* m_progress;
};

View File

@ -135,11 +135,11 @@ inline void MakeAbsolutePath (const char* in, char* _out)
{
ai_assert(in && _out);
char* ret;
#ifdef _WIN32
ret = ::_fullpath(_out, in,PATHLIMIT);
#if defined( _MSC_VER ) || defined( __MINGW32__ )
ret = ::_fullpath( _out, in, PATHLIMIT );
#else
// use realpath
ret = realpath(in, _out);
// use realpath
ret = realpath(in, _out);
#endif
if(!ret) {
// preserve the input path, maybe someone else is able to fix
@ -167,8 +167,8 @@ bool DefaultIOSystem::ComparePaths (const char* one, const char* second) const
return !ASSIMP_stricmp(temp1,temp2);
}
std::string DefaultIOSystem::fileName(std::string path)
// ------------------------------------------------------------------------------------------------
std::string DefaultIOSystem::fileName( const std::string &path )
{
std::string ret = path;
std::size_t last = ret.find_last_of("\\/");
@ -177,7 +177,8 @@ std::string DefaultIOSystem::fileName(std::string path)
}
std::string DefaultIOSystem::completeBaseName(std::string path)
// ------------------------------------------------------------------------------------------------
std::string DefaultIOSystem::completeBaseName( const std::string &path )
{
std::string ret = fileName(path);
std::size_t pos = ret.find_last_of('.');
@ -185,8 +186,8 @@ std::string DefaultIOSystem::completeBaseName(std::string path)
return ret;
}
std::string DefaultIOSystem::absolutePath(std::string path)
// ------------------------------------------------------------------------------------------------
std::string DefaultIOSystem::absolutePath( const std::string &path )
{
std::string ret = path;
std::size_t last = ret.find_last_of("\\/");
@ -194,4 +195,6 @@ std::string DefaultIOSystem::absolutePath(std::string path)
return ret;
}
// ------------------------------------------------------------------------------------------------
#undef PATHLIMIT

View File

@ -80,17 +80,17 @@ public:
/** @brief get the file name of a full filepath
* example: /tmp/archive.tar.gz -> archive.tar.gz
*/
static std::string fileName(std::string path);
static std::string fileName( const std::string &path );
/** @brief get the complete base name of a full filepath
* example: /tmp/archive.tar.gz -> archive.tar
*/
static std::string completeBaseName(std::string path);
static std::string completeBaseName( const std::string &path);
/** @brief get the path of a full filepath
* example: /tmp/archive.tar.gz -> /tmp/
*/
static std::string absolutePath(std::string path);
static std::string absolutePath( const std::string &path);
};
} //!ns Assimp

View File

@ -285,9 +285,6 @@ void MD5Importer::AttachChilds_Mesh(int iParentID,aiNode* piParent, BoneList& bo
aiQuaternion quat;
MD5::ConvertQuaternion ( bones[i].mRotationQuat, quat );
// FIX to get to Assimp's quaternion conventions
quat.w *= -1.f;
bones[i].mTransform = aiMatrix4x4 ( quat.GetMatrix());
bones[i].mTransform.a4 = bones[i].mPositionXYZ.x;
bones[i].mTransform.b4 = bones[i].mPositionXYZ.y;
@ -656,9 +653,6 @@ void MD5Importer::LoadMD5AnimFile ()
MD5::ConvertQuaternion(vTemp, qKey->mValue);
qKey->mTime = vKey->mTime = dTime;
// we need this to get to Assimp quaternion conventions
qKey->mValue.w *= -1.f;
}
}

View File

@ -262,6 +262,9 @@ inline void ConvertQuaternion (const aiVector3D& in, aiQuaternion& out) {
if (t < 0.0f)
out.w = 0.0f;
else out.w = std::sqrt (t);
// Assimp convention.
out.w *= -1.f;
}
// ---------------------------------------------------------------------------

View File

@ -156,6 +156,7 @@ struct Material
aiString textureEmissive;
aiString textureBump;
aiString textureNormal;
aiString textureReflection[6];
aiString textureSpecularity;
aiString textureOpacity;
aiString textureDisp;
@ -167,6 +168,13 @@ struct Material
TextureEmissiveType,
TextureBumpType,
TextureNormalType,
TextureReflectionSphereType,
TextureReflectionCubeTopType,
TextureReflectionCubeBottomType,
TextureReflectionCubeFrontType,
TextureReflectionCubeBackType,
TextureReflectionCubeLeftType,
TextureReflectionCubeRightType,
TextureSpecularityType,
TextureOpacityType,
TextureDispType,

View File

@ -636,6 +636,22 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc
}
}
if( 0 != pCurrentMaterial->textureReflection[0].length )
{
ObjFile::Material::TextureType type = 0 != pCurrentMaterial->textureReflection[1].length ?
ObjFile::Material::TextureReflectionCubeTopType :
ObjFile::Material::TextureReflectionSphereType;
unsigned count = type == ObjFile::Material::TextureReflectionSphereType ? 1 : 6;
for( unsigned i = 0; i < count; i++ )
mat->AddProperty(&pCurrentMaterial->textureReflection[i], AI_MATKEY_TEXTURE_REFLECTION(i));
if(pCurrentMaterial->clamp[type])
//TODO addTextureMappingModeProperty should accept an index to handle clamp option for each
//texture of a cubemap
addTextureMappingModeProperty(mat, aiTextureType_REFLECTION);
}
if ( 0 != pCurrentMaterial->textureDisp.length )
{
mat->AddProperty( &pCurrentMaterial->textureDisp, AI_MATKEY_TEXTURE_DISPLACEMENT(0) );

View File

@ -64,6 +64,7 @@ static const std::string BumpTexture1 = "map_bump";
static const std::string BumpTexture2 = "map_Bump";
static const std::string BumpTexture3 = "bump";
static const std::string NormalTexture = "map_Kn";
static const std::string ReflectionTexture = "refl";
static const std::string DisplacementTexture = "disp";
static const std::string SpecularityTexture = "map_ns";
@ -200,6 +201,7 @@ void ObjFileMtlImporter::load()
case 'm': // Texture
case 'b': // quick'n'dirty - for 'bump' sections
case 'r': // quick'n'dirty - for 'refl' sections
{
getTexture();
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
@ -332,6 +334,9 @@ void ObjFileMtlImporter::getTexture() {
// Normal map
out = & m_pModel->m_pCurrentMaterial->textureNormal;
clampIndex = ObjFile::Material::TextureNormalType;
} else if(!ASSIMP_strincmp( pPtr, ReflectionTexture.c_str(), ReflectionTexture.size() ) ) {
// Reflection texture(s)
//Do nothing here
} else if (!ASSIMP_strincmp( pPtr, DisplacementTexture.c_str(), DisplacementTexture.size() ) ) {
// Displacement texture
out = &m_pModel->m_pCurrentMaterial->textureDisp;
@ -346,7 +351,7 @@ void ObjFileMtlImporter::getTexture() {
}
bool clamp = false;
getTextureOption(clamp);
getTextureOption(clamp, clampIndex, out);
m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp;
std::string texture;
@ -369,7 +374,7 @@ void ObjFileMtlImporter::getTexture() {
* Because aiMaterial supports clamp option, so we also want to return it
* /////////////////////////////////////////////////////////////////////////////
*/
void ObjFileMtlImporter::getTextureOption(bool &clamp)
void ObjFileMtlImporter::getTextureOption(bool &clamp, int &clampIndex, aiString *&out)
{
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
@ -392,13 +397,55 @@ void ObjFileMtlImporter::getTextureOption(bool &clamp)
skipToken = 2;
}
else if ( !ASSIMP_strincmp(pPtr, BlendUOption.c_str(), BlendUOption.size())
else if( !ASSIMP_strincmp( pPtr, TypeOption.c_str(), TypeOption.size() ) )
{
DataArrayIt it = getNextToken<DataArrayIt>( m_DataIt, m_DataItEnd );
char value[ 12 ];
CopyNextWord( it, m_DataItEnd, value, sizeof( value ) / sizeof( *value ) );
if( !ASSIMP_strincmp( value, "cube_top", 8 ) )
{
clampIndex = ObjFile::Material::TextureReflectionCubeTopType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
}
else if( !ASSIMP_strincmp( value, "cube_bottom", 11 ) )
{
clampIndex = ObjFile::Material::TextureReflectionCubeBottomType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[1];
}
else if( !ASSIMP_strincmp( value, "cube_front", 10 ) )
{
clampIndex = ObjFile::Material::TextureReflectionCubeFrontType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[2];
}
else if( !ASSIMP_strincmp( value, "cube_back", 9 ) )
{
clampIndex = ObjFile::Material::TextureReflectionCubeBackType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[3];
}
else if( !ASSIMP_strincmp( value, "cube_left", 9 ) )
{
clampIndex = ObjFile::Material::TextureReflectionCubeLeftType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[4];
}
else if( !ASSIMP_strincmp( value, "cube_right", 10 ) )
{
clampIndex = ObjFile::Material::TextureReflectionCubeRightType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[5];
}
else if( !ASSIMP_strincmp( value, "sphere", 6 ) )
{
clampIndex = ObjFile::Material::TextureReflectionSphereType;
out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
}
skipToken = 2;
}
else if (!ASSIMP_strincmp(pPtr, BlendUOption.c_str(), BlendUOption.size())
|| !ASSIMP_strincmp(pPtr, BlendVOption.c_str(), BlendVOption.size())
|| !ASSIMP_strincmp(pPtr, BoostOption.c_str(), BoostOption.size())
|| !ASSIMP_strincmp(pPtr, ResolutionOption.c_str(), ResolutionOption.size())
|| !ASSIMP_strincmp(pPtr, BumpOption.c_str(), BumpOption.size())
|| !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), ChannelOption.size())
|| !ASSIMP_strincmp(pPtr, TypeOption.c_str(), TypeOption.size()) )
|| !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), ChannelOption.size()))
{
skipToken = 2;
}

View File

@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string>
struct aiColor3D;
struct aiString;
namespace Assimp {
@ -89,7 +90,7 @@ private:
void createMaterial();
/// Get texture name from loaded data.
void getTexture();
void getTextureOption(bool &clamp);
void getTextureOption(bool &clamp, int &clampIndex, aiString *&out);
private:
//! Absolute pathname

View File

@ -857,7 +857,7 @@ bool PLY::PropertyInstance::ParseValueBinary(
case EDT_UShort:
{
int16_t i = *((uint16_t*)pCur);
uint16_t i = *((uint16_t*)pCur);
// Swap endianess
if (p_bBE)ByteSwap::Swap(&i);

View File

@ -74,7 +74,7 @@ static const aiImporterDesc desc = {
// 1) 80 byte header
// 2) 4 byte face count
// 3) 50 bytes per face
bool IsBinarySTL(const char* buffer, unsigned int fileSize) {
static bool IsBinarySTL(const char* buffer, unsigned int fileSize) {
if( fileSize < 84 ) {
return false;
}
@ -88,7 +88,7 @@ bool IsBinarySTL(const char* buffer, unsigned int fileSize) {
// An ascii STL buffer will begin with "solid NAME", where NAME is optional.
// Note: The "solid NAME" check is necessary, but not sufficient, to determine
// if the buffer is ASCII; a binary header could also begin with "solid NAME".
bool IsAsciiSTL(const char* buffer, unsigned int fileSize) {
static bool IsAsciiSTL(const char* buffer, unsigned int fileSize) {
if (IsBinarySTL(buffer, fileSize))
return false;

View File

@ -47,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Some runtime headers
#include <sys/types.h>
#include <memory.h>
#include <math.h>
#include <stddef.h>
#include <string.h>

View File

@ -10,7 +10,9 @@ if sys.version_info < (2,6):
import ctypes
import os
import numpy
try: import numpy
except: numpy = None
import logging
logger = logging.getLogger("pyassimp")
@ -33,12 +35,30 @@ _assimp_lib = AssimpLib()
def make_tuple(ai_obj, type = None):
res = None
#notes:
# ai_obj._fields_ = [ ("attr", c_type), ... ]
# getattr(ai_obj, e[0]).__class__ == float
if isinstance(ai_obj, structs.Matrix4x4):
res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]).reshape((4,4))
if numpy:
res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]).reshape((4,4))
#import pdb;pdb.set_trace()
else:
res = [getattr(ai_obj, e[0]) for e in ai_obj._fields_]
res = [res[i:i+4] for i in xrange(0,16,4)]
elif isinstance(ai_obj, structs.Matrix3x3):
res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]).reshape((3,3))
if numpy:
res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]).reshape((3,3))
else:
res = [getattr(ai_obj, e[0]) for e in ai_obj._fields_]
res = [res[i:i+3] for i in xrange(0,9,3)]
else:
res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_])
if numpy:
res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_])
else:
res = [getattr(ai_obj, e[0]) for e in ai_obj._fields_]
return res
# It is faster and more correct to have an init function for each assimp class
@ -135,9 +155,14 @@ def _init(self, target = None, parent = None):
try:
if obj._type_ in structs.assimp_structs_as_tuple:
setattr(target, name, numpy.array([make_tuple(obj[i]) for i in range(length)], dtype=numpy.float32))
if numpy:
setattr(target, name, numpy.array([make_tuple(obj[i]) for i in range(length)], dtype=numpy.float32))
logger.debug(str(self) + ": Added an array of numpy arrays (type "+ str(type(obj)) + ") as self." + name)
logger.debug(str(self) + ": Added an array of numpy arrays (type "+ str(type(obj)) + ") as self." + name)
else:
setattr(target, name, [make_tuple(obj[i]) for i in range(length)])
logger.debug(str(self) + ": Added a list of lists (type "+ str(type(obj)) + ") as self." + name)
else:
setattr(target, name, [obj[i] for i in range(length)]) #TODO: maybe not necessary to recreate an array?
@ -292,7 +317,10 @@ def release(scene):
def _finalize_texture(tex, target):
setattr(target, "achformathint", tex.achFormatHint)
data = numpy.array([make_tuple(getattr(tex, "pcData")[i]) for i in range(tex.mWidth * tex.mHeight)])
if numpy:
data = numpy.array([make_tuple(getattr(tex, "pcData")[i]) for i in range(tex.mWidth * tex.mHeight)])
else:
data = [make_tuple(getattr(tex, "pcData")[i]) for i in range(tex.mWidth * tex.mHeight)]
setattr(target, "data", data)
def _finalize_mesh(mesh, target):
@ -308,11 +336,18 @@ def _finalize_mesh(mesh, target):
def fill(name):
mAttr = getattr(mesh, name)
if mAttr:
data = numpy.array([make_tuple(getattr(mesh, name)[i]) for i in range(nb_vertices)], dtype=numpy.float32)
setattr(target, name[1:].lower(), data)
if numpy:
if mAttr:
data = numpy.array([make_tuple(getattr(mesh, name)[i]) for i in range(nb_vertices)], dtype=numpy.float32)
setattr(target, name[1:].lower(), data)
else:
setattr(target, name[1:].lower(), numpy.array([], dtype="float32"))
else:
setattr(target, name[1:].lower(), numpy.array([], dtype="float32"))
if mAttr:
data = [make_tuple(getattr(mesh, name)[i]) for i in range(nb_vertices)]
setattr(target, name[1:].lower(), data)
else:
setattr(target, name[1:].lower(), [])
def fillarray(name):
mAttr = getattr(mesh, name)
@ -322,7 +357,10 @@ def _finalize_mesh(mesh, target):
if mSubAttr:
data.append([make_tuple(getattr(mesh, name)[index][i]) for i in range(nb_vertices)])
setattr(target, name[1:].lower(), numpy.array(data, dtype=numpy.float32))
if numpy:
setattr(target, name[1:].lower(), numpy.array(data, dtype=numpy.float32))
else:
setattr(target, name[1:].lower(), data)
fill("mNormals")
fill("mTangents")
@ -332,7 +370,10 @@ def _finalize_mesh(mesh, target):
fillarray("mTextureCoords")
# prepare faces
faces = numpy.array([f.indices for f in target.faces], dtype=numpy.int32)
if numpy:
faces = numpy.array([f.indices for f in target.faces], dtype=numpy.int32)
else:
faces = [f.indices for f in target.faces]
setattr(target, 'faces', faces)

View File

@ -8,8 +8,9 @@ import os
import ctypes
from ctypes import POINTER
import operator
import numpy
from numpy import linalg
try: import numpy
except: numpy = None
import logging;logger = logging.getLogger("pyassimp")
@ -46,20 +47,88 @@ def vec2tuple(x):
def transform(vector3, matrix4x4):
""" Apply a transformation matrix on a 3D vector.
:param vector3: a numpy array with 3 elements
:param matrix4x4: a numpy 4x4 matrix
:param vector3: array with 3 elements
:param matrix4x4: 4x4 matrix
"""
return numpy.dot(matrix4x4, numpy.append(vector3, 1.))
if numpy:
return numpy.dot(matrix4x4, numpy.append(vector3, 1.))
else:
m0,m1,m2,m3 = matrix4x4; x,y,z = vector3
return [
m0[0]*x + m0[1]*y + m0[2]*z + m0[3],
m1[0]*x + m1[1]*y + m1[2]*z + m1[3],
m2[0]*x + m2[1]*y + m2[2]*z + m2[3],
m3[0]*x + m3[1]*y + m3[2]*z + m3[3]
]
def _inv(matrix4x4):
m0,m1,m2,m3 = matrix4x4
det = m0[3]*m1[2]*m2[1]*m3[0] - m0[2]*m1[3]*m2[1]*m3[0] - \
m0[3]*m1[1]*m2[2]*m3[0] + m0[1]*m1[3]*m2[2]*m3[0] + \
m0[2]*m1[1]*m2[3]*m3[0] - m0[1]*m1[2]*m2[3]*m3[0] - \
m0[3]*m1[2]*m2[0]*m3[1] + m0[2]*m1[3]*m2[0]*m3[1] + \
m0[3]*m1[0]*m2[2]*m3[1] - m0[0]*m1[3]*m2[2]*m3[1] - \
m0[2]*m1[0]*m2[3]*m3[1] + m0[0]*m1[2]*m2[3]*m3[1] + \
m0[3]*m1[1]*m2[0]*m3[2] - m0[1]*m1[3]*m2[0]*m3[2] - \
m0[3]*m1[0]*m2[1]*m3[2] + m0[0]*m1[3]*m2[1]*m3[2] + \
m0[1]*m1[0]*m2[3]*m3[2] - m0[0]*m1[1]*m2[3]*m3[2] - \
m0[2]*m1[1]*m2[0]*m3[3] + m0[1]*m1[2]*m2[0]*m3[3] + \
m0[2]*m1[0]*m2[1]*m3[3] - m0[0]*m1[2]*m2[1]*m3[3] - \
m0[1]*m1[0]*m2[2]*m3[3] + m0[0]*m1[1]*m2[2]*m3[3]
return[[( m1[2]*m2[3]*m3[1] - m1[3]*m2[2]*m3[1] + m1[3]*m2[1]*m3[2] - m1[1]*m2[3]*m3[2] - m1[2]*m2[1]*m3[3] + m1[1]*m2[2]*m3[3]) /det,
( m0[3]*m2[2]*m3[1] - m0[2]*m2[3]*m3[1] - m0[3]*m2[1]*m3[2] + m0[1]*m2[3]*m3[2] + m0[2]*m2[1]*m3[3] - m0[1]*m2[2]*m3[3]) /det,
( m0[2]*m1[3]*m3[1] - m0[3]*m1[2]*m3[1] + m0[3]*m1[1]*m3[2] - m0[1]*m1[3]*m3[2] - m0[2]*m1[1]*m3[3] + m0[1]*m1[2]*m3[3]) /det,
( m0[3]*m1[2]*m2[1] - m0[2]*m1[3]*m2[1] - m0[3]*m1[1]*m2[2] + m0[1]*m1[3]*m2[2] + m0[2]*m1[1]*m2[3] - m0[1]*m1[2]*m2[3]) /det],
[( m1[3]*m2[2]*m3[0] - m1[2]*m2[3]*m3[0] - m1[3]*m2[0]*m3[2] + m1[0]*m2[3]*m3[2] + m1[2]*m2[0]*m3[3] - m1[0]*m2[2]*m3[3]) /det,
( m0[2]*m2[3]*m3[0] - m0[3]*m2[2]*m3[0] + m0[3]*m2[0]*m3[2] - m0[0]*m2[3]*m3[2] - m0[2]*m2[0]*m3[3] + m0[0]*m2[2]*m3[3]) /det,
( m0[3]*m1[2]*m3[0] - m0[2]*m1[3]*m3[0] - m0[3]*m1[0]*m3[2] + m0[0]*m1[3]*m3[2] + m0[2]*m1[0]*m3[3] - m0[0]*m1[2]*m3[3]) /det,
( m0[2]*m1[3]*m2[0] - m0[3]*m1[2]*m2[0] + m0[3]*m1[0]*m2[2] - m0[0]*m1[3]*m2[2] - m0[2]*m1[0]*m2[3] + m0[0]*m1[2]*m2[3]) /det],
[( m1[1]*m2[3]*m3[0] - m1[3]*m2[1]*m3[0] + m1[3]*m2[0]*m3[1] - m1[0]*m2[3]*m3[1] - m1[1]*m2[0]*m3[3] + m1[0]*m2[1]*m3[3]) /det,
( m0[3]*m2[1]*m3[0] - m0[1]*m2[3]*m3[0] - m0[3]*m2[0]*m3[1] + m0[0]*m2[3]*m3[1] + m0[1]*m2[0]*m3[3] - m0[0]*m2[1]*m3[3]) /det,
( m0[1]*m1[3]*m3[0] - m0[3]*m1[1]*m3[0] + m0[3]*m1[0]*m3[1] - m0[0]*m1[3]*m3[1] - m0[1]*m1[0]*m3[3] + m0[0]*m1[1]*m3[3]) /det,
( m0[3]*m1[1]*m2[0] - m0[1]*m1[3]*m2[0] - m0[3]*m1[0]*m2[1] + m0[0]*m1[3]*m2[1] + m0[1]*m1[0]*m2[3] - m0[0]*m1[1]*m2[3]) /det],
[( m1[2]*m2[1]*m3[0] - m1[1]*m2[2]*m3[0] - m1[2]*m2[0]*m3[1] + m1[0]*m2[2]*m3[1] + m1[1]*m2[0]*m3[2] - m1[0]*m2[1]*m3[2]) /det,
( m0[1]*m2[2]*m3[0] - m0[2]*m2[1]*m3[0] + m0[2]*m2[0]*m3[1] - m0[0]*m2[2]*m3[1] - m0[1]*m2[0]*m3[2] + m0[0]*m2[1]*m3[2]) /det,
( m0[2]*m1[1]*m3[0] - m0[1]*m1[2]*m3[0] - m0[2]*m1[0]*m3[1] + m0[0]*m1[2]*m3[1] + m0[1]*m1[0]*m3[2] - m0[0]*m1[1]*m3[2]) /det,
( m0[1]*m1[2]*m2[0] - m0[2]*m1[1]*m2[0] + m0[2]*m1[0]*m2[1] - m0[0]*m1[2]*m2[1] - m0[1]*m1[0]*m2[2] + m0[0]*m1[1]*m2[2]) /det]]
def get_bounding_box(scene):
bb_min = [1e10, 1e10, 1e10] # x,y,z
bb_max = [-1e10, -1e10, -1e10] # x,y,z
return get_bounding_box_for_node(scene.rootnode, bb_min, bb_max, linalg.inv(scene.rootnode.transformation))
inv = numpy.linalg.inv if numpy else _inv
return get_bounding_box_for_node(scene.rootnode, bb_min, bb_max, inv(scene.rootnode.transformation))
def get_bounding_box_for_node(node, bb_min, bb_max, transformation):
transformation = numpy.dot(transformation, node.transformation)
if numpy:
transformation = numpy.dot(transformation, node.transformation)
else:
t0,t1,t2,t3 = transformation
T0,T1,T2,T3 = node.transformation
transformation = [ [
t0[0]*T0[0] + t0[1]*T1[0] + t0[2]*T2[0] + t0[3]*T3[0],
t0[0]*T0[1] + t0[1]*T1[1] + t0[2]*T2[1] + t0[3]*T3[1],
t0[0]*T0[2] + t0[1]*T1[2] + t0[2]*T2[2] + t0[3]*T3[2],
t0[0]*T0[3] + t0[1]*T1[3] + t0[2]*T2[3] + t0[3]*T3[3]
],[
t1[0]*T0[0] + t1[1]*T1[0] + t1[2]*T2[0] + t1[3]*T3[0],
t1[0]*T0[1] + t1[1]*T1[1] + t1[2]*T2[1] + t1[3]*T3[1],
t1[0]*T0[2] + t1[1]*T1[2] + t1[2]*T2[2] + t1[3]*T3[2],
t1[0]*T0[3] + t1[1]*T1[3] + t1[2]*T2[3] + t1[3]*T3[3]
],[
t2[0]*T0[0] + t2[1]*T1[0] + t2[2]*T2[0] + t2[3]*T3[0],
t2[0]*T0[1] + t2[1]*T1[1] + t2[2]*T2[1] + t2[3]*T3[1],
t2[0]*T0[2] + t2[1]*T1[2] + t2[2]*T2[2] + t2[3]*T3[2],
t2[0]*T0[3] + t2[1]*T1[3] + t2[2]*T2[3] + t2[3]*T3[3]
],[
t3[0]*T0[0] + t3[1]*T1[0] + t3[2]*T2[0] + t3[3]*T3[0],
t3[0]*T0[1] + t3[1]*T1[1] + t3[2]*T2[1] + t3[3]*T3[1],
t3[0]*T0[2] + t3[1]*T1[2] + t3[2]*T2[2] + t3[3]*T3[2],
t3[0]*T0[3] + t3[1]*T1[3] + t3[2]*T2[3] + t3[3]*T3[3]
] ]
for mesh in node.meshes:
for v in mesh.vertices:
v = transform(v, transformation)

View File

@ -1,28 +0,0 @@
# ---------------------------------------------------------------------------
# Makefile for assimp/Sample_SimpleOpenGL
# aramis_acg@users.sourceforge.net
#
# Usage: make <target> <macros>
# TARGETS:
# all Build the sample + assimp itself
# clean Cleanup all object files
# ---------------------------------------------------------------------------
VPATH = ./usr/include/
# Include flags for gcc
INCLUDEFLAGS = -I../../include
# Library flags for gcc
LIBFLAGS = -L../../bin/gcc
# Output name of executable
OUTPUT = samplegl
all: $(OBJECTS)
cd ../../code/ && $(MAKE) static
gcc -o $(OUTPUT) $(INCLUDEFLAGS) -s Sample_SimpleOpenGL.c $(LIBFLAGS) -Wl,-Bstatic -lassimp -Wl,-Bdynamic -lstdc++ -lglut
.PHONY: clean
clean:
-rm *.o

Binary file not shown.