Merge branch 'master' into md5-fix
commit
bfe3bee34b
|
@ -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
|
||||
|
|
|
@ -113,6 +113,7 @@ 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 .
|
||||
### Contributing ###
|
||||
|
||||
Contributions to assimp are highly appreciated. The easiest way to get involved is to submit
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -656,11 +656,6 @@ if ( MSVC )
|
|||
ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS )
|
||||
endif ( MSVC )
|
||||
|
||||
if (APPLE)
|
||||
SET_TARGET_PROPERTIES( assimp PROPERTIES
|
||||
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}"
|
||||
)
|
||||
endif()
|
||||
if (UNZIP_FOUND)
|
||||
SET (unzip_compile_SRCS "")
|
||||
else (UNZIP_FOUND)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,352 +0,0 @@
|
|||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2015, assimp 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 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 ColladaParser.h
|
||||
* @brief Defines the parser helper class for the collada loader
|
||||
*/
|
||||
|
||||
#ifndef AI_COLLADAPARSER_H_INC
|
||||
#define AI_COLLADAPARSER_H_INC
|
||||
|
||||
#include "irrXMLWrapper.h"
|
||||
#include "ColladaHelper.h"
|
||||
#include "../include/assimp/ai_assert.h"
|
||||
#include <boost/format.hpp>
|
||||
|
||||
namespace Assimp
|
||||
{
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
/** Parser helper class for the Collada loader.
|
||||
*
|
||||
* Does all the XML reading and builds internal data structures from it,
|
||||
* but leaves the resolving of all the references to the loader.
|
||||
*/
|
||||
class ColladaParser
|
||||
{
|
||||
friend class ColladaLoader;
|
||||
|
||||
protected:
|
||||
/** Constructor from XML file */
|
||||
ColladaParser( IOSystem* pIOHandler, const std::string& pFile);
|
||||
|
||||
/** Destructor */
|
||||
~ColladaParser();
|
||||
|
||||
/** Reads the contents of the file */
|
||||
void ReadContents();
|
||||
|
||||
/** Reads the structure of the file */
|
||||
void ReadStructure();
|
||||
|
||||
/** Reads asset informations such as coordinate system informations and legal blah */
|
||||
void ReadAssetInfo();
|
||||
|
||||
/** Reads the animation library */
|
||||
void ReadAnimationLibrary();
|
||||
|
||||
/** Reads an animation into the given parent structure */
|
||||
void ReadAnimation( Collada::Animation* pParent);
|
||||
|
||||
/** Reads an animation sampler into the given anim channel */
|
||||
void ReadAnimationSampler( Collada::AnimationChannel& pChannel);
|
||||
|
||||
/** Reads the skeleton controller library */
|
||||
void ReadControllerLibrary();
|
||||
|
||||
/** Reads a controller into the given mesh structure */
|
||||
void ReadController( Collada::Controller& pController);
|
||||
|
||||
/** Reads the joint definitions for the given controller */
|
||||
void ReadControllerJoints( Collada::Controller& pController);
|
||||
|
||||
/** Reads the joint weights for the given controller */
|
||||
void ReadControllerWeights( Collada::Controller& pController);
|
||||
|
||||
/** Reads the image library contents */
|
||||
void ReadImageLibrary();
|
||||
|
||||
/** Reads an image entry into the given image */
|
||||
void ReadImage( Collada::Image& pImage);
|
||||
|
||||
/** Reads the material library */
|
||||
void ReadMaterialLibrary();
|
||||
|
||||
/** Reads a material entry into the given material */
|
||||
void ReadMaterial( Collada::Material& pMaterial);
|
||||
|
||||
/** Reads the camera library */
|
||||
void ReadCameraLibrary();
|
||||
|
||||
/** Reads a camera entry into the given camera */
|
||||
void ReadCamera( Collada::Camera& pCamera);
|
||||
|
||||
/** Reads the light library */
|
||||
void ReadLightLibrary();
|
||||
|
||||
/** Reads a light entry into the given light */
|
||||
void ReadLight( Collada::Light& pLight);
|
||||
|
||||
/** Reads the effect library */
|
||||
void ReadEffectLibrary();
|
||||
|
||||
/** Reads an effect entry into the given effect*/
|
||||
void ReadEffect( Collada::Effect& pEffect);
|
||||
|
||||
/** Reads an COMMON effect profile */
|
||||
void ReadEffectProfileCommon( Collada::Effect& pEffect);
|
||||
|
||||
/** Read sampler properties */
|
||||
void ReadSamplerProperties( Collada::Sampler& pSampler);
|
||||
|
||||
/** Reads an effect entry containing a color or a texture defining that color */
|
||||
void ReadEffectColor( aiColor4D& pColor, Collada::Sampler& pSampler);
|
||||
|
||||
/** Reads an effect entry containing a float */
|
||||
void ReadEffectFloat( float& pFloat);
|
||||
|
||||
/** Reads an effect parameter specification of any kind */
|
||||
void ReadEffectParam( Collada::EffectParam& pParam);
|
||||
|
||||
/** Reads the geometry library contents */
|
||||
void ReadGeometryLibrary();
|
||||
|
||||
/** Reads a geometry from the geometry library. */
|
||||
void ReadGeometry( Collada::Mesh* pMesh);
|
||||
|
||||
/** Reads a mesh from the geometry library */
|
||||
void ReadMesh( Collada::Mesh* pMesh);
|
||||
|
||||
/** Reads a source element - a combination of raw data and an accessor defining
|
||||
* things that should not be redefinable. Yes, that's another rant.
|
||||
*/
|
||||
void ReadSource();
|
||||
|
||||
/** Reads a data array holding a number of elements, and stores it in the global library.
|
||||
* Currently supported are array of floats and arrays of strings.
|
||||
*/
|
||||
void ReadDataArray();
|
||||
|
||||
/** Reads an accessor and stores it in the global library under the given ID -
|
||||
* accessors use the ID of the parent <source> element
|
||||
*/
|
||||
void ReadAccessor( const std::string& pID);
|
||||
|
||||
/** Reads input declarations of per-vertex mesh data into the given mesh */
|
||||
void ReadVertexData( Collada::Mesh* pMesh);
|
||||
|
||||
/** Reads input declarations of per-index mesh data into the given mesh */
|
||||
void ReadIndexData( Collada::Mesh* pMesh);
|
||||
|
||||
/** Reads a single input channel element and stores it in the given array, if valid */
|
||||
void ReadInputChannel( std::vector<Collada::InputChannel>& poChannels);
|
||||
|
||||
/** Reads a <p> primitive index list and assembles the mesh data into the given mesh */
|
||||
size_t ReadPrimitives( Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
|
||||
size_t pNumPrimitives, const std::vector<size_t>& pVCount, Collada::PrimitiveType pPrimType);
|
||||
|
||||
/** Copies the data for a single primitive into the mesh, based on the InputChannels */
|
||||
void CopyVertex(size_t currentVertex, size_t numOffsets, size_t numPoints, size_t perVertexOffset,
|
||||
Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
|
||||
size_t currentPrimitive, const std::vector<size_t>& indices);
|
||||
|
||||
/** Reads one triangle of a tristrip into the mesh */
|
||||
void ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Collada::Mesh* pMesh,
|
||||
std::vector<Collada::InputChannel>& pPerIndexChannels, size_t currentPrimitive, const std::vector<size_t>& indices);
|
||||
|
||||
/** Extracts a single object from an input channel and stores it in the appropriate mesh data array */
|
||||
void ExtractDataObjectFromChannel( const Collada::InputChannel& pInput, size_t pLocalIndex, Collada::Mesh* pMesh);
|
||||
|
||||
/** Reads the library of node hierarchies and scene parts */
|
||||
void ReadSceneLibrary();
|
||||
|
||||
/** Reads a scene node's contents including children and stores it in the given node */
|
||||
void ReadSceneNode( Collada::Node* pNode);
|
||||
|
||||
/** Reads a node transformation entry of the given type and adds it to the given node's transformation list. */
|
||||
void ReadNodeTransformation( Collada::Node* pNode, Collada::TransformType pType);
|
||||
|
||||
/** Reads a mesh reference in a node and adds it to the node's mesh list */
|
||||
void ReadNodeGeometry( Collada::Node* pNode);
|
||||
|
||||
/** Reads the collada scene */
|
||||
void ReadScene();
|
||||
|
||||
// Processes bind_vertex_input and bind elements
|
||||
void ReadMaterialVertexInputBinding( Collada::SemanticMappingTable& tbl);
|
||||
|
||||
protected:
|
||||
/** Aborts the file reading with an exception */
|
||||
AI_WONT_RETURN void ThrowException( const std::string& pError) const AI_WONT_RETURN_SUFFIX;
|
||||
|
||||
/** Skips all data until the end node of the current element */
|
||||
void SkipElement();
|
||||
|
||||
/** Skips all data until the end node of the given element */
|
||||
void SkipElement( const char* pElement);
|
||||
|
||||
/** Compares the current xml element name to the given string and returns true if equal */
|
||||
bool IsElement( const char* pName) const;
|
||||
|
||||
/** Tests for the opening tag of the given element, throws an exception if not found */
|
||||
void TestOpening( const char* pName);
|
||||
|
||||
/** Tests for the closing tag of the given element, throws an exception if not found */
|
||||
void TestClosing( const char* pName);
|
||||
|
||||
/** Checks the present element for the presence of the attribute, returns its index
|
||||
or throws an exception if not found */
|
||||
int GetAttribute( const char* pAttr) const;
|
||||
|
||||
/** Returns the index of the named attribute or -1 if not found. Does not throw,
|
||||
therefore useful for optional attributes */
|
||||
int TestAttribute( const char* pAttr) const;
|
||||
|
||||
/** Reads the text contents of an element, throws an exception if not given.
|
||||
Skips leading whitespace. */
|
||||
const char* GetTextContent();
|
||||
|
||||
/** Reads the text contents of an element, returns NULL if not given.
|
||||
Skips leading whitespace. */
|
||||
const char* TestTextContent();
|
||||
|
||||
/** Reads a single bool from current text content */
|
||||
bool ReadBoolFromTextContent();
|
||||
|
||||
/** Reads a single float from current text content */
|
||||
float ReadFloatFromTextContent();
|
||||
|
||||
/** Calculates the resulting transformation from all the given transform steps */
|
||||
aiMatrix4x4 CalculateResultTransform( const std::vector<Collada::Transform>& pTransforms) const;
|
||||
|
||||
/** Determines the input data type for the given semantic string */
|
||||
Collada::InputType GetTypeForSemantic( const std::string& pSemantic);
|
||||
|
||||
/** Finds the item in the given library by its reference, throws if not found */
|
||||
template <typename Type> const Type& ResolveLibraryReference(
|
||||
const std::map<std::string, Type>& pLibrary, const std::string& pURL) const;
|
||||
|
||||
protected:
|
||||
/** Filename, for a verbose error message */
|
||||
std::string mFileName;
|
||||
|
||||
/** XML reader, member for everyday use */
|
||||
irr::io::IrrXMLReader* mReader;
|
||||
|
||||
/** All data arrays found in the file by ID. Might be referred to by actually
|
||||
everyone. Collada, you are a steaming pile of indirection. */
|
||||
typedef std::map<std::string, Collada::Data> DataLibrary;
|
||||
DataLibrary mDataLibrary;
|
||||
|
||||
/** Same for accessors which define how the data in a data array is accessed. */
|
||||
typedef std::map<std::string, Collada::Accessor> AccessorLibrary;
|
||||
AccessorLibrary mAccessorLibrary;
|
||||
|
||||
/** Mesh library: mesh by ID */
|
||||
typedef std::map<std::string, Collada::Mesh*> MeshLibrary;
|
||||
MeshLibrary mMeshLibrary;
|
||||
|
||||
/** node library: root node of the hierarchy part by ID */
|
||||
typedef std::map<std::string, Collada::Node*> NodeLibrary;
|
||||
NodeLibrary mNodeLibrary;
|
||||
|
||||
/** Image library: stores texture properties by ID */
|
||||
typedef std::map<std::string, Collada::Image> ImageLibrary;
|
||||
ImageLibrary mImageLibrary;
|
||||
|
||||
/** Effect library: surface attributes by ID */
|
||||
typedef std::map<std::string, Collada::Effect> EffectLibrary;
|
||||
EffectLibrary mEffectLibrary;
|
||||
|
||||
/** Material library: surface material by ID */
|
||||
typedef std::map<std::string, Collada::Material> MaterialLibrary;
|
||||
MaterialLibrary mMaterialLibrary;
|
||||
|
||||
/** Light library: surface light by ID */
|
||||
typedef std::map<std::string, Collada::Light> LightLibrary;
|
||||
LightLibrary mLightLibrary;
|
||||
|
||||
/** Camera library: surface material by ID */
|
||||
typedef std::map<std::string, Collada::Camera> CameraLibrary;
|
||||
CameraLibrary mCameraLibrary;
|
||||
|
||||
/** Controller library: joint controllers by ID */
|
||||
typedef std::map<std::string, Collada::Controller> ControllerLibrary;
|
||||
ControllerLibrary mControllerLibrary;
|
||||
|
||||
/** Pointer to the root node. Don't delete, it just points to one of
|
||||
the nodes in the node library. */
|
||||
Collada::Node* mRootNode;
|
||||
|
||||
/** Root animation container */
|
||||
Collada::Animation mAnims;
|
||||
|
||||
/** Size unit: how large compared to a meter */
|
||||
float mUnitSize;
|
||||
|
||||
/** Which is the up vector */
|
||||
enum { UP_X, UP_Y, UP_Z } mUpDirection;
|
||||
|
||||
/** Collada file format version */
|
||||
Collada::FormatVersion mFormat;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Check for element match
|
||||
inline bool ColladaParser::IsElement( const char* pName) const
|
||||
{
|
||||
ai_assert( mReader->getNodeType() == irr::io::EXN_ELEMENT);
|
||||
return ::strcmp( mReader->getNodeName(), pName) == 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Finds the item in the given library by its reference, throws if not found
|
||||
template <typename Type>
|
||||
const Type& ColladaParser::ResolveLibraryReference( const std::map<std::string, Type>& pLibrary, const std::string& pURL) const
|
||||
{
|
||||
typename std::map<std::string, Type>::const_iterator it = pLibrary.find( pURL);
|
||||
if( it == pLibrary.end())
|
||||
ThrowException( boost::str( boost::format( "Unable to resolve library reference \"%s\".") % pURL));
|
||||
return it->second;
|
||||
}
|
||||
|
||||
} // end of namespace Assimp
|
||||
|
||||
#endif // AI_COLLADAPARSER_H_INC
|
File diff suppressed because it is too large
Load Diff
|
@ -1067,6 +1067,12 @@ void ColladaParser::ReadLight( Collada::Light& pLight)
|
|||
pLight.mFalloffAngle = ReadFloatFromTextContent();
|
||||
TestClosing("hotspot_beam");
|
||||
}
|
||||
// OpenCOLLADA extensions
|
||||
// -------------------------------------------------------
|
||||
else if (IsElement("decay_falloff")) {
|
||||
pLight.mOuterAngle = ReadFloatFromTextContent();
|
||||
TestClosing("decay_falloff");
|
||||
}
|
||||
}
|
||||
else if( mReader->getNodeType() == irr::io::EXN_ELEMENT_END) {
|
||||
if( strcmp( mReader->getNodeName(), "light") == 0)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -133,15 +133,16 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
|
|||
TextFileToBuffer(file.get(),m_Buffer);
|
||||
|
||||
// Get the model name
|
||||
std::string strModelName;
|
||||
std::string modelName, folderName;
|
||||
std::string::size_type pos = pFile.find_last_of( "\\/" );
|
||||
if ( pos != std::string::npos )
|
||||
{
|
||||
strModelName = pFile.substr(pos+1, pFile.size() - pos - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
strModelName = pFile;
|
||||
if ( pos != std::string::npos ) {
|
||||
modelName = pFile.substr(pos+1, pFile.size() - pos - 1);
|
||||
folderName = pFile.substr( 0, pos );
|
||||
if ( folderName.empty() ) {
|
||||
pIOHandler->PushDirectory( folderName );
|
||||
}
|
||||
} else {
|
||||
modelName = pFile;
|
||||
}
|
||||
|
||||
// process all '\'
|
||||
|
@ -161,13 +162,18 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
|
|||
}
|
||||
|
||||
// parse the file into a temporary representation
|
||||
ObjFileParser parser(m_Buffer, strModelName, pIOHandler);
|
||||
ObjFileParser parser(m_Buffer, modelName, pIOHandler);
|
||||
|
||||
// And create the proper return structures out of it
|
||||
CreateDataFromImport(parser.GetModel(), pScene);
|
||||
|
||||
// Clean up allocated storage for the next import
|
||||
m_Buffer.clear();
|
||||
|
||||
// Pop directory stack
|
||||
if ( pIOHandler->StackSize() > 0 ) {
|
||||
pIOHandler->PopDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -61,21 +61,21 @@ const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
// Constructor with loaded data and directories.
|
||||
ObjFileParser::ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem *io ) :
|
||||
m_DataIt(Data.begin()),
|
||||
m_DataItEnd(Data.end()),
|
||||
ObjFileParser::ObjFileParser(std::vector<char> &data,const std::string &modelName, IOSystem *io ) :
|
||||
m_DataIt(data.begin()),
|
||||
m_DataItEnd(data.end()),
|
||||
m_pModel(NULL),
|
||||
m_uiLine(0),
|
||||
m_pIO( io )
|
||||
{
|
||||
std::fill_n(m_buffer,BUFFERSIZE,0);
|
||||
std::fill_n(m_buffer,Buffersize,0);
|
||||
|
||||
// Create the model instance to store all the data
|
||||
m_pModel = new ObjFile::Model();
|
||||
m_pModel->m_ModelName = strModelName;
|
||||
m_pModel->m_ModelName = modelName;
|
||||
|
||||
// create default material and store it
|
||||
m_pModel->m_pDefaultMaterial = new ObjFile::Material();
|
||||
m_pModel->m_pDefaultMaterial = new ObjFile::Material;
|
||||
m_pModel->m_pDefaultMaterial->MaterialName.Set( DEFAULT_MATERIAL );
|
||||
m_pModel->m_MaterialLib.push_back( DEFAULT_MATERIAL );
|
||||
m_pModel->m_MaterialMap[ DEFAULT_MATERIAL ] = m_pModel->m_pDefaultMaterial;
|
||||
|
@ -248,20 +248,20 @@ void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
|
|||
}
|
||||
float x, y, z;
|
||||
if( 2 == numComponents ) {
|
||||
copyNextWord( m_buffer, BUFFERSIZE );
|
||||
copyNextWord( m_buffer, Buffersize );
|
||||
x = ( float ) fast_atof( m_buffer );
|
||||
|
||||
copyNextWord( m_buffer, BUFFERSIZE );
|
||||
copyNextWord( m_buffer, Buffersize );
|
||||
y = ( float ) fast_atof( m_buffer );
|
||||
z = 0.0;
|
||||
} else if( 3 == numComponents ) {
|
||||
copyNextWord( m_buffer, BUFFERSIZE );
|
||||
copyNextWord( m_buffer, Buffersize );
|
||||
x = ( float ) fast_atof( m_buffer );
|
||||
|
||||
copyNextWord( m_buffer, BUFFERSIZE );
|
||||
copyNextWord( m_buffer, Buffersize );
|
||||
y = ( float ) fast_atof( m_buffer );
|
||||
|
||||
copyNextWord( m_buffer, BUFFERSIZE );
|
||||
copyNextWord( m_buffer, Buffersize );
|
||||
z = ( float ) fast_atof( m_buffer );
|
||||
} else {
|
||||
throw DeadlyImportError( "OBJ: Invalid number of components" );
|
||||
|
@ -274,13 +274,13 @@ void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
|
|||
// Get values for a new 3D vector instance
|
||||
void ObjFileParser::getVector3(std::vector<aiVector3D> &point3d_array) {
|
||||
float x, y, z;
|
||||
copyNextWord(m_buffer, BUFFERSIZE);
|
||||
copyNextWord(m_buffer, Buffersize);
|
||||
x = (float) fast_atof(m_buffer);
|
||||
|
||||
copyNextWord(m_buffer, BUFFERSIZE);
|
||||
copyNextWord(m_buffer, Buffersize);
|
||||
y = (float) fast_atof(m_buffer);
|
||||
|
||||
copyNextWord( m_buffer, BUFFERSIZE );
|
||||
copyNextWord( m_buffer, Buffersize );
|
||||
z = ( float ) fast_atof( m_buffer );
|
||||
|
||||
point3d_array.push_back( aiVector3D( x, y, z ) );
|
||||
|
@ -291,10 +291,10 @@ void ObjFileParser::getVector3(std::vector<aiVector3D> &point3d_array) {
|
|||
// Get values for a new 2D vector instance
|
||||
void ObjFileParser::getVector2( std::vector<aiVector2D> &point2d_array ) {
|
||||
float x, y;
|
||||
copyNextWord(m_buffer, BUFFERSIZE);
|
||||
copyNextWord(m_buffer, Buffersize);
|
||||
x = (float) fast_atof(m_buffer);
|
||||
|
||||
copyNextWord(m_buffer, BUFFERSIZE);
|
||||
copyNextWord(m_buffer, Buffersize);
|
||||
y = (float) fast_atof(m_buffer);
|
||||
|
||||
point2d_array.push_back(aiVector2D(x, y));
|
||||
|
@ -306,12 +306,12 @@ void ObjFileParser::getVector2( std::vector<aiVector2D> &point2d_array ) {
|
|||
// Get values for a new face instance
|
||||
void ObjFileParser::getFace(aiPrimitiveType type)
|
||||
{
|
||||
copyNextLine(m_buffer, BUFFERSIZE);
|
||||
copyNextLine(m_buffer, Buffersize);
|
||||
if (m_DataIt == m_DataItEnd)
|
||||
return;
|
||||
|
||||
char *pPtr = m_buffer;
|
||||
char *pEnd = &pPtr[BUFFERSIZE];
|
||||
char *pEnd = &pPtr[Buffersize];
|
||||
pPtr = getNextToken<char*>(pPtr, pEnd);
|
||||
if (pPtr == pEnd || *pPtr == '\0')
|
||||
return;
|
||||
|
@ -468,8 +468,9 @@ void ObjFileParser::getMaterialDesc()
|
|||
|
||||
// Get next data for material data
|
||||
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
|
||||
if (m_DataIt == m_DataItEnd)
|
||||
if (m_DataIt == m_DataItEnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *pStart = &(*m_DataIt);
|
||||
while( m_DataIt != m_DataItEnd && !IsLineEnd( *m_DataIt ) ) {
|
||||
|
@ -483,14 +484,11 @@ void ObjFileParser::getMaterialDesc()
|
|||
|
||||
// Search for material
|
||||
std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( strName );
|
||||
if ( it == m_pModel->m_MaterialMap.end() )
|
||||
{
|
||||
if ( it == m_pModel->m_MaterialMap.end() ) {
|
||||
// Not found, use default material
|
||||
m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial;
|
||||
DefaultLogger::get()->error("OBJ: failed to locate material " + strName + ", skipping");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Found, using detected material
|
||||
m_pModel->m_pCurrentMaterial = (*it).second;
|
||||
if ( needsNewMesh( strName ))
|
||||
|
@ -539,18 +537,24 @@ void ObjFileParser::getMaterialLib()
|
|||
|
||||
// Check for existence
|
||||
const std::string strMatName(pStart, &(*m_DataIt));
|
||||
IOStream *pFile = m_pIO->Open(strMatName);
|
||||
std::string absName;
|
||||
if ( m_pIO->StackSize() > 0 ) {
|
||||
const std::string &path = m_pIO->CurrentDirectory();
|
||||
absName = path + strMatName;
|
||||
} else {
|
||||
absName = strMatName;
|
||||
}
|
||||
IOStream *pFile = m_pIO->Open( absName );
|
||||
|
||||
if (!pFile )
|
||||
{
|
||||
DefaultLogger::get()->error("OBJ: Unable to locate material file " + strMatName);
|
||||
if (!pFile ) {
|
||||
DefaultLogger::get()->error( "OBJ: Unable to locate material file " + strMatName );
|
||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||
return;
|
||||
}
|
||||
|
||||
// Import material library data from file
|
||||
std::vector<char> buffer;
|
||||
BaseImporter::TextFileToBuffer(pFile,buffer);
|
||||
BaseImporter::TextFileToBuffer( pFile, buffer );
|
||||
m_pIO->Close( pFile );
|
||||
|
||||
// Importing the material library
|
||||
|
|
|
@ -62,10 +62,9 @@ class IOSystem;
|
|||
|
||||
/// \class ObjFileParser
|
||||
/// \brief Parser for a obj waveform file
|
||||
class ObjFileParser
|
||||
{
|
||||
class ObjFileParser {
|
||||
public:
|
||||
static const size_t BUFFERSIZE = 4096;
|
||||
static const size_t Buffersize = 4096;
|
||||
typedef std::vector<char> DataArray;
|
||||
typedef std::vector<char>::iterator DataArrayIt;
|
||||
typedef std::vector<char>::const_iterator ConstDataArrayIt;
|
||||
|
@ -137,9 +136,10 @@ private:
|
|||
//! Current line (for debugging)
|
||||
unsigned int m_uiLine;
|
||||
//! Helper buffer
|
||||
char m_buffer[BUFFERSIZE];
|
||||
char m_buffer[Buffersize];
|
||||
/// Pointer to IO system instance.
|
||||
IOSystem *m_pIO;
|
||||
/// Path to the current model
|
||||
};
|
||||
|
||||
} // Namespace Assimp
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -399,10 +399,14 @@ void CatmullClarkSubdivider::InternSubdivide (
|
|||
bool haveit = false;
|
||||
for (unsigned int i = 0; i < f.mNumIndices; ++i) {
|
||||
if (maptbl[FLATTEN_VERTEX_IDX(n,f.mIndices[i])]==(unsigned int)t) {
|
||||
haveit = true; break;
|
||||
haveit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ai_assert(haveit);
|
||||
if (!haveit) {
|
||||
DefaultLogger::get()->debug("Catmull-Clark Subdivider: Index not used");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#endif
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Assimp {
|
||||
class IOStream;
|
||||
|
||||
|
@ -102,18 +105,14 @@ public:
|
|||
* @param pFile Path to the file
|
||||
* @return true if there is a file with this path, else false.
|
||||
*/
|
||||
|
||||
virtual bool Exists( const char* pFile) const = 0;
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Returns the system specific directory separator
|
||||
* @return System specific directory separator
|
||||
*/
|
||||
virtual char getOsSeparator() const = 0;
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Open a new file with a given path.
|
||||
*
|
||||
|
@ -139,8 +138,6 @@ public:
|
|||
inline IOStream* Open(const std::string& pFile,
|
||||
const std::string& pMode = std::string("rb"));
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Closes the given file and releases all resources
|
||||
* associated with it.
|
||||
|
@ -170,10 +167,41 @@ public:
|
|||
*/
|
||||
inline bool ComparePaths (const std::string& one,
|
||||
const std::string& second) const;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Pushes a new directory onto the directory stack.
|
||||
* @param path Path to push onto the stack.
|
||||
* @return True, when push was successful, false if path is empty.
|
||||
*/
|
||||
virtual bool PushDirectory( const std::string &path );
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Returns the top directory from the stack.
|
||||
* @return The directory on the top of the stack.
|
||||
* Returns empty when no directory was pushed to the stack.
|
||||
*/
|
||||
virtual const std::string &CurrentDirectory() const;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Returns the number of directories stored on the stack.
|
||||
* @return The number of directories of the stack.
|
||||
*/
|
||||
virtual size_t StackSize() const;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Pops the top directory from the stack.
|
||||
* @return True, when a directory was on the stack. False if no
|
||||
* directory was on the stack.
|
||||
*/
|
||||
virtual bool PopDirectory();
|
||||
|
||||
private:
|
||||
std::vector<std::string> m_pathStack;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
AI_FORCE_INLINE IOSystem::IOSystem()
|
||||
AI_FORCE_INLINE IOSystem::IOSystem() :
|
||||
m_pathStack()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
@ -220,6 +248,43 @@ inline bool IOSystem::ComparePaths (const std::string& one,
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
inline bool IOSystem::PushDirectory( const std::string &path ) {
|
||||
if ( path.empty() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pathStack.push_back( path );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
inline const std::string &IOSystem::CurrentDirectory() const {
|
||||
if ( m_pathStack.empty() ) {
|
||||
static const std::string Dummy("");
|
||||
return Dummy;
|
||||
}
|
||||
return m_pathStack[ m_pathStack.size()-1 ];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
inline size_t IOSystem::StackSize() const {
|
||||
return m_pathStack.size();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
inline bool IOSystem::PopDirectory() {
|
||||
if ( m_pathStack.empty() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pathStack.pop_back();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
} //!ns Assimp
|
||||
|
||||
#endif //AI_IOSYSTEM_H_INC
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
|
@ -24,6 +24,7 @@ SET( TEST_SRCS
|
|||
unit/utGenNormals.cpp
|
||||
unit/utImporter.cpp
|
||||
unit/utImproveCacheLocality.cpp
|
||||
unit/utIOSystem.cpp
|
||||
unit/utJoinVertices.cpp
|
||||
unit/utLimitBoneWeights.cpp
|
||||
unit/utMaterialSystem.cpp
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2014, assimp 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 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.
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
#include "UnitTestPCH.h"
|
||||
|
||||
#include <assimp/IOSystem.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace Assimp;
|
||||
|
||||
static const string Sep = "/";
|
||||
class TestIOSystem : public IOSystem {
|
||||
public:
|
||||
TestIOSystem() : IOSystem() {}
|
||||
virtual ~TestIOSystem() {}
|
||||
virtual bool Exists( const char* ) const {
|
||||
return true;
|
||||
}
|
||||
virtual char getOsSeparator() const {
|
||||
return Sep[ 0 ];
|
||||
}
|
||||
|
||||
virtual IOStream* Open(const char* pFile, const char* pMode = "rb") {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual void Close( IOStream* pFile) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
class IOSystemTest : public ::testing::Test {
|
||||
public:
|
||||
virtual void SetUp() { pImp = new TestIOSystem(); }
|
||||
virtual void TearDown() { delete pImp; }
|
||||
|
||||
protected:
|
||||
TestIOSystem* pImp;
|
||||
};
|
||||
|
||||
/*
|
||||
virtual bool PushDirectory( const std::string &path );
|
||||
virtual const std::string &CurrentDirectory() const;
|
||||
virtual bool PopDirectory();
|
||||
*/
|
||||
|
||||
TEST_F( IOSystemTest, accessDirectoryStackTest ) {
|
||||
EXPECT_FALSE( pImp->PopDirectory() );
|
||||
EXPECT_EQ( 0, pImp->StackSize() );
|
||||
EXPECT_FALSE( pImp->PushDirectory( "" ) );
|
||||
std::string path = "test/";
|
||||
EXPECT_TRUE( pImp->PushDirectory( path ) );
|
||||
EXPECT_EQ( 1, pImp->StackSize() );
|
||||
EXPECT_EQ( path, pImp->CurrentDirectory() );
|
||||
EXPECT_TRUE( pImp->PopDirectory() );
|
||||
EXPECT_EQ( 0, pImp->StackSize() );
|
||||
}
|
Loading…
Reference in New Issue