Fix issues with Vertex + Color4

pull/5660/head
Kim Kulling 2024-07-10 16:13:03 +02:00
parent 565b7f6d56
commit b14a50a124
9 changed files with 76 additions and 56 deletions

View File

@ -384,17 +384,17 @@ void AMFImporter::ParseNode_Instance(XmlNode &node) {
for (auto &currentNode : node.children()) { for (auto &currentNode : node.children()) {
const std::string &currentName = currentNode.name(); const std::string &currentName = currentNode.name();
if (currentName == "deltax") { if (currentName == "deltax") {
XmlParser::getValueAsFloat(currentNode, als.Delta.x); XmlParser::getValueAsReal(currentNode, als.Delta.x);
} else if (currentName == "deltay") { } else if (currentName == "deltay") {
XmlParser::getValueAsFloat(currentNode, als.Delta.y); XmlParser::getValueAsReal(currentNode, als.Delta.y);
} else if (currentName == "deltaz") { } else if (currentName == "deltaz") {
XmlParser::getValueAsFloat(currentNode, als.Delta.z); XmlParser::getValueAsReal(currentNode, als.Delta.z);
} else if (currentName == "rx") { } else if (currentName == "rx") {
XmlParser::getValueAsFloat(currentNode, als.Delta.x); XmlParser::getValueAsReal(currentNode, als.Delta.x);
} else if (currentName == "ry") { } else if (currentName == "ry") {
XmlParser::getValueAsFloat(currentNode, als.Delta.y); XmlParser::getValueAsReal(currentNode, als.Delta.y);
} else if (currentName == "rz") { } else if (currentName == "rz") {
XmlParser::getValueAsFloat(currentNode, als.Delta.z); XmlParser::getValueAsReal(currentNode, als.Delta.z);
} }
} }
ParseHelper_Node_Exit(); ParseHelper_Node_Exit();

View File

@ -167,11 +167,11 @@ void AMFImporter::ParseNode_Coordinates(XmlNode &node) {
AMFCoordinates &als = *((AMFCoordinates *)ne); // alias for convenience AMFCoordinates &als = *((AMFCoordinates *)ne); // alias for convenience
const std::string &currentName = ai_tolower(currentNode.name()); const std::string &currentName = ai_tolower(currentNode.name());
if (currentName == "x") { if (currentName == "x") {
XmlParser::getValueAsFloat(currentNode, als.Coordinate.x); XmlParser::getValueAsReal(currentNode, als.Coordinate.x);
} else if (currentName == "y") { } else if (currentName == "y") {
XmlParser::getValueAsFloat(currentNode, als.Coordinate.y); XmlParser::getValueAsReal(currentNode, als.Coordinate.y);
} else if (currentName == "z") { } else if (currentName == "z") {
XmlParser::getValueAsFloat(currentNode, als.Coordinate.z); XmlParser::getValueAsReal(currentNode, als.Coordinate.z);
} }
} }
ParseHelper_Node_Exit(); ParseHelper_Node_Exit();

View File

