2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2022-01-10 20:13:43 +00:00
|
|
|
Copyright (c) 2006-2022, 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 MakeLeftHandedProcess.cpp
|
|
|
|
* @brief Implementation of the post processing step to convert all
|
|
|
|
* imported data to a left-handed coordinate system.
|
|
|
|
*
|
|
|
|
* Face order & UV flip are also implemented here, for the sake of a
|
|
|
|
* better location.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ConvertToLHProcess.h"
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/postprocess.h>
|
2020-06-23 19:05:42 +00:00
|
|
|
#include <assimp/scene.h>
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/DefaultLogger.hpp>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_NO_MAKELEFTHANDED_PROCESS
|
|
|
|
|
2018-07-28 17:18:17 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
template <typename aiMeshType>
|
2020-06-23 19:05:42 +00:00
|
|
|
void flipUVs(aiMeshType *pMesh) {
|
|
|
|
if (pMesh == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-28 17:18:17 +00:00
|
|
|
// mirror texture y coordinate
|
|
|
|
for (unsigned int tcIdx = 0; tcIdx < AI_MAX_NUMBER_OF_TEXTURECOORDS; tcIdx++) {
|
|
|
|
if (!pMesh->HasTextureCoords(tcIdx)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int vIdx = 0; vIdx < pMesh->mNumVertices; vIdx++) {
|
|
|
|
pMesh->mTextureCoords[tcIdx][vIdx].y = 1.0f - pMesh->mTextureCoords[tcIdx][vIdx].y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
2022-08-25 15:19:26 +00:00
|
|
|
MakeLeftHandedProcess::MakeLeftHandedProcess() = default;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Destructor, private as well
|
2022-08-25 15:19:26 +00:00
|
|
|
MakeLeftHandedProcess::~MakeLeftHandedProcess() = default;
|
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 MakeLeftHandedProcess::IsActive(unsigned int pFlags) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return 0 != (pFlags & aiProcess_MakeLeftHanded);
|
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
|
|
|
void MakeLeftHandedProcess::Execute(aiScene *pScene) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// Check for an existent root node to proceed
|
2020-06-23 19:05:42 +00:00
|
|
|
ai_assert(pScene->mRootNode != nullptr);
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("MakeLeftHandedProcess begin");
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// recursively convert all the nodes
|
2020-06-23 19:05:42 +00:00
|
|
|
ProcessNode(pScene->mRootNode, aiMatrix4x4());
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// process the meshes accordingly
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < pScene->mNumMeshes; ++a) {
|
|
|
|
ProcessMesh(pScene->mMeshes[a]);
|
2018-03-09 22:35:12 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// process the materials accordingly
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < pScene->mNumMaterials; ++a) {
|
|
|
|
ProcessMaterial(pScene->mMaterials[a]);
|
2018-03-09 22:35:12 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// transform all animation channels as well
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < pScene->mNumAnimations; a++) {
|
|
|
|
aiAnimation *anim = pScene->mAnimations[a];
|
|
|
|
for (unsigned int b = 0; b < anim->mNumChannels; b++) {
|
|
|
|
aiNodeAnim *nodeAnim = anim->mChannels[b];
|
|
|
|
ProcessAnimation(nodeAnim);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("MakeLeftHandedProcess finished");
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Recursively converts a node, all of its children and all of its meshes
|
2020-06-23 19:05:42 +00:00
|
|
|
void MakeLeftHandedProcess::ProcessNode(aiNode *pNode, const aiMatrix4x4 &pParentGlobalRotation) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// mirror all base vectors at the local Z axis
|
|
|
|
pNode->mTransformation.c1 = -pNode->mTransformation.c1;
|
|
|
|
pNode->mTransformation.c2 = -pNode->mTransformation.c2;
|
|
|
|
pNode->mTransformation.c3 = -pNode->mTransformation.c3;
|
|
|
|
pNode->mTransformation.c4 = -pNode->mTransformation.c4;
|
|
|
|
|
|
|
|
// now invert the Z axis again to keep the matrix determinant positive.
|
|
|
|
// The local meshes will be inverted accordingly so that the result should look just fine again.
|
|
|
|
pNode->mTransformation.a3 = -pNode->mTransformation.a3;
|
|
|
|
pNode->mTransformation.b3 = -pNode->mTransformation.b3;
|
|
|
|
pNode->mTransformation.c3 = -pNode->mTransformation.c3;
|
|
|
|
pNode->mTransformation.d3 = -pNode->mTransformation.d3; // useless, but anyways...
|
|
|
|
|
|
|
|
// continue for all children
|
2020-06-23 19:05:42 +00:00
|
|
|
for (size_t a = 0; a < pNode->mNumChildren; ++a) {
|
|
|
|
ProcessNode(pNode->mChildren[a], pParentGlobalRotation * pNode->mTransformation);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Converts a single mesh to left handed coordinates.
|
2020-06-23 19:05:42 +00:00
|
|
|
void MakeLeftHandedProcess::ProcessMesh(aiMesh *pMesh) {
|
|
|
|
if (nullptr == pMesh) {
|
|
|
|
ASSIMP_LOG_ERROR("Nullptr to mesh found.");
|
2018-03-09 22:35:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
// mirror positions, normals and stuff along the Z axis
|
2020-06-23 19:05:42 +00:00
|
|
|
for (size_t a = 0; a < pMesh->mNumVertices; ++a) {
|
2015-05-19 03:57:13 +00:00
|
|
|
pMesh->mVertices[a].z *= -1.0f;
|
2019-01-06 18:37:30 +00:00
|
|
|
if (pMesh->HasNormals()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
pMesh->mNormals[a].z *= -1.0f;
|
2019-01-06 18:37:30 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pMesh->HasTangentsAndBitangents()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
pMesh->mTangents[a].z *= -1.0f;
|
|
|
|
pMesh->mBitangents[a].z *= -1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-06 18:37:30 +00:00
|
|
|
// mirror anim meshes positions, normals and stuff along the Z axis
|
2020-06-23 19:05:42 +00:00
|
|
|
for (size_t m = 0; m < pMesh->mNumAnimMeshes; ++m) {
|
|
|
|
for (size_t a = 0; a < pMesh->mAnimMeshes[m]->mNumVertices; ++a) {
|
2019-01-06 18:37:30 +00:00
|
|
|
pMesh->mAnimMeshes[m]->mVertices[a].z *= -1.0f;
|
|
|
|
if (pMesh->mAnimMeshes[m]->HasNormals()) {
|
|
|
|
pMesh->mAnimMeshes[m]->mNormals[a].z *= -1.0f;
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pMesh->mAnimMeshes[m]->HasTangentsAndBitangents()) {
|
2019-01-06 18:37:30 +00:00
|
|
|
pMesh->mAnimMeshes[m]->mTangents[a].z *= -1.0f;
|
|
|
|
pMesh->mAnimMeshes[m]->mBitangents[a].z *= -1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// mirror offset matrices of all bones
|
2020-06-23 19:05:42 +00:00
|
|
|
for (size_t a = 0; a < pMesh->mNumBones; ++a) {
|
|
|
|
aiBone *bone = pMesh->mBones[a];
|
2015-05-19 03:57:13 +00:00
|
|
|
bone->mOffsetMatrix.a3 = -bone->mOffsetMatrix.a3;
|
|
|
|
bone->mOffsetMatrix.b3 = -bone->mOffsetMatrix.b3;
|
|
|
|
bone->mOffsetMatrix.d3 = -bone->mOffsetMatrix.d3;
|
|
|
|
bone->mOffsetMatrix.c1 = -bone->mOffsetMatrix.c1;
|
|
|
|
bone->mOffsetMatrix.c2 = -bone->mOffsetMatrix.c2;
|
|
|
|
bone->mOffsetMatrix.c4 = -bone->mOffsetMatrix.c4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mirror bitangents as well as they're derived from the texture coords
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pMesh->HasTangentsAndBitangents()) {
|
|
|
|
for (unsigned int a = 0; a < pMesh->mNumVertices; a++)
|
2015-05-19 03:57:13 +00:00
|
|
|
pMesh->mBitangents[a] *= -1.0f;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Converts a single material to left handed coordinates.
|
2020-06-23 19:05:42 +00:00
|
|
|
void MakeLeftHandedProcess::ProcessMaterial(aiMaterial *_mat) {
|
|
|
|
if (nullptr == _mat) {
|
|
|
|
ASSIMP_LOG_ERROR("Nullptr to aiMaterial found.");
|
2018-03-09 22:35:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
aiMaterial *mat = (aiMaterial *)_mat;
|
|
|
|
for (unsigned int a = 0; a < mat->mNumProperties; ++a) {
|
|
|
|
aiMaterialProperty *prop = mat->mProperties[a];
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Mapping axis for UV mappings?
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!::strcmp(prop->mKey.data, "$tex.mapaxis")) {
|
|
|
|
ai_assert(prop->mDataLength >= sizeof(aiVector3D)); // something is wrong with the validation if we end up here
|
|
|
|
aiVector3D *pff = (aiVector3D *)prop->mData;
|
2015-05-19 03:57:13 +00:00
|
|
|
pff->z *= -1.f;
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Converts the given animation to LH coordinates.
|
2020-06-23 19:05:42 +00:00
|
|
|
void MakeLeftHandedProcess::ProcessAnimation(aiNodeAnim *pAnim) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// position keys
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < pAnim->mNumPositionKeys; a++)
|
2015-05-19 03:57:13 +00:00
|
|
|
pAnim->mPositionKeys[a].mValue.z *= -1.0f;
|
|
|
|
|
|
|
|
// rotation keys
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < pAnim->mNumRotationKeys; a++) {
|
2015-05-19 03:57:13 +00:00
|
|
|
/* 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.y *= -1.0f;
|
|
|
|
}
|
2015-05-19 03:52:10 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
#endif // !! ASSIMP_BUILD_NO_MAKELEFTHANDED_PROCESS
|
2020-06-23 19:05:42 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_FLIPUVS_PROCESS
|
2015-05-19 03:48:29 +00:00
|
|
|
// # FlipUVsProcess
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
2022-08-25 15:19:26 +00:00
|
|
|
FlipUVsProcess::FlipUVsProcess() = default;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Destructor, private as well
|
2022-08-25 15:19:26 +00:00
|
|
|
FlipUVsProcess::~FlipUVsProcess() = default;
|
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 FlipUVsProcess::IsActive(unsigned int pFlags) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return 0 != (pFlags & aiProcess_FlipUVs);
|
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
|
|
|
void FlipUVsProcess::Execute(aiScene *pScene) {
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("FlipUVsProcess begin");
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i)
|
2015-05-19 03:57:13 +00:00
|
|
|
ProcessMesh(pScene->mMeshes[i]);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pScene->mNumMaterials; ++i)
|
2015-05-19 03:57:13 +00:00
|
|
|
ProcessMaterial(pScene->mMaterials[i]);
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("FlipUVsProcess finished");
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Converts a single material
|
2020-06-23 19:05:42 +00:00
|
|
|
void FlipUVsProcess::ProcessMaterial(aiMaterial *_mat) {
|
|
|
|
aiMaterial *mat = (aiMaterial *)_mat;
|
|
|
|
for (unsigned int a = 0; a < mat->mNumProperties; ++a) {
|
|
|
|
aiMaterialProperty *prop = mat->mProperties[a];
|
|
|
|
if (!prop) {
|
|
|
|
ASSIMP_LOG_VERBOSE_DEBUG("Property is null");
|
2015-05-19 03:48:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// UV transformation key?
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!::strcmp(prop->mKey.data, "$tex.uvtrafo")) {
|
|
|
|
ai_assert(prop->mDataLength >= sizeof(aiUVTransform)); // something is wrong with the validation if we end up here
|
|
|
|
aiUVTransform *uv = (aiUVTransform *)prop->mData;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// just flip it, that's everything
|
|
|
|
uv->mTranslation.y *= -1.f;
|
|
|
|
uv->mRotation *= -1.f;
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Converts a single mesh
|
2020-06-23 19:05:42 +00:00
|
|
|
void FlipUVsProcess::ProcessMesh(aiMesh *pMesh) {
|
2018-07-28 17:18:17 +00:00
|
|
|
flipUVs(pMesh);
|
|
|
|
for (unsigned int idx = 0; idx < pMesh->mNumAnimMeshes; idx++) {
|
|
|
|
flipUVs(pMesh->mAnimMeshes[idx]);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !ASSIMP_BUILD_NO_FLIPUVS_PROCESS
|
2020-06-23 19:05:42 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_FLIPWINDING_PROCESS
|
2015-05-19 03:48:29 +00:00
|
|
|
// # FlipWindingOrderProcess
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
2022-08-25 15:19:26 +00:00
|
|
|
FlipWindingOrderProcess::FlipWindingOrderProcess() = default;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Destructor, private as well
|
2022-08-25 15:19:26 +00:00
|
|
|
FlipWindingOrderProcess::~FlipWindingOrderProcess() = default;
|
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 FlipWindingOrderProcess::IsActive(unsigned int pFlags) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return 0 != (pFlags & aiProcess_FlipWindingOrder);
|
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
|
|
|
void FlipWindingOrderProcess::Execute(aiScene *pScene) {
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("FlipWindingOrderProcess begin");
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i)
|
2015-05-19 03:57:13 +00:00
|
|
|
ProcessMesh(pScene->mMeshes[i]);
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("FlipWindingOrderProcess finished");
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Converts a single mesh
|
2020-06-23 19:05:42 +00:00
|
|
|
void FlipWindingOrderProcess::ProcessMesh(aiMesh *pMesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// invert the order of all faces in this mesh
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < pMesh->mNumFaces; a++) {
|
|
|
|
aiFace &face = pMesh->mFaces[a];
|
2019-01-06 18:37:30 +00:00
|
|
|
for (unsigned int b = 0; b < face.mNumIndices / 2; b++) {
|
|
|
|
std::swap(face.mIndices[b], face.mIndices[face.mNumIndices - 1 - b]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// invert the order of all components in this mesh anim meshes
|
|
|
|
for (unsigned int m = 0; m < pMesh->mNumAnimMeshes; m++) {
|
2020-06-23 19:05:42 +00:00
|
|
|
aiAnimMesh *animMesh = pMesh->mAnimMeshes[m];
|
2019-01-06 18:37:30 +00:00
|
|
|
unsigned int numVertices = animMesh->mNumVertices;
|
|
|
|
if (animMesh->HasPositions()) {
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < numVertices; a++) {
|
2019-01-06 18:37:30 +00:00
|
|
|
std::swap(animMesh->mVertices[a], animMesh->mVertices[numVertices - 1 - a]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (animMesh->HasNormals()) {
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < numVertices; a++) {
|
2019-01-06 18:37:30 +00:00
|
|
|
std::swap(animMesh->mNormals[a], animMesh->mNormals[numVertices - 1 - a]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; i++) {
|
|
|
|
if (animMesh->HasTextureCoords(i)) {
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < numVertices; a++) {
|
2019-01-06 18:37:30 +00:00
|
|
|
std::swap(animMesh->mTextureCoords[i][a], animMesh->mTextureCoords[i][numVertices - 1 - a]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (animMesh->HasTangentsAndBitangents()) {
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < numVertices; a++) {
|
2019-01-06 18:37:30 +00:00
|
|
|
std::swap(animMesh->mTangents[a], animMesh->mTangents[numVertices - 1 - a]);
|
|
|
|
std::swap(animMesh->mBitangents[a], animMesh->mBitangents[numVertices - 1 - a]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (unsigned int v = 0; v < AI_MAX_NUMBER_OF_COLOR_SETS; v++) {
|
|
|
|
if (animMesh->HasVertexColors(v)) {
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < numVertices; a++) {
|
2019-01-06 18:37:30 +00:00
|
|
|
std::swap(animMesh->mColors[v][a], animMesh->mColors[v][numVertices - 1 - a]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !! ASSIMP_BUILD_NO_FLIPWINDING_PROCESS
|