2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2021-02-28 11:17:54 +00:00
|
|
|
Copyright (c) 2006-2021, 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 following
|
2015-05-19 03:48:29 +00:00
|
|
|
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 Implementation of the post processing step to remove
|
|
|
|
* any parts of the mesh structure from the imported data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "RemoveVCProcess.h"
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/postprocess.h>
|
|
|
|
#include <assimp/scene.h>
|
2020-06-23 19:05:42 +00:00
|
|
|
#include <assimp/DefaultLogger.hpp>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
|
|
|
RemoveVCProcess::RemoveVCProcess() :
|
2020-06-23 19:05:42 +00:00
|
|
|
configDeleteFlags(), mScene() {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Destructor, private as well
|
2020-06-23 19:05:42 +00:00
|
|
|
RemoveVCProcess::~RemoveVCProcess() {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Returns whether the processing step is present in the given flag field.
|
2020-06-23 19:05:42 +00:00
|
|
|
bool RemoveVCProcess::IsActive(unsigned int pFlags) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return (pFlags & aiProcess_RemoveComponent) != 0;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-10-05 08:59:43 +00:00
|
|
|
// Small helper function to delete all elements in a T** array using delete
|
2015-05-19 03:48:29 +00:00
|
|
|
template <typename T>
|
2020-06-23 19:05:42 +00:00
|
|
|
inline void ArrayDelete(T **&in, unsigned int &num) {
|
2015-05-19 03:57:13 +00:00
|
|
|
for (unsigned int i = 0; i < num; ++i)
|
|
|
|
delete in[i];
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
delete[] in;
|
2020-06-23 19:05:42 +00:00
|
|
|
in = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
num = 0;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Updates the node graph - removes all nodes which have the "remove" flag set and the
|
2015-05-19 03:48:29 +00:00
|
|
|
// "don't remove" flag not set. Nodes with meshes are never deleted.
|
|
|
|
bool UpdateNodeGraph(aiNode* node,std::list<aiNode*>& childsOfParent,bool root)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
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());
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
// set all children to nullptr to make sure they are not deleted when we delete ourself
|
2015-05-19 03:57:13 +00:00
|
|
|
for (unsigned int i = 0; i < node->mNumChildren;++i)
|
2020-06-23 19:05:42 +00:00
|
|
|
node->mChildren[i] = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
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;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Executes the post processing step on the given imported data.
|
2020-06-23 19:05:42 +00:00
|
|
|
void RemoveVCProcess::Execute(aiScene *pScene) {
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("RemoveVCProcess begin");
|
2015-05-19 03:57:13 +00:00
|
|
|
bool bHas = false; //,bMasked = false;
|
|
|
|
|
|
|
|
mScene = pScene;
|
|
|
|
|
|
|
|
// handle animations
|
2020-06-23 19:05:42 +00:00
|
|
|
if (configDeleteFlags & aiComponent_ANIMATIONS) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
bHas = true;
|
2020-06-23 19:05:42 +00:00
|
|
|
ArrayDelete(pScene->mAnimations, pScene->mNumAnimations);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// handle textures
|
2020-06-23 19:05:42 +00:00
|
|
|
if (configDeleteFlags & aiComponent_TEXTURES) {
|
2015-05-19 03:57:13 +00:00
|
|
|
bHas = true;
|
2020-06-23 19:05:42 +00:00
|
|
|
ArrayDelete(pScene->mTextures, pScene->mNumTextures);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// handle materials
|
2020-06-23 19:05:42 +00:00
|
|
|
if (configDeleteFlags & aiComponent_MATERIALS && pScene->mNumMaterials) {
|
2015-05-19 03:57:13 +00:00
|
|
|
bHas = true;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 1; i < pScene->mNumMaterials; ++i)
|
2015-05-19 03:57:13 +00:00
|
|
|
delete pScene->mMaterials[i];
|
|
|
|
|
|
|
|
pScene->mNumMaterials = 1;
|
2020-06-23 19:05:42 +00:00
|
|
|
aiMaterial *helper = (aiMaterial *)pScene->mMaterials[0];
|
|
|
|
ai_assert(nullptr != helper);
|
2015-05-19 03:57:13 +00:00
|
|
|
helper->Clear();
|
|
|
|
|
|
|
|
// gray
|
2020-06-23 19:05:42 +00:00
|
|
|
aiColor3D clr(0.6f, 0.6f, 0.6f);
|
|
|
|
helper->AddProperty(&clr, 1, AI_MATKEY_COLOR_DIFFUSE);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// add a small ambient color value
|
2020-06-23 19:05:42 +00:00
|
|
|
clr = aiColor3D(0.05f, 0.05f, 0.05f);
|
|
|
|
helper->AddProperty(&clr, 1, AI_MATKEY_COLOR_AMBIENT);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
aiString s;
|
|
|
|
s.Set("Dummy_MaterialsRemoved");
|
2020-06-23 19:05:42 +00:00
|
|
|
helper->AddProperty(&s, AI_MATKEY_NAME);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// handle light sources
|
2020-06-23 19:05:42 +00:00
|
|
|
if (configDeleteFlags & aiComponent_LIGHTS) {
|
|
|
|
bHas = true;
|
|
|
|
ArrayDelete(pScene->mLights, pScene->mNumLights);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// handle camneras
|
2020-06-23 19:05:42 +00:00
|
|
|
if (configDeleteFlags & aiComponent_CAMERAS) {
|
2015-05-19 03:57:13 +00:00
|
|
|
bHas = true;
|
2020-06-23 19:05:42 +00:00
|
|
|
ArrayDelete(pScene->mCameras, pScene->mNumCameras);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// handle meshes
|
2020-06-23 19:05:42 +00:00
|
|
|
if (configDeleteFlags & aiComponent_MESHES) {
|
2015-05-19 03:57:13 +00:00
|
|
|
bHas = true;
|
2020-06-23 19:05:42 +00:00
|
|
|
ArrayDelete(pScene->mMeshes, pScene->mNumMeshes);
|
|
|
|
} else {
|
|
|
|
for (unsigned int a = 0; a < pScene->mNumMeshes; a++) {
|
|
|
|
if (ProcessMesh(pScene->mMeshes[a]))
|
2015-05-19 03:57:13 +00:00
|
|
|
bHas = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now check whether the result is still a full scene
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!pScene->mNumMeshes || !pScene->mNumMaterials) {
|
2015-05-19 03:57:13 +00:00
|
|
|
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("Setting AI_SCENE_FLAGS_INCOMPLETE flag");
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// If we have no meshes anymore we should also clear another flag ...
|
|
|
|
if (!pScene->mNumMeshes)
|
|
|
|
pScene->mFlags &= ~AI_SCENE_FLAGS_NON_VERBOSE_FORMAT;
|
|
|
|
}
|
|
|
|
|
2018-04-26 12:10:18 +00:00
|
|
|
if (bHas) {
|
|
|
|
ASSIMP_LOG_INFO("RemoveVCProcess finished. Data structure cleanup has been done.");
|
|
|
|
} else {
|
|
|
|
ASSIMP_LOG_DEBUG("RemoveVCProcess finished. Nothing to be done ...");
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Setup configuration properties for the step
|
2020-06-23 19:05:42 +00:00
|
|
|
void RemoveVCProcess::SetupProperties(const Importer *pImp) {
|
|
|
|
configDeleteFlags = pImp->GetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS, 0x0);
|
|
|
|
if (!configDeleteFlags) {
|
2018-04-19 15:21:21 +00:00
|
|
|
ASSIMP_LOG_WARN("RemoveVCProcess: AI_CONFIG_PP_RVC_FLAGS is zero.");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Executes the post processing step on the given imported data.
|
2020-06-23 19:05:42 +00:00
|
|
|
bool RemoveVCProcess::ProcessMesh(aiMesh *pMesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
// if all materials have been deleted let the material
|
|
|
|
// index of the mesh point to the created default material
|
2020-06-23 19:05:42 +00:00
|
|
|
if (configDeleteFlags & aiComponent_MATERIALS)
|
2015-05-19 03:57:13 +00:00
|
|
|
pMesh->mMaterialIndex = 0;
|
|
|
|
|
|
|
|
// handle normals
|
2020-06-23 19:05:42 +00:00
|
|
|
if (configDeleteFlags & aiComponent_NORMALS && pMesh->mNormals) {
|
2015-05-19 03:57:13 +00:00
|
|
|
delete[] pMesh->mNormals;
|
2020-06-23 19:05:42 +00:00
|
|
|
pMesh->mNormals = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle tangents and bitangents
|
2020-06-23 19:05:42 +00:00
|
|
|
if (configDeleteFlags & aiComponent_TANGENTS_AND_BITANGENTS && pMesh->mTangents) {
|
2015-05-19 03:57:13 +00:00
|
|
|
delete[] pMesh->mTangents;
|
2020-06-23 19:05:42 +00:00
|
|
|
pMesh->mTangents = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
delete[] pMesh->mBitangents;
|
2020-06-23 19:05:42 +00:00
|
|
|
pMesh->mBitangents = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle texture coordinates
|
|
|
|
bool b = (0 != (configDeleteFlags & aiComponent_TEXCOORDS));
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0, real = 0; real < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++real) {
|
|
|
|
if (!pMesh->mTextureCoords[i]) break;
|
|
|
|
if (configDeleteFlags & aiComponent_TEXCOORDSn(real) || b) {
|
|
|
|
delete[] pMesh->mTextureCoords[i];
|
|
|
|
pMesh->mTextureCoords[i] = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
ret = true;
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!b) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// collapse the rest of the array
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = i + 1; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a)
|
|
|
|
pMesh->mTextureCoords[a - 1] = pMesh->mTextureCoords[a];
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
pMesh->mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS - 1] = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle vertex colors
|
|
|
|
b = (0 != (configDeleteFlags & aiComponent_COLORS));
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0, real = 0; real < AI_MAX_NUMBER_OF_COLOR_SETS; ++real) {
|
|
|
|
if (!pMesh->mColors[i]) break;
|
|
|
|
if (configDeleteFlags & aiComponent_COLORSn(i) || b) {
|
|
|
|
delete[] pMesh->mColors[i];
|
|
|
|
pMesh->mColors[i] = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
ret = true;
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!b) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// collapse the rest of the array
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = i + 1; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a)
|
|
|
|
pMesh->mColors[a - 1] = pMesh->mColors[a];
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
pMesh->mColors[AI_MAX_NUMBER_OF_COLOR_SETS - 1] = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle bones
|
2020-06-23 19:05:42 +00:00
|
|
|
if (configDeleteFlags & aiComponent_BONEWEIGHTS && pMesh->mBones) {
|
|
|
|
ArrayDelete(pMesh->mBones, pMesh->mNumBones);
|
2015-05-19 03:57:13 +00:00
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
return ret;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|