------------------------------------------------------------------------------- Load the current asset The path to the asset is specified in the global variable g_szFileName -------------------------------------------------------------------------------
| 195 | // The path to the asset is specified in the global variable g_szFileName |
| 196 | //------------------------------------------------------------------------------- |
| 197 | int LoadAsset() { |
| 198 | // set the world and world rotation matrices to the identity |
| 199 | g_mWorldRotate = aiMatrix4x4(); |
| 200 | g_mWorld = aiMatrix4x4(); |
| 201 | |
| 202 | // char szTemp[MAX_PATH+64]; |
| 203 | // sprintf(szTemp,"Starting to load %s",g_szFileName); |
| 204 | CLogWindow::Instance().WriteLine( |
| 205 | "----------------------------------------------------------------------------"); |
| 206 | // CLogWindow::Instance().WriteLine(szTemp); |
| 207 | // CLogWindow::Instance().WriteLine( |
| 208 | // "----------------------------------------------------------------------------"); |
| 209 | CLogWindow::Instance().SetAutoUpdate(false); |
| 210 | |
| 211 | // create a helper thread to load the asset |
| 212 | DWORD dwID; |
| 213 | g_bLoadingCanceled = false; |
| 214 | g_pcAsset = new AssetHelper(); |
| 215 | g_hThreadHandle = CreateThread(nullptr, 0, &LoadThreadProc, nullptr, 0, &dwID); |
| 216 | |
| 217 | if (!g_hThreadHandle) { |
| 218 | CLogDisplay::Instance().AddEntry( |
| 219 | "[ERROR] Unable to create helper thread for loading", |
| 220 | D3DCOLOR_ARGB(0xFF, 0xFF, 0, 0)); |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | // show the progress bar dialog |
| 225 | DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_LOADDIALOG), |
| 226 | g_hDlg, &ProgressMessageProc); |
| 227 | |
| 228 | // update the log window |
| 229 | CLogWindow::Instance().SetAutoUpdate(true); |
| 230 | CLogWindow::Instance().Update(); |
| 231 | |
| 232 | // now we should have loaded the asset. Check this ... |
| 233 | g_bLoadingFinished = false; |
| 234 | if (!g_pcAsset || !g_pcAsset->pcScene) { |
| 235 | if (g_pcAsset) { |
| 236 | delete g_pcAsset; |
| 237 | g_pcAsset = nullptr; |
| 238 | } |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | // allocate a new MeshHelper array and build a new instance |
| 243 | // for each mesh in the original asset |
| 244 | g_pcAsset->apcMeshes = new AssetHelper::MeshHelper *[g_pcAsset->pcScene->mNumMeshes](); |
| 245 | for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes; ++i) |
| 246 | g_pcAsset->apcMeshes[i] = new AssetHelper::MeshHelper(); |
| 247 | |
| 248 | // create animator |
| 249 | g_pcAsset->mAnimator = new SceneAnimator(g_pcAsset->pcScene); |
| 250 | |
| 251 | // build a new caption string for the viewer |
| 252 | static const size_t Size = MAX_PATH + 10; |
| 253 | char szOut[Size]; |
| 254 | ai_snprintf(szOut, Size, AI_VIEW_CAPTION_BASE " [%s]", g_szFileName); |
no test coverage detected