Fix review findings.

pull/2316/head
kimkulling 2019-01-30 16:07:40 +01:00
parent a06133ab52
commit de02fb2129
15 changed files with 464 additions and 731 deletions

View File

@ -47,17 +47,21 @@ using namespace AssimpView;
// ------------------------------------------------------------------------------------------------
// Constructor on a given animation.
AnimEvaluator::AnimEvaluator( const aiAnimation* pAnim)
{
mAnim = pAnim;
mLastTime = 0.0;
AnimEvaluator::AnimEvaluator( const aiAnimation *pAnim )
: mAnim(pAnim)
, mLastTime(0.0) {
mLastPositions.resize( pAnim->mNumChannels, std::make_tuple( 0, 0, 0));
}
// ------------------------------------------------------------------------------------------------
// Destructor.
AnimEvaluator::~AnimEvaluator() {
// empty
}
// ------------------------------------------------------------------------------------------------
// Evaluates the animation tracks for a given time stamp.
void AnimEvaluator::Evaluate( double pTime)
{
void AnimEvaluator::Evaluate( double pTime ) {
// extract ticks per second. Assume default value if not given
double ticksPerSecond = mAnim->mTicksPerSecond != 0.0 ? mAnim->mTicksPerSecond : 25.0;
// every following time calculation happens in ticks
@ -65,29 +69,29 @@ void AnimEvaluator::Evaluate( double pTime)
// map into anim's duration
double time = 0.0f;
if( mAnim->mDuration > 0.0)
time = fmod( pTime, mAnim->mDuration);
if (mAnim->mDuration > 0.0) {
time = fmod(pTime, mAnim->mDuration);
}
if( mTransforms.size() != mAnim->mNumChannels)
mTransforms.resize( mAnim->mNumChannels);
if (mTransforms.size() != mAnim->mNumChannels) {
mTransforms.resize(mAnim->mNumChannels);
}
// calculate the transformations for each animation channel
for( unsigned int a = 0; a < mAnim->mNumChannels; a++)
{
for( unsigned int a = 0; a < mAnim->mNumChannels; ++a ) {
const aiNodeAnim* channel = mAnim->mChannels[a];
// ******** Position *****
aiVector3D presentPosition( 0, 0, 0);
if( channel->mNumPositionKeys > 0)
{
if( channel->mNumPositionKeys > 0) {
// Look for present frame number. Search from last position if time is after the last time, else from beginning
// Should be much quicker than always looking from start for the average use case.
unsigned int frame = (time >= mLastTime) ? std::get<0>(mLastPositions[a]) : 0;
while( frame < channel->mNumPositionKeys - 1)
{
if( time < channel->mPositionKeys[frame+1].mTime)
while( frame < channel->mNumPositionKeys - 1) {
if (time < channel->mPositionKeys[frame + 1].mTime) {
break;
frame++;
}
++frame;
}
// interpolate between this frame's value and next frame's value
@ -95,14 +99,13 @@ void AnimEvaluator::Evaluate( double pTime)
const aiVectorKey& key = channel->mPositionKeys[frame];
const aiVectorKey& nextKey = channel->mPositionKeys[nextFrame];
double diffTime = nextKey.mTime - key.mTime;
if( diffTime < 0.0)
if (diffTime < 0.0) {
diffTime += mAnim->mDuration;
if( diffTime > 0)
{
}
if( diffTime > 0) {
float factor = float( (time - key.mTime) / diffTime);
presentPosition = key.mValue + (nextKey.mValue - key.mValue) * factor;
} else
{
} else {
presentPosition = key.mValue;
}
@ -111,14 +114,13 @@ void AnimEvaluator::Evaluate( double pTime)
// ******** Rotation *********
aiQuaternion presentRotation( 1, 0, 0, 0);
if( channel->mNumRotationKeys > 0)
{
if( channel->mNumRotationKeys > 0) {
unsigned int frame = (time >= mLastTime) ? std::get<1>(mLastPositions[a]) : 0;
while( frame < channel->mNumRotationKeys - 1)
{
if( time < channel->mRotationKeys[frame+1].mTime)
while( frame < channel->mNumRotationKeys - 1) {
if (time < channel->mRotationKeys[frame + 1].mTime) {
break;
frame++;
}
++frame;
}
// interpolate between this frame's value and next frame's value
@ -126,14 +128,13 @@ void AnimEvaluator::Evaluate( double pTime)
const aiQuatKey& key = channel->mRotationKeys[frame];
const aiQuatKey& nextKey = channel->mRotationKeys[nextFrame];
double diffTime = nextKey.mTime - key.mTime;
if( diffTime < 0.0)
if (diffTime < 0.0) {
diffTime += mAnim->mDuration;
if( diffTime > 0)
{
}
if( diffTime > 0) {
float factor = float( (time - key.mTime) / diffTime);
aiQuaternion::Interpolate( presentRotation, key.mValue, nextKey.mValue, factor);
} else
{
} else {
presentRotation = key.mValue;
}
@ -142,14 +143,13 @@ void AnimEvaluator::Evaluate( double pTime)
// ******** Scaling **********
aiVector3D presentScaling( 1, 1, 1);
if( channel->mNumScalingKeys > 0)
{
if( channel->mNumScalingKeys > 0) {
unsigned int frame = (time >= mLastTime) ? std::get<2>(mLastPositions[a]) : 0;
while( frame < channel->mNumScalingKeys - 1)
{
if( time < channel->mScalingKeys[frame+1].mTime)
while( frame < channel->mNumScalingKeys - 1) {
if (time < channel->mScalingKeys[frame + 1].mTime) {
break;
frame++;
}
++frame;
}
// TODO: (thom) interpolation maybe? This time maybe even logarithmic, not linear
@ -164,7 +164,6 @@ void AnimEvaluator::Evaluate( double pTime)
mat.a2 *= presentScaling.y; mat.b2 *= presentScaling.y; mat.c2 *= presentScaling.y;
mat.a3 *= presentScaling.z; mat.b3 *= presentScaling.z; mat.c3 *= presentScaling.z;
mat.a4 = presentPosition.x; mat.b4 = presentPosition.y; mat.c4 = presentPosition.z;
//mat.Transpose();
}
mLastTime = time;

View File

@ -4,7 +4,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.
@ -46,22 +46,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <tuple>
#include <vector>
namespace AssimpView
{
namespace AssimpView {
/** Calculates transformations for a given timestamp from a set of animation tracks. Not directly useful,
* better use the AnimPlayer class.
/**
* @brief Calculates transformations for a given timestamp from a set of animation tracks. Not directly useful,
* better use the AnimPlayer class.
*/
class AnimEvaluator
{
class AnimEvaluator {
public:
/** Constructor on a given animation. The animation is fixed throughout the lifetime of
* the object.
* @param pAnim The animation to calculate poses for. Ownership of the animation object stays
* at the caller, the evaluator just keeps a reference to it as long as it persists.
*/
/// @brief Constructor on a given animation. The animation is fixed throughout the lifetime of
/// the object.
/// @param pAnim The animation to calculate poses for. Ownership of the animation object stays
/// at the caller, the evaluator just keeps a reference to it as long as it persists.
AnimEvaluator( const aiAnimation* pAnim);
/// @brief The class destructor.
~AnimEvaluator();
/** Evaluates the animation tracks for a given time stamp. The calculated pose can be retrieved as a
* array of transformation matrices afterwards by calling GetTransformations().
* @param pTime The time for which you want to evaluate the animation, in seconds. Will be mapped into the animation cycle, so
@ -74,16 +75,9 @@ public:
const std::vector<aiMatrix4x4>& GetTransformations() const { return mTransforms; }
protected:
/** The animation we're working on */
const aiAnimation* mAnim;
/** At which frame the last evaluation happened for each channel.
* Useful to quickly find the corresponding frame for slightly increased time stamps
*/
double mLastTime;
std::vector<std::tuple<unsigned int, unsigned int, unsigned int> > mLastPositions;
/** The array to store the transformations results of the evaluation */
std::vector<aiMatrix4x4> mTransforms;
};

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.
@ -48,14 +48,10 @@ namespace AssimpView {
//-------------------------------------------------------------------------------
// Message procedure for the help dialog
//-------------------------------------------------------------------------------
INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam)
{
(void)lParam;
switch (uMsg)
{
INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM ) {
switch (uMsg) {
case WM_INITDIALOG:
{
{
// load the help file ...
HRSRC res = FindResource(NULL,MAKEINTRESOURCE(IDR_TEXT1),"TEXT");
HGLOBAL hg = LoadResource(NULL,res);
@ -70,39 +66,38 @@ INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg,
FreeResource(hg);
return TRUE;
}
}
case WM_CLOSE:
EndDialog(hwndDlg,0);
return TRUE;
case WM_COMMAND:
if (IDOK == LOWORD(wParam))
{
if (IDOK == LOWORD(wParam)) {
EndDialog(hwndDlg,0);
return TRUE;
}
}
case WM_PAINT:
{
PAINTSTRUCT sPaint;
HDC hdc = BeginPaint(hwndDlg,&sPaint);
PAINTSTRUCT sPaint;
HDC hdc = BeginPaint(hwndDlg,&sPaint);
HBRUSH hBrush = CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
HBRUSH hBrush = CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
RECT sRect;
sRect.left = 0;
sRect.top = 26;
sRect.right = 1000;
sRect.bottom = 507;
FillRect(hdc, &sRect, hBrush);
RECT sRect;
sRect.left = 0;
sRect.top = 26;
sRect.right = 1000;
sRect.bottom = 507;
FillRect(hdc, &sRect, hBrush);
EndPaint(hwndDlg,&sPaint);
return TRUE;
EndPaint(hwndDlg,&sPaint);
return TRUE;
}
};
return FALSE;
}
};
return FALSE;
}
}

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.
@ -46,32 +46,26 @@ namespace AssimpView {
CLogDisplay CLogDisplay::s_cInstance;
//-------------------------------------------------------------------------------
void CLogDisplay::AddEntry(const std::string& szText,
const D3DCOLOR clrColor)
{
void CLogDisplay::AddEntry(const std::string& szText, const D3DCOLOR clrColor) {
SEntry sNew;
sNew.clrColor = clrColor;
sNew.szText = szText;
sNew.dwStartTicks = (DWORD)GetTickCount();
this->asEntries.push_back(sNew);
}
}
//-------------------------------------------------------------------------------
void CLogDisplay::ReleaseNativeResource()
{
if (this->piFont)
{
void CLogDisplay::ReleaseNativeResource() {
if (this->piFont) {
this->piFont->Release();
this->piFont = NULL;
}
this->piFont = nullptr;
}
}
//-------------------------------------------------------------------------------
void CLogDisplay::RecreateNativeResource()
{
if (!this->piFont)
{
void CLogDisplay::RecreateNativeResource() {
if (!this->piFont) {
if (FAILED(D3DXCreateFont(g_piDevice,
16, //Font height
0, //Font width
@ -84,20 +78,17 @@ void CLogDisplay::RecreateNativeResource()
5, //Quality
DEFAULT_PITCH|FF_DONTCARE, //PitchAndFamily
"Verdana", //pFacename,
&this->piFont)))
{
&this->piFont))) {
CLogDisplay::Instance().AddEntry("Unable to load font",D3DCOLOR_ARGB(0xFF,0xFF,0,0));
this->piFont = NULL;
this->piFont = nullptr;
return;
}
}
return;
}
}
//-------------------------------------------------------------------------------
void CLogDisplay::OnRender()
{
void CLogDisplay::OnRender() {
DWORD dwTick = (DWORD) GetTickCount();
DWORD dwLimit = dwTick - 8000;
DWORD dwLimit2 = dwLimit + 3000;
@ -117,9 +108,8 @@ void CLogDisplay::OnRender()
sRect.bottom = sWndRect.bottom;
// if no asset is loaded draw a "no asset loaded" text in the center
if (!g_pcAsset)
{
const char* szText = "Nothing to display ... \r\nTry [Viewer | Open asset] to load an asset";
if (!g_pcAsset) {
const char* szText = "Nothing to display ... \r\nTry [Viewer | Open asset] to load an asset";
// shadow
RECT sCopy;
@ -151,38 +141,34 @@ void CLogDisplay::OnRender()
// text
this->piFont->DrawText(NULL,szText ,
-1,&sWndRect,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF));
}
}
// update all elements in the queue and render them
for (std::list<SEntry>::iterator
i = this->asEntries.begin();
i != this->asEntries.end();++i,++iCnt)
{
if ((*i).dwStartTicks < dwLimit)
{
i = this->asEntries.begin();
i != this->asEntries.end();++i,++iCnt) {
if ((*i).dwStartTicks < dwLimit) {
i = this->asEntries.erase(i);
if(i == this->asEntries.end())break;
if (i == this->asEntries.end()) {
break;
}
else if (NULL != this->piFont)
{
} else if (nullptr != this->piFont) {
float fAlpha = 1.0f;
if ((*i).dwStartTicks <= dwLimit2)
{
if ((*i).dwStartTicks <= dwLimit2) {
// linearly interpolate to create the fade out effect
fAlpha = 1.0f - (float)(dwLimit2 - (*i).dwStartTicks) / 3000.0f;
}
}
D3DCOLOR& clrColor = (*i).clrColor;
clrColor &= ~(0xFFu << 24);
clrColor |= (((unsigned char)(fAlpha * 255.0f)) & 0xFFu) << 24;
const char* szText = (*i).szText.c_str();
if (sRect.top + 30 > sWndRect.bottom)
{
if (sRect.top + 30 > sWndRect.bottom) {
// end of window. send a special message
szText = "... too many errors";
clrColor = D3DCOLOR_ARGB(0xFF,0xFF,100,0x0);
}
}
// draw the black shadow
RECT sCopy;
@ -225,9 +211,11 @@ void CLogDisplay::OnRender()
sRect.top += iPX;
sRect.bottom += iPX;
if (szText != (*i).szText.c_str())break;
if (szText != (*i).szText.c_str()) {
break;
}
}
return;
}
};
}
}

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.
@ -101,13 +101,11 @@ INT_PTR CALLBACK LogDialogProc(HWND hwndDlg,UINT uMsg,
}
//-------------------------------------------------------------------------------
void CLogWindow::Init ()
{
void CLogWindow::Init () {
this->hwnd = ::CreateDialog(g_hInstance,MAKEINTRESOURCE(IDD_LOGVIEW),
NULL,&LogDialogProc);
if (!this->hwnd)
{
if (!this->hwnd) {
CLogDisplay::Instance().AddEntry("[ERROR] Unable to create logger window",
D3DCOLOR_ARGB(0xFF,0,0xFF,0));
}
@ -116,11 +114,10 @@ void CLogWindow::Init ()
this->szText = AI_VIEW_RTF_LOG_HEADER;;
this->szPlainText = "";
}
//-------------------------------------------------------------------------------
void CLogWindow::Show()
{
if (this->hwnd)
{
void CLogWindow::Show() {
if (this->hwnd) {
ShowWindow(this->hwnd,SW_SHOW);
this->bIsVisible = true;
@ -128,24 +125,23 @@ void CLogWindow::Show()
this->Update();
}
}
//-------------------------------------------------------------------------------
void CMyLogStream::write(const char* message)
{
void CMyLogStream::write(const char* message) {
CLogWindow::Instance().WriteLine(message);
}
//-------------------------------------------------------------------------------
void CLogWindow::Clear()
{
void CLogWindow::Clear() {
this->szText = AI_VIEW_RTF_LOG_HEADER;;
this->szPlainText = "";
this->Update();
}
//-------------------------------------------------------------------------------
void CLogWindow::Update()
{
if (this->bIsVisible)
{
void CLogWindow::Update() {
if (this->bIsVisible) {
SETTEXTEX sInfo;
sInfo.flags = ST_DEFAULT;
sInfo.codepage = CP_ACP;
@ -154,20 +150,16 @@ void CLogWindow::Update()
EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM)this->szText.c_str());
}
}
//-------------------------------------------------------------------------------
void CLogWindow::Save()
{
void CLogWindow::Save() {
char szFileName[MAX_PATH];
DWORD dwTemp = MAX_PATH;
if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LogDestination",NULL,NULL,
(BYTE*)szFileName,&dwTemp))
{
if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LogDestination",NULL,NULL,(BYTE*)szFileName,&dwTemp)) {
// Key was not found. Use C:
strcpy(szFileName,"");
}
else
{
} else {
// need to remove the file name
char* sz = strrchr(szFileName,'\\');
if (!sz)
@ -196,14 +188,13 @@ void CLogWindow::Save()
CLogDisplay::Instance().AddEntry("[INFO] The log file has been saved",
D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
}
//-------------------------------------------------------------------------------
void CLogWindow::WriteLine(const char* message)
{
void CLogWindow::WriteLine(const char* message) {
this->szPlainText.append(message);
this->szPlainText.append("\r\n");
if (0 != this->szText.length())
{
if (0 != this->szText.length()) {
this->szText.resize(this->szText.length()-1);
}
@ -231,12 +222,10 @@ void CLogWindow::WriteLine(const char* message)
}
std::string _message = message;
for (unsigned int i = 0; i < _message.length();++i)
{
for (unsigned int i = 0; i < _message.length();++i) {
if ('\\' == _message[i] ||
'}' == _message[i] ||
'{' == _message[i])
{
'{' == _message[i]) {
_message.insert(i++,"\\");
}
}
@ -244,8 +233,7 @@ void CLogWindow::WriteLine(const char* message)
this->szText.append(_message);
this->szText.append("\\par}}");
if (this->bIsVisible && this->bUpdate)
{
if (this->bIsVisible && this->bUpdate) {
SETTEXTEX sInfo;
sInfo.flags = ST_DEFAULT;
sInfo.codepage = CP_ACP;
@ -253,7 +241,6 @@ void CLogWindow::WriteLine(const char* message)
SendDlgItemMessage(this->hwnd,IDC_EDIT1,
EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM)this->szText.c_str());
}
return;
}
}; //! AssimpView
} //! AssimpView

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.
@ -136,7 +136,6 @@ extern float g_smoothAngle /*= 80.f*/;
extern unsigned int ppsteps, ppstepsdefault;
extern bool nopointslines;
CMaterialManager CMaterialManager::s_cInstance;
//-------------------------------------------------------------------------------

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.
@ -49,8 +49,7 @@ namespace AssimpView {
CMeshRenderer CMeshRenderer::s_cInstance;
//-------------------------------------------------------------------------------
int CMeshRenderer::DrawUnsorted(unsigned int iIndex)
{
int CMeshRenderer::DrawUnsorted(unsigned int iIndex) {
ai_assert(iIndex < g_pcAsset->pcScene->mNumMeshes);
// set vertex and index buffer
@ -77,8 +76,7 @@ int CMeshRenderer::DrawUnsorted(unsigned int iIndex)
return 1;
}
//-------------------------------------------------------------------------------
int CMeshRenderer::DrawSorted(unsigned int iIndex,const aiMatrix4x4& mWorld)
{
int CMeshRenderer::DrawSorted(unsigned int iIndex,const aiMatrix4x4& mWorld) {
ai_assert(iIndex < g_pcAsset->pcScene->mNumMeshes);
AssetHelper::MeshHelper* pcHelper = g_pcAsset->apcMeshes[iIndex];

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.
@ -39,11 +39,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
// note: these are no longer part of the public API, but they are
// exported on Windows to keep AssimpView alive.
#include "GenFaceNormalsProcess.h"
#include "GenVertexNormalsProcess.h"
#include "JoinVerticesProcess.h"
@ -60,15 +57,14 @@ float g_smoothAngle = 80.f;
//-------------------------------------------------------------------------------
// Flip all normal vectors
//-------------------------------------------------------------------------------
void AssetHelper::FlipNormalsInt()
{
void AssetHelper::FlipNormalsInt() {
// invert all normal vectors
for (unsigned int i = 0; i < this->pcScene->mNumMeshes;++i)
{
for (unsigned int i = 0; i < this->pcScene->mNumMeshes;++i) {
aiMesh* pcMesh = this->pcScene->mMeshes[i];
if (!pcMesh->mNormals)
if (!pcMesh->mNormals) {
continue;
}
for (unsigned int a = 0; a < pcMesh->mNumVertices;++a){
pcMesh->mNormals[a] *= -1.0f;
@ -77,8 +73,7 @@ void AssetHelper::FlipNormalsInt()
}
//-------------------------------------------------------------------------------
void AssetHelper::FlipNormals()
{
void AssetHelper::FlipNormals() {
FlipNormalsInt();
// recreate native data
@ -90,53 +85,42 @@ void AssetHelper::FlipNormals()
//-------------------------------------------------------------------------------
// Set the normal set of the scene
//-------------------------------------------------------------------------------
void AssetHelper::SetNormalSet(unsigned int iSet)
{
void AssetHelper::SetNormalSet(unsigned int iSet) {
// we need to build an unique set of vertices for this ...
{
MakeVerboseFormatProcess* pcProcess = new MakeVerboseFormatProcess();
pcProcess->Execute(pcScene);
delete pcProcess;
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i)
{
if (!apcMeshes[i]->pvOriginalNormals)
{
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i) {
if (!apcMeshes[i]->pvOriginalNormals) {
apcMeshes[i]->pvOriginalNormals = new aiVector3D[pcScene->mMeshes[i]->mNumVertices];
memcpy( apcMeshes[i]->pvOriginalNormals,pcScene->mMeshes[i]->mNormals,
pcScene->mMeshes[i]->mNumVertices * sizeof(aiVector3D));
}
delete[] pcScene->mMeshes[i]->mNormals;
pcScene->mMeshes[i]->mNormals = NULL;
pcScene->mMeshes[i]->mNormals = nullptr;
}
}
// now we can start to calculate a new set of normals
if (HARD == iSet)
{
if (HARD == iSet) {
GenFaceNormalsProcess* pcProcess = new GenFaceNormalsProcess();
pcProcess->Execute(pcScene);
FlipNormalsInt();
delete pcProcess;
}
else if (SMOOTH == iSet)
{
} else if (SMOOTH == iSet) {
GenVertexNormalsProcess* pcProcess = new GenVertexNormalsProcess();
pcProcess->SetMaxSmoothAngle((float)AI_DEG_TO_RAD(g_smoothAngle));
pcProcess->Execute(pcScene);
FlipNormalsInt();
delete pcProcess;
}
else if (ORIGINAL == iSet)
{
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i)
{
if (apcMeshes[i]->pvOriginalNormals)
{
} else if (ORIGINAL == iSet) {
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i) {
if (apcMeshes[i]->pvOriginalNormals) {
delete[] pcScene->mMeshes[i]->mNormals;
pcScene->mMeshes[i]->mNormals = apcMeshes[i]->pvOriginalNormals;
apcMeshes[i]->pvOriginalNormals = NULL;
apcMeshes[i]->pvOriginalNormals = nullptr;
}
}
}
@ -153,14 +137,11 @@ void AssetHelper::SetNormalSet(unsigned int iSet)
iNormalSet = iSet;
if (g_bWasFlipped)
{
if (g_bWasFlipped) {
// invert all normal vectors
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i)
{
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i) {
aiMesh* pcMesh = pcScene->mMeshes[i];
for (unsigned int a = 0; a < pcMesh->mNumVertices;++a)
{
for (unsigned int a = 0; a < pcMesh->mNumVertices;++a) {
pcMesh->mNormals[a] *= -1.0f;
}
}
@ -169,7 +150,6 @@ void AssetHelper::SetNormalSet(unsigned int iSet)
// recreate native data
DeleteAssetData(true);
CreateAssetData();
return;
}
};
}

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.
@ -47,21 +47,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace AssimpView;
const aiMatrix4x4 IdentityMatrix;
// ------------------------------------------------------------------------------------------------
// Constructor for a given scene.
SceneAnimator::SceneAnimator( const aiScene* pScene, size_t pAnimIndex)
{
mScene = pScene;
mCurrentAnimIndex = -1;
mAnimEvaluator = NULL;
mRootNode = NULL;
: mScene( pScene )
, mCurrentAnimIndex( -1 )
, mAnimEvaluator( nullptr )
, mRootNode( nullptr ) {
// build the nodes-for-bones table
for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
{
for (unsigned int i = 0; i < pScene->mNumMeshes;++i) {
const aiMesh* mesh = pScene->mMeshes[i];
for (unsigned int n = 0; n < mesh->mNumBones;++n)
{
for (unsigned int n = 0; n < mesh->mNumBones;++n) {
const aiBone* bone = mesh->mBones[n];
mBoneNodesByName[bone->mName.data] = pScene->mRootNode->FindNode(bone->mName);
@ -74,34 +72,34 @@ SceneAnimator::SceneAnimator( const aiScene* pScene, size_t pAnimIndex)
// ------------------------------------------------------------------------------------------------
// Destructor
SceneAnimator::~SceneAnimator()
{
SceneAnimator::~SceneAnimator() {
delete mRootNode;
delete mAnimEvaluator;
}
// ------------------------------------------------------------------------------------------------
// Sets the animation to use for playback.
void SceneAnimator::SetAnimIndex( size_t pAnimIndex)
{
void SceneAnimator::SetAnimIndex( size_t pAnimIndex) {
// no change
if( pAnimIndex == mCurrentAnimIndex)
if (pAnimIndex == static_cast<unsigned int>( mCurrentAnimIndex ) ) {
return;
}
// kill data of the previous anim
delete mRootNode; mRootNode = NULL;
delete mAnimEvaluator; mAnimEvaluator = NULL;
delete mRootNode; mRootNode = nullptr;
delete mAnimEvaluator; mAnimEvaluator = nullptr;
mNodesByName.clear();
mCurrentAnimIndex = pAnimIndex;
// create the internal node tree. Do this even in case of invalid animation index
// so that the transformation matrices are properly set up to mimic the current scene
mRootNode = CreateNodeTree( mScene->mRootNode, NULL);
mRootNode = CreateNodeTree( mScene->mRootNode, nullptr);
// invalid anim index
if( mCurrentAnimIndex >= mScene->mNumAnimations)
if (static_cast<unsigned int>( mCurrentAnimIndex )>= mScene->mNumAnimations) {
return;
}
// create an evaluator for this animation
mAnimEvaluator = new AnimEvaluator( mScene->mAnimations[mCurrentAnimIndex]);
@ -109,11 +107,11 @@ void SceneAnimator::SetAnimIndex( size_t pAnimIndex)
// ------------------------------------------------------------------------------------------------
// Calculates the node transformations for the scene.
void SceneAnimator::Calculate( double pTime)
{
void SceneAnimator::Calculate( double pTime) {
// invalid anim
if( !mAnimEvaluator)
if (!mAnimEvaluator) {
return;
}
// calculate current local transformations
mAnimEvaluator->Evaluate( pTime);
@ -124,36 +122,35 @@ void SceneAnimator::Calculate( double pTime)
// ------------------------------------------------------------------------------------------------
// Retrieves the most recent local transformation matrix for the given node.
const aiMatrix4x4& SceneAnimator::GetLocalTransform( const aiNode* node) const
{
const aiMatrix4x4& SceneAnimator::GetLocalTransform( const aiNode* node) const {
NodeMap::const_iterator it = mNodesByName.find( node);
if( it == mNodesByName.end())
return mIdentityMatrix;
if (it == mNodesByName.end()) {
return IdentityMatrix;
}
return it->second->mLocalTransform;
}
// ------------------------------------------------------------------------------------------------
// Retrieves the most recent global transformation matrix for the given node.
const aiMatrix4x4& SceneAnimator::GetGlobalTransform( const aiNode* node) const
{
const aiMatrix4x4& SceneAnimator::GetGlobalTransform( const aiNode* node) const {
NodeMap::const_iterator it = mNodesByName.find( node);
if( it == mNodesByName.end())
return mIdentityMatrix;
if (it == mNodesByName.end()) {
return IdentityMatrix;
}
return it->second->mGlobalTransform;
}
// ------------------------------------------------------------------------------------------------
// Calculates the bone matrices for the given mesh.
const std::vector<aiMatrix4x4>& SceneAnimator::GetBoneMatrices( const aiNode* pNode, size_t pMeshIndex /* = 0 */)
{
const std::vector<aiMatrix4x4>& SceneAnimator::GetBoneMatrices( const aiNode* pNode, size_t pMeshIndex /* = 0 */) {
ai_assert( pMeshIndex < pNode->mNumMeshes);
size_t meshIndex = pNode->mMeshes[pMeshIndex];
ai_assert( meshIndex < mScene->mNumMeshes);
const aiMesh* mesh = mScene->mMeshes[meshIndex];
// resize array and initialise it with identity matrices
// resize array and initialize it with identity matrices
mTransforms.resize( mesh->mNumBones, aiMatrix4x4());
// calculate the mesh's inverse global transform
@ -162,8 +159,7 @@ const std::vector<aiMatrix4x4>& SceneAnimator::GetBoneMatrices( const aiNode* pN
// Bone matrices transform from mesh coordinates in bind pose to mesh coordinates in skinned pose
// Therefore the formula is offsetMatrix * currentGlobalTransform * inverseCurrentMeshTransform
for( size_t a = 0; a < mesh->mNumBones; ++a)
{
for( size_t a = 0; a < mesh->mNumBones; ++a) {
const aiBone* bone = mesh->mBones[a];
const aiMatrix4x4& currentGlobalTransform = GetGlobalTransform( mBoneNodesByName[ bone->mName.data ]);
mTransforms[a] = globalInverseMeshTransform * currentGlobalTransform * bone->mOffsetMatrix;
@ -175,8 +171,7 @@ const std::vector<aiMatrix4x4>& SceneAnimator::GetBoneMatrices( const aiNode* pN
// ------------------------------------------------------------------------------------------------
// Recursively creates an internal node structure matching the current scene and animation.
SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pParent)
{
SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pParent) {
// create a node
SceneAnimNode* internalNode = new SceneAnimNode( pNode->mName.data);
internalNode->mParent = pParent;
@ -187,14 +182,11 @@ SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pPar
CalculateGlobalTransform( internalNode);
// find the index of the animation track affecting this node, if any
if( mCurrentAnimIndex < mScene->mNumAnimations)
{
if(static_cast<unsigned int>( mCurrentAnimIndex ) < mScene->mNumAnimations) {
internalNode->mChannelIndex = -1;
const aiAnimation* currentAnim = mScene->mAnimations[mCurrentAnimIndex];
for( unsigned int a = 0; a < currentAnim->mNumChannels; a++)
{
if( currentAnim->mChannels[a]->mNodeName.data == internalNode->mName)
{
for( unsigned int a = 0; a < currentAnim->mNumChannels; a++) {
if( currentAnim->mChannels[a]->mNodeName.data == internalNode->mName) {
internalNode->mChannelIndex = a;
break;
}
@ -202,8 +194,7 @@ SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pPar
}
// continue for all child nodes and assign the created internal nodes as our children
for( unsigned int a = 0; a < pNode->mNumChildren; a++)
{
for( unsigned int a = 0; a < pNode->mNumChildren; ++a ) {
SceneAnimNode* childNode = CreateNodeTree( pNode->mChildren[a], internalNode);
internalNode->mChildren.push_back( childNode);
}
@ -213,12 +204,10 @@ SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pPar
// ------------------------------------------------------------------------------------------------
// Recursively updates the internal node transformations from the given matrix array
void SceneAnimator::UpdateTransforms( SceneAnimNode* pNode, const std::vector<aiMatrix4x4>& pTransforms)
{
void SceneAnimator::UpdateTransforms( SceneAnimNode* pNode, const std::vector<aiMatrix4x4>& pTransforms) {
// update node local transform
if( pNode->mChannelIndex != -1)
{
ai_assert( pNode->mChannelIndex < pTransforms.size());
if( pNode->mChannelIndex != -1) {
ai_assert(static_cast<unsigned int>( pNode->mChannelIndex ) < pTransforms.size());
pNode->mLocalTransform = pTransforms[pNode->mChannelIndex];
}
@ -226,19 +215,18 @@ void SceneAnimator::UpdateTransforms( SceneAnimNode* pNode, const std::vector<ai
CalculateGlobalTransform( pNode);
// continue for all children
for( std::vector<SceneAnimNode*>::iterator it = pNode->mChildren.begin(); it != pNode->mChildren.end(); ++it)
UpdateTransforms( *it, pTransforms);
for (std::vector<SceneAnimNode*>::iterator it = pNode->mChildren.begin(); it != pNode->mChildren.end(); ++it) {
UpdateTransforms(*it, pTransforms);
}
}
// ------------------------------------------------------------------------------------------------
// Calculates the global transformation matrix for the given internal node
void SceneAnimator::CalculateGlobalTransform( SceneAnimNode* pInternalNode)
{
void SceneAnimator::CalculateGlobalTransform( SceneAnimNode* pInternalNode) {
// concatenate all parent transforms to get the global transform for this node
pInternalNode->mGlobalTransform = pInternalNode->mLocalTransform;
SceneAnimNode* node = pInternalNode->mParent;
while( node)
{
while( node) {
pInternalNode->mGlobalTransform = node->mLocalTransform * pInternalNode->mGlobalTransform;
node = node->mParent;
}

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.
@ -49,15 +49,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <map>
namespace AssimpView {
namespace AssimpView {
// ---------------------------------------------------------------------------------
/** A little tree structure to match the scene's node structure, but holding
* additional data. Needs to be public to allow using it in templates at
* certain compilers.
*/
struct SceneAnimNode
{
struct SceneAnimNode {
std::string mName;
SceneAnimNode* mParent;
std::vector<SceneAnimNode*> mChildren;
@ -69,12 +68,15 @@ struct SceneAnimNode
aiMatrix4x4 mGlobalTransform;
//! index in the current animation's channel array. -1 if not animated.
size_t mChannelIndex;
int mChannelIndex;
//! Default construction
SceneAnimNode()
: mName()
, mParent(NULL)
, mParent(nullptr)
, mChildren()
, mLocalTransform()
, mGlobalTransform()
, mChannelIndex(-1) {
// empty
}
@ -82,8 +84,11 @@ struct SceneAnimNode
//! Construction from a given name
SceneAnimNode( const std::string& pName)
: mName( pName)
, mParent(NULL)
, mChannelIndex( -1 ) {
, mParent(nullptr)
, mChildren()
, mLocalTransform()
, mGlobalTransform()
, mChannelIndex(-1) {
// empty
}
@ -105,8 +110,7 @@ struct SceneAnimNode
* GetGlobalTransform(). A full set of bone matrices can be retrieved by
* GetBoneMatrices() for a given mesh.
*/
class SceneAnimator
{
class SceneAnimator {
public:
// ----------------------------------------------------------------------------
@ -186,7 +190,6 @@ public:
const std::vector<aiMatrix4x4>& GetBoneMatrices( const aiNode* pNode,
size_t pMeshIndex = 0);
// ----------------------------------------------------------------------------
/** @brief Get the current animation index
*/
@ -198,7 +201,7 @@ public:
/** @brief Get the current animation or NULL
*/
aiAnimation* CurrentAnim() const {
return mCurrentAnimIndex < mScene->mNumAnimations ? mScene->mAnimations[ mCurrentAnimIndex ] : NULL;
return static_cast<unsigned int>( mCurrentAnimIndex ) < mScene->mNumAnimations ? mScene->mAnimations[ mCurrentAnimIndex ] : NULL;
}
protected:
@ -221,7 +224,7 @@ protected:
const aiScene* mScene;
/** Current animation index */
size_t mCurrentAnimIndex;
int mCurrentAnimIndex;
/** The AnimEvaluator we use to calculate the current pose for the current animation */
AnimEvaluator* mAnimEvaluator;
@ -239,9 +242,6 @@ protected:
/** Array to return transformations results inside. */
std::vector<aiMatrix4x4> mTransforms;
/** Identity matrix to return a reference to in case of error */
aiMatrix4x4 mIdentityMatrix;
};
} // end of namespace AssimpView

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.