Skip to content

Commit

Permalink
Kimkulling/fix double precision tests (assimp#5660)
Browse files Browse the repository at this point in the history
* Make color single precision

* Fix the unittests for double precision

* Fix merge issues

* Fix issues with Vertex + Color4

* Fix vertex operator, some tests are still red.
  • Loading branch information
kimkulling authored Jul 12, 2024
1 parent 0cb1693 commit 35e4f1b
Show file tree
Hide file tree
Showing 22 changed files with 291 additions and 145 deletions.
5 changes: 2 additions & 3 deletions code/AssetLib/3DS/3DSHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,13 @@ struct Texture {
#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER

// ---------------------------------------------------------------------------
/** Helper structure representing a 3ds material */
struct Material {
//! Default constructor has been deleted
Material() :
mName(),
mDiffuse(ai_real(0.6), ai_real(0.6), ai_real(0.6)),
mDiffuse(0.6f, 0.6f, 0.6f),
mSpecularExponent(ai_real(0.0)),
mShininessStrength(ai_real(1.0)),
mShading(Discreet3DS::Gouraud),
Expand All @@ -385,7 +384,7 @@ struct Material {
//! Constructor with explicit name
explicit Material(const std::string &name) :
mName(name),
mDiffuse(ai_real(0.6), ai_real(0.6), ai_real(0.6)),
mDiffuse(0.6f, 0.6f, 0.6f),
mSpecularExponent(ai_real(0.0)),
mShininessStrength(ai_real(1.0)),
mShading(Discreet3DS::Gouraud),
Expand Down
12 changes: 6 additions & 6 deletions code/AssetLib/AMF/AMFImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,17 +384,17 @@ void AMFImporter::ParseNode_Instance(XmlNode &node) {
for (auto &currentNode : node.children()) {
const std::string &currentName = currentNode.name();
if (currentName == "deltax") {
XmlParser::getValueAsFloat(currentNode, als.Delta.x);
XmlParser::getValueAsReal(currentNode, als.Delta.x);
} else if (currentName == "deltay") {
XmlParser::getValueAsFloat(currentNode, als.Delta.y);
XmlParser::getValueAsReal(currentNode, als.Delta.y);
} else if (currentName == "deltaz") {
XmlParser::getValueAsFloat(currentNode, als.Delta.z);
XmlParser::getValueAsReal(currentNode, als.Delta.z);
} else if (currentName == "rx") {
XmlParser::getValueAsFloat(currentNode, als.Delta.x);
XmlParser::getValueAsReal(currentNode, als.Delta.x);
} else if (currentName == "ry") {
XmlParser::getValueAsFloat(currentNode, als.Delta.y);
XmlParser::getValueAsReal(currentNode, als.Delta.y);
} else if (currentName == "rz") {
XmlParser::getValueAsFloat(currentNode, als.Delta.z);
XmlParser::getValueAsReal(currentNode, als.Delta.z);
}
}
ParseHelper_Node_Exit();
Expand Down
6 changes: 3 additions & 3 deletions code/AssetLib/AMF/AMFImporter_Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ void AMFImporter::ParseNode_Coordinates(XmlNode &node) {
AMFCoordinates &als = *((AMFCoordinates *)ne); // alias for convenience
const std::string &currentName = ai_tolower(currentNode.name());
if (currentName == "x") {
XmlParser::getValueAsFloat(currentNode, als.Coordinate.x);
XmlParser::getValueAsReal(currentNode, als.Coordinate.x);
} else if (currentName == "y") {
XmlParser::getValueAsFloat(currentNode, als.Coordinate.y);
XmlParser::getValueAsReal(currentNode, als.Coordinate.y);
} else if (currentName == "z") {
XmlParser::getValueAsFloat(currentNode, als.Coordinate.z);
XmlParser::getValueAsReal(currentNode, als.Coordinate.z);
}
}
ParseHelper_Node_Exit();
Expand Down
13 changes: 6 additions & 7 deletions code/AssetLib/AMF/AMFImporter_Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,25 @@ void AMFImporter::ParseNode_TexMap(XmlNode &node, const bool pUseOldName) {
const std::string &name = currentNode.name();
if (name == "utex1") {
read_flag[0] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[0].x);
XmlParser::getValueAsReal(node, als.TextureCoordinate[0].x);
} else if (name == "utex2") {
read_flag[1] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[1].x);
XmlParser::getValueAsReal(node, als.TextureCoordinate[1].x);
} else if (name == "utex3") {
read_flag[2] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[2].x);
XmlParser::getValueAsReal(node, als.TextureCoordinate[2].x);
} else if (name == "vtex1") {
read_flag[3] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[0].y);
XmlParser::getValueAsReal(node, als.TextureCoordinate[0].y);
} else if (name == "vtex2") {
read_flag[4] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[1].y);
XmlParser::getValueAsReal(node, als.TextureCoordinate[1].y);
} else if (name == "vtex3") {
read_flag[5] = true;
XmlParser::getValueAsFloat(node, als.TextureCoordinate[2].y);
XmlParser::getValueAsReal(node, als.TextureCoordinate[2].y);
}
}
ParseHelper_Node_Exit();

} else {
for (pugi::xml_attribute &attr : node.attributes()) {
const std::string name = attr.name();
Expand Down
97 changes: 64 additions & 33 deletions code/AssetLib/ASE/ASEParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void Parser::ParseLV1SoftSkinBlock() {
me.first = static_cast<int>(curMesh->mBones.size());
curMesh->mBones.emplace_back(bone);
}
ParseLV4MeshFloat(me.second);
ParseLV4MeshReal(me.second);

// Add the new bone weight to list
vert.mBoneWeights.push_back(me);
Expand Down Expand Up @@ -580,14 +580,14 @@ void Parser::ParseLV2MaterialBlock(ASE::Material &mat) {
}
// material transparency
if (TokenMatch(mFilePtr, "MATERIAL_TRANSPARENCY", 21)) {
ParseLV4MeshFloat(mat.mTransparency);
ParseLV4MeshReal(mat.mTransparency);
mat.mTransparency = ai_real(1.0) - mat.mTransparency;
continue;
}
// material self illumination
if (TokenMatch(mFilePtr, "MATERIAL_SELFILLUM", 18)) {
ai_real f = 0.0;
ParseLV4MeshFloat(f);
ParseLV4MeshReal(f);

mat.mEmissive.r = f;
mat.mEmissive.g = f;
Expand All @@ -596,7 +596,7 @@ void Parser::ParseLV2MaterialBlock(ASE::Material &mat) {
}
// material shininess
if (TokenMatch(mFilePtr, "MATERIAL_SHINE", 14)) {
ParseLV4MeshFloat(mat.mSpecularExponent);
ParseLV4MeshReal(mat.mSpecularExponent);
mat.mSpecularExponent *= 15;
continue;
}
Expand All @@ -607,7 +607,7 @@ void Parser::ParseLV2MaterialBlock(ASE::Material &mat) {
}
// material shininess strength
if (TokenMatch(mFilePtr, "MATERIAL_SHINESTRENGTH", 22)) {
ParseLV4MeshFloat(mat.mShininessStrength);
ParseLV4MeshReal(mat.mShininessStrength);
continue;
}
// diffuse color map
Expand Down Expand Up @@ -731,32 +731,32 @@ void Parser::ParseLV3MapBlock(Texture &map) {
}
// offset on the u axis
if (TokenMatch(mFilePtr, "UVW_U_OFFSET", 12)) {
ParseLV4MeshFloat(map.mOffsetU);
ParseLV4MeshReal(map.mOffsetU);
continue;
}
// offset on the v axis
if (TokenMatch(mFilePtr, "UVW_V_OFFSET", 12)) {
ParseLV4MeshFloat(map.mOffsetV);
ParseLV4MeshReal(map.mOffsetV);
continue;
}
// tiling on the u axis
if (TokenMatch(mFilePtr, "UVW_U_TILING", 12)) {
ParseLV4MeshFloat(map.mScaleU);
ParseLV4MeshReal(map.mScaleU);
continue;
}
// tiling on the v axis
if (TokenMatch(mFilePtr, "UVW_V_TILING", 12)) {
ParseLV4MeshFloat(map.mScaleV);
ParseLV4MeshReal(map.mScaleV);
continue;
}
// rotation around the z-axis
if (TokenMatch(mFilePtr, "UVW_ANGLE", 9)) {
ParseLV4MeshFloat(map.mRotation);
ParseLV4MeshReal(map.mRotation);
continue;
}
// map blending factor
if (TokenMatch(mFilePtr, "MAP_AMOUNT", 10)) {
ParseLV4MeshFloat(map.mTextureBlend);
ParseLV4MeshReal(map.mTextureBlend);
continue;
}
}
Expand Down Expand Up @@ -895,15 +895,15 @@ void Parser::ParseLV2CameraSettingsBlock(ASE::Camera &camera) {
if ('*' == *mFilePtr) {
++mFilePtr;
if (TokenMatch(mFilePtr, "CAMERA_NEAR", 11)) {
ParseLV4MeshFloat(camera.mNear);
ParseLV4MeshReal(camera.mNear);
continue;
}
if (TokenMatch(mFilePtr, "CAMERA_FAR", 10)) {
ParseLV4MeshFloat(camera.mFar);
ParseLV4MeshReal(camera.mFar);
continue;
}
if (TokenMatch(mFilePtr, "CAMERA_FOV", 10)) {
ParseLV4MeshFloat(camera.mFOV);
ParseLV4MeshReal(camera.mFOV);
continue;
}
}
Expand All @@ -922,15 +922,15 @@ void Parser::ParseLV2LightSettingsBlock(ASE::Light &light) {
continue;
}
if (TokenMatch(mFilePtr, "LIGHT_INTENS", 12)) {
ParseLV4MeshFloat(light.mIntensity);
ParseLV4MeshReal(light.mIntensity);
continue;
}
if (TokenMatch(mFilePtr, "LIGHT_HOTSPOT", 13)) {
ParseLV4MeshFloat(light.mAngle);
ParseLV4MeshReal(light.mAngle);
continue;
}
if (TokenMatch(mFilePtr, "LIGHT_FALLOFF", 13)) {
ParseLV4MeshFloat(light.mFalloff);
ParseLV4MeshReal(light.mFalloff);
continue;
}
}
Expand Down Expand Up @@ -1038,7 +1038,7 @@ void Parser::ParseLV3ScaleAnimationBlock(ASE::Animation &anim) {
if (b) {
anim.akeyScaling.emplace_back();
aiVectorKey &key = anim.akeyScaling.back();
ParseLV4MeshFloatTriple(&key.mValue.x, iIndex);
ParseLV4MeshRealTriple(&key.mValue.x, iIndex);
key.mTime = (double)iIndex;
}
}
Expand Down Expand Up @@ -1077,7 +1077,7 @@ void Parser::ParseLV3PosAnimationBlock(ASE::Animation &anim) {
if (b) {
anim.akeyPositions.emplace_back();
aiVectorKey &key = anim.akeyPositions.back();
ParseLV4MeshFloatTriple(&key.mValue.x, iIndex);
ParseLV4MeshRealTriple(&key.mValue.x, iIndex);
key.mTime = (double)iIndex;
}
}
Expand Down Expand Up @@ -1118,8 +1118,8 @@ void Parser::ParseLV3RotAnimationBlock(ASE::Animation &anim) {
aiQuatKey &key = anim.akeyRotations.back();
aiVector3D v;
ai_real f;
ParseLV4MeshFloatTriple(&v.x, iIndex);
ParseLV4MeshFloat(f);
ParseLV4MeshRealTriple(&v.x, iIndex);
ParseLV4MeshReal(f);
key.mTime = (double)iIndex;
key.mValue = aiQuaternion(v, f);
}
Expand Down Expand Up @@ -1163,23 +1163,23 @@ void Parser::ParseLV2NodeTransformBlock(ASE::BaseNode &mesh) {
// fourth row of the transformation matrix - and also the
// only information here that is interesting for targets
if (TokenMatch(mFilePtr, "TM_ROW3", 7)) {
ParseLV4MeshFloatTriple((mode == 1 ? mesh.mTransform[3] : &mesh.mTargetPosition.x));
ParseLV4MeshRealTriple((mode == 1 ? mesh.mTransform[3] : &mesh.mTargetPosition.x));
continue;
}
if (mode == 1) {
// first row of the transformation matrix
if (TokenMatch(mFilePtr, "TM_ROW0", 7)) {
ParseLV4MeshFloatTriple(mesh.mTransform[0]);
ParseLV4MeshRealTriple(mesh.mTransform[0]);
continue;
}
// second row of the transformation matrix
if (TokenMatch(mFilePtr, "TM_ROW1", 7)) {
ParseLV4MeshFloatTriple(mesh.mTransform[1]);
ParseLV4MeshRealTriple(mesh.mTransform[1]);
continue;
}
// third row of the transformation matrix
if (TokenMatch(mFilePtr, "TM_ROW2", 7)) {
ParseLV4MeshFloatTriple(mesh.mTransform[2]);
ParseLV4MeshRealTriple(mesh.mTransform[2]);
continue;
}
// inherited position axes
Expand Down Expand Up @@ -1414,7 +1414,7 @@ void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices, ASE::Mesh &mes

// --- ignored
ai_real afVert[3];
ParseLV4MeshFloatTriple(afVert);
ParseLV4MeshRealTriple(afVert);

std::pair<int, float> pairOut;
while (true) {
Expand Down Expand Up @@ -1453,7 +1453,7 @@ void Parser::ParseLV3MeshVertexListBlock(

aiVector3D vTemp;
unsigned int iIndex;
ParseLV4MeshFloatTriple(&vTemp.x, iIndex);
ParseLV4MeshRealTriple(&vTemp.x, iIndex);

if (iIndex >= iNumVertices) {
LogWarning("Invalid vertex index. It will be ignored");
Expand Down Expand Up @@ -1506,7 +1506,7 @@ void Parser::ParseLV3MeshTListBlock(unsigned int iNumVertices,
if (TokenMatch(mFilePtr, "MESH_TVERT", 10)) {
aiVector3D vTemp;
unsigned int iIndex;
ParseLV4MeshFloatTriple(&vTemp.x, iIndex);
ParseLV4MeshRealTriple(&vTemp.x, iIndex);

if (iIndex >= iNumVertices) {
LogWarning("Tvertex has an invalid index. It will be ignored");
Expand Down Expand Up @@ -1657,7 +1657,7 @@ void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh &sMesh) {
++mFilePtr;
if (faceIdx != UINT_MAX && TokenMatch(mFilePtr, "MESH_VERTEXNORMAL", 17)) {
aiVector3D vNormal;
ParseLV4MeshFloatTriple(&vNormal.x, index);
ParseLV4MeshRealTriple(&vNormal.x, index);
if (faceIdx >= sMesh.mFaces.size())
continue;

Expand All @@ -1679,7 +1679,7 @@ void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh &sMesh) {
}
if (TokenMatch(mFilePtr, "MESH_FACENORMAL", 15)) {
aiVector3D vNormal;
ParseLV4MeshFloatTriple(&vNormal.x, faceIdx);
ParseLV4MeshRealTriple(&vNormal.x, faceIdx);

if (faceIdx >= sMesh.mFaces.size()) {
ASSIMP_LOG_ERROR("ASE: Invalid vertex index in MESH_FACENORMAL section");
Expand Down Expand Up @@ -1844,7 +1844,17 @@ void Parser::ParseLV4MeshLongTriple(unsigned int *apOut, unsigned int &rIndexOut
ParseLV4MeshLongTriple(apOut);
}
// ------------------------------------------------------------------------------------------------
void Parser::ParseLV4MeshFloatTriple(ai_real *apOut, unsigned int &rIndexOut) {
void Parser::ParseLV4MeshRealTriple(ai_real *apOut, unsigned int &rIndexOut) {
ai_assert(nullptr != apOut);

// parse the index
ParseLV4MeshLong(rIndexOut);

// parse the three others
ParseLV4MeshRealTriple(apOut);
}
// ------------------------------------------------------------------------------------------------
void Parser::ParseLV4MeshFloatTriple(float* apOut, unsigned int& rIndexOut) {
ai_assert(nullptr != apOut);

// parse the index
Expand All @@ -1854,15 +1864,23 @@ void Parser::ParseLV4MeshFloatTriple(ai_real *apOut, unsigned int &rIndexOut) {
ParseLV4MeshFloatTriple(apOut);
}
// ------------------------------------------------------------------------------------------------
void Parser::ParseLV4MeshFloatTriple(ai_real *apOut) {
void Parser::ParseLV4MeshRealTriple(ai_real *apOut) {
ai_assert(nullptr != apOut);

for (unsigned int i = 0; i < 3; ++i) {
ParseLV4MeshReal(apOut[i]);
}
}
// ------------------------------------------------------------------------------------------------
void Parser::ParseLV4MeshFloatTriple(float* apOut) {
ai_assert(nullptr != apOut);

for (unsigned int i = 0; i < 3; ++i) {
ParseLV4MeshFloat(apOut[i]);
}
}
// ------------------------------------------------------------------------------------------------
void Parser::ParseLV4MeshFloat(ai_real &fOut) {
void Parser::ParseLV4MeshReal(ai_real &fOut) {
// skip spaces and tabs
if (!SkipSpaces(&mFilePtr, mEnd)) {
// LOG
Expand All @@ -1875,6 +1893,19 @@ void Parser::ParseLV4MeshFloat(ai_real &fOut) {
mFilePtr = fast_atoreal_move<ai_real>(mFilePtr, fOut);
}
// ------------------------------------------------------------------------------------------------
void Parser::ParseLV4MeshFloat(float &fOut) {
// skip spaces and tabs
if (!SkipSpaces(&mFilePtr, mEnd)) {
// LOG
LogWarning("Unable to parse float: unexpected EOL [#1]");
fOut = 0.0;
++iLineNumber;
return;
}
// parse the first float
mFilePtr = fast_atoreal_move<float>(mFilePtr, fOut);
}
// ------------------------------------------------------------------------------------------------
void Parser::ParseLV4MeshLong(unsigned int &iOut) {
// Skip spaces and tabs
if (!SkipSpaces(&mFilePtr, mEnd)) {
Expand Down
Loading

0 comments on commit 35e4f1b

Please sign in to comment.