Assimp viewer fixes (#5582)

* AssimpViewer: Fix statistics reset + rename Time -> Loading time (more explicit)

* AssimpViewer: Fix bug where it was not possible to reload a closed asset

* AssimpViewer: Add a name in combobox for unnamed animations and disable anim UI when there is no animation

* AssimpViewer: Fixes the case where moving the anim cursor can break the animation

* AssimpViewer: Fixes the fact that when you press "play" on the animation after stopping it, there was a time jump in the animation

---------

Co-authored-by: Kim Kulling <kimkulling@users.noreply.github.com>
pull/5578/head^2
Jean-Louis Boudrand 2024-05-18 19:20:06 +02:00 committed by GitHub
parent 2521909b8c
commit 787c9afdf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 84 additions and 54 deletions

View File

@ -106,6 +106,11 @@ int CDisplay::EnableAnimTools(BOOL hm) {
EnableWindow(GetDlgItem(g_hDlg,IDC_PLAY),hm);
EnableWindow(GetDlgItem(g_hDlg,IDC_SLIDERANIM),hm);
if (hm == FALSE) {
g_dCurrent = 0.0;
SendDlgItemMessage(g_hDlg, IDC_SLIDERANIM, TBM_SETPOS, TRUE, LPARAM(0));
}
return 1;
}
@ -115,9 +120,16 @@ int CDisplay::FillAnimList(void) {
if (0 != g_pcAsset->pcScene->mNumAnimations)
{
// now fill in all animation names
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumAnimations;++i) {
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumAnimations; ++i)
{
std::string animationLabel(g_pcAsset->pcScene->mAnimations[i]->mName.data);
if (animationLabel.empty())
{
animationLabel = std::string("Animation ") + std::to_string(i) + " (UNNAMED)";
}
SendDlgItemMessage(g_hDlg,IDC_COMBO1,CB_ADDSTRING,0,
( LPARAM ) g_pcAsset->pcScene->mAnimations[i]->mName.data);
(LPARAM)animationLabel.c_str());
}
// also add a dummy - 'none'
@ -139,6 +151,7 @@ int CDisplay::ClearAnimList(void)
{
// clear the combo box
SendDlgItemMessage(g_hDlg,IDC_COMBO1,CB_RESETCONTENT,0,0);
EnableAnimTools(FALSE);
return 1;
}
//-------------------------------------------------------------------------------
@ -725,23 +738,25 @@ int CDisplay::OnRender()
// update possible animation
if( g_pcAsset)
{
static double lastPlaying = 0.;
static double lastRenderTime = 0.;
ai_assert( g_pcAsset->mAnimator);
double currentTime = clock() / double(CLOCKS_PER_SEC);
if (g_bPlay) {
g_dCurrent += clock()/ double( CLOCKS_PER_SEC) -lastPlaying;
g_dCurrent += currentTime - lastRenderTime;
double time = g_dCurrent;
aiAnimation* mAnim = g_pcAsset->mAnimator->CurrentAnim();
if( mAnim && mAnim->mDuration > 0.0) {
double tps = mAnim->mTicksPerSecond ? mAnim->mTicksPerSecond : 25.f;
time = fmod( time, mAnim->mDuration/tps);
SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_SETPOS,TRUE,LPARAM(10000 * (time/(mAnim->mDuration/tps))));
if (mAnim && mAnim->mDuration > 0.0) {
double tps = mAnim->mTicksPerSecond ? mAnim->mTicksPerSecond : ANIM_DEFAULT_TICKS_PER_SECOND;
time = fmod(time, mAnim->mDuration/tps);
SendDlgItemMessage(g_hDlg, IDC_SLIDERANIM, TBM_SETPOS, TRUE, LPARAM(ANIM_SLIDER_MAX * (time / (mAnim->mDuration / tps))));
}
g_pcAsset->mAnimator->Calculate( time );
lastPlaying = g_dCurrent;
}
lastRenderTime = currentTime;
}
// begin the frame
g_piDevice->BeginScene();
@ -793,8 +808,10 @@ int CDisplay::FillDefaultStatistics(void)
SetDlgItemText(g_hDlg,IDC_EVERT,"0");
SetDlgItemText(g_hDlg,IDC_EFACE,"0");
SetDlgItemText(g_hDlg,IDC_EMAT,"0");
SetDlgItemText(g_hDlg,IDC_ENODE,"0");
SetDlgItemText(g_hDlg,IDC_EMESH,"0");
SetDlgItemText(g_hDlg,IDC_ENODEWND,"0");
SetDlgItemText(g_hDlg,IDC_ESHADER,"0");
SetDlgItemText(g_hDlg,IDC_ELOAD,"");
SetDlgItemText(g_hDlg,IDC_ETEX,"0");
return 1;
}
@ -877,7 +894,7 @@ int CDisplay::OnSetupNormalView()
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMSHADERS),"Shaders:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMMATS),"Materials:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMMESHES),"Meshes:");
SetWindowText(GetDlgItem(g_hDlg,IDC_LOADTIME),"Time:");
SetWindowText(GetDlgItem(g_hDlg,IDC_LOADTIME),"Loading Time:");
FillDefaultStatistics();
SetViewMode(VIEWMODE_FULL);

