Merge pull request #546 from terziman/master

Minor improvments & bug fixes
pull/547/head
Alexander Gessler 2015-04-30 02:35:52 +02:00
commit 880cb473b0
17 changed files with 122 additions and 94 deletions

View File

@ -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);
}

View File

@ -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)

View File

@ -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

View File

@ -241,6 +241,7 @@ protected:
bool noSkeletonMesh;
bool ignoreUpDirection;
bool invertTransparency;
/** Used by FindNameForNode() to generate unique node names */
unsigned int mNodeNameCounter;

View File

@ -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"))

View File

@ -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);
}
// ------------------------------------------------------------------------------------------------

View File

@ -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;
}
// ------------------------------------------------------------------------------------------------

View File

@ -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;
}
// ------------------------------------------------------------------------------------------------

View File

@ -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);

View File

@ -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();

View File

@ -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) );
}

View File

@ -348,16 +348,14 @@ public:
* are defined in the aiConfig.g header (all constants share the
* prefix AI_CONFIG_XXX and are simple strings).
* @param iValue New value of the property
* @param bWasExisting Optional pointer to receive true if the
* property was set before. The new value replaces the previous value
* in this case.
* @return true if the property was set before. The new value replaces
* the previous value in this case.
* @note Property of different types (float, int, string ..) are kept
* on different stacks, so calling SetPropertyInteger() for a
* floating-point property has no effect - the loader will call
* GetPropertyFloat() to read the property, but it won't be there.
*/
void SetPropertyInteger(const char* szName, int iValue,
bool* bWasExisting = NULL);
bool SetPropertyInteger(const char* szName, int iValue);
// -------------------------------------------------------------------
/** Set a boolean configuration property. Boolean properties
@ -366,30 +364,27 @@ public:
* #GetPropertyBool and vice versa.
* @see SetPropertyInteger()
*/
void SetPropertyBool(const char* szName, bool value, bool* bWasExisting = NULL) {
SetPropertyInteger(szName,value,bWasExisting);
bool SetPropertyBool(const char* szName, bool value) {
return SetPropertyInteger(szName,value);
}
// -------------------------------------------------------------------
/** Set a floating-point configuration property.
* @see SetPropertyInteger()
*/
void SetPropertyFloat(const char* szName, float fValue,
bool* bWasExisting = NULL);
bool SetPropertyFloat(const char* szName, float fValue);
// -------------------------------------------------------------------
/** Set a string configuration property.
* @see SetPropertyInteger()
*/
void SetPropertyString(const char* szName, const std::string& sValue,
bool* bWasExisting = NULL);
bool SetPropertyString(const char* szName, const std::string& sValue);
// -------------------------------------------------------------------
/** Set a matrix configuration property.
* @see SetPropertyInteger()
*/
void SetPropertyMatrix(const char* szName, const aiMatrix4x4& sValue,
bool* bWasExisting = NULL);
bool SetPropertyMatrix(const char* szName, const aiMatrix4x4& sValue);
// -------------------------------------------------------------------
/** Get a configuration property.

View File

@ -194,16 +194,14 @@ public:
* are defined in the aiConfig.g header (all constants share the
* prefix AI_CONFIG_XXX and are simple strings).
* @param iValue New value of the property
* @param bWasExisting Optional pointer to receive true if the
* property was set before. The new value replaces the previous value
* in this case.
* @return true if the property was set before. The new value replaces
* the previous value in this case.
* @note Property of different types (float, int, string ..) are kept
* on different stacks, so calling SetPropertyInteger() for a
* floating-point property has no effect - the loader will call
* GetPropertyFloat() to read the property, but it won't be there.
*/
void SetPropertyInteger(const char* szName, int iValue,
bool* bWasExisting = NULL);
bool SetPropertyInteger(const char* szName, int iValue);
// -------------------------------------------------------------------
/** Set a boolean configuration property. Boolean properties
@ -212,30 +210,27 @@ public:
* #GetPropertyBool and vice versa.
* @see SetPropertyInteger()
*/
void SetPropertyBool(const char* szName, bool value, bool* bWasExisting = NULL) {
SetPropertyInteger(szName,value,bWasExisting);
bool SetPropertyBool(const char* szName, bool value) {
return SetPropertyInteger(szName,value);
}
// -------------------------------------------------------------------
/** Set a floating-point configuration property.
* @see SetPropertyInteger()
*/
void SetPropertyFloat(const char* szName, float fValue,
bool* bWasExisting = NULL);
bool SetPropertyFloat(const char* szName, float fValue);
// -------------------------------------------------------------------
/** Set a string configuration property.
* @see SetPropertyInteger()
*/
void SetPropertyString(const char* szName, const std::string& sValue,
bool* bWasExisting = NULL);
bool SetPropertyString(const char* szName, const std::string& sValue);
// -------------------------------------------------------------------
/** Set a matrix configuration property.
* @see SetPropertyInteger()
*/
void SetPropertyMatrix(const char* szName, const aiMatrix4x4& sValue,
bool* bWasExisting = NULL);
bool SetPropertyMatrix(const char* szName, const aiMatrix4x4& sValue);
// -------------------------------------------------------------------
/** Get a configuration property.

View File

@ -877,8 +877,24 @@ enum aiComponent
*/
#define AI_CONFIG_IMPORT_IFC_CUSTOM_TRIANGULATION "IMPORT_IFC_CUSTOM_TRIANGULATION"
// ---------------------------------------------------------------------------
/** @brief Specifies whether the Collada loader will ignore the provided up direction.
*
* If this property is set to true, the up direction provided in the file header will
* be ignored and the file will be loaded as is.
* Property type: Bool. Default value: false.
*/
#define AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION "IMPORT_COLLADA_IGNORE_UP_DIRECTION"
// ---------------------------------------------------------------------------
/** @brief Specifies whether the Collada loader will invert the transparency value.
*
* If this property is set to true, the transparency value will be interpreted as the
* inverse of the usual transparency. This is useful because lots of exporters does
* not respect the standard and do the opposite of what is normally expected.
* Property type: Bool. Default value: false.
*/
#define AI_CONFIG_IMPORT_COLLADA_INVERT_TRANSPARENCY "IMPORT_COLLADA_INVERT_TRANSPARENCY"
// ---------- All the Export defines ------------
@ -889,5 +905,4 @@ enum aiComponent
#define AI_CONFIG_EXPORT_XFILE_64BIT "EXPORT_XFILE_64BIT"
#endif // !! AI_CONFIG_H_INC

View File

@ -131,21 +131,19 @@ TEST_F(ImporterTest, testMemoryRead)
// ------------------------------------------------------------------------------------------------
TEST_F(ImporterTest, testIntProperty)
{
bool b;
pImp->SetPropertyInteger("quakquak",1503,&b);
bool b = pImp->SetPropertyInteger("quakquak",1503);
EXPECT_FALSE(b);
EXPECT_EQ(1503, pImp->GetPropertyInteger("quakquak",0));
EXPECT_EQ(314159, pImp->GetPropertyInteger("not_there",314159));
pImp->SetPropertyInteger("quakquak",1504,&b);
b = pImp->SetPropertyInteger("quakquak",1504);
EXPECT_TRUE(b);
}
// ------------------------------------------------------------------------------------------------
TEST_F(ImporterTest, testFloatProperty)
{
bool b;
pImp->SetPropertyFloat("quakquak",1503.f,&b);
bool b = pImp->SetPropertyFloat("quakquak",1503.f);
EXPECT_TRUE(!b);
EXPECT_EQ(1503.f, pImp->GetPropertyFloat("quakquak",0.f));
EXPECT_EQ(314159.f, pImp->GetPropertyFloat("not_there",314159.f));
@ -154,8 +152,7 @@ TEST_F(ImporterTest, testFloatProperty)
// ------------------------------------------------------------------------------------------------
TEST_F(ImporterTest, testStringProperty)
{
bool b;
pImp->SetPropertyString("quakquak","test",&b);
bool b = pImp->SetPropertyString("quakquak","test");
EXPECT_TRUE(!b);
EXPECT_EQ("test", pImp->GetPropertyString("quakquak","weghwekg"));
EXPECT_EQ("ILoveYou", pImp->GetPropertyString("not_there","ILoveYou"));

View File

@ -693,7 +693,7 @@ int CDisplay::FillDisplayList(void)
// fill in the first entry
TVITEMEX tvi;
TVINSERTSTRUCT sNew;
tvi.pszText = "Model";
tvi.pszText = (char*) "Model";
tvi.cchTextMax = (int)strlen(tvi.pszText);
tvi.mask = TVIF_TEXT | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_HANDLE | TVIF_STATE;
tvi.state = TVIS_EXPANDED;

View File

@ -72,12 +72,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../code/StringComparison.h" // ASSIMP_stricmp and ASSIMP_strincmp
// in order for std::min and std::max to behave properly
/*#ifdef min
#undef min
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif // max
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif // min
#ifdef max
#undef max
#endif // min*/
#include <time.h>