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 "AssetLib/IFC/IFCUtil.h"
|
||||||
#include "Common/PolyTools.h"
|
#include "Common/PolyTools.h"
|
||||||
|
#include "Geometry/GeometryUtils.h"
|
||||||
#include "PostProcessing/ProcessHelper.h"
|
#include "PostProcessing/ProcessHelper.h"
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
@ -235,7 +236,7 @@ IfcVector3 TempMesh::ComputeLastPolygonNormal(bool normalize) const {
|
||||||
struct CompareVector {
|
struct CompareVector {
|
||||||
bool operator () (const IfcVector3& a, const IfcVector3& b) const {
|
bool operator () (const IfcVector3& a, const IfcVector3& b) const {
|
||||||
IfcVector3 d = a - b;
|
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);
|
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
|
Copyright (c) 2006-2022, 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,
|
||||||
|
@ -51,6 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "AssetLib/LWO/LWOLoader.h"
|
#include "AssetLib/LWO/LWOLoader.h"
|
||||||
#include "PostProcessing/ConvertToLHProcess.h"
|
#include "PostProcessing/ConvertToLHProcess.h"
|
||||||
#include "PostProcessing/ProcessHelper.h"
|
#include "PostProcessing/ProcessHelper.h"
|
||||||
|
#include "Geometry/GeometryUtils.h"
|
||||||
|
|
||||||
#include <assimp/ByteSwapper.h>
|
#include <assimp/ByteSwapper.h>
|
||||||
#include <assimp/SGSpatialSort.h>
|
#include <assimp/SGSpatialSort.h>
|
||||||
|
@ -528,7 +527,6 @@ void LWOImporter::ComputeNormals(aiMesh *mesh, const std::vector<unsigned int> &
|
||||||
continue;
|
continue;
|
||||||
vNormals += v;
|
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];
|
const aiVector3D &v = faceNormals[*a];
|
||||||
vNormals += v;
|
vNormals += v;
|
||||||
}
|
}
|
||||||
vNormals.Normalize();
|
|
||||||
for (std::vector<unsigned int>::const_iterator a = poResult.begin(); a != poResult.end(); ++a) {
|
for (std::vector<unsigned int>::const_iterator a = poResult.begin(); a != poResult.end(); ++a) {
|
||||||
mesh->mNormals[*a] = vNormals;
|
mesh->mNormals[*a] = vNormals;
|
||||||
vertexDone[*a] = true;
|
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 {
|
namespace Assimp {
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
ai_real GeometryUtils::heron( ai_real a, ai_real b, ai_real c ) {
|
ai_real GeometryUtils::heron( ai_real a, ai_real b, ai_real c ) {
|
||||||
ai_real s = (a + b + c) / 2;
|
const 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 area = pow((s * ( s - a ) * ( s - b ) * ( s - c ) ), (ai_real)0.5 );
|
||||||
return area;
|
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 lx = ( vB.x - vA.x );
|
||||||
const ai_real ly = ( vB.y - vA.y );
|
const ai_real ly = ( vB.y - vA.y );
|
||||||
const ai_real lz = ( vB.z - vA.z );
|
const ai_real lz = ( vB.z - vA.z );
|
||||||
ai_real a = lx*lx + ly*ly + lz*lz;
|
const ai_real a = lx*lx + ly*ly + lz*lz;
|
||||||
ai_real d = pow( a, (ai_real)0.5 );
|
const ai_real d = pow( a, (ai_real)0.5 );
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
ai_real GeometryUtils::calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh ) {
|
ai_real GeometryUtils::calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh ) {
|
||||||
ai_real area = 0;
|
ai_real area = 0;
|
||||||
|
|
||||||
aiVector3D vA( mesh->mVertices[ face.mIndices[ 0 ] ] );
|
const aiVector3D vA( mesh->mVertices[ face.mIndices[ 0 ] ] );
|
||||||
aiVector3D vB( mesh->mVertices[ face.mIndices[ 1 ] ] );
|
const aiVector3D vB( mesh->mVertices[ face.mIndices[ 1 ] ] );
|
||||||
aiVector3D vC( mesh->mVertices[ face.mIndices[ 2 ] ] );
|
const aiVector3D vC( mesh->mVertices[ face.mIndices[ 2 ] ] );
|
||||||
|
|
||||||
ai_real a( distance3D( vA, vB ) );
|
const ai_real a = distance3D( vA, vB );
|
||||||
ai_real b( distance3D( vB, vC ) );
|
const ai_real b = distance3D( vB, vC );
|
||||||
ai_real c( distance3D( vC, vA ) );
|
const ai_real c = distance3D( vC, vA );
|
||||||
area = heron( a, b, c );
|
area = heron( a, b, c );
|
||||||
|
|
||||||
return area;
|
return area;
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
/// @param vA Vector a.
|
/// @param vA Vector a.
|
||||||
/// @param vB Vector b.
|
/// @param vB Vector b.
|
||||||
/// @return The distance.
|
/// @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.
|
/// @brief Will calculate the area of a triangle described by a aiFace.
|
||||||
/// @param face The face
|
/// @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/DefaultLogger.hpp>
|
||||||
#include <assimp/postprocess.h>
|
#include <assimp/postprocess.h>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <iostream>
|
//#include <iostream>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ void ArmaturePopulate::Execute(aiScene *out) {
|
||||||
BuildBoneList(out->mRootNode, out->mRootNode, out, bones);
|
BuildBoneList(out->mRootNode, out->mRootNode, out, bones);
|
||||||
BuildNodeList(out->mRootNode, nodes);
|
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());
|
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 to have multiple armatures, with the same bone names
|
||||||
// A bone stack allows us also to retrieve bones true transform even with
|
// A bone stack allows us also to retrieve bones true transform even with
|
||||||
// duplicate names :)
|
// duplicate names :)
|
||||||
void ArmaturePopulate::BuildBoneStack(aiNode *,
|
void ArmaturePopulate::BuildBoneStack(const aiNode *root_node,
|
||||||
const aiNode *root_node,
|
|
||||||
const aiScene*,
|
const aiScene*,
|
||||||
const std::vector<aiBone *> &bones,
|
const std::vector<aiBone *> &bones,
|
||||||
std::map<aiBone *, aiNode *> &bone_stack,
|
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
|
// 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
|
// until it cannot find another bone and return the node No known failure
|
||||||
// points. (yet)
|
// points. (yet)
|
||||||
aiNode *ArmaturePopulate::GetArmatureRoot(aiNode *bone_node,
|
aiNode *ArmaturePopulate::GetArmatureRoot(aiNode *bone_node, std::vector<aiBone *> &bone_list) {
|
||||||
std::vector<aiBone *> &bone_list) {
|
|
||||||
while (nullptr != bone_node) {
|
while (nullptr != bone_node) {
|
||||||
if (!IsBoneNode(bone_node->mName, bone_list)) {
|
if (!IsBoneNode(bone_node->mName, bone_list)) {
|
||||||
ASSIMP_LOG_VERBOSE_DEBUG("GetArmatureRoot() Found valid armature: ", bone_node->mName.C_Str());
|
ASSIMP_LOG_VERBOSE_DEBUG("GetArmatureRoot() Found valid armature: ", bone_node->mName.C_Str());
|
||||||
|
|
|
@ -96,7 +96,7 @@ public:
|
||||||
const aiScene *scene,
|
const aiScene *scene,
|
||||||
std::vector<aiBone *> &bones);
|
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 aiScene *scene,
|
||||||
const std::vector<aiBone *> &bones,
|
const std::vector<aiBone *> &bones,
|
||||||
std::map<aiBone *, aiNode *> &bone_stack,
|
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)
|
#define AI_RAD_TO_DEG(x) ((x) * (ai_real) 57.2957795)
|
||||||
|
|
||||||
/* Numerical limits */
|
/* 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 */
|
/* Support for big-endian builds */
|
||||||
#if defined(__BYTE_ORDER__)
|
#if defined(__BYTE_ORDER__)
|
||||||
|
|
Loading…
Reference in New Issue