View File

@ -874,9 +874,10 @@ void OpenAsset() {
RegSetValueExA(g_hRegistry,"CurrentApp",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
if (0 != strcmp(g_szFileName,szFileName)) {
strcpy(g_szFileName, szFileName);
DeleteAssetData();
DeleteAsset();
strcpy(g_szFileName, szFileName);
LoadAsset();
// update the history
@ -1197,7 +1198,7 @@ void InitUI() {
LoadCheckerPatternColors();
SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_SETRANGEMIN,TRUE,0);
SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_SETRANGEMAX,TRUE,10000);
SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_SETRANGEMAX,TRUE,ANIM_SLIDER_MAX);
}
//-------------------------------------------------------------------------------
@ -1274,11 +1275,14 @@ INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM lParam
// XXX quick and dirty fix for #3029892
if (GetDlgItem(g_hDlg, IDC_SLIDERANIM) == (HWND)lParam && g_pcAsset && g_pcAsset->pcScene->mAnimations)
{
double num = (double)SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_GETPOS,0,0);
const aiAnimation* anim = g_pcAsset->pcScene->mAnimations[ g_pcAsset->mAnimator->CurrentAnimIndex() ];
g_dCurrent = (anim->mDuration/anim->mTicksPerSecond) * num/10000;
g_pcAsset->mAnimator->Calculate(g_dCurrent);
if (anim && anim->mDuration > 0.0)
{
double tps = anim->mTicksPerSecond ? anim->mTicksPerSecond : ANIM_DEFAULT_TICKS_PER_SECOND;
double sliderValue = (double)SendDlgItemMessage(g_hDlg, IDC_SLIDERANIM, TBM_GETPOS, 0, 0);
g_dCurrent = (anim->mDuration / tps) * sliderValue / ANIM_SLIDER_MAX;
g_pcAsset->mAnimator->Calculate(g_dCurrent);
}
}
break;
@ -1666,10 +1670,11 @@ INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM lParam
}
fclose(pFile);
} else {
strcpy(g_szFileName,szFile);
DeleteAsset();
strcpy(g_szFileName, szFile);
LoadAsset();
UpdateHistory();
SaveHistory();
}
@ -1690,6 +1695,9 @@ INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM lParam
g_pcAsset->mAnimator->SetAnimIndex(sel);
SendDlgItemMessage(hwndDlg,IDC_SLIDERANIM,TBM_SETPOS,TRUE,0);
}
const size_t count = static_cast<size_t>(ComboBox_GetCount(GetDlgItem(hwndDlg, IDC_COMBO1)));
CDisplay::Instance().EnableAnimTools(g_pcAsset && count > 0 && sel < count - 1 ? TRUE : FALSE);
}
} else if (ID_VIEWER_RESETVIEW == LOWORD(wParam)) {
g_sCamera.vPos = aiVector3D(0.0f,0.0f,-10.0f);
@ -1827,7 +1835,12 @@ INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM lParam
}
else if (ID_VIEWER_RELOAD == LOWORD(wParam))
{
// Save the filename to reload and clear
char toReloadFileName[MAX_PATH];
strcpy(toReloadFileName, g_szFileName);
DeleteAsset();
strcpy(g_szFileName, toReloadFileName);
LoadAsset();
}
else if (ID_IMPORTSETTINGS_RESETTODEFAULT == LOWORD(wParam))
@ -2036,9 +2049,10 @@ INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM lParam
{
if (AI_VIEW_RECENT_FILE_ID(i) == LOWORD(wParam))
{
strcpy(g_szFileName,g_aPreviousFiles[i].c_str());
DeleteAssetData();
DeleteAsset();
strcpy(g_szFileName, g_aPreviousFiles[i].c_str());
LoadAsset();
// update and safe the history
@ -2209,6 +2223,8 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
CLogDisplay::Instance().AddEntry("[OK] Here we go!");
CDisplay::Instance().EnableAnimTools(FALSE);
// create the log window
CLogWindow::Instance().Init();
// set the focus to the main window
@ -2397,7 +2413,6 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
}
}
// render the scene
CDisplay::Instance().OnRender();

View File

