2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2024-02-23 21:30:05 +00:00
|
|
|
Copyright (c) 2006-2024, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
2015-05-19 03:48:29 +00:00
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// @file ProcessHelper.cpp
|
|
|
|
/** Implement shared utility functions for postprocessing steps */
|
|
|
|
|
|
|
|
#include "ProcessHelper.h"
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
namespace Assimp {
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ConvertListToStrings(const std::string &in, std::list<std::string> &out) {
|
|
|
|
const char *s = in.c_str();
|
2024-01-30 13:32:41 +00:00
|
|
|
const char *end = in.c_str() + in.size();
|
2015-05-19 03:57:13 +00:00
|
|
|
while (*s) {
|
2024-01-30 13:32:41 +00:00
|
|
|
SkipSpacesAndLineEnd(&s, end);
|
2015-05-19 03:57:13 +00:00
|
|
|
if (*s == '\'') {
|
2020-06-23 19:05:42 +00:00
|
|
|
const char *base = ++s;
|
2015-05-19 03:57:13 +00:00
|
|
|
while (*s != '\'') {
|
|
|
|
++s;
|
|
|
|
if (*s == '\0') {
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_ERROR("ConvertListToString: String list is ill-formatted");
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-08-23 15:41:49 +00:00
|
|
|
out.emplace_back(base, (size_t)(s - base));
|
2015-05-19 03:57:13 +00:00
|
|
|
++s;
|
2020-06-23 19:05:42 +00:00
|
|
|
} else {
|
2024-01-30 13:32:41 +00:00
|
|
|
out.push_back(GetNextToken(s, end));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void FindAABBTransformed(const aiMesh *mesh, aiVector3D &min, aiVector3D &max,
|
|
|
|
const aiMatrix4x4 &m) {
|
|
|
|
min = aiVector3D(ai_real(10e10), ai_real(10e10), ai_real(10e10));
|
|
|
|
max = aiVector3D(ai_real(-10e10), ai_real(-10e10), ai_real(-10e10));
|
|
|
|
for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
const aiVector3D v = m * mesh->mVertices[i];
|
2020-06-23 19:05:42 +00:00
|
|
|
min = std::min(v, min);
|
|
|
|
max = std::max(v, max);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void FindMeshCenter(aiMesh *mesh, aiVector3D &out, aiVector3D &min, aiVector3D &max) {
|
|
|
|
ArrayBounds(mesh->mVertices, mesh->mNumVertices, min, max);
|
|
|
|
out = min + (max - min) * (ai_real)0.5;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void FindSceneCenter(aiScene *scene, aiVector3D &out, aiVector3D &min, aiVector3D &max) {
|
|
|
|
if (nullptr == scene) {
|
2015-12-30 18:43:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (0 == scene->mNumMeshes) {
|
2015-12-30 18:43:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
FindMeshCenter(scene->mMeshes[0], out, min, max);
|
2015-12-30 18:43:57 +00:00
|
|
|
for (unsigned int i = 1; i < scene->mNumMeshes; ++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiVector3D tout, tmin, tmax;
|
|
|
|
FindMeshCenter(scene->mMeshes[i], tout, tmin, tmax);
|
|
|
|
if (min[0] > tmin[0]) min[0] = tmin[0];
|
|
|
|
if (min[1] > tmin[1]) min[1] = tmin[1];
|
|
|
|
if (min[2] > tmin[2]) min[2] = tmin[2];
|
|
|
|
if (max[0] < tmax[0]) max[0] = tmax[0];
|
|
|
|
if (max[1] < tmax[1]) max[1] = tmax[1];
|
|
|
|
if (max[2] < tmax[2]) max[2] = tmax[2];
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
out = min + (max - min) * (ai_real)0.5;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void FindMeshCenterTransformed(aiMesh *mesh, aiVector3D &out, aiVector3D &min,
|
|
|
|
aiVector3D &max, const aiMatrix4x4 &m) {
|
|
|
|
FindAABBTransformed(mesh, min, max, m);
|
|
|
|
out = min + (max - min) * (ai_real)0.5;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void FindMeshCenter(aiMesh *mesh, aiVector3D &out) {
|
|
|
|
aiVector3D min, max;
|
|
|
|
FindMeshCenter(mesh, out, min, max);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void FindMeshCenterTransformed(aiMesh *mesh, aiVector3D &out,
|
|
|
|
const aiMatrix4x4 &m) {
|
|
|
|
aiVector3D min, max;
|
|
|
|
FindMeshCenterTransformed(mesh, out, min, max, m);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
ai_real ComputePositionEpsilon(const aiMesh *pMesh) {
|
|
|
|
const ai_real epsilon = ai_real(1e-4);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// calculate the position bounds so we have a reliable epsilon to check position differences against
|
|
|
|
aiVector3D minVec, maxVec;
|
2020-06-23 19:05:42 +00:00
|
|
|
ArrayBounds(pMesh->mVertices, pMesh->mNumVertices, minVec, maxVec);
|
2015-05-19 03:57:13 +00:00
|
|
|
return (maxVec - minVec).Length() * epsilon;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
ai_real ComputePositionEpsilon(const aiMesh *const *pMeshes, size_t num) {
|
|
|
|
ai_assert(nullptr != pMeshes);
|
2015-12-30 18:43:57 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
const ai_real epsilon = ai_real(1e-4);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// calculate the position bounds so we have a reliable epsilon to check position differences against
|
|
|
|
aiVector3D minVec, maxVec, mi, ma;
|
2020-06-23 19:05:42 +00:00
|
|
|
MinMaxChooser<aiVector3D>()(minVec, maxVec);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
for (size_t a = 0; a < num; ++a) {
|
2020-06-23 19:05:42 +00:00
|
|
|
const aiMesh *pMesh = pMeshes[a];
|
|
|
|
ArrayBounds(pMesh->mVertices, pMesh->mNumVertices, mi, ma);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
minVec = std::min(minVec, mi);
|
|
|
|
maxVec = std::max(maxVec, ma);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return (maxVec - minVec).Length() * epsilon;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
unsigned int GetMeshVFormatUnique(const aiMesh *pcMesh) {
|
|
|
|
ai_assert(nullptr != pcMesh);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// FIX: the hash may never be 0. Otherwise a comparison against
|
|
|
|
// nullptr could be successful
|
|
|
|
unsigned int iRet = 1;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// normals
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pcMesh->HasNormals()) iRet |= 0x2;
|
2015-05-19 03:57:13 +00:00
|
|
|
// tangents and bitangents
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pcMesh->HasTangentsAndBitangents()) iRet |= 0x4;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2023-05-03 22:00:52 +00:00
|
|
|
|
|
|
|
static_assert(8 >= AI_MAX_NUMBER_OF_COLOR_SETS);
|
|
|
|
static_assert(8 >= AI_MAX_NUMBER_OF_TEXTURECOORDS);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// texture coordinates
|
|
|
|
unsigned int p = 0;
|
2020-06-23 19:05:42 +00:00
|
|
|
while (pcMesh->HasTextureCoords(p)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
iRet |= (0x100 << p);
|
|
|
|
if (3 == pcMesh->mNumUVComponents[p])
|
|
|
|
iRet |= (0x10000 << p);
|
|
|
|
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
// vertex colors
|
|
|
|
p = 0;
|
2020-06-23 19:05:42 +00:00
|
|
|
while (pcMesh->HasVertexColors(p))
|
|
|
|
iRet |= (0x1000000 << p++);
|
2015-05-19 03:57:13 +00:00
|
|
|
return iRet;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
VertexWeightTable *ComputeVertexBoneWeightTable(const aiMesh *pMesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
if (!pMesh || !pMesh->mNumVertices || !pMesh->mNumBones) {
|
2020-06-23 19:05:42 +00:00
|
|
|
return nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
VertexWeightTable *avPerVertexWeights = new VertexWeightTable[pMesh->mNumVertices];
|
|
|
|
for (unsigned int i = 0; i < pMesh->mNumBones; ++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
aiBone *bone = pMesh->mBones[i];
|
|
|
|
for (unsigned int a = 0; a < bone->mNumWeights; ++a) {
|
|
|
|
const aiVertexWeight &weight = bone->mWeights[a];
|
2022-09-02 15:20:02 +00:00
|
|
|
avPerVertexWeights[weight.mVertexId].emplace_back(i, weight.mWeight);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return avPerVertexWeights;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
const char *MappingTypeToString(aiTextureMapping in) {
|
|
|
|
switch (in) {
|
2015-05-19 03:57:13 +00:00
|
|
|
case aiTextureMapping_UV:
|
|
|
|
return "UV";
|
|
|
|
case aiTextureMapping_BOX:
|
|
|
|
return "Box";
|
|
|
|
case aiTextureMapping_SPHERE:
|
|
|
|
return "Sphere";
|
|
|
|
case aiTextureMapping_CYLINDER:
|
|
|
|
return "Cylinder";
|
|
|
|
case aiTextureMapping_PLANE:
|
|
|
|
return "Plane";
|
|
|
|
case aiTextureMapping_OTHER:
|
|
|
|
return "Other";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ai_assert(false);
|
2020-06-23 19:05:42 +00:00
|
|
|
return "BUG";
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
aiMesh *MakeSubmesh(const aiMesh *pMesh, const std::vector<unsigned int> &subMeshFaces, unsigned int subFlags) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiMesh *oMesh = new aiMesh();
|
2020-06-23 19:05:42 +00:00
|
|
|
std::vector<unsigned int> vMap(pMesh->mNumVertices, UINT_MAX);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
size_t numSubVerts = 0;
|
|
|
|
size_t numSubFaces = subMeshFaces.size();
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < numSubFaces; i++) {
|
2015-05-19 03:57:13 +00:00
|
|
|
const aiFace &f = pMesh->mFaces[subMeshFaces[i]];
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int j = 0; j < f.mNumIndices; j++) {
|
|
|
|
if (vMap[f.mIndices[j]] == UINT_MAX) {
|
2016-11-20 02:18:11 +00:00
|
|
|
vMap[f.mIndices[j]] = static_cast<unsigned int>(numSubVerts++);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
oMesh->mName = pMesh->mName;
|
|
|
|
|
|
|
|
oMesh->mMaterialIndex = pMesh->mMaterialIndex;
|
|
|
|
oMesh->mPrimitiveTypes = pMesh->mPrimitiveTypes;
|
|
|
|
|
|
|
|
// create all the arrays for this mesh if the old mesh contained them
|
|
|
|
|
2016-11-20 02:18:11 +00:00
|
|
|
oMesh->mNumFaces = static_cast<unsigned int>(subMeshFaces.size());
|
|
|
|
oMesh->mNumVertices = static_cast<unsigned int>(numSubVerts);
|
2015-05-19 03:57:13 +00:00
|
|
|
oMesh->mVertices = new aiVector3D[numSubVerts];
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pMesh->HasNormals()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
oMesh->mNormals = new aiVector3D[numSubVerts];
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pMesh->HasTangentsAndBitangents()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
oMesh->mTangents = new aiVector3D[numSubVerts];
|
|
|
|
oMesh->mBitangents = new aiVector3D[numSubVerts];
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (size_t a = 0; pMesh->HasTextureCoords(static_cast<unsigned int>(a)); ++a) {
|
2015-05-19 03:57:13 +00:00
|
|
|
oMesh->mTextureCoords[a] = new aiVector3D[numSubVerts];
|
|
|
|
oMesh->mNumUVComponents[a] = pMesh->mNumUVComponents[a];
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (size_t a = 0; pMesh->HasVertexColors(static_cast<unsigned int>(a)); ++a) {
|
2015-05-19 03:57:13 +00:00
|
|
|
oMesh->mColors[a] = new aiColor4D[numSubVerts];
|
|
|
|
}
|
|
|
|
|
|
|
|
// and copy over the data, generating faces with linear indices along the way
|
|
|
|
oMesh->mFaces = new aiFace[numSubFaces];
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < numSubFaces; ++a) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
const aiFace &srcFace = pMesh->mFaces[subMeshFaces[a]];
|
|
|
|
aiFace &dstFace = oMesh->mFaces[a];
|
2015-05-19 03:57:13 +00:00
|
|
|
dstFace.mNumIndices = srcFace.mNumIndices;
|
|
|
|
dstFace.mIndices = new unsigned int[dstFace.mNumIndices];
|
|
|
|
|
|
|
|
// accumulate linearly all the vertices of the source face
|
2020-06-23 19:05:42 +00:00
|
|
|
for (size_t b = 0; b < dstFace.mNumIndices; ++b) {
|
2015-05-19 03:57:13 +00:00
|
|
|
dstFace.mIndices[b] = vMap[srcFace.mIndices[b]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int srcIndex = 0; srcIndex < pMesh->mNumVertices; ++srcIndex) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int nvi = vMap[srcIndex];
|
2020-06-23 19:05:42 +00:00
|
|
|
if (nvi == UINT_MAX) {
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
oMesh->mVertices[nvi] = pMesh->mVertices[srcIndex];
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pMesh->HasNormals()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
oMesh->mNormals[nvi] = pMesh->mNormals[srcIndex];
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pMesh->HasTangentsAndBitangents()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
oMesh->mTangents[nvi] = pMesh->mTangents[srcIndex];
|
|
|
|
oMesh->mBitangents[nvi] = pMesh->mBitangents[srcIndex];
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
for (size_t c = 0, cc = pMesh->GetNumUVChannels(); c < cc; ++c) {
|
|
|
|
oMesh->mTextureCoords[c][nvi] = pMesh->mTextureCoords[c][srcIndex];
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
for (size_t c = 0, cc = pMesh->GetNumColorChannels(); c < cc; ++c) {
|
2015-05-19 03:57:13 +00:00
|
|
|
oMesh->mColors[c][nvi] = pMesh->mColors[c][srcIndex];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (~subFlags & AI_SUBMESH_FLAGS_SANS_BONES) {
|
|
|
|
std::vector<unsigned int> subBones(pMesh->mNumBones, 0);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < pMesh->mNumBones; ++a) {
|
|
|
|
const aiBone *bone = pMesh->mBones[a];
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int b = 0; b < bone->mNumWeights; b++) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int v = vMap[bone->mWeights[b].mVertexId];
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (v != UINT_MAX) {
|
2015-05-19 03:57:13 +00:00
|
|
|
subBones[a]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < pMesh->mNumBones; ++a) {
|
|
|
|
if (subBones[a] > 0) {
|
2015-05-19 03:57:13 +00:00
|
|
|
oMesh->mNumBones++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (oMesh->mNumBones) {
|
|
|
|
oMesh->mBones = new aiBone *[oMesh->mNumBones]();
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int nbParanoia = oMesh->mNumBones;
|
|
|
|
|
|
|
|
oMesh->mNumBones = 0; //rewind
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < pMesh->mNumBones; ++a) {
|
|
|
|
if (subBones[a] == 0) {
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
aiBone *newBone = new aiBone;
|
|
|
|
oMesh->mBones[oMesh->mNumBones++] = newBone;
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
const aiBone *bone = pMesh->mBones[a];
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
newBone->mName = bone->mName;
|
|
|
|
newBone->mOffsetMatrix = bone->mOffsetMatrix;
|
|
|
|
newBone->mWeights = new aiVertexWeight[subBones[a]];
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int b = 0; b < bone->mNumWeights; b++) {
|
2015-05-19 03:57:13 +00:00
|
|
|
const unsigned int v = vMap[bone->mWeights[b].mVertexId];
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (v != UINT_MAX) {
|
|
|
|
aiVertexWeight w(v, bone->mWeights[b].mWeight);
|
2015-05-19 03:57:13 +00:00
|
|
|
newBone->mWeights[newBone->mNumWeights++] = w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
ai_assert(nbParanoia == oMesh->mNumBones);
|
2015-05-19 03:57:13 +00:00
|
|
|
(void)nbParanoia; // remove compiler warning on release build
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return oMesh;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Assimp
|