@ -263,26 +263,25 @@ void AMFImporter::ParseNode_TexMap(XmlNode &node, const bool pUseOldName) {
const std::string &name = currentNode.name(); const std::string &name = currentNode.name();
if (name == "utex1") { if (name == "utex1") {
read_flag[0] = true; read_flag[0] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[0].x); XmlParser::getValueAsReal(node, als.TextureCoordinate[0].x);
} else if (name == "utex2") { } else if (name == "utex2") {
read_flag[1] = true; read_flag[1] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[1].x); XmlParser::getValueAsReal(node, als.TextureCoordinate[1].x);
} else if (name == "utex3") { } else if (name == "utex3") {
read_flag[2] = true; read_flag[2] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[2].x); XmlParser::getValueAsReal(node, als.TextureCoordinate[2].x);
} else if (name == "vtex1") { } else if (name == "vtex1") {
read_flag[3] = true; read_flag[3] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[0].y); XmlParser::getValueAsReal(node, als.TextureCoordinate[0].y);
} else if (name == "vtex2") { } else if (name == "vtex2") {
read_flag[4] = true; read_flag[4] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[1].y); XmlParser::getValueAsReal(node, als.TextureCoordinate[1].y);
} else if (name == "vtex3") { } else if (name == "vtex3") {
read_flag[5] = true; read_flag[5] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[2].y); XmlParser::getValueAsReal(node, als.TextureCoordinate[2].y);
} }
} }
ParseHelper_Node_Exit(); ParseHelper_Node_Exit();
} else { } else {
for (pugi::xml_attribute &attr : node.attributes()) { for (pugi::xml_attribute &attr : node.attributes()) {
const std::string name = attr.name(); const std::string name = attr.name();

View File

@ -1600,7 +1600,7 @@ void Parser::ParseLV3MeshCListBlock(unsigned int iNumVertices, ASE::Mesh &mesh)
aiColor4D vTemp; aiColor4D vTemp;
vTemp.a = 1.0f; vTemp.a = 1.0f;
unsigned int iIndex; unsigned int iIndex;
ParseLV4MeshRealTriple(&vTemp.r, iIndex); ParseLV4MeshFloatTriple(&vTemp.r, iIndex);
if (iIndex >= iNumVertices) { if (iIndex >= iNumVertices) {
LogWarning("Vertex color has an invalid index. It will be ignored"); LogWarning("Vertex color has an invalid index. It will be ignored");

View File

@ -968,34 +968,34 @@ void ColladaParser::ReadLight(XmlNode &node, Collada::Light &pLight) {
content = fast_atoreal_move<ai_real>(content, (ai_real &)pLight.mColor.b); content = fast_atoreal_move<ai_real>(content, (ai_real &)pLight.mColor.b);
SkipSpacesAndLineEnd(&content, end); SkipSpacesAndLineEnd(&content, end);
} else if (currentName == "constant_attenuation") { } else if (currentName == "constant_attenuation") {
XmlParser::getValueAsFloat(currentNode, pLight.mAttConstant); XmlParser::getValueAsReal(currentNode, pLight.mAttConstant);
} else if (currentName == "linear_attenuation") { } else if (currentName == "linear_attenuation") {
XmlParser::getValueAsFloat(currentNode, pLight.mAttLinear); XmlParser::getValueAsReal(currentNode, pLight.mAttLinear);
} else if (currentName == "quadratic_attenuation") { } else if (currentName == "quadratic_attenuation") {
XmlParser::getValueAsFloat(currentNode, pLight.mAttQuadratic); XmlParser::getValueAsReal(currentNode, pLight.mAttQuadratic);
} else if (currentName == "falloff_angle") { } else if (currentName == "falloff_angle") {
XmlParser::getValueAsFloat(currentNode, pLight.mFalloffAngle); XmlParser::getValueAsReal(currentNode, pLight.mFalloffAngle);
} else if (currentName == "falloff_exponent") { } else if (currentName == "falloff_exponent") {
XmlParser::getValueAsFloat(currentNode, pLight.mFalloffExponent); XmlParser::getValueAsReal(currentNode, pLight.mFalloffExponent);
} }
// FCOLLADA extensions // FCOLLADA extensions
// ------------------------------------------------------- // -------------------------------------------------------
else if (currentName == "outer_cone") { else if (currentName == "outer_cone") {
XmlParser::getValueAsFloat(currentNode, pLight.mOuterAngle); XmlParser::getValueAsReal(currentNode, pLight.mOuterAngle);
} else if (currentName == "penumbra_angle") { // this one is deprecated, now calculated using outer_cone } else if (currentName == "penumbra_angle") { // this one is deprecated, now calculated using outer_cone
XmlParser::getValueAsFloat(currentNode, pLight.mPenumbraAngle); XmlParser::getValueAsReal(currentNode, pLight.mPenumbraAngle);
} else if (currentName == "intensity") { } else if (currentName == "intensity") {
XmlParser::getValueAsFloat(currentNode, pLight.mIntensity); XmlParser::getValueAsReal(currentNode, pLight.mIntensity);
} }
else if (currentName == "falloff") { else if (currentName == "falloff") {
XmlParser::getValueAsFloat(currentNode, pLight.mOuterAngle); XmlParser::getValueAsReal(currentNode, pLight.mOuterAngle);
} else if (currentName == "hotspot_beam") { } else if (currentName == "hotspot_beam") {
XmlParser::getValueAsFloat(currentNode, pLight.mFalloffAngle); XmlParser::getValueAsReal(currentNode, pLight.mFalloffAngle);
} }
// OpenCOLLADA extensions // OpenCOLLADA extensions
// ------------------------------------------------------- // -------------------------------------------------------
else if (currentName == "decay_falloff") { else if (currentName == "decay_falloff") {
XmlParser::getValueAsFloat(currentNode, pLight.mOuterAngle); XmlParser::getValueAsReal(currentNode, pLight.mOuterAngle);
} }
} }
} }
@ -1010,15 +1010,15 @@ void ColladaParser::ReadCamera(XmlNode &node, Collada::Camera &camera) {
if (currentName == "orthographic") { if (currentName == "orthographic") {
camera.mOrtho = true; camera.mOrtho = true;
} else if (currentName == "xfov" || currentName == "xmag") { } else if (currentName == "xfov" || currentName == "xmag") {
XmlParser::getValueAsFloat(currentNode, camera.mHorFov); XmlParser::getValueAsReal(currentNode, camera.mHorFov);
} else if (currentName == "yfov" || currentName == "ymag") { } else if (currentName == "yfov" || currentName == "ymag") {
XmlParser::getValueAsFloat(currentNode, camera.mVerFov); XmlParser::getValueAsReal(currentNode, camera.mVerFov);
} else if (currentName == "aspect_ratio") { } else if (currentName == "aspect_ratio") {
XmlParser::getValueAsFloat(currentNode, camera.mAspect); XmlParser::getValueAsReal(currentNode, camera.mAspect);
} else if (currentName == "znear") { } else if (currentName == "znear") {
XmlParser::getValueAsFloat(currentNode, camera.mZNear); XmlParser::getValueAsReal(currentNode, camera.mZNear);
} else if (currentName == "zfar") { } else if (currentName == "zfar") {
XmlParser::getValueAsFloat(currentNode, camera.mZFar); XmlParser::getValueAsReal(currentNode, camera.mZFar);
} }
} }
} }
@ -1170,15 +1170,15 @@ void ColladaParser::ReadSamplerProperties(XmlNode &node, Sampler &out) {
} else if (currentName == "mirrorV") { } else if (currentName == "mirrorV") {
XmlParser::getValueAsBool(currentNode, out.mMirrorV); XmlParser::getValueAsBool(currentNode, out.mMirrorV);
} else if (currentName == "repeatU") { } else if (currentName == "repeatU") {
XmlParser::getValueAsFloat(currentNode, out.mTransform.mScaling.x); XmlParser::getValueAsReal(currentNode, out.mTransform.mScaling.x);
} else if (currentName == "repeatV") { } else if (currentName == "repeatV") {
XmlParser::getValueAsFloat(currentNode, out.mTransform.mScaling.y); XmlParser::getValueAsReal(currentNode, out.mTransform.mScaling.y);
} else if (currentName == "offsetU") { } else if (currentName == "offsetU") {
XmlParser::getValueAsFloat(currentNode, out.mTransform.mTranslation.x); XmlParser::getValueAsReal(currentNode, out.mTransform.mTranslation.x);
} else if (currentName == "offsetV") { } else if (currentName == "offsetV") {
XmlParser::getValueAsFloat(currentNode, out.mTransform.mTranslation.y); XmlParser::getValueAsReal(currentNode, out.mTransform.mTranslation.y);
} else if (currentName == "rotateUV") { } else if (currentName == "rotateUV") {
XmlParser::getValueAsFloat(currentNode, out.mTransform.mRotation); XmlParser::getValueAsReal(currentNode, out.mTransform.mRotation);
} else if (currentName == "blend_mode") { } else if (currentName == "blend_mode") {
std::string v; std::string v;
XmlParser::getValueAsString(currentNode, v); XmlParser::getValueAsString(currentNode, v);
@ -1198,14 +1198,14 @@ void ColladaParser::ReadSamplerProperties(XmlNode &node, Sampler &out) {
// OKINO extensions // OKINO extensions
// ------------------------------------------------------- // -------------------------------------------------------
else if (currentName == "weighting") { else if (currentName == "weighting") {
XmlParser::getValueAsFloat(currentNode, out.mWeighting); XmlParser::getValueAsReal(currentNode, out.mWeighting);
} else if (currentName == "mix_with_previous_layer") { } else if (currentName == "mix_with_previous_layer") {
XmlParser::getValueAsFloat(currentNode, out.mMixWithPrevious); XmlParser::getValueAsReal(currentNode, out.mMixWithPrevious);
} }
// MAX3D extensions // MAX3D extensions
// ------------------------------------------------------- // -------------------------------------------------------
else if (currentName == "amount") { else if (currentName == "amount") {
XmlParser::getValueAsFloat(currentNode, out.mWeighting); XmlParser::getValueAsReal(currentNode, out.mWeighting);
} }
} }
} }
@ -1265,13 +1265,13 @@ void ColladaParser::ReadEffectColor(XmlNode &node, aiColor4D &pColor, Sampler &p
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Reads an effect entry containing a float // Reads an effect entry containing a float
void ColladaParser::ReadEffectFloat(XmlNode &node, ai_real &pFloat) { void ColladaParser::ReadEffectFloat(XmlNode &node, ai_real &pReal) {
pFloat = 0.f; pReal = 0.f;
XmlNode floatNode = node.child("float"); XmlNode floatNode = node.child("float");
if (floatNode.empty()) { if (floatNode.empty()) {
return; return;
} }
XmlParser::getValueAsFloat(floatNode, pFloat); XmlParser::getValueAsReal(floatNode, pReal);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -316,7 +316,7 @@ void OFFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials]; pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials];
aiMaterial *pcMat = new aiMaterial(); aiMaterial *pcMat = new aiMaterial();
aiColor4D clr(ai_real(0.6), ai_real(0.6), ai_real(0.6), ai_real(1.0)); aiColor4D clr(0.6f, 0.6f, 0.6f, 1.0f);
pcMat->AddProperty(&clr, 1, AI_MATKEY_COLOR_DIFFUSE); pcMat->AddProperty(&clr, 1, AI_MATKEY_COLOR_DIFFUSE);
pScene->mMaterials[0] = pcMat; pScene->mMaterials[0] = pcMat;

View File

@ -181,7 +181,7 @@ void STLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
mBuffer = &buffer2[0]; mBuffer = &buffer2[0];
// the default vertex color is light gray. // the default vertex color is light gray.
mClrColorDefault.r = mClrColorDefault.g = mClrColorDefault.b = mClrColorDefault.a = (ai_real)0.6; mClrColorDefault.r = mClrColorDefault.g = mClrColorDefault.b = mClrColorDefault.a = 0.6f;
// allocate a single node // allocate a single node
mScene->mRootNode = new aiNode(); mScene->mRootNode = new aiNode();
@ -209,7 +209,7 @@ void STLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
} }
pcMat->AddProperty(&clrDiffuse, 1, AI_MATKEY_COLOR_DIFFUSE); pcMat->AddProperty(&clrDiffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
pcMat->AddProperty(&clrDiffuse, 1, AI_MATKEY_COLOR_SPECULAR); pcMat->AddProperty(&clrDiffuse, 1, AI_MATKEY_COLOR_SPECULAR);
clrDiffuse = aiColor4D(ai_real(0.05), ai_real(0.05), ai_real(0.05), ai_real(1.0)); clrDiffuse = aiColor4D(0.05f, 0.05f, 0.05f, 1.0f);
pcMat->AddProperty(&clrDiffuse, 1, AI_MATKEY_COLOR_AMBIENT); pcMat->AddProperty(&clrDiffuse, 1, AI_MATKEY_COLOR_AMBIENT);
mScene->mNumMaterials = 1; mScene->mNumMaterials = 1;

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2024, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -61,7 +60,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <functional> #include <functional>
namespace Assimp { namespace Assimp {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// std::plus-family operates on operands with identical types - we need to // std::plus-family operates on operands with identical types - we need to
@ -287,6 +286,10 @@ AI_FORCE_INLINE Vertex operator / (const Vertex& v0,ai_real f) {
return Vertex::BinaryOp<Intern::multiplies>(v0,1.f/f); return Vertex::BinaryOp<Intern::multiplies>(v0,1.f/f);
} }
#ifdef AI_DO
#endif // AI_DO
AI_FORCE_INLINE Vertex operator * (ai_real f,const Vertex& v0) { AI_FORCE_INLINE Vertex operator * (ai_real f,const Vertex& v0) {
return Vertex::BinaryOp<Intern::multiplies>(f,v0); return Vertex::BinaryOp<Intern::multiplies>(f,v0);
} }

View File

@ -211,21 +211,27 @@ public:
/// @return true, if the value can be read out. /// @return true, if the value can be read out.
static inline bool getValueAsString(XmlNode &node, std::string &text); static inline bool getValueAsString(XmlNode &node, std::string &text);
/// @brief Will try to get the value of the node as a real.
/// @param[in] node The node to search in.
/// @param[out] v The value as a ai_real.
/// @return true, if the value can be read out.
static inline bool getValueAsReal(XmlNode &node, ai_real &v);
/// @brief Will try to get the value of the node as a float. /// @brief Will try to get the value of the node as a float.
/// @param[in] node The node to search in. /// @param[in] node The node to search in.
/// @param[out] text The value as a float. /// @param[out]v The value as a float.
/// @return true, if the value can be read out. /// @return true, if the value can be read out.
static inline bool getValueAsFloat(XmlNode &node, ai_real &v); static inline bool getValueAsFloat(XmlNode &node, float &v);
/// @brief Will try to get the value of the node as an integer. /// @brief Will try to get the value of the node as an integer.
/// @param[in] node The node to search in. /// @param[in] node The node to search in.
/// @param[out] text The value as a int. /// @param[out] i The value as a int.
/// @return true, if the value can be read out. /// @return true, if the value can be read out.
static inline bool getValueAsInt(XmlNode &node, int &v); static inline bool getValueAsInt(XmlNode &node, int &v);
/// @brief Will try to get the value of the node as an bool. /// @brief Will try to get the value of the node as an bool.
/// @param[in] node The node to search in. /// @param[in] node The node to search in.
/// @param[out] text The value as a bool. /// @param[out] v The value as a bool.
/// @return true, if the value can be read out. /// @return true, if the value can be read out.
static inline bool getValueAsBool(XmlNode &node, bool &v); static inline bool getValueAsBool(XmlNode &node, bool &v);
@ -454,7 +460,19 @@ inline bool TXmlParser<TNodeType>::getValueAsString(XmlNode &node, std::string &
} }
template <class TNodeType> template <class TNodeType>
inline bool TXmlParser<TNodeType>::getValueAsFloat(XmlNode &node, ai_real &v) { inline bool TXmlParser<TNodeType>::getValueAsReal(XmlNode& node, ai_real& v) {
if (node.empty()) {
return false;
}
v = node.text().as_float();
return true;
}
template <class TNodeType>
inline bool TXmlParser<TNodeType>::getValueAsFloat(XmlNode &node, float &v) {
if (node.empty()) { if (node.empty()) {
return false; return false;
} }