Reafctoring: Add GeoUtils usage
parent
167d811ff7
commit
75d024c91b
|
@ -48,6 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "AssetLib/IFC/IFCUtil.h"
|
||||
#include "Common/PolyTools.h"
|
||||
#include "Geometry/GeometryUtils.h"
|
||||
#include "PostProcessing/ProcessHelper.h"
|
||||
|
||||
namespace Assimp {
|
||||
|
@ -235,7 +236,7 @@ IfcVector3 TempMesh::ComputeLastPolygonNormal(bool normalize) const {
|
|||
struct CompareVector {
|
||||
bool operator () (const IfcVector3& a, const IfcVector3& b) const {
|
||||
IfcVector3 d = a - b;
|
||||
IfcFloat eps = ai_epsilon;
|
||||
constexpr IfcFloat eps = ai_epsilon;
|
||||
return d.x < -eps || (std::abs(d.x) < eps && d.y < -eps) || (std::abs(d.x) < eps && std::abs(d.y) < eps && d.z < -eps);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
|||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
@ -51,6 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "AssetLib/LWO/LWOLoader.h"
|
||||
#include "PostProcessing/ConvertToLHProcess.h"
|
||||
#include "PostProcessing/ProcessHelper.h"
|
||||
#include "Geometry/GeometryUtils.h"
|
||||
|
||||
#include <assimp/ByteSwapper.h>
|
||||
#include <assimp/SGSpatialSort.h>
|
||||
|
@ -528,7 +527,6 @@ void LWOImporter::ComputeNormals(aiMesh *mesh, const std::vector<unsigned int> &
|
|||
continue;
|
||||
vNormals += v;
|
||||
}
|
||||
mesh->mNormals[idx] = vNormals.Normalize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -549,7 +547,6 @@ void LWOImporter::ComputeNormals(aiMesh *mesh, const std::vector<unsigned int> &
|
|||
const aiVector3D &v = faceNormals[*a];
|
||||
vNormals += v;
|
||||
}
|
||||
vNormals.Normalize();
|
||||
for (std::vector<unsigned int>::const_iterator a = poResult.begin(); a != poResult.end(); ++a) {
|
||||
mesh->mNormals[*a] = vNormals;
|
||||
vertexDone[*a] = true;
|
||||
|
@ -557,6 +554,7 @@ void LWOImporter::ComputeNormals(aiMesh *mesh, const std::vector<unsigned int> &
|
|||
}
|
||||
}
|
||||
}
|
||||
GeometryUtils::normalizeVectorArray(mesh->mNormals, mesh->mNormals, mesh->mNumVertices);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -45,32 +45,35 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace Assimp {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ai_real GeometryUtils::heron( ai_real a, ai_real b, ai_real c ) {
|
||||
ai_real s = (a + b + c) / 2;
|
||||
ai_real area = pow((s * ( s - a ) * ( s - b ) * ( s - c ) ), (ai_real)0.5 );
|
||||
const ai_real s = (a + b + c) / 2;
|
||||
const ai_real area = pow((s * ( s - a ) * ( s - b ) * ( s - c ) ), (ai_real)0.5 );
|
||||
return area;
|
||||
}
|
||||
|
||||
ai_real GeometryUtils::distance3D( const aiVector3D &vA, aiVector3D &vB ) {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ai_real GeometryUtils::distance3D( const aiVector3D &vA, const aiVector3D &vB ) {
|
||||
const ai_real lx = ( vB.x - vA.x );
|
||||
const ai_real ly = ( vB.y - vA.y );
|
||||
const ai_real lz = ( vB.z - vA.z );
|
||||
ai_real a = lx*lx + ly*ly + lz*lz;
|
||||
ai_real d = pow( a, (ai_real)0.5 );
|
||||
const ai_real a = lx*lx + ly*ly + lz*lz;
|
||||
const ai_real d = pow( a, (ai_real)0.5 );
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ai_real GeometryUtils::calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh ) {
|
||||
ai_real area = 0;
|
||||
|
||||
aiVector3D vA( mesh->mVertices[ face.mIndices[ 0 ] ] );
|
||||
aiVector3D vB( mesh->mVertices[ face.mIndices[ 1 ] ] );
|
||||
aiVector3D vC( mesh->mVertices[ face.mIndices[ 2 ] ] );
|
||||
const aiVector3D vA( mesh->mVertices[ face.mIndices[ 0 ] ] );
|
||||
const aiVector3D vB( mesh->mVertices[ face.mIndices[ 1 ] ] );
|
||||
const aiVector3D vC( mesh->mVertices[ face.mIndices[ 2 ] ] );
|
||||
|
||||
ai_real a( distance3D( vA, vB ) );
|
||||
ai_real b( distance3D( vB, vC ) );
|
||||
ai_real c( distance3D( vC, vA ) );
|
||||
const ai_real a = distance3D( vA, vB );
|
||||
const ai_real b = distance3D( vB, vC );
|
||||
const ai_real c = distance3D( vC, vA );
|
||||
area = heron( a, b, c );
|
||||
|
||||
return area;
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
/// @param vA Vector a.
|
||||
/// @param vB Vector b.
|
||||
/// @return The distance.
|
||||
static ai_real distance3D( const aiVector3D &vA, aiVector3D &vB );
|
||||
static ai_real distance3D( const aiVector3D &vA, const aiVector3D &vB );
|
||||
|
||||
/// @brief Will calculate the area of a triangle described by a aiFace.
|
||||
/// @param face The face
|
||||
|
|
|
@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <iostream>
|
||||
//#include <iostream>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
|
@ -74,7 +74,7 @@ void ArmaturePopulate::Execute(aiScene *out) {
|
|||
BuildBoneList(out->mRootNode, out->mRootNode, out, bones);
|
||||
BuildNodeList(out->mRootNode, nodes);
|
||||
|
||||
BuildBoneStack(out->mRootNode, out->mRootNode, out, bones, bone_stack, nodes);
|
||||
BuildBoneStack(out->mRootNode, out, bones, bone_stack, nodes);
|
||||
|
||||
ASSIMP_LOG_DEBUG("Bone stack size: ", bone_stack.size());
|
||||
|
||||
|
@ -162,8 +162,7 @@ void ArmaturePopulate::BuildNodeList(const aiNode *current_node,
|
|||
// A bone stack allows us to have multiple armatures, with the same bone names
|
||||
// A bone stack allows us also to retrieve bones true transform even with
|
||||
// duplicate names :)
|
||||
void ArmaturePopulate::BuildBoneStack(aiNode *,
|
||||
const aiNode *root_node,
|
||||
void ArmaturePopulate::BuildBoneStack(const aiNode *root_node,
|
||||
const aiScene*,
|
||||
const std::vector<aiBone *> &bones,
|
||||
std::map<aiBone *, aiNode *> &bone_stack,
|
||||
|
@ -199,8 +198,7 @@ void ArmaturePopulate::BuildBoneStack(aiNode *,
|
|||
// This is required to be detected for a bone initially, it will recurse up
|
||||
// until it cannot find another bone and return the node No known failure
|
||||
// points. (yet)
|
||||
aiNode *ArmaturePopulate::GetArmatureRoot(aiNode *bone_node,
|
||||
std::vector<aiBone *> &bone_list) {
|
||||
aiNode *ArmaturePopulate::GetArmatureRoot(aiNode *bone_node, std::vector<aiBone *> &bone_list) {
|
||||
while (nullptr != bone_node) {
|
||||
if (!IsBoneNode(bone_node->mName, bone_list)) {
|
||||
ASSIMP_LOG_VERBOSE_DEBUG("GetArmatureRoot() Found valid armature: ", bone_node->mName.C_Str());
|
||||
|
|
|
@ -96,7 +96,7 @@ public:
|
|||
const aiScene *scene,
|
||||
std::vector<aiBone *> &bones);
|
||||
|
||||
static void BuildBoneStack(aiNode *current_node, const aiNode *root_node,
|
||||
static void BuildBoneStack(const aiNode *root_node,
|
||||
const aiScene *scene,
|
||||
const std::vector<aiBone *> &bones,
|
||||
std::map<aiBone *, aiNode *> &bone_stack,
|
||||
|
|
|
@ -283,7 +283,11 @@ typedef unsigned int ai_uint;
|
|||
#define AI_RAD_TO_DEG(x) ((x) * (ai_real) 57.2957795)
|
||||
|
||||
/* Numerical limits */
|
||||
static const ai_real ai_epsilon = (ai_real) 1e-6;
|
||||
#ifdef __cplusplus
|
||||
constexpr ai_real ai_epsilon = (ai_real) 1e-6;
|
||||
#else
|
||||
const ai_real ai_epsilon = (ai_real) 1e-6;
|
||||
#endif
|
||||
|
||||
/* Support for big-endian builds */
|
||||
#if defined(__BYTE_ORDER__)
|
||||
|
|
Loading…
Reference in New Issue