Refactoring: Cleanup post-processing steps.
parent
7e5a178637
commit
5d841ec9a5
|
@ -397,10 +397,6 @@ struct Material {
|
||||||
|
|
||||||
Material(const Material &other) = default;
|
Material(const Material &other) = default;
|
||||||
|
|
||||||
Material(Material &&other) AI_NO_EXCEPT = default;
|
|
||||||
|
|
||||||
Material &operator=(Material &&other) AI_NO_EXCEPT = default;
|
|
||||||
|
|
||||||
virtual ~Material() = default;
|
virtual ~Material() = default;
|
||||||
|
|
||||||
//! Name of the material
|
//! Name of the material
|
||||||
|
|
|
@ -58,8 +58,6 @@ class X3DExporter {
|
||||||
Value(value) {
|
Value(value) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
SAttribute(SAttribute &&rhs) AI_NO_EXCEPT = default;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/***********************************************/
|
/***********************************************/
|
||||||
|
|
|
@ -76,4 +76,17 @@ ai_real GeometryUtils::calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh
|
||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
// Check whether a ray intersects a plane and find the intersection point
|
||||||
|
bool GeometryUtils::PlaneIntersect(const aiRay& ray, const aiVector3D& planePos,
|
||||||
|
const aiVector3D& planeNormal, aiVector3D& pos) {
|
||||||
|
const ai_real b = planeNormal * (planePos - ray.pos);
|
||||||
|
ai_real h = ray.dir * planeNormal;
|
||||||
|
if ((h < 10e-5 && h > -10e-5) || (h = b/h) < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
pos = ray.pos + (ray.dir * h);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Assimp
|
} // namespace Assimp
|
||||||
|
|
|
@ -62,6 +62,8 @@ public:
|
||||||
/// @param mesh The mesh containing the face
|
/// @param mesh The mesh containing the face
|
||||||
/// @return The area.
|
/// @return The area.
|
||||||
static ai_real calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh );
|
static ai_real calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh );
|
||||||
|
|
||||||
|
static bool PlaneIntersect(const aiRay& ray, const aiVector3D& planePos, const aiVector3D& planeNormal, aiVector3D& pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Assimp
|
} // namespace Assimp
|
||||||
|
|
|
@ -47,11 +47,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
/// The default class constructor.
|
static bool IsBoneNode(const aiString &bone_name, std::vector<aiBone *> &bones) {
|
||||||
ArmaturePopulate::ArmaturePopulate() = default;
|
for (aiBone *bone : bones) {
|
||||||
|
if (bone->mName == bone_name) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The class destructor.
|
return false;
|
||||||
ArmaturePopulate::~ArmaturePopulate() = default;
|
}
|
||||||
|
|
||||||
bool ArmaturePopulate::IsActive(unsigned int pFlags) const {
|
bool ArmaturePopulate::IsActive(unsigned int pFlags) const {
|
||||||
return (pFlags & aiProcess_PopulateArmatureData) != 0;
|
return (pFlags & aiProcess_PopulateArmatureData) != 0;
|
||||||
|
@ -78,9 +82,8 @@ void ArmaturePopulate::Execute(aiScene *out) {
|
||||||
aiBone *bone = kvp.first;
|
aiBone *bone = kvp.first;
|
||||||
aiNode *bone_node = kvp.second;
|
aiNode *bone_node = kvp.second;
|
||||||
ASSIMP_LOG_VERBOSE_DEBUG("active node lookup: ", bone->mName.C_Str());
|
ASSIMP_LOG_VERBOSE_DEBUG("active node lookup: ", bone->mName.C_Str());
|
||||||
// lcl transform grab - done in generate_nodes :)
|
|
||||||
|
|
||||||
// bone->mOffsetMatrix = bone_node->mTransformation;
|
// lcl transform grab - done in generate_nodes :)
|
||||||
aiNode *armature = GetArmatureRoot(bone_node, bones);
|
aiNode *armature = GetArmatureRoot(bone_node, bones);
|
||||||
|
|
||||||
ai_assert(armature);
|
ai_assert(armature);
|
||||||
|
@ -212,18 +215,6 @@ aiNode *ArmaturePopulate::GetArmatureRoot(aiNode *bone_node,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple IsBoneNode check if this could be a bone
|
|
||||||
bool ArmaturePopulate::IsBoneNode(const aiString &bone_name,
|
|
||||||
std::vector<aiBone *> &bones) {
|
|
||||||
for (aiBone *bone : bones) {
|
|
||||||
if (bone->mName == bone_name) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pop this node by name from the stack if found
|
// Pop this node by name from the stack if found
|
||||||
// Used in multiple armature situations with duplicate node / bone names
|
// Used in multiple armature situations with duplicate node / bone names
|
||||||
// Known flaw: cannot have nodes with bone names, will be fixed in later release
|
// Known flaw: cannot have nodes with bone names, will be fixed in later release
|
||||||
|
|
|
@ -69,10 +69,10 @@ namespace Assimp {
|
||||||
class ASSIMP_API ArmaturePopulate : public BaseProcess {
|
class ASSIMP_API ArmaturePopulate : public BaseProcess {
|
||||||
public:
|
public:
|
||||||
/// The default class constructor.
|
/// The default class constructor.
|
||||||
ArmaturePopulate();
|
ArmaturePopulate() = default;
|
||||||
|
|
||||||
/// The class destructor.
|
/// The class destructor.
|
||||||
virtual ~ArmaturePopulate();
|
virtual ~ArmaturePopulate() = default;
|
||||||
|
|
||||||
/// Overwritten, @see BaseProcess
|
/// Overwritten, @see BaseProcess
|
||||||
virtual bool IsActive( unsigned int pFlags ) const;
|
virtual bool IsActive( unsigned int pFlags ) const;
|
||||||
|
@ -86,9 +86,6 @@ public:
|
||||||
static aiNode *GetArmatureRoot(aiNode *bone_node,
|
static aiNode *GetArmatureRoot(aiNode *bone_node,
|
||||||
std::vector<aiBone *> &bone_list);
|
std::vector<aiBone *> &bone_list);
|
||||||
|
|
||||||
static bool IsBoneNode(const aiString &bone_name,
|
|
||||||
std::vector<aiBone *> &bones);
|
|
||||||
|
|
||||||
static aiNode *GetNodeFromStack(const aiString &node_name,
|
static aiNode *GetNodeFromStack(const aiString &node_name,
|
||||||
std::vector<aiNode *> &nodes);
|
std::vector<aiNode *> &nodes);
|
||||||
|
|
||||||
|
@ -108,5 +105,4 @@ public:
|
||||||
|
|
||||||
} // Namespace Assimp
|
} // Namespace Assimp
|
||||||
|
|
||||||
|
|
||||||
#endif // SCALE_PROCESS_H_
|
#endif // SCALE_PROCESS_H_
|
||||||
|
|
|
@ -4,7 +4,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,
|
||||||
|
@ -42,10 +41,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
/** @file GenUVCoords step */
|
/** @file GenUVCoords step */
|
||||||
|
|
||||||
|
|
||||||
#include "ComputeUVMappingProcess.h"
|
#include "ComputeUVMappingProcess.h"
|
||||||
#include "ProcessHelper.h"
|
#include "ProcessHelper.h"
|
||||||
#include <assimp/Exceptional.h>
|
#include <assimp/Exceptional.h>
|
||||||
|
#include "Geometry/GeometryUtils.h"
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
|
@ -59,31 +58,17 @@ namespace {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Returns whether the processing step is present in the given flag field.
|
// Returns whether the processing step is present in the given flag field.
|
||||||
bool ComputeUVMappingProcess::IsActive( unsigned int pFlags) const
|
bool ComputeUVMappingProcess::IsActive( unsigned int pFlags) const {
|
||||||
{
|
|
||||||
return (pFlags & aiProcess_GenUVCoords) != 0;
|
return (pFlags & aiProcess_GenUVCoords) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
// Check whether a ray intersects a plane and find the intersection point
|
|
||||||
inline bool PlaneIntersect(const aiRay& ray, const aiVector3D& planePos,
|
|
||||||
const aiVector3D& planeNormal, aiVector3D& pos)
|
|
||||||
{
|
|
||||||
const ai_real b = planeNormal * (planePos - ray.pos);
|
|
||||||
ai_real h = ray.dir * planeNormal;
|
|
||||||
if ((h < 10e-5 && h > -10e-5) || (h = b/h) < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
pos = ray.pos + (ray.dir * h);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Find the first empty UV channel in a mesh
|
// Find the first empty UV channel in a mesh
|
||||||
inline unsigned int FindEmptyUVChannel (aiMesh* mesh)
|
inline unsigned int FindEmptyUVChannel (aiMesh* mesh) {
|
||||||
{
|
|
||||||
for (unsigned int m = 0; m < AI_MAX_NUMBER_OF_TEXTURECOORDS;++m)
|
for (unsigned int m = 0; m < AI_MAX_NUMBER_OF_TEXTURECOORDS;++m)
|
||||||
if (!mesh->mTextureCoords[m])return m;
|
if (!mesh->mTextureCoords[m]) {
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
ASSIMP_LOG_ERROR("Unable to compute UV coordinates, no free UV slot found");
|
ASSIMP_LOG_ERROR("Unable to compute UV coordinates, no free UV slot found");
|
||||||
return UINT_MAX;
|
return UINT_MAX;
|
||||||
|
@ -91,8 +76,7 @@ inline unsigned int FindEmptyUVChannel (aiMesh* mesh)
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Try to remove UV seams
|
// Try to remove UV seams
|
||||||
void RemoveUVSeams (aiMesh* mesh, aiVector3D* out)
|
void RemoveUVSeams (aiMesh* mesh, aiVector3D* out) {
|
||||||
{
|
|
||||||
// TODO: just a very rough algorithm. I think it could be done
|
// TODO: just a very rough algorithm. I think it could be done
|
||||||
// much easier, but I don't know how and am currently too tired to
|
// much easier, but I don't know how and am currently too tired to
|
||||||
// to think about a better solution.
|
// to think about a better solution.
|
||||||
|
@ -103,10 +87,11 @@ void RemoveUVSeams (aiMesh* mesh, aiVector3D* out)
|
||||||
const static ai_real LOWER_EPSILON = ai_real( 10e-3 );
|
const static ai_real LOWER_EPSILON = ai_real( 10e-3 );
|
||||||
const static ai_real UPPER_EPSILON = ai_real( 1.0-10e-3 );
|
const static ai_real UPPER_EPSILON = ai_real( 1.0-10e-3 );
|
||||||
|
|
||||||
for (unsigned int fidx = 0; fidx < mesh->mNumFaces;++fidx)
|
for (unsigned int fidx = 0; fidx < mesh->mNumFaces;++fidx) {
|
||||||
{
|
|
||||||
const aiFace& face = mesh->mFaces[fidx];
|
const aiFace& face = mesh->mFaces[fidx];
|
||||||
if (face.mNumIndices < 3) continue; // triangles and polygons only, please
|
if (face.mNumIndices < 3) {
|
||||||
|
continue; // triangles and polygons only, please
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int smallV = face.mNumIndices, large = smallV;
|
unsigned int smallV = face.mNumIndices, large = smallV;
|
||||||
bool zero = false, one = false, round_to_zero = false;
|
bool zero = false, one = false, round_to_zero = false;
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -219,13 +217,6 @@ void MakeLeftHandedProcess::ProcessAnimation(aiNodeAnim *pAnim) {
|
||||||
|
|
||||||
// rotation keys
|
// rotation keys
|
||||||
for (unsigned int a = 0; a < pAnim->mNumRotationKeys; a++) {
|
for (unsigned int a = 0; a < pAnim->mNumRotationKeys; a++) {
|
||||||
/* That's the safe version, but the float errors add up. So we try the short version instead
|
|
||||||
aiMatrix3x3 rotmat = pAnim->mRotationKeys[a].mValue.GetMatrix();
|
|
||||||
rotmat.a3 = -rotmat.a3; rotmat.b3 = -rotmat.b3;
|
|
||||||
rotmat.c1 = -rotmat.c1; rotmat.c2 = -rotmat.c2;
|
|
||||||
aiQuaternion rotquat( rotmat);
|
|
||||||
pAnim->mRotationKeys[a].mValue = rotquat;
|
|
||||||
*/
|
|
||||||
pAnim->mRotationKeys[a].mValue.x *= -1.0f;
|
pAnim->mRotationKeys[a].mValue.x *= -1.0f;
|
||||||
pAnim->mRotationKeys[a].mValue.y *= -1.0f;
|
pAnim->mRotationKeys[a].mValue.y *= -1.0f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,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,
|
||||||
|
@ -87,7 +86,7 @@ void DeboneProcess::Execute( aiScene* pScene) {
|
||||||
if(!!mNumBonesCanDoWithout && (!mAllOrNone||mNumBonesCanDoWithout==mNumBones)) {
|
if(!!mNumBonesCanDoWithout && (!mAllOrNone||mNumBonesCanDoWithout==mNumBones)) {
|
||||||
for(unsigned int a = 0; a < pScene->mNumMeshes; a++) {
|
for(unsigned int a = 0; a < pScene->mNumMeshes; a++) {
|
||||||
if(splitList[a]) {
|
if(splitList[a]) {
|
||||||
numSplits++;
|
++numSplits;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,8 +118,8 @@ void DeboneProcess::Execute( aiScene* pScene) {
|
||||||
aiNode *theNode = find ? pScene->mRootNode->FindNode(*find) : nullptr;
|
aiNode *theNode = find ? pScene->mRootNode->FindNode(*find) : nullptr;
|
||||||
std::pair<unsigned int,aiNode*> push_pair(static_cast<unsigned int>(meshes.size()),theNode);
|
std::pair<unsigned int,aiNode*> push_pair(static_cast<unsigned int>(meshes.size()),theNode);
|
||||||
|
|
||||||
mSubMeshIndices[a].push_back(push_pair);
|
mSubMeshIndices[a].emplace_back(push_pair);
|
||||||
meshes.push_back(newMeshes[b].first);
|
meshes.emplace_back(newMeshes[b].first);
|
||||||
|
|
||||||
out+=newMeshes[b].first->mNumBones;
|
out+=newMeshes[b].first->mNumBones;
|
||||||
}
|
}
|
||||||
|
@ -360,9 +359,7 @@ void DeboneProcess::UpdateNode(aiNode* pNode) const {
|
||||||
unsigned int m = static_cast<unsigned int>(pNode->mNumMeshes), n = static_cast<unsigned int>(mSubMeshIndices.size());
|
unsigned int m = static_cast<unsigned int>(pNode->mNumMeshes), n = static_cast<unsigned int>(mSubMeshIndices.size());
|
||||||
|
|
||||||
// first pass, look for meshes which have not moved
|
// first pass, look for meshes which have not moved
|
||||||
|
|
||||||
for(unsigned int a=0;a<m;a++) {
|
for(unsigned int a=0;a<m;a++) {
|
||||||
|
|
||||||
unsigned int srcIndex = pNode->mMeshes[a];
|
unsigned int srcIndex = pNode->mMeshes[a];
|
||||||
const std::vector< std::pair< unsigned int,aiNode* > > &subMeshes = mSubMeshIndices[srcIndex];
|
const std::vector< std::pair< unsigned int,aiNode* > > &subMeshes = mSubMeshIndices[srcIndex];
|
||||||
unsigned int nSubmeshes = static_cast<unsigned int>(subMeshes.size());
|
unsigned int nSubmeshes = static_cast<unsigned int>(subMeshes.size());
|
||||||
|
@ -376,8 +373,7 @@ void DeboneProcess::UpdateNode(aiNode* pNode) const {
|
||||||
|
|
||||||
// second pass, collect deboned meshes
|
// second pass, collect deboned meshes
|
||||||
|
|
||||||
for(unsigned int a=0;a<n;a++)
|
for(unsigned int a=0;a<n;a++) {
|
||||||
{
|
|
||||||
const std::vector< std::pair< unsigned int,aiNode* > > &subMeshes = mSubMeshIndices[a];
|
const std::vector< std::pair< unsigned int,aiNode* > > &subMeshes = mSubMeshIndices[a];
|
||||||
unsigned int nSubmeshes = static_cast<unsigned int>(subMeshes.size());
|
unsigned int nSubmeshes = static_cast<unsigned int>(subMeshes.size());
|
||||||
|
|
||||||
|
|
|
@ -236,8 +236,7 @@ evil_jump_outside:
|
||||||
face_src.mNumIndices = 0;
|
face_src.mNumIndices = 0;
|
||||||
face_src.mIndices = nullptr;
|
face_src.mIndices = nullptr;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Otherwise delete it if we don't need this face
|
// Otherwise delete it if we don't need this face
|
||||||
delete[] face_src.mIndices;
|
delete[] face_src.mIndices;
|
||||||
face_src.mIndices = nullptr;
|
face_src.mIndices = nullptr;
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -74,63 +72,6 @@ inline void ArrayDelete(T **&in, unsigned int &num) {
|
||||||
num = 0;
|
num = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
// Updates the node graph - removes all nodes which have the "remove" flag set and the
|
|
||||||
// "don't remove" flag not set. Nodes with meshes are never deleted.
|
|
||||||
bool UpdateNodeGraph(aiNode* node,std::list<aiNode*>& childsOfParent,bool root)
|
|
||||||
{
|
|
||||||
bool b = false;
|
|
||||||
|
|
||||||
std::list<aiNode*> mine;
|
|
||||||
for (unsigned int i = 0; i < node->mNumChildren;++i)
|
|
||||||
{
|
|
||||||
if(UpdateNodeGraph(node->mChildren[i],mine,false))
|
|
||||||
b = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// somewhat tricky ... mNumMeshes must be originally 0 and MSB2 may not be set,
|
|
||||||
// so we can do a simple comparison against MSB here
|
|
||||||
if (!root && AI_RC_UINT_MSB == node->mNumMeshes )
|
|
||||||
{
|
|
||||||
// this node needs to be removed
|
|
||||||
if(node->mNumChildren)
|
|
||||||
{
|
|
||||||
childsOfParent.insert(childsOfParent.end(),mine.begin(),mine.end());
|
|
||||||
|
|
||||||
// set all children to nullptr to make sure they are not deleted when we delete ourself
|
|
||||||
for (unsigned int i = 0; i < node->mNumChildren;++i)
|
|
||||||
node->mChildren[i] = nullptr;
|
|
||||||
}
|
|
||||||
b = true;
|
|
||||||
delete node;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AI_RC_UNMASK(node->mNumMeshes);
|
|
||||||
childsOfParent.push_back(node);
|
|
||||||
|
|
||||||
if (b)
|
|
||||||
{
|
|
||||||
// reallocate the array of our children here
|
|
||||||
node->mNumChildren = (unsigned int)mine.size();
|
|
||||||
aiNode** const children = new aiNode*[mine.size()];
|
|
||||||
aiNode** ptr = children;
|
|
||||||
|
|
||||||
for (std::list<aiNode*>::iterator it = mine.begin(), end = mine.end();
|
|
||||||
it != end; ++it)
|
|
||||||
{
|
|
||||||
*ptr++ = *it;
|
|
||||||
}
|
|
||||||
delete[] node->mChildren;
|
|
||||||
node->mChildren = children;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Executes the post processing step on the given imported data.
|
// Executes the post processing step on the given imported data.
|
||||||
void RemoveVCProcess::Execute(aiScene *pScene) {
|
void RemoveVCProcess::Execute(aiScene *pScene) {
|
||||||
|
|
|
@ -86,9 +86,9 @@ void ScaleProcess::Execute( aiScene* pScene ) {
|
||||||
return; // nothing to scale
|
return; // nothing to scale
|
||||||
}
|
}
|
||||||
|
|
||||||
ai_assert( mScale != 0 );
|
ai_assert(mScale != 0 );
|
||||||
ai_assert( nullptr != pScene );
|
ai_assert(nullptr != pScene );
|
||||||
ai_assert( nullptr != pScene->mRootNode );
|
ai_assert(nullptr != pScene->mRootNode );
|
||||||
|
|
||||||
if ( nullptr == pScene ) {
|
if ( nullptr == pScene ) {
|
||||||
return;
|
return;
|
||||||
|
@ -140,7 +140,7 @@ void ScaleProcess::Execute( aiScene* pScene ) {
|
||||||
aiMatrix4x4 scaling;
|
aiMatrix4x4 scaling;
|
||||||
aiMatrix4x4::Scaling( aiVector3D(scale), scaling );
|
aiMatrix4x4::Scaling( aiVector3D(scale), scaling );
|
||||||
|
|
||||||
aiMatrix4x4 RotMatrix = aiMatrix4x4 (rotation.GetMatrix());
|
const aiMatrix4x4 RotMatrix = aiMatrix4x4(rotation.GetMatrix());
|
||||||
|
|
||||||
bone->mOffsetMatrix = translation * RotMatrix * scaling;
|
bone->mOffsetMatrix = translation * RotMatrix * scaling;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -54,10 +52,7 @@ using namespace Assimp;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructor to be privately used by Importer
|
// Constructor to be privately used by Importer
|
||||||
SortByPTypeProcess::SortByPTypeProcess() :
|
SortByPTypeProcess::SortByPTypeProcess() : mConfigRemoveMeshes(0) {}
|
||||||
mConfigRemoveMeshes(0) {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Returns whether the processing step is present in the given flag field.
|
// Returns whether the processing step is present in the given flag field.
|
||||||
|
@ -155,7 +150,7 @@ void SortByPTypeProcess::Execute(aiScene *pScene) {
|
||||||
if (1 == num) {
|
if (1 == num) {
|
||||||
if (!(mConfigRemoveMeshes & mesh->mPrimitiveTypes)) {
|
if (!(mConfigRemoveMeshes & mesh->mPrimitiveTypes)) {
|
||||||
*meshIdx = static_cast<unsigned int>(outMeshes.size());
|
*meshIdx = static_cast<unsigned int>(outMeshes.size());
|
||||||
outMeshes.push_back(mesh);
|
outMeshes.emplace_back(mesh);
|
||||||
} else {
|
} else {
|
||||||
delete mesh;
|
delete mesh;
|
||||||
pScene->mMeshes[i] = nullptr;
|
pScene->mMeshes[i] = nullptr;
|
||||||
|
@ -311,21 +306,23 @@ void SortByPTypeProcess::Execute(aiScene *pScene) {
|
||||||
|
|
||||||
if (vert) {
|
if (vert) {
|
||||||
*vert++ = mesh->mVertices[idx];
|
*vert++ = mesh->mVertices[idx];
|
||||||
//mesh->mVertices[idx].x = get_qnan();
|
|
||||||
}
|
}
|
||||||
if (nor) *nor++ = mesh->mNormals[idx];
|
if (nor)
|
||||||
|
*nor++ = mesh->mNormals[idx];
|
||||||
if (tan) {
|
if (tan) {
|
||||||
*tan++ = mesh->mTangents[idx];
|
*tan++ = mesh->mTangents[idx];
|
||||||
*bit++ = mesh->mBitangents[idx];
|
*bit++ = mesh->mBitangents[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int pp = 0; pp < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++pp) {
|
for (unsigned int pp = 0; pp < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++pp) {
|
||||||
if (!uv[pp]) break;
|
if (!uv[pp])
|
||||||
|
break;
|
||||||
*uv[pp]++ = mesh->mTextureCoords[pp][idx];
|
*uv[pp]++ = mesh->mTextureCoords[pp][idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int pp = 0; pp < AI_MAX_NUMBER_OF_COLOR_SETS; ++pp) {
|
for (unsigned int pp = 0; pp < AI_MAX_NUMBER_OF_COLOR_SETS; ++pp) {
|
||||||
if (!cols[pp]) break;
|
if (!cols[pp])
|
||||||
|
break;
|
||||||
*cols[pp]++ = mesh->mColors[pp][idx];
|
*cols[pp]++ = mesh->mColors[pp][idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +348,7 @@ void SortByPTypeProcess::Execute(aiScene *pScene) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pp == mesh->mNumAnimMeshes)
|
if (pp == mesh->mNumAnimMeshes)
|
||||||
amIdx++;
|
++amIdx;
|
||||||
|
|
||||||
in.mIndices[q] = outIdx++;
|
in.mIndices[q] = outIdx++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,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,
|
||||||
|
@ -166,7 +165,7 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
|
||||||
unsigned int numBones = 0;
|
unsigned int numBones = 0;
|
||||||
std::vector<bool> isBoneUsed( pMesh->mNumBones, false);
|
std::vector<bool> isBoneUsed( pMesh->mNumBones, false);
|
||||||
// indices of the faces which are going to go into this submesh
|
// indices of the faces which are going to go into this submesh
|
||||||
std::vector<unsigned int> subMeshFaces;
|
IndexArray subMeshFaces;
|
||||||
subMeshFaces.reserve( pMesh->mNumFaces);
|
subMeshFaces.reserve( pMesh->mNumFaces);
|
||||||
// accumulated vertex count of all the faces in this submesh
|
// accumulated vertex count of all the faces in this submesh
|
||||||
unsigned int numSubMeshVertices = 0;
|
unsigned int numSubMeshVertices = 0;
|
||||||
|
@ -202,7 +201,7 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
|
||||||
for (std::set<unsigned int>::iterator it = newBonesAtCurrentFace.begin(); it != newBonesAtCurrentFace.end(); ++it) {
|
for (std::set<unsigned int>::iterator it = newBonesAtCurrentFace.begin(); it != newBonesAtCurrentFace.end(); ++it) {
|
||||||
if (!isBoneUsed[*it]) {
|
if (!isBoneUsed[*it]) {
|
||||||
isBoneUsed[*it] = true;
|
isBoneUsed[*it] = true;
|
||||||
numBones++;
|
++numBones;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,18 +211,17 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
|
||||||
|
|
||||||
// remember that this face is handled
|
// remember that this face is handled
|
||||||
isFaceHandled[a] = true;
|
isFaceHandled[a] = true;
|
||||||
numFacesHandled++;
|
++numFacesHandled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a new mesh to hold this subset of the source mesh
|
// create a new mesh to hold this subset of the source mesh
|
||||||
aiMesh* newMesh = new aiMesh;
|
aiMesh* newMesh = new aiMesh;
|
||||||
if( pMesh->mName.length > 0 )
|
if( pMesh->mName.length > 0 ) {
|
||||||
{
|
|
||||||
newMesh->mName.Set( format() << pMesh->mName.data << "_sub" << poNewMeshes.size());
|
newMesh->mName.Set( format() << pMesh->mName.data << "_sub" << poNewMeshes.size());
|
||||||
}
|
}
|
||||||
newMesh->mMaterialIndex = pMesh->mMaterialIndex;
|
newMesh->mMaterialIndex = pMesh->mMaterialIndex;
|
||||||
newMesh->mPrimitiveTypes = pMesh->mPrimitiveTypes;
|
newMesh->mPrimitiveTypes = pMesh->mPrimitiveTypes;
|
||||||
poNewMeshes.push_back( newMesh);
|
poNewMeshes.emplace_back( newMesh);
|
||||||
|
|
||||||
// create all the arrays for this mesh if the old mesh contained them
|
// create all the arrays for this mesh if the old mesh contained them
|
||||||
newMesh->mNumVertices = numSubMeshVertices;
|
newMesh->mNumVertices = numSubMeshVertices;
|
||||||
|
@ -251,7 +249,7 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
|
||||||
// and copy over the data, generating faces with linear indices along the way
|
// and copy over the data, generating faces with linear indices along the way
|
||||||
newMesh->mFaces = new aiFace[subMeshFaces.size()];
|
newMesh->mFaces = new aiFace[subMeshFaces.size()];
|
||||||
unsigned int nvi = 0; // next vertex index
|
unsigned int nvi = 0; // next vertex index
|
||||||
std::vector<unsigned int> previousVertexIndices( numSubMeshVertices, std::numeric_limits<unsigned int>::max()); // per new vertex: its index in the source mesh
|
IndexArray previousVertexIndices( numSubMeshVertices, std::numeric_limits<unsigned int>::max()); // per new vertex: its index in the source mesh
|
||||||
for( unsigned int a = 0; a < subMeshFaces.size(); ++a ) {
|
for( unsigned int a = 0; a < subMeshFaces.size(); ++a ) {
|
||||||
const aiFace& srcFace = pMesh->mFaces[subMeshFaces[a]];
|
const aiFace& srcFace = pMesh->mFaces[subMeshFaces[a]];
|
||||||
aiFace& dstFace = newMesh->mFaces[a];
|
aiFace& dstFace = newMesh->mFaces[a];
|
||||||
|
@ -399,10 +397,10 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
|
||||||
void SplitByBoneCountProcess::UpdateNode( aiNode* pNode) const {
|
void SplitByBoneCountProcess::UpdateNode( aiNode* pNode) const {
|
||||||
// rebuild the node's mesh index list
|
// rebuild the node's mesh index list
|
||||||
if( pNode->mNumMeshes == 0 ) {
|
if( pNode->mNumMeshes == 0 ) {
|
||||||
std::vector<unsigned int> newMeshList;
|
IndexArray newMeshList;
|
||||||
for( unsigned int a = 0; a < pNode->mNumMeshes; ++a) {
|
for( unsigned int a = 0; a < pNode->mNumMeshes; ++a) {
|
||||||
unsigned int srcIndex = pNode->mMeshes[a];
|
unsigned int srcIndex = pNode->mMeshes[a];
|
||||||
const std::vector<unsigned int>& replaceMeshes = mSubMeshIndices[srcIndex];
|
const IndexArray& replaceMeshes = mSubMeshIndices[srcIndex];
|
||||||
newMeshList.insert( newMeshList.end(), replaceMeshes.begin(), replaceMeshes.end());
|
newMeshList.insert( newMeshList.end(), replaceMeshes.begin(), replaceMeshes.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,10 @@ public:
|
||||||
/// basing on the Importer's configuration property list.
|
/// basing on the Importer's configuration property list.
|
||||||
virtual void SetupProperties(const Importer* pImp) override;
|
virtual void SetupProperties(const Importer* pImp) override;
|
||||||
|
|
||||||
|
/// @brief Will return the maximal number of bones.
|
||||||
|
/// @return The maximal number of bones.
|
||||||
|
size_t getMaxNumberOfBones() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Executes the post processing step on the given imported data.
|
/// Executes the post processing step on the given imported data.
|
||||||
/// At the moment a process is not supposed to fail.
|
/// At the moment a process is not supposed to fail.
|
||||||
|
@ -90,14 +94,19 @@ protected:
|
||||||
/// Recursively updates the node's mesh list to account for the changed mesh list
|
/// Recursively updates the node's mesh list to account for the changed mesh list
|
||||||
void UpdateNode( aiNode* pNode) const;
|
void UpdateNode( aiNode* pNode) const;
|
||||||
|
|
||||||
public:
|
private:
|
||||||
/// Max bone count. Splitting occurs if a mesh has more than that number of bones.
|
/// Max bone count. Splitting occurs if a mesh has more than that number of bones.
|
||||||
size_t mMaxBoneCount;
|
size_t mMaxBoneCount;
|
||||||
|
|
||||||
/// Per mesh index: Array of indices of the new submeshes.
|
/// Per mesh index: Array of indices of the new submeshes.
|
||||||
std::vector< std::vector<unsigned int> > mSubMeshIndices;
|
using IndexArray = std::vector<unsigned int>;
|
||||||
|
std::vector<IndexArray> mSubMeshIndices;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline size_t SplitByBoneCountProcess::getMaxNumberOfBones() const {
|
||||||
|
return mMaxBoneCount;
|
||||||
|
}
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
||||||
#endif // !!AI_SPLITBYBONECOUNTPROCESS_H_INC
|
#endif // !!AI_SPLITBYBONECOUNTPROCESS_H_INC
|
||||||
|
|
|
@ -105,7 +105,7 @@ class Vertex {
|
||||||
friend Vertex operator * (ai_real, const Vertex&);
|
friend Vertex operator * (ai_real, const Vertex&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Vertex() {}
|
Vertex() = default;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Extract a particular vertex from a mesh and interleave all components */
|
/** Extract a particular vertex from a mesh and interleave all components */
|
||||||
|
|
Loading…
Reference in New Issue