Merge branch 'master' into master
commit
09eba0f039
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
@ -50,27 +49,25 @@ namespace Assimp {
|
|||
namespace FBX {
|
||||
|
||||
/** FBX import settings, parts of which are publicly accessible via their corresponding AI_CONFIG constants */
|
||||
struct ImportSettings
|
||||
{
|
||||
ImportSettings()
|
||||
: strictMode(true)
|
||||
, readAllLayers(true)
|
||||
, readAllMaterials(false)
|
||||
, readMaterials(true)
|
||||
, readTextures(true)
|
||||
, readCameras(true)
|
||||
, readLights(true)
|
||||
, readAnimations(true)
|
||||
, readWeights(true)
|
||||
, preservePivots(true)
|
||||
, optimizeEmptyAnimationCurves(true)
|
||||
, useLegacyEmbeddedTextureNaming(false)
|
||||
, removeEmptyBones( true )
|
||||
, convertToMeters( false ) {
|
||||
struct ImportSettings {
|
||||
ImportSettings() :
|
||||
strictMode(true),
|
||||
readAllLayers(true),
|
||||
readAllMaterials(false),
|
||||
readMaterials(true),
|
||||
readTextures(true),
|
||||
readCameras(true),
|
||||
readLights(true),
|
||||
readAnimations(true),
|
||||
readWeights(true),
|
||||
preservePivots(true),
|
||||
optimizeEmptyAnimationCurves(true),
|
||||
useLegacyEmbeddedTextureNaming(false),
|
||||
removeEmptyBones(true),
|
||||
convertToMeters(false) {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
/** enable strict mode:
|
||||
* - only accept fbx 2012, 2013 files
|
||||
* - on the slightest error, give up.
|
||||
|
@ -94,7 +91,6 @@ struct ImportSettings
|
|||
* This bit is ignored unless readMaterials=true*/
|
||||
bool readAllMaterials;
|
||||
|
||||
|
||||
/** import materials (true) or skip them and assign a default
|
||||
* material. The default value is true.*/
|
||||
bool readMaterials;
|
||||
|
@ -156,9 +152,7 @@ struct ImportSettings
|
|||
bool convertToMeters;
|
||||
};
|
||||
|
||||
|
||||
} // !FBX
|
||||
} // !Assimp
|
||||
} // namespace FBX
|
||||
} // namespace Assimp
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
@ -51,45 +50,44 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "FBXImportSettings.h"
|
||||
|
||||
namespace Assimp {
|
||||
namespace Assimp {
|
||||
|
||||
// TinyFormatter.h
|
||||
namespace Formatter {
|
||||
template <typename T,typename TR, typename A> class basic_formatter;
|
||||
typedef class basic_formatter< char, std::char_traits<char>, std::allocator<char> > format;
|
||||
}
|
||||
|
||||
template <typename T, typename TR, typename A>
|
||||
class basic_formatter;
|
||||
|
||||
typedef class basic_formatter<char, std::char_traits<char>, std::allocator<char>> format;
|
||||
|
||||
} // namespace Formatter
|
||||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
/** Load the Autodesk FBX file format.
|
||||
|
||||
See http://en.wikipedia.org/wiki/FBX
|
||||
*/
|
||||
/// Loads the Autodesk FBX file format.
|
||||
///
|
||||
/// See http://en.wikipedia.org/wiki/FBX
|
||||
// -------------------------------------------------------------------------------------------
|
||||
class FBXImporter : public BaseImporter, public LogFunctions<FBXImporter>
|
||||
{
|
||||
class FBXImporter : public BaseImporter, public LogFunctions<FBXImporter> {
|
||||
public:
|
||||
FBXImporter();
|
||||
virtual ~FBXImporter();
|
||||
|
||||
// --------------------
|
||||
bool CanRead( const std::string& pFile,
|
||||
IOSystem* pIOHandler,
|
||||
bool checkSig
|
||||
) const;
|
||||
bool CanRead(const std::string &pFile,
|
||||
IOSystem *pIOHandler,
|
||||
bool checkSig) const;
|
||||
|
||||
protected:
|
||||
// --------------------
|
||||
const aiImporterDesc *GetInfo() const;
|
||||
|
||||
// --------------------
|
||||
const aiImporterDesc* GetInfo () const;
|
||||
void SetupProperties(const Importer *pImp);
|
||||
|
||||
// --------------------
|
||||
void SetupProperties(const Importer* pImp);
|
||||
|
||||
// --------------------
|
||||
void InternReadFile( const std::string& pFile,
|
||||
aiScene* pScene,
|
||||
IOSystem* pIOHandler
|
||||
);
|
||||
void InternReadFile(const std::string &pFile,
|
||||
aiScene *pScene,
|
||||
IOSystem *pIOHandler);
|
||||
|
||||
private:
|
||||
FBX::ImportSettings settings;
|
||||
|
@ -97,4 +95,3 @@ private:
|
|||
|
||||
} // end of namespace Assimp
|
||||
#endif // !INCLUDED_AI_FBX_IMPORTER_H
|
||||
|
||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
@ -49,29 +47,29 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#define AI_METADATA_H_INC
|
||||
|
||||
#ifdef __GNUC__
|
||||
# pragma GCC system_header
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER <= 1500)
|
||||
# include "Compiler/pstdint.h"
|
||||
#include "Compiler/pstdint.h"
|
||||
#else
|
||||
# include <stdint.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
/**
|
||||
* Enum used to distinguish data types
|
||||
*/
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
typedef enum aiMetadataType {
|
||||
AI_BOOL = 0,
|
||||
AI_INT32 = 1,
|
||||
AI_UINT64 = 2,
|
||||
AI_FLOAT = 3,
|
||||
AI_DOUBLE = 4,
|
||||
AI_AISTRING = 5,
|
||||
AI_BOOL = 0,
|
||||
AI_INT32 = 1,
|
||||
AI_UINT64 = 2,
|
||||
AI_FLOAT = 3,
|
||||
AI_DOUBLE = 4,
|
||||
AI_AISTRING = 5,
|
||||
AI_AIVECTOR3D = 6,
|
||||
AI_META_MAX = 7,
|
||||
AI_META_MAX = 7,
|
||||
|
||||
#ifndef SWIG
|
||||
FORCE_32BIT = INT_MAX
|
||||
|
@ -84,10 +82,10 @@ typedef enum aiMetadataType {
|
|||
*
|
||||
* The type field uniquely identifies the underlying type of the data field
|
||||
*/
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
struct aiMetadataEntry {
|
||||
aiMetadataType mType;
|
||||
void* mData;
|
||||
void *mData;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -98,15 +96,29 @@ struct aiMetadataEntry {
|
|||
/**
|
||||
* Helper functions to get the aiType enum entry for a type
|
||||
*/
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
|
||||
inline aiMetadataType GetAiType( bool ) { return AI_BOOL; }
|
||||
inline aiMetadataType GetAiType( int32_t ) { return AI_INT32; }
|
||||
inline aiMetadataType GetAiType( uint64_t ) { return AI_UINT64; }
|
||||
inline aiMetadataType GetAiType( float ) { return AI_FLOAT; }
|
||||
inline aiMetadataType GetAiType( double ) { return AI_DOUBLE; }
|
||||
inline aiMetadataType GetAiType( const aiString & ) { return AI_AISTRING; }
|
||||
inline aiMetadataType GetAiType( const aiVector3D & ) { return AI_AIVECTOR3D; }
|
||||
inline aiMetadataType GetAiType(bool) {
|
||||
return AI_BOOL;
|
||||
}
|
||||
inline aiMetadataType GetAiType(int32_t) {
|
||||
return AI_INT32;
|
||||
}
|
||||
inline aiMetadataType GetAiType(uint64_t) {
|
||||
return AI_UINT64;
|
||||
}
|
||||
inline aiMetadataType GetAiType(float) {
|
||||
return AI_FLOAT;
|
||||
}
|
||||
inline aiMetadataType GetAiType(double) {
|
||||
return AI_DOUBLE;
|
||||
}
|
||||
inline aiMetadataType GetAiType(const aiString &) {
|
||||
return AI_AISTRING;
|
||||
}
|
||||
inline aiMetadataType GetAiType(const aiVector3D &) {
|
||||
return AI_AIVECTOR3D;
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
|
@ -116,17 +128,17 @@ inline aiMetadataType GetAiType( const aiVector3D & ) { return AI_AIVECTOR3D; }
|
|||
*
|
||||
* Metadata is a key-value store using string keys and values.
|
||||
*/
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
struct aiMetadata {
|
||||
/** Length of the mKeys and mValues arrays, respectively */
|
||||
unsigned int mNumProperties;
|
||||
|
||||
/** Arrays of keys, may not be NULL. Entries in this array may not be NULL as well. */
|
||||
C_STRUCT aiString* mKeys;
|
||||
C_STRUCT aiString *mKeys;
|
||||
|
||||
/** Arrays of values, may not be NULL. Entries in this array may be NULL if the
|
||||
* corresponding property key has no assigned value. */
|
||||
C_STRUCT aiMetadataEntry* mValues;
|
||||
C_STRUCT aiMetadataEntry *mValues;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
|
@ -134,71 +146,62 @@ struct aiMetadata {
|
|||
* @brief The default constructor, set all members to zero by default.
|
||||
*/
|
||||
aiMetadata() AI_NO_EXCEPT
|
||||
: mNumProperties(0)
|
||||
, mKeys(nullptr)
|
||||
, mValues(nullptr) {
|
||||
: mNumProperties(0),
|
||||
mKeys(nullptr),
|
||||
mValues(nullptr) {
|
||||
// empty
|
||||
}
|
||||
|
||||
aiMetadata( const aiMetadata &rhs )
|
||||
: mNumProperties( rhs.mNumProperties )
|
||||
, mKeys( nullptr )
|
||||
, mValues( nullptr ) {
|
||||
mKeys = new aiString[ mNumProperties ];
|
||||
for ( size_t i = 0; i < static_cast<size_t>( mNumProperties ); ++i ) {
|
||||
mKeys[ i ] = rhs.mKeys[ i ];
|
||||
aiMetadata(const aiMetadata &rhs) :
|
||||
mNumProperties(rhs.mNumProperties), mKeys(nullptr), mValues(nullptr) {
|
||||
mKeys = new aiString[mNumProperties];
|
||||
for (size_t i = 0; i < static_cast<size_t>(mNumProperties); ++i) {
|
||||
mKeys[i] = rhs.mKeys[i];
|
||||
}
|
||||
mValues = new aiMetadataEntry[ mNumProperties ];
|
||||
for ( size_t i = 0; i < static_cast<size_t>(mNumProperties); ++i ) {
|
||||
mValues[ i ].mType = rhs.mValues[ i ].mType;
|
||||
switch ( rhs.mValues[ i ].mType ) {
|
||||
mValues = new aiMetadataEntry[mNumProperties];
|
||||
for (size_t i = 0; i < static_cast<size_t>(mNumProperties); ++i) {
|
||||
mValues[i].mType = rhs.mValues[i].mType;
|
||||
switch (rhs.mValues[i].mType) {
|
||||
case AI_BOOL:
|
||||
mValues[ i ].mData = new bool;
|
||||
::memcpy( mValues[ i ].mData, rhs.mValues[ i ].mData, sizeof(bool) );
|
||||
mValues[i].mData = new bool;
|
||||
::memcpy(mValues[i].mData, rhs.mValues[i].mData, sizeof(bool));
|
||||
break;
|
||||
case AI_INT32: {
|
||||
int32_t v;
|
||||
::memcpy( &v, rhs.mValues[ i ].mData, sizeof( int32_t ) );
|
||||
mValues[ i ].mData = new int32_t( v );
|
||||
}
|
||||
break;
|
||||
::memcpy(&v, rhs.mValues[i].mData, sizeof(int32_t));
|
||||
mValues[i].mData = new int32_t(v);
|
||||
} break;
|
||||
case AI_UINT64: {
|
||||
uint64_t v;
|
||||
::memcpy( &v, rhs.mValues[ i ].mData, sizeof( uint64_t ) );
|
||||
mValues[ i ].mData = new uint64_t( v );
|
||||
}
|
||||
break;
|
||||
uint64_t v;
|
||||
::memcpy(&v, rhs.mValues[i].mData, sizeof(uint64_t));
|
||||
mValues[i].mData = new uint64_t(v);
|
||||
} break;
|
||||
case AI_FLOAT: {
|
||||
float v;
|
||||
::memcpy( &v, rhs.mValues[ i ].mData, sizeof( float ) );
|
||||
mValues[ i ].mData = new float( v );
|
||||
}
|
||||
break;
|
||||
float v;
|
||||
::memcpy(&v, rhs.mValues[i].mData, sizeof(float));
|
||||
mValues[i].mData = new float(v);
|
||||
} break;
|
||||
case AI_DOUBLE: {
|
||||
double v;
|
||||
::memcpy( &v, rhs.mValues[ i ].mData, sizeof( double ) );
|
||||
mValues[ i ].mData = new double( v );
|
||||
}
|
||||
break;
|
||||
double v;
|
||||
::memcpy(&v, rhs.mValues[i].mData, sizeof(double));
|
||||
mValues[i].mData = new double(v);
|
||||
} break;
|
||||
case AI_AISTRING: {
|
||||
aiString v;
|
||||
rhs.Get<aiString>( mKeys[ i ], v );
|
||||
mValues[ i ].mData = new aiString( v );
|
||||
}
|
||||
break;
|
||||
aiString v;
|
||||
rhs.Get<aiString>(mKeys[i], v);
|
||||
mValues[i].mData = new aiString(v);
|
||||
} break;
|
||||
case AI_AIVECTOR3D: {
|
||||
aiVector3D v;
|
||||
rhs.Get<aiVector3D>( mKeys[ i ], v );
|
||||
mValues[ i ].mData = new aiVector3D( v );
|
||||
}
|
||||
break;
|
||||
aiVector3D v;
|
||||
rhs.Get<aiVector3D>(mKeys[i], v);
|
||||
mValues[i].mData = new aiVector3D(v);
|
||||
} break;
|
||||
#ifndef SWIG
|
||||
case FORCE_32BIT:
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,33 +209,33 @@ struct aiMetadata {
|
|||
* @brief The destructor.
|
||||
*/
|
||||
~aiMetadata() {
|
||||
delete [] mKeys;
|
||||
delete[] mKeys;
|
||||
mKeys = nullptr;
|
||||
if (mValues) {
|
||||
// Delete each metadata entry
|
||||
for (unsigned i=0; i<mNumProperties; ++i) {
|
||||
void* data = mValues[i].mData;
|
||||
for (unsigned i = 0; i < mNumProperties; ++i) {
|
||||
void *data = mValues[i].mData;
|
||||
switch (mValues[i].mType) {
|
||||
case AI_BOOL:
|
||||
delete static_cast< bool* >( data );
|
||||
delete static_cast<bool *>(data);
|
||||
break;
|
||||
case AI_INT32:
|
||||
delete static_cast< int32_t* >( data );
|
||||
delete static_cast<int32_t *>(data);
|
||||
break;
|
||||
case AI_UINT64:
|
||||
delete static_cast< uint64_t* >( data );
|
||||
delete static_cast<uint64_t *>(data);
|
||||
break;
|
||||
case AI_FLOAT:
|
||||
delete static_cast< float* >( data );
|
||||
delete static_cast<float *>(data);
|
||||
break;
|
||||
case AI_DOUBLE:
|
||||
delete static_cast< double* >( data );
|
||||
delete static_cast<double *>(data);
|
||||
break;
|
||||
case AI_AISTRING:
|
||||
delete static_cast< aiString* >( data );
|
||||
delete static_cast<aiString *>(data);
|
||||
break;
|
||||
case AI_AIVECTOR3D:
|
||||
delete static_cast< aiVector3D* >( data );
|
||||
delete static_cast<aiVector3D *>(data);
|
||||
break;
|
||||
#ifndef SWIG
|
||||
case FORCE_32BIT:
|
||||
|
@ -243,7 +246,7 @@ struct aiMetadata {
|
|||
}
|
||||
|
||||
// Delete the metadata array
|
||||
delete [] mValues;
|
||||
delete[] mValues;
|
||||
mValues = nullptr;
|
||||
}
|
||||
}
|
||||
|
@ -252,16 +255,15 @@ struct aiMetadata {
|
|||
* @brief Allocates property fields + keys.
|
||||
* @param numProperties Number of requested properties.
|
||||
*/
|
||||
static inline
|
||||
aiMetadata *Alloc( unsigned int numProperties ) {
|
||||
if ( 0 == numProperties ) {
|
||||
static inline aiMetadata *Alloc(unsigned int numProperties) {
|
||||
if (0 == numProperties) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
aiMetadata *data = new aiMetadata;
|
||||
data->mNumProperties = numProperties;
|
||||
data->mKeys = new aiString[ data->mNumProperties ]();
|
||||
data->mValues = new aiMetadataEntry[ data->mNumProperties ]();
|
||||
data->mKeys = new aiString[data->mNumProperties]();
|
||||
data->mValues = new aiMetadataEntry[data->mNumProperties]();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -269,44 +271,40 @@ struct aiMetadata {
|
|||
/**
|
||||
* @brief Deallocates property fields + keys.
|
||||
*/
|
||||
static inline
|
||||
void Dealloc( aiMetadata *metadata ) {
|
||||
static inline void Dealloc(aiMetadata *metadata) {
|
||||
delete metadata;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline
|
||||
void Add(const std::string& key, const T& value) {
|
||||
aiString* new_keys = new aiString[mNumProperties + 1];
|
||||
aiMetadataEntry* new_values = new aiMetadataEntry[mNumProperties + 1];
|
||||
template <typename T>
|
||||
inline void Add(const std::string &key, const T &value) {
|
||||
aiString *new_keys = new aiString[mNumProperties + 1];
|
||||
aiMetadataEntry *new_values = new aiMetadataEntry[mNumProperties + 1];
|
||||
|
||||
for(unsigned int i = 0; i < mNumProperties; ++i)
|
||||
{
|
||||
new_keys[i] = mKeys[i];
|
||||
new_values[i] = mValues[i];
|
||||
}
|
||||
for (unsigned int i = 0; i < mNumProperties; ++i) {
|
||||
new_keys[i] = mKeys[i];
|
||||
new_values[i] = mValues[i];
|
||||
}
|
||||
|
||||
delete[] mKeys;
|
||||
delete[] mValues;
|
||||
delete[] mKeys;
|
||||
delete[] mValues;
|
||||
|
||||
mKeys = new_keys;
|
||||
mValues = new_values;
|
||||
mKeys = new_keys;
|
||||
mValues = new_values;
|
||||
|
||||
mNumProperties++;
|
||||
mNumProperties++;
|
||||
|
||||
Set(mNumProperties - 1, key, value);
|
||||
}
|
||||
Set(mNumProperties - 1, key, value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline
|
||||
bool Set( unsigned index, const std::string& key, const T& value ) {
|
||||
template <typename T>
|
||||
inline bool Set(unsigned index, const std::string &key, const T &value) {
|
||||
// In range assertion
|
||||
if ( index >= mNumProperties ) {
|
||||
if (index >= mNumProperties) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ensure that we have a valid key.
|
||||
if ( key.empty() ) {
|
||||
if (key.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -321,73 +319,86 @@ struct aiMetadata {
|
|||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline
|
||||
bool Get( unsigned index, T& value ) const {
|
||||
template <typename T>
|
||||
inline bool Set( const std::string &key, const T &value ) {
|
||||
if (key.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
for (unsigned int i = 0; i < mNumProperties; ++i) {
|
||||
if (key == mKeys[i].C_Str()) {
|
||||
Set(i, key, value);
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool Get(unsigned index, T &value) const {
|
||||
// In range assertion
|
||||
if ( index >= mNumProperties ) {
|
||||
if (index >= mNumProperties) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return false if the output data type does
|
||||
// not match the found value's data type
|
||||
if ( GetAiType( value ) != mValues[ index ].mType ) {
|
||||
if (GetAiType(value) != mValues[index].mType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise, output the found value and
|
||||
// return true
|
||||
value = *static_cast<T*>(mValues[index].mData);
|
||||
value = *static_cast<T *>(mValues[index].mData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline
|
||||
bool Get( const aiString& key, T& value ) const {
|
||||
template <typename T>
|
||||
inline bool Get(const aiString &key, T &value) const {
|
||||
// Search for the given key
|
||||
for ( unsigned int i = 0; i < mNumProperties; ++i ) {
|
||||
if ( mKeys[ i ] == key ) {
|
||||
return Get( i, value );
|
||||
for (unsigned int i = 0; i < mNumProperties; ++i) {
|
||||
if (mKeys[i] == key) {
|
||||
return Get(i, value);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline
|
||||
bool Get( const std::string& key, T& value ) const {
|
||||
template <typename T>
|
||||
inline bool Get(const std::string &key, T &value) const {
|
||||
return Get(aiString(key), value);
|
||||
}
|
||||
|
||||
/// Return metadata entry for analyzing it by user.
|
||||
/// \param [in] pIndex - index of the entry.
|
||||
/// \param [out] pKey - pointer to the key value.
|
||||
/// \param [out] pEntry - pointer to the entry: type and value.
|
||||
/// \return false - if pIndex is out of range, else - true.
|
||||
inline
|
||||
bool Get(size_t index, const aiString*& key, const aiMetadataEntry*& entry) const {
|
||||
if ( index >= mNumProperties ) {
|
||||
/// Return metadata entry for analyzing it by user.
|
||||
/// \param [in] pIndex - index of the entry.
|
||||
/// \param [out] pKey - pointer to the key value.
|
||||
/// \param [out] pEntry - pointer to the entry: type and value.
|
||||
/// \return false - if pIndex is out of range, else - true.
|
||||
inline bool Get(size_t index, const aiString *&key, const aiMetadataEntry *&entry) const {
|
||||
if (index >= mNumProperties) {
|
||||
return false;
|
||||
}
|
||||
|
||||
key = &mKeys[index];
|
||||
entry = &mValues[index];
|
||||
key = &mKeys[index];
|
||||
entry = &mValues[index];
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Check whether there is a metadata entry for the given key.
|
||||
/// \param [in] Key - the key value value to check for.
|
||||
inline
|
||||
bool HasKey(const char* key) {
|
||||
if ( nullptr == key ) {
|
||||
inline bool HasKey(const char *key) {
|
||||
if (nullptr == key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Search for the given key
|
||||
for (unsigned int i = 0; i < mNumProperties; ++i) {
|
||||
if ( 0 == strncmp(mKeys[i].C_Str(), key, mKeys[i].length ) ) {
|
||||
if (0 == strncmp(mKeys[i].C_Str(), key, mKeys[i].length)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +406,6 @@ struct aiMetadata {
|
|||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
};
|
||||
|
||||
#endif // AI_METADATA_H_INC
|
||||
|
|
|
@ -31,40 +31,40 @@ struct Texture {
|
|||
|
||||
class Mesh {
|
||||
public:
|
||||
std::vector<VERTEX> vertices;
|
||||
std::vector<UINT> indices;
|
||||
std::vector<Texture> textures;
|
||||
ID3D11Device *dev;
|
||||
std::vector<VERTEX> vertices_;
|
||||
std::vector<UINT> indices_;
|
||||
std::vector<Texture> textures_;
|
||||
ID3D11Device *dev_;
|
||||
|
||||
Mesh(ID3D11Device *dev, const std::vector<VERTEX>& vertices, const std::vector<UINT>& indices, const std::vector<Texture>& textures) :
|
||||
vertices(vertices),
|
||||
indices(indices),
|
||||
textures(textures),
|
||||
dev(dev),
|
||||
VertexBuffer(nullptr),
|
||||
IndexBuffer(nullptr) {
|
||||
this->setupMesh(this->dev);
|
||||
vertices_(vertices),
|
||||
indices_(indices),
|
||||
textures_(textures),
|
||||
dev_(dev),
|
||||
VertexBuffer_(nullptr),
|
||||
IndexBuffer_(nullptr) {
|
||||
this->setupMesh(this->dev_);
|
||||
}
|
||||
|
||||
void Draw(ID3D11DeviceContext *devcon) {
|
||||
UINT stride = sizeof(VERTEX);
|
||||
UINT offset = 0;
|
||||
|
||||
devcon->IASetVertexBuffers(0, 1, &VertexBuffer, &stride, &offset);
|
||||
devcon->IASetIndexBuffer(IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
|
||||
devcon->IASetVertexBuffers(0, 1, &VertexBuffer_, &stride, &offset);
|
||||
devcon->IASetIndexBuffer(IndexBuffer_, DXGI_FORMAT_R32_UINT, 0);
|
||||
|
||||
devcon->PSSetShaderResources(0, 1, &textures[0].texture);
|
||||
devcon->PSSetShaderResources(0, 1, &textures_[0].texture);
|
||||
|
||||
devcon->DrawIndexed(static_cast<UINT>(indices.size()), 0, 0);
|
||||
devcon->DrawIndexed(static_cast<UINT>(indices_.size()), 0, 0);
|
||||
}
|
||||
|
||||
void Close() {
|
||||
SafeRelease(VertexBuffer);
|
||||
SafeRelease(IndexBuffer);
|
||||
SafeRelease(VertexBuffer_);
|
||||
SafeRelease(IndexBuffer_);
|
||||
}
|
||||
private:
|
||||
// Render data
|
||||
ID3D11Buffer *VertexBuffer, *IndexBuffer;
|
||||
ID3D11Buffer *VertexBuffer_, *IndexBuffer_;
|
||||
|
||||
// Functions
|
||||
// Initializes all the buffer objects/arrays
|
||||
|
@ -73,15 +73,15 @@ private:
|
|||
|
||||
D3D11_BUFFER_DESC vbd;
|
||||
vbd.Usage = D3D11_USAGE_IMMUTABLE;
|
||||
vbd.ByteWidth = static_cast<UINT>(sizeof(VERTEX) * vertices.size());
|
||||
vbd.ByteWidth = static_cast<UINT>(sizeof(VERTEX) * vertices_.size());
|
||||
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
vbd.CPUAccessFlags = 0;
|
||||
vbd.MiscFlags = 0;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA initData;
|
||||
initData.pSysMem = &vertices[0];
|
||||
initData.pSysMem = &vertices_[0];
|
||||
|
||||
hr = dev->CreateBuffer(&vbd, &initData, &VertexBuffer);
|
||||
hr = dev->CreateBuffer(&vbd, &initData, &VertexBuffer_);
|
||||
if (FAILED(hr)) {
|
||||
Close();
|
||||
throw std::runtime_error("Failed to create vertex buffer.");
|
||||
|
@ -89,14 +89,14 @@ private:
|
|||
|
||||
D3D11_BUFFER_DESC ibd;
|
||||
ibd.Usage = D3D11_USAGE_IMMUTABLE;
|
||||
ibd.ByteWidth = static_cast<UINT>(sizeof(UINT) * indices.size());
|
||||
ibd.ByteWidth = static_cast<UINT>(sizeof(UINT) * indices_.size());
|
||||
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
ibd.CPUAccessFlags = 0;
|
||||
ibd.MiscFlags = 0;
|
||||
|
||||
initData.pSysMem = &indices[0];
|
||||
initData.pSysMem = &indices_[0];
|
||||
|
||||
hr = dev->CreateBuffer(&ibd, &initData, &IndexBuffer);
|
||||
hr = dev->CreateBuffer(&ibd, &initData, &IndexBuffer_);
|
||||
if (FAILED(hr)) {
|
||||
Close();
|
||||
throw std::runtime_error("Failed to create index buffer.");
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#include "ModelLoader.h"
|
||||
|
||||
ModelLoader::ModelLoader() :
|
||||
dev(nullptr),
|
||||
devcon(nullptr),
|
||||
meshes(),
|
||||
directory(),
|
||||
textures_loaded(),
|
||||
hwnd(nullptr) {
|
||||
dev_(nullptr),
|
||||
devcon_(nullptr),
|
||||
meshes_(),
|
||||
directory_(),
|
||||
textures_loaded_(),
|
||||
hwnd_(nullptr) {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
@ -25,11 +25,11 @@ bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devc
|
|||
if (pScene == NULL)
|
||||
return false;
|
||||
|
||||
this->directory = filename.substr(0, filename.find_last_of("/\\"));
|
||||
this->directory_ = filename.substr(0, filename.find_last_of("/\\"));
|
||||
|
||||
this->dev = dev;
|
||||
this->devcon = devcon;
|
||||
this->hwnd = hwnd;
|
||||
this->dev_ = dev;
|
||||
this->devcon_ = devcon;
|
||||
this->hwnd_ = hwnd;
|
||||
|
||||
processNode(pScene->mRootNode, pScene);
|
||||
|
||||
|
@ -37,8 +37,8 @@ bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devc
|
|||
}
|
||||
|
||||
void ModelLoader::Draw(ID3D11DeviceContext * devcon) {
|
||||
for (int i = 0; i < meshes.size(); ++i ) {
|
||||
meshes[i].Draw(devcon);
|
||||
for (size_t i = 0; i < meshes_.size(); ++i ) {
|
||||
meshes_[i].Draw(devcon);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene) {
|
|||
textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end());
|
||||
}
|
||||
|
||||
return Mesh(dev, vertices, indices, textures);
|
||||
return Mesh(dev_, vertices, indices, textures);
|
||||
}
|
||||
|
||||
std::vector<Texture> ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureType type, std::string typeName, const aiScene * scene) {
|
||||
|
@ -98,9 +98,9 @@ std::vector<Texture> ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextu
|
|||
mat->GetTexture(type, i, &str);
|
||||
// Check if texture was loaded before and if so, continue to next iteration: skip loading a new texture
|
||||
bool skip = false;
|
||||
for (UINT j = 0; j < textures_loaded.size(); j++) {
|
||||
if (std::strcmp(textures_loaded[j].path.c_str(), str.C_Str()) == 0) {
|
||||
textures.push_back(textures_loaded[j]);
|
||||
for (UINT j = 0; j < textures_loaded_.size(); j++) {
|
||||
if (std::strcmp(textures_loaded_[j].path.c_str(), str.C_Str()) == 0) {
|
||||
textures.push_back(textures_loaded_[j]);
|
||||
skip = true; // A texture with the same filepath has already been loaded, continue to next one. (optimization)
|
||||
break;
|
||||
}
|
||||
|
@ -113,34 +113,34 @@ std::vector<Texture> ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextu
|
|||
texture.texture = getTextureFromModel(scene, textureindex);
|
||||
} else {
|
||||
std::string filename = std::string(str.C_Str());
|
||||
filename = directory + '/' + filename;
|
||||
filename = directory_ + '/' + filename;
|
||||
std::wstring filenamews = std::wstring(filename.begin(), filename.end());
|
||||
hr = CreateWICTextureFromFile(dev, devcon, filenamews.c_str(), nullptr, &texture.texture);
|
||||
hr = CreateWICTextureFromFile(dev_, devcon_, filenamews.c_str(), nullptr, &texture.texture);
|
||||
if (FAILED(hr))
|
||||
MessageBox(hwnd, "Texture couldn't be loaded", "Error!", MB_ICONERROR | MB_OK);
|
||||
MessageBox(hwnd_, "Texture couldn't be loaded", "Error!", MB_ICONERROR | MB_OK);
|
||||
}
|
||||
texture.type = typeName;
|
||||
texture.path = str.C_Str();
|
||||
textures.push_back(texture);
|
||||
this->textures_loaded.push_back(texture); // Store it as texture loaded for entire model, to ensure we won't unnecesery load duplicate textures.
|
||||
this->textures_loaded_.push_back(texture); // Store it as texture loaded for entire model, to ensure we won't unnecesery load duplicate textures.
|
||||
}
|
||||
}
|
||||
return textures;
|
||||
}
|
||||
|
||||
void ModelLoader::Close() {
|
||||
for (auto& t : textures_loaded)
|
||||
for (auto& t : textures_loaded_)
|
||||
t.Release();
|
||||
|
||||
for (int i = 0; i < meshes.size(); i++) {
|
||||
meshes[i].Close();
|
||||
for (size_t i = 0; i < meshes_.size(); i++) {
|
||||
meshes_[i].Close();
|
||||
}
|
||||
}
|
||||
|
||||
void ModelLoader::processNode(aiNode * node, const aiScene * scene) {
|
||||
for (UINT i = 0; i < node->mNumMeshes; i++) {
|
||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||
meshes.push_back(this->processMesh(mesh, scene));
|
||||
meshes_.push_back(this->processMesh(mesh, scene));
|
||||
}
|
||||
|
||||
for (UINT i = 0; i < node->mNumChildren; i++) {
|
||||
|
@ -179,9 +179,9 @@ ID3D11ShaderResourceView * ModelLoader::getTextureFromModel(const aiScene * scen
|
|||
|
||||
int* size = reinterpret_cast<int*>(&scene->mTextures[textureindex]->mWidth);
|
||||
|
||||
hr = CreateWICTextureFromMemory(dev, devcon, reinterpret_cast<unsigned char*>(scene->mTextures[textureindex]->pcData), *size, nullptr, &texture);
|
||||
hr = CreateWICTextureFromMemory(dev_, devcon_, reinterpret_cast<unsigned char*>(scene->mTextures[textureindex]->pcData), *size, nullptr, &texture);
|
||||
if (FAILED(hr))
|
||||
MessageBox(hwnd, "Texture couldn't be created from memory!", "Error!", MB_ICONERROR | MB_OK);
|
||||
MessageBox(hwnd_, "Texture couldn't be created from memory!", "Error!", MB_ICONERROR | MB_OK);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
|
|
@ -25,12 +25,12 @@ public:
|
|||
|
||||
void Close();
|
||||
private:
|
||||
ID3D11Device *dev;
|
||||
ID3D11DeviceContext *devcon;
|
||||
std::vector<Mesh> meshes;
|
||||
std::string directory;
|
||||
std::vector<Texture> textures_loaded;
|
||||
HWND hwnd;
|
||||
ID3D11Device *dev_;
|
||||
ID3D11DeviceContext *devcon_;
|
||||
std::vector<Mesh> meshes_;
|
||||
std::string directory_;
|
||||
std::vector<Texture> textures_loaded_;
|
||||
HWND hwnd_;
|
||||
|
||||
void processNode(aiNode* node, const aiScene* scene);
|
||||
Mesh processMesh(aiMesh* mesh, const aiScene* scene);
|
||||
|
|
|
@ -56,7 +56,7 @@ const char g_szClassName[] = "directxWindowClass";
|
|||
static std::string g_ModelPath;
|
||||
|
||||
UINT width, height;
|
||||
HWND hwnd = nullptr;
|
||||
HWND g_hwnd = nullptr;
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// DirectX Variables
|
||||
|
@ -120,8 +120,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
LPWSTR lpCmdLine, int nCmdShow)
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/,
|
||||
LPWSTR /*lpCmdLine*/, int nCmdShow)
|
||||
{
|
||||
int argc;
|
||||
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||
|
@ -182,7 +182,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|||
RECT wr = { 0,0, SCREEN_WIDTH, SCREEN_HEIGHT };
|
||||
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
|
||||
|
||||
hwnd = CreateWindowEx(
|
||||
g_hwnd = CreateWindowEx(
|
||||
WS_EX_CLIENTEDGE,
|
||||
g_szClassName,
|
||||
" Simple Textured Directx11 Sample ",
|
||||
|
@ -191,21 +191,21 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|||
NULL, NULL, hInstance, NULL
|
||||
);
|
||||
|
||||
if (hwnd == NULL)
|
||||
if (g_hwnd == NULL)
|
||||
{
|
||||
MessageBox(NULL, "Window Creation Failed!", "Error!",
|
||||
MB_ICONEXCLAMATION | MB_OK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ShowWindow(hwnd, nCmdShow);
|
||||
UpdateWindow(hwnd);
|
||||
ShowWindow(g_hwnd, nCmdShow);
|
||||
UpdateWindow(g_hwnd);
|
||||
|
||||
width = wr.right - wr.left;
|
||||
height = wr.bottom - wr.top;
|
||||
|
||||
try {
|
||||
InitD3D(hInstance, hwnd);
|
||||
InitD3D(hInstance, g_hwnd);
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
@ -225,17 +225,17 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|||
CleanD3D();
|
||||
return static_cast<int>(msg.wParam);
|
||||
} catch (const std::exception& e) {
|
||||
MessageBox(hwnd, e.what(), TEXT("Error!"), MB_ICONERROR | MB_OK);
|
||||
MessageBox(g_hwnd, e.what(), TEXT("Error!"), MB_ICONERROR | MB_OK);
|
||||
CleanD3D();
|
||||
return EXIT_FAILURE;
|
||||
} catch (...) {
|
||||
MessageBox(hwnd, TEXT("Caught an unknown exception."), TEXT("Error!"), MB_ICONERROR | MB_OK);
|
||||
MessageBox(g_hwnd, TEXT("Caught an unknown exception."), TEXT("Error!"), MB_ICONERROR | MB_OK);
|
||||
CleanD3D();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
void InitD3D(HINSTANCE hinstance, HWND hWnd)
|
||||
void InitD3D(HINSTANCE /*hinstance*/, HWND hWnd)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
|
@ -362,7 +362,7 @@ void InitD3D(HINSTANCE hinstance, HWND hWnd)
|
|||
}
|
||||
|
||||
// Note this tutorial doesn't handle full-screen swapchains so we block the ALT+ENTER shortcut
|
||||
dxgiFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);
|
||||
dxgiFactory->MakeWindowAssociation(g_hwnd, DXGI_MWA_NO_ALT_ENTER);
|
||||
|
||||
dxgiFactory->Release();
|
||||
|
||||
|
@ -564,7 +564,7 @@ void InitGraphics()
|
|||
m_View = XMMatrixLookAtLH(Eye, At, Up);
|
||||
|
||||
ourModel = new ModelLoader;
|
||||
if (!ourModel->Load(hwnd, dev, devcon, g_ModelPath))
|
||||
if (!ourModel->Load(g_hwnd, dev, devcon, g_ModelPath))
|
||||
Throwanerror("Model couldn't be loaded");
|
||||
}
|
||||
|
||||
|
|
|
@ -213,6 +213,10 @@ TEST_F(utFBXImporterExporter, importUnitScaleFactor) {
|
|||
double factor(0.0);
|
||||
scene->mMetaData->Get("UnitScaleFactor", factor);
|
||||
EXPECT_DOUBLE_EQ(500.0, factor);
|
||||
|
||||
scene->mMetaData->Set("UnitScaleFactor", factor * 2);
|
||||
scene->mMetaData->Get("UnitScaleFactor", factor);
|
||||
EXPECT_DOUBLE_EQ(1000.0, factor);
|
||||
}
|
||||
|
||||
TEST_F(utFBXImporterExporter, importEmbeddedAsciiTest) {
|
||||
|
|
Loading…
Reference in New Issue