Merge pull request #546 from terziman/master
Minor improvments & bug fixes
This commit is contained in:
@@ -490,7 +490,7 @@ ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore* p, const char* szNam
|
||||
{
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
||||
SetGenericProperty<int>(pp->ints,szName,value,NULL);
|
||||
SetGenericProperty<int>(pp->ints,szName,value);
|
||||
ASSIMP_END_EXCEPTION_REGION(void);
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName,
|
||||
{
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
||||
SetGenericProperty<float>(pp->floats,szName,value,NULL);
|
||||
SetGenericProperty<float>(pp->floats,szName,value);
|
||||
ASSIMP_END_EXCEPTION_REGION(void);
|
||||
}
|
||||
|
||||
@@ -514,7 +514,7 @@ ASSIMP_API void aiSetImportPropertyString(aiPropertyStore* p, const char* szName
|
||||
}
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
||||
SetGenericProperty<std::string>(pp->strings,szName,std::string(st->C_Str()),NULL);
|
||||
SetGenericProperty<std::string>(pp->strings,szName,std::string(st->C_Str()));
|
||||
ASSIMP_END_EXCEPTION_REGION(void);
|
||||
}
|
||||
|
||||
@@ -528,7 +528,7 @@ ASSIMP_API void aiSetImportPropertyMatrix(aiPropertyStore* p, const char* szName
|
||||
}
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
||||
SetGenericProperty<aiMatrix4x4>(pp->matrices,szName,*mat,NULL);
|
||||
SetGenericProperty<aiMatrix4x4>(pp->matrices,szName,*mat);
|
||||
ASSIMP_END_EXCEPTION_REGION(void);
|
||||
}
|
||||
|
||||
|
||||
@@ -513,6 +513,8 @@ struct Effect
|
||||
// Scalar factory
|
||||
float mShininess, mRefractIndex, mReflectivity;
|
||||
float mTransparency;
|
||||
bool mHasTransparency;
|
||||
bool mRGBTransparency;
|
||||
|
||||
// local params referring to each other by their SID
|
||||
typedef std::map<std::string, Collada::EffectParam> ParamLibrary;
|
||||
@@ -533,7 +535,9 @@ struct Effect
|
||||
, mShininess (10.0f)
|
||||
, mRefractIndex (1.f)
|
||||
, mReflectivity (1.f)
|
||||
, mTransparency (0.f)
|
||||
, mTransparency (1.f)
|
||||
, mHasTransparency (false)
|
||||
, mRGBTransparency(false)
|
||||
, mDoubleSided (false)
|
||||
, mWireframe (false)
|
||||
, mFaceted (false)
|
||||
|
||||
@@ -117,6 +117,7 @@ void ColladaLoader::SetupProperties(const Importer* pImp)
|
||||
{
|
||||
noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES,0) != 0;
|
||||
ignoreUpDirection = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION,0) != 0;
|
||||
invertTransparency = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_INVERT_TRANSPARENCY,0) != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1338,11 +1339,25 @@ void ColladaLoader::FillMaterials( const ColladaParser& pParser, aiScene* /*pSce
|
||||
mat.AddProperty( &effect.mRefractIndex, 1, AI_MATKEY_REFRACTI);
|
||||
|
||||
// transparency, a very hard one. seemingly not all files are following the
|
||||
// specification here .. but we can trick.
|
||||
if (effect.mTransparency >= 0.f && effect.mTransparency < 1.f) {
|
||||
effect.mTransparency = 1.f- effect.mTransparency;
|
||||
mat.AddProperty( &effect.mTransparency, 1, AI_MATKEY_OPACITY );
|
||||
mat.AddProperty( &effect.mTransparent, 1, AI_MATKEY_COLOR_TRANSPARENT );
|
||||
// specification here (1.0 transparency => completly opaque)...
|
||||
// therefore, we let the opportunity for the user to manually invert
|
||||
// the transparency if necessary and we add preliminary support for RGB_ZERO mode
|
||||
if(effect.mTransparency >= 0.f && effect.mTransparency <= 1.f) {
|
||||
// Trying some support for RGB_ZERO mode
|
||||
if(effect.mRGBTransparency) {
|
||||
effect.mTransparency = 1.f - effect.mTransparent.a;
|
||||
}
|
||||
|
||||
// Global option
|
||||
if(invertTransparency) {
|
||||
effect.mTransparency = 1.f - effect.mTransparency;
|
||||
}
|
||||
|
||||
// Is the material finally transparent ?
|
||||
if (effect.mHasTransparency || effect.mTransparency < 1.f) {
|
||||
mat.AddProperty( &effect.mTransparency, 1, AI_MATKEY_OPACITY );
|
||||
mat.AddProperty( &effect.mTransparent, 1, AI_MATKEY_COLOR_TRANSPARENT );
|
||||
}
|
||||
}
|
||||
|
||||
// add textures, if given
|
||||
|
||||
@@ -241,6 +241,7 @@ protected:
|
||||
|
||||
bool noSkeletonMesh;
|
||||
bool ignoreUpDirection;
|
||||
bool invertTransparency;
|
||||
|
||||
/** Used by FindNameForNode() to generate unique node names */
|
||||
unsigned int mNodeNameCounter;
|
||||
|
||||
@@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_COLLADA_IMPORTER
|
||||
|
||||
#include <sstream>
|
||||
#include "ColladaParser.h"
|
||||
#include "fast_atof.h"
|
||||
#include "ParsingUtils.h"
|
||||
@@ -1230,6 +1231,14 @@ void ColladaParser::ReadEffectProfileCommon( Collada::Effect& pEffect)
|
||||
ReadEffectColor( pEffect.mReflective, pEffect.mTexReflective);
|
||||
}
|
||||
else if( IsElement( "transparent")) {
|
||||
pEffect.mHasTransparency = true;
|
||||
|
||||
// In RGB_ZERO mode, the transparency is interpreted in reverse, go figure...
|
||||
if(::strcmp(mReader->getAttributeValueSafe("opaque"), "RGB_ZERO") == 0) {
|
||||
// TODO: handle RGB_ZERO mode completely
|
||||
pEffect.mRGBTransparency = true;
|
||||
}
|
||||
|
||||
ReadEffectColor( pEffect.mTransparent,pEffect.mTexTransparent);
|
||||
}
|
||||
else if( IsElement( "shininess"))
|
||||
@@ -1987,12 +1996,12 @@ void ColladaParser::ReadIndexData( Mesh* pMesh)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef ASSIMP_BUILD_DEBUG
|
||||
if (primType != Prim_TriFans && primType != Prim_TriStrips) {
|
||||
ai_assert(actualPrimitives == numPrimitives);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// only when we're done reading all <p> tags (and thus know the final vertex count) can we commit the submesh
|
||||
subgroup.mNumFaces = actualPrimitives;
|
||||
|
||||
@@ -513,34 +513,30 @@ ExportProperties::ExportProperties(const ExportProperties &other)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void ExportProperties :: SetPropertyInteger(const char* szName, int iValue,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
bool ExportProperties :: SetPropertyInteger(const char* szName, int iValue)
|
||||
{
|
||||
SetGenericProperty<int>(mIntProperties, szName,iValue,bWasExisting);
|
||||
return SetGenericProperty<int>(mIntProperties, szName,iValue);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void ExportProperties :: SetPropertyFloat(const char* szName, float iValue,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
bool ExportProperties :: SetPropertyFloat(const char* szName, float iValue)
|
||||
{
|
||||
SetGenericProperty<float>(mFloatProperties, szName,iValue,bWasExisting);
|
||||
return SetGenericProperty<float>(mFloatProperties, szName,iValue);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void ExportProperties :: SetPropertyString(const char* szName, const std::string& value,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
bool ExportProperties :: SetPropertyString(const char* szName, const std::string& value)
|
||||
{
|
||||
SetGenericProperty<std::string>(mStringProperties, szName,value,bWasExisting);
|
||||
return SetGenericProperty<std::string>(mStringProperties, szName,value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void ExportProperties :: SetPropertyMatrix(const char* szName, const aiMatrix4x4& value,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
bool ExportProperties :: SetPropertyMatrix(const char* szName, const aiMatrix4x4& value)
|
||||
{
|
||||
SetGenericProperty<aiMatrix4x4>(mMatrixProperties, szName,value,bWasExisting);
|
||||
return SetGenericProperty<aiMatrix4x4>(mMatrixProperties, szName,value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -49,22 +49,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
inline void SetGenericProperty(std::map< unsigned int, T >& list,
|
||||
const char* szName, const T& value, bool* bWasExisting = NULL)
|
||||
inline bool SetGenericProperty(std::map< unsigned int, T >& list,
|
||||
const char* szName, const T& value)
|
||||
{
|
||||
ai_assert(NULL != szName);
|
||||
const uint32_t hash = SuperFastHash(szName);
|
||||
|
||||
typename std::map<unsigned int, T>::iterator it = list.find(hash);
|
||||
if (it == list.end()) {
|
||||
if (bWasExisting)
|
||||
*bWasExisting = false;
|
||||
list.insert(std::pair<unsigned int, T>( hash, value ));
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
(*it).second = value;
|
||||
if (bWasExisting)
|
||||
*bWasExisting = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -925,42 +925,46 @@ void Importer::GetExtensionList(aiString& szOut) const
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void Importer::SetPropertyInteger(const char* szName, int iValue,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
bool Importer::SetPropertyInteger(const char* szName, int iValue)
|
||||
{
|
||||
bool existing;
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
SetGenericProperty<int>(pimpl->mIntProperties, szName,iValue,bWasExisting);
|
||||
ASSIMP_END_EXCEPTION_REGION(void);
|
||||
existing = SetGenericProperty<int>(pimpl->mIntProperties, szName,iValue);
|
||||
ASSIMP_END_EXCEPTION_REGION(bool);
|
||||
return existing;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void Importer::SetPropertyFloat(const char* szName, float iValue,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
bool Importer::SetPropertyFloat(const char* szName, float iValue)
|
||||
{
|
||||
bool exising;
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
SetGenericProperty<float>(pimpl->mFloatProperties, szName,iValue,bWasExisting);
|
||||
ASSIMP_END_EXCEPTION_REGION(void);
|
||||
exising = SetGenericProperty<float>(pimpl->mFloatProperties, szName,iValue);
|
||||
ASSIMP_END_EXCEPTION_REGION(bool);
|
||||
return exising;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void Importer::SetPropertyString(const char* szName, const std::string& value,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
bool Importer::SetPropertyString(const char* szName, const std::string& value)
|
||||
{
|
||||
bool exising;
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
SetGenericProperty<std::string>(pimpl->mStringProperties, szName,value,bWasExisting);
|
||||
ASSIMP_END_EXCEPTION_REGION(void);
|
||||
exising = SetGenericProperty<std::string>(pimpl->mStringProperties, szName,value);
|
||||
ASSIMP_END_EXCEPTION_REGION(bool);
|
||||
return exising;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void Importer::SetPropertyMatrix(const char* szName, const aiMatrix4x4& value,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
bool Importer::SetPropertyMatrix(const char* szName, const aiMatrix4x4& value)
|
||||
{
|
||||
bool exising;
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
SetGenericProperty<aiMatrix4x4>(pimpl->mMatrixProperties, szName,value,bWasExisting);
|
||||
ASSIMP_END_EXCEPTION_REGION(void);
|
||||
exising = SetGenericProperty<aiMatrix4x4>(pimpl->mMatrixProperties, szName,value);
|
||||
ASSIMP_END_EXCEPTION_REGION(bool);
|
||||
return exising;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -563,7 +563,7 @@ bool MD3Importer::ReadMultipartFile()
|
||||
|
||||
// ensure we won't try to load ourselves recursively
|
||||
BatchLoader::PropertyMap props;
|
||||
SetGenericProperty( props.ints, AI_CONFIG_IMPORT_MD3_HANDLE_MULTIPART, 0, NULL);
|
||||
SetGenericProperty( props.ints, AI_CONFIG_IMPORT_MD3_HANDLE_MULTIPART, 0);
|
||||
|
||||
// now read these three files
|
||||
BatchLoader batch(mIOHandler);
|
||||
|
||||
@@ -920,7 +920,7 @@ void SceneCombiner::MergeMaterials(aiMaterial** dest,
|
||||
|
||||
// Test if we already have a matching property
|
||||
const aiMaterialProperty* prop_exist;
|
||||
if(aiGetMaterialProperty(out, sprop->mKey.C_Str(), sprop->mType, sprop->mIndex, &prop_exist) != AI_SUCCESS) {
|
||||
if(aiGetMaterialProperty(out, sprop->mKey.C_Str(), sprop->mSemantic, sprop->mIndex, &prop_exist) != AI_SUCCESS) {
|
||||
// If not, we add it to the new material
|
||||
aiMaterialProperty* prop = out->mProperties[out->mNumProperties] = new aiMaterialProperty();
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ inline int64_t strtol10_64(const char* in, const char** out = 0, unsigned int* m
|
||||
// If you find any bugs, please send them to me, niko (at) irrlicht3d.org.
|
||||
// ------------------------------------------------------------------------------------
|
||||
template <typename Real>
|
||||
inline const char* fast_atoreal_move( const char* c, Real& out, bool check_comma = true)
|
||||
inline const char* fast_atoreal_move(const char* c, Real& out, bool check_comma = true)
|
||||
{
|
||||
Real f = 0;
|
||||
|
||||
@@ -286,14 +286,14 @@ inline const char* fast_atoreal_move( const char* c, Real& out, bool check_comma
|
||||
}
|
||||
|
||||
if (!(c[0] >= '0' && c[0] <= '9') &&
|
||||
!(c[0] == '.' && c[1] >= '0' && c[1] <= '9'))
|
||||
!((c[0] == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9'))
|
||||
{
|
||||
throw std::invalid_argument("Cannot parse string "
|
||||
"as real number: does not start with digit "
|
||||
"or decimal point followed by digit.");
|
||||
}
|
||||
|
||||
if (*c != '.')
|
||||
if (*c != '.' && (! check_comma || c[0] != ','))
|
||||
{
|
||||
f = static_cast<Real>( strtoul10_64 ( c, &c) );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user