@ -81,7 +81,7 @@ float g_fWheelPos = -10.0f;
bool g_bLoadingCanceled = false;
IDirect3DTexture9 *g_pcTexture = nullptr;
bool g_bPlay = false;
double g_dCurrent = 0.;
double g_dCurrent = 0.; // Animation time
// default pp steps
unsigned int ppsteps = aiProcess_CalcTangentSpace | // calculate tangents and bitangents if possible
@ -191,8 +191,8 @@ DWORD WINAPI LoadThreadProc(LPVOID) {
}
//-------------------------------------------------------------------------------
// load the current asset
// THe path to the asset is specified in the global path variable
// Load the current asset
// The path to the asset is specified in the global variable g_szFileName
//-------------------------------------------------------------------------------
int LoadAsset() {
// set the world and world rotation matrices to the identity
@ -267,14 +267,6 @@ int LoadAsset() {
if (1 != CreateAssetData())
return 0;
if (!g_pcAsset->pcScene->HasAnimations()) {
EnableWindow(GetDlgItem(g_hDlg, IDC_PLAY), FALSE);
EnableWindow(GetDlgItem(g_hDlg, IDC_SLIDERANIM), FALSE);
} else {
EnableWindow(GetDlgItem(g_hDlg, IDC_PLAY), TRUE);
EnableWindow(GetDlgItem(g_hDlg, IDC_SLIDERANIM), TRUE);
}
CLogDisplay::Instance().AddEntry("[OK] The asset has been loaded successfully");
CDisplay::Instance().FillDisplayList();
CDisplay::Instance().FillAnimList();
@ -312,6 +304,8 @@ int DeleteAsset(void) {
delete g_pcAsset;
g_pcAsset = nullptr;
g_szFileName[0] = '\0';
// reset the caption of the viewer window
SetWindowText(g_hDlg, AI_VIEW_CAPTION_BASE);

View File

@ -78,6 +78,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// default movement speed
#define MOVE_SPEED 3.f
// Anim constants
#define ANIM_DEFAULT_TICKS_PER_SECOND 25.f
#define ANIM_SLIDER_MAX 10000
#include "AssetHelper.h"
#include "Background.h"
#include "Camera.h"

View File

@ -80,32 +80,32 @@ BEGIN
CONTROL "Two lights [L]",IDC_3LIGHTS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,93,393,80,10
CONTROL "Backface culling [C]",IDC_BFCULL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,93,405,80,10
CONTROL "No transparency [T]",IDC_NOAB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,93,417,80,10
GROUPBOX "Statistics",IDC_STATIC,186,345,164,63
GROUPBOX "Statistics",IDC_STATIC,186,345,200,63
LTEXT "Vertices:",IDC_NUMVERTS,192,357,35,8
LTEXT "Nodes:",IDC_NUMNODES,192,369,35,8
LTEXT "Shaders:",IDC_NUMSHADERS,192,381,35,8
LTEXT "Time:",IDC_LOADTIME,192,393,35,8
EDITTEXT IDC_EVERT,227,357,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_ENODEWND,227,369,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_ESHADER,227,381,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_ELOAD,227,393,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
LTEXT "Faces:",IDC_NUMFACES,272,357,35,8
LTEXT "Materials:",IDC_NUMMATS,272,369,35,8
LTEXT "Meshes:",IDC_NUMMESHES,272,381,35,8
LTEXT "FPS:",IDC_FPS,272,393,35,8
EDITTEXT IDC_EFACE,307,357,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_EMAT,307,369,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_EMESH,307,381,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_EFPS,307,393,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
LTEXT "Loading Time:",IDC_LOADTIME,192,393,46,8
EDITTEXT IDC_EVERT,241,357,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_ENODEWND,241,369,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_ESHADER,241,381,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_ELOAD,241,393,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
LTEXT "Faces:",IDC_NUMFACES,306,357,35,8
LTEXT "Materials:",IDC_NUMMATS,306,369,35,8
LTEXT "Meshes:",IDC_NUMMESHES,306,381,35,8
LTEXT "FPS:",IDC_FPS,306,393,35,8
EDITTEXT IDC_EFACE,341,357,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_EMAT,341,369,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_EMESH,341,381,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_EFPS,341,393,35,8,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER
EDITTEXT IDC_VIEWMATRIX,192,412,72,44,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | NOT WS_VISIBLE | NOT WS_BORDER
GROUPBOX "Colors",IDC_STATIC,357,345,109,87
LTEXT "Primary:",IDC_STATIC,363,360,48,8
LTEXT "Secondary:",IDC_STATIC,363,378,54,8
LTEXT "Ambient:",IDC_STATIC,363,396,54,8
CONTROL "Button1",IDC_LCOLOR1,"Button",BS_OWNERDRAW | WS_TABSTOP,423,357,35,14
CONTROL "Button1",IDC_LCOLOR2,"Button",BS_OWNERDRAW | WS_TABSTOP,423,375,35,14
CONTROL "Button1",IDC_LCOLOR3,"Button",BS_OWNERDRAW | WS_TABSTOP,423,393,35,14
PUSHBUTTON "Reset",IDC_LRESET,423,411,35,14
GROUPBOX "Colors",IDC_STATIC,397,345,109,87
LTEXT "Primary:",IDC_STATIC,403,360,48,8
LTEXT "Secondary:",IDC_STATIC,403,377,54,8
LTEXT "Ambient:",IDC_STATIC,403,396,54,8
CONTROL "Button1",IDC_LCOLOR1,"Button",BS_OWNERDRAW | WS_TABSTOP,463,357,35,14
CONTROL "Button1",IDC_LCOLOR2,"Button",BS_OWNERDRAW | WS_TABSTOP,463,374,35,14
CONTROL "Button1",IDC_LCOLOR3,"Button",BS_OWNERDRAW | WS_TABSTOP,463,393,35,14
PUSHBUTTON "Reset",IDC_LRESET,463,411,35,14
END
IDD_LOADDIALOG DIALOGEX 0, 0, 143, 60