2008-05-13 23:26:52 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
2008-05-22 10:20:31 +00:00
|
|
|
Open Asset Import Library (ASSIMP)
|
2008-05-13 23:26:52 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2010-04-10 15:30:22 +00:00
|
|
|
Copyright (c) 2006-2010, ASSIMP Development Team
|
2008-05-13 23:26:52 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
|
|
|
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 Development Team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
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
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "assimp_view.h"
|
2008-05-13 23:26:52 +00:00
|
|
|
#include <map>
|
|
|
|
using namespace std;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
namespace AssimpView {
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
// evil globals
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
HINSTANCE g_hInstance = NULL;
|
|
|
|
HWND g_hDlg = NULL;
|
|
|
|
IDirect3D9* g_piD3D = NULL;
|
|
|
|
IDirect3DDevice9* g_piDevice = NULL;
|
2008-10-29 17:08:03 +00:00
|
|
|
IDirect3DVertexDeclaration9* gDefaultVertexDecl = NULL;
|
2008-05-05 12:36:31 +00:00
|
|
|
double g_fFPS = 0.0f;
|
|
|
|
char g_szFileName[MAX_PATH];
|
|
|
|
ID3DXEffect* g_piDefaultEffect = NULL;
|
|
|
|
ID3DXEffect* g_piNormalsEffect = NULL;
|
|
|
|
ID3DXEffect* g_piPassThroughEffect = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
ID3DXEffect* g_piPatternEffect = NULL;
|
2008-05-05 12:36:31 +00:00
|
|
|
bool g_bMousePressed = false;
|
|
|
|
bool g_bMousePressedR = false;
|
|
|
|
bool g_bMousePressedM = false;
|
|
|
|
bool g_bMousePressedBoth = false;
|
|
|
|
float g_fElpasedTime = 0.0f;
|
|
|
|
D3DCAPS9 g_sCaps;
|
|
|
|
bool g_bLoadingFinished = false;
|
|
|
|
HANDLE g_hThreadHandle = NULL;
|
|
|
|
float g_fWheelPos = -10.0f;
|
|
|
|
bool g_bLoadingCanceled = false;
|
|
|
|
IDirect3DTexture9* g_pcTexture = NULL;
|
2009-02-11 20:56:05 +00:00
|
|
|
bool g_bPlay = false;
|
|
|
|
double g_dCurrent = 0.;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2009-05-09 23:27:48 +00:00
|
|
|
// default pp steps
|
|
|
|
unsigned int ppsteps = aiProcess_CalcTangentSpace | // calculate tangents and bitangents if possible
|
|
|
|
aiProcess_JoinIdenticalVertices | // join identical vertices/ optimize indexing
|
|
|
|
aiProcess_ValidateDataStructure | // perform a full validation of the loader's output
|
|
|
|
aiProcess_ImproveCacheLocality | // improve the cache locality of the output vertices
|
|
|
|
aiProcess_RemoveRedundantMaterials | // remove redundant materials
|
|
|
|
aiProcess_FindDegenerates | // remove degenerated polygons from the import
|
|
|
|
aiProcess_FindInvalidData | // detect invalid model data, such as invalid normal vectors
|
|
|
|
aiProcess_GenUVCoords | // convert spherical, cylindrical, box and planar mapping to proper UVs
|
|
|
|
aiProcess_TransformUVCoords | // preprocess UV transformations (scaling, translation ...)
|
|
|
|
aiProcess_FindInstances | // search for instanced meshes and remove them by references to one master
|
|
|
|
aiProcess_LimitBoneWeights | // limit bone weights to 4 per vertex
|
|
|
|
aiProcess_OptimizeMeshes | // join small meshes, if possible;
|
|
|
|
0;
|
|
|
|
|
|
|
|
unsigned int ppstepsdefault = ppsteps;
|
|
|
|
|
|
|
|
bool nopointslines = false;
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
extern bool g_bWasFlipped /*= false*/;
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
aiMatrix4x4 g_mWorld;
|
|
|
|
aiMatrix4x4 g_mWorldRotate;
|
|
|
|
aiVector3D g_vRotateSpeed = aiVector3D(0.5f,0.5f,0.5f);
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
// NOTE: The second light direction is no computed from the first
|
|
|
|
aiVector3D g_avLightDirs[1] =
|
|
|
|
{ aiVector3D(-0.5f,0.6f,0.2f) };
|
|
|
|
|
|
|
|
extern D3DCOLOR g_avLightColors[3] =
|
|
|
|
{
|
|
|
|
D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF),
|
|
|
|
D3DCOLOR_ARGB(0xFF,0xFF,0x00,0x00),
|
|
|
|
D3DCOLOR_ARGB(0xFF,0x05,0x05,0x05),
|
|
|
|
};
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
POINT g_mousePos;
|
|
|
|
POINT g_LastmousePos;
|
|
|
|
bool g_bFPSView = false;
|
|
|
|
bool g_bInvert = false;
|
|
|
|
EClickPos g_eClick = EClickPos_Circle;
|
|
|
|
unsigned int g_iCurrentColor = 0;
|
|
|
|
|
|
|
|
float g_fLightIntensity = 1.0f;
|
|
|
|
float g_fLightColor = 1.0f;
|
|
|
|
|
|
|
|
RenderOptions g_sOptions;
|
|
|
|
Camera g_sCamera;
|
|
|
|
AssetHelper *g_pcAsset = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Contains the mask image for the HUD
|
|
|
|
// (used to determine the position of a click)
|
|
|
|
//
|
|
|
|
unsigned char* g_szImageMask = NULL;
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
float g_fLoadTime = 0.0f;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
// Entry point for the loader thread
|
|
|
|
// The laoder thread loads the asset while the progress dialog displays the
|
|
|
|
// smart progress bar
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
DWORD WINAPI LoadThreadProc(LPVOID lpParameter)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
UNREFERENCED_PARAMETER(lpParameter);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// get current time
|
2008-05-05 12:36:31 +00:00
|
|
|
double fCur = (double)timeGetTime();
|
|
|
|
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
aiSetImportPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS,1);
|
2009-05-09 23:27:48 +00:00
|
|
|
aiSetImportPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,g_smoothAngle);
|
|
|
|
aiSetImportPropertyInteger(AI_CONFIG_PP_SBP_REMOVE,nopointslines ? aiPrimitiveType_LINE | aiPrimitiveType_POINT : 0 );
|
|
|
|
|
2009-03-26 22:05:56 +00:00
|
|
|
//aiSetImportPropertyInteger(AI_CONFIG_PP_FD_REMOVE,1);
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
//aiSetImportPropertyInteger(AI_CONFIG_PP_PTV_KEEP_HIERARCHY,1);
|
|
|
|
|
2009-01-11 15:20:06 +00:00
|
|
|
// Call ASSIMPs C-API to load the file
|
2008-05-13 23:26:52 +00:00
|
|
|
g_pcAsset->pcScene = (aiScene*)aiImportFile(g_szFileName,
|
2009-05-09 23:27:48 +00:00
|
|
|
|
|
|
|
ppsteps | /* configurable pp steps */
|
2009-01-11 15:20:06 +00:00
|
|
|
aiProcess_GenSmoothNormals | // generate smooth normal vectors if not existing
|
|
|
|
aiProcess_SplitLargeMeshes | // split large, unrenderable meshes into submeshes
|
2009-05-09 23:27:48 +00:00
|
|
|
aiProcess_Triangulate | // triangulate polygons with more than 3 edges
|
|
|
|
aiProcess_ConvertToLeftHanded | // convert everything to D3D left handed space
|
2009-01-11 15:20:06 +00:00
|
|
|
aiProcess_SortByPType | // make 'clean' meshes which consist of a single typ of primitives
|
|
|
|
0);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// get the end time of zje operation, calculate delta t
|
2008-05-05 12:36:31 +00:00
|
|
|
double fEnd = (double)timeGetTime();
|
2008-05-13 23:26:52 +00:00
|
|
|
g_fLoadTime = (float)((fEnd - fCur) / 1000);
|
|
|
|
// char szTemp[128];
|
2008-05-05 12:36:31 +00:00
|
|
|
g_bLoadingFinished = true;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// check whether the loading process has failed ...
|
2008-05-05 12:36:31 +00:00
|
|
|
if (NULL == g_pcAsset->pcScene)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
CLogDisplay::Instance().AddEntry("[ERROR] Unable to load this asset:",
|
|
|
|
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// print ASSIMPs error string to the log display
|
2008-05-05 12:36:31 +00:00
|
|
|
CLogDisplay::Instance().AddEntry(aiGetErrorString(),
|
|
|
|
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
|
|
|
|
return 1;
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
return 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
// load the current asset
|
|
|
|
// THe path to the asset is specified in the global path variable
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int LoadAsset(void)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
// set the world and world rotation matrices to the identuty
|
2008-05-05 12:36:31 +00:00
|
|
|
g_mWorldRotate = aiMatrix4x4();
|
|
|
|
g_mWorld = aiMatrix4x4();
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
char szTemp[MAX_PATH+64];
|
|
|
|
sprintf(szTemp,"Starting to load %s",g_szFileName);
|
|
|
|
CLogWindow::Instance().WriteLine(
|
|
|
|
"****************************************************************************");
|
|
|
|
CLogWindow::Instance().WriteLine(szTemp);
|
|
|
|
CLogWindow::Instance().WriteLine(
|
|
|
|
"****************************************************************************");
|
|
|
|
CLogWindow::Instance().SetAutoUpdate(false);
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// create a helper thread to load the asset
|
2008-05-05 12:36:31 +00:00
|
|
|
DWORD dwID;
|
|
|
|
g_bLoadingCanceled = false;
|
|
|
|
g_pcAsset = new AssetHelper();
|
|
|
|
g_hThreadHandle = CreateThread(NULL,0,&LoadThreadProc,NULL,0,&dwID);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
if (!g_hThreadHandle)
|
|
|
|
{
|
|
|
|
CLogDisplay::Instance().AddEntry(
|
|
|
|
"[ERROR] Unable to create helper thread for loading",
|
|
|
|
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// show the progress bar dialog
|
2008-05-05 12:36:31 +00:00
|
|
|
DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_LOADDIALOG),
|
|
|
|
g_hDlg,&ProgressMessageProc);
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
// update the log window
|
|
|
|
CLogWindow::Instance().SetAutoUpdate(true);
|
|
|
|
CLogWindow::Instance().Update();
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// now we should have loaded the asset. Check this ...
|
2008-05-05 12:36:31 +00:00
|
|
|
g_bLoadingFinished = false;
|
|
|
|
if (!g_pcAsset || !g_pcAsset->pcScene)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
if (g_pcAsset)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
delete g_pcAsset;
|
|
|
|
g_pcAsset = NULL;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// allocate a new MeshHelper array and build a new instance
|
|
|
|
// for each mesh in the original asset
|
2008-05-13 23:26:52 +00:00
|
|
|
g_pcAsset->apcMeshes = new AssetHelper::MeshHelper*[g_pcAsset->pcScene->mNumMeshes]();
|
2008-05-05 12:36:31 +00:00
|
|
|
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
|
|
|
|
g_pcAsset->apcMeshes[i] = new AssetHelper::MeshHelper();
|
2009-02-11 20:56:05 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-10-29 17:08:03 +00:00
|
|
|
// create animator
|
|
|
|
g_pcAsset->mAnimator = new SceneAnimator( g_pcAsset->pcScene);
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// build a new caption string for the viewer
|
2008-05-13 23:26:52 +00:00
|
|
|
char szOut[MAX_PATH + 10];
|
2008-05-09 17:24:28 +00:00
|
|
|
sprintf(szOut,AI_VIEW_CAPTION_BASE " [%s]",g_szFileName);
|
|
|
|
SetWindowText(g_hDlg,szOut);
|
|
|
|
|
|
|
|
// scale the asset vertices to fit into the viewer window
|
2008-05-05 12:36:31 +00:00
|
|
|
ScaleAsset();
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// reset the camera view to the default position
|
2008-05-05 12:36:31 +00:00
|
|
|
g_sCamera.vPos = aiVector3D(0.0f,0.0f,-10.0f);
|
|
|
|
g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f);
|
|
|
|
g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f);
|
|
|
|
g_sCamera.vRight = aiVector3D(0.0f,1.0f,0.0f);
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// build native D3D vertex/index buffers, textures, materials
|
2009-02-11 20:56:05 +00:00
|
|
|
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);
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
|
|
|
|
CLogDisplay::Instance().AddEntry("[OK] The asset has been loaded successfully");
|
|
|
|
CDisplay::Instance().FillDisplayList();
|
|
|
|
CDisplay::Instance().FillAnimList();
|
|
|
|
|
|
|
|
CDisplay::Instance().FillDefaultStatistics();
|
2009-02-11 20:56:05 +00:00
|
|
|
|
|
|
|
// render the scene once
|
|
|
|
CDisplay::Instance().OnRender();
|
2008-05-13 23:26:52 +00:00
|
|
|
|
|
|
|
g_pcAsset->iNormalSet = AssetHelper::ORIGINAL;
|
|
|
|
g_bWasFlipped = false;
|
|
|
|
return 1;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
// Delete the loaded asset
|
2008-05-13 23:26:52 +00:00
|
|
|
// The function does nothing is no asset is loaded
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int DeleteAsset(void)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
if (!g_pcAsset)return 0;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// don't anymore know why this was necessary ...
|
2008-05-13 23:26:52 +00:00
|
|
|
CDisplay::Instance().OnRender();
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// delete everything
|
2008-05-05 12:36:31 +00:00
|
|
|
DeleteAssetData();
|
|
|
|
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
delete g_pcAsset->apcMeshes[i];
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
aiReleaseImport(g_pcAsset->pcScene);
|
|
|
|
delete[] g_pcAsset->apcMeshes;
|
2008-10-29 17:08:03 +00:00
|
|
|
delete g_pcAsset->mAnimator;
|
2008-05-05 12:36:31 +00:00
|
|
|
delete g_pcAsset;
|
|
|
|
g_pcAsset = NULL;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// reset the caption of the viewer window
|
|
|
|
SetWindowText(g_hDlg,AI_VIEW_CAPTION_BASE);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
|
|
|
// clear UI
|
|
|
|
CDisplay::Instance().ClearAnimList();
|
|
|
|
CDisplay::Instance().ClearDisplayList();
|
|
|
|
|
|
|
|
CMaterialManager::Instance().Reset();
|
2008-05-30 23:01:25 +00:00
|
|
|
UpdateWindow(g_hDlg);
|
2008-05-05 12:36:31 +00:00
|
|
|
return 1;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
// Calculate the boundaries of a given node and all of its children
|
|
|
|
// The boundaries are in Worldspace (AABB)
|
|
|
|
// piNode Input node
|
|
|
|
// p_avOut Receives the min/max boundaries. Must point to 2 vec3s
|
|
|
|
// piMatrix Transformation matrix of the graph at this position
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int CalculateBounds(aiNode* piNode, aiVector3D* p_avOut,
|
|
|
|
const aiMatrix4x4& piMatrix)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != piNode);
|
|
|
|
ai_assert(NULL != p_avOut);
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
aiMatrix4x4 mTemp = piNode->mTransformation;
|
|
|
|
mTemp.Transpose();
|
|
|
|
aiMatrix4x4 aiMe = mTemp * piMatrix;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < piNode->mNumMeshes;++i)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
for( unsigned int a = 0; a < g_pcAsset->pcScene->mMeshes[
|
|
|
|
piNode->mMeshes[i]]->mNumVertices;++a)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
|
|
|
aiVector3D pc =g_pcAsset->pcScene->mMeshes[piNode->mMeshes[i]]->mVertices[a];
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
aiVector3D pc1;
|
|
|
|
D3DXVec3TransformCoord((D3DXVECTOR3*)&pc1,(D3DXVECTOR3*)&pc,
|
|
|
|
(D3DXMATRIX*)&aiMe);
|
|
|
|
|
|
|
|
p_avOut[0].x = std::min( p_avOut[0].x, pc1.x);
|
|
|
|
p_avOut[0].y = std::min( p_avOut[0].y, pc1.y);
|
|
|
|
p_avOut[0].z = std::min( p_avOut[0].z, pc1.z);
|
|
|
|
p_avOut[1].x = std::max( p_avOut[1].x, pc1.x);
|
|
|
|
p_avOut[1].y = std::max( p_avOut[1].y, pc1.y);
|
|
|
|
p_avOut[1].z = std::max( p_avOut[1].z, pc1.z);
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
for (unsigned int i = 0; i < piNode->mNumChildren;++i)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
CalculateBounds( piNode->mChildren[i], p_avOut, aiMe );
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
// Scale the asset that it fits perfectly into the viewer window
|
|
|
|
// The function calculates the boundaries of the mesh and modifies the
|
|
|
|
// global world transformation matrix according to the aset AABB
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int ScaleAsset(void)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
aiVector3D aiVecs[2] = {aiVector3D( 1e10f, 1e10f, 1e10f),
|
|
|
|
aiVector3D( -1e10f, -1e10f, -1e10f) };
|
|
|
|
|
|
|
|
if (g_pcAsset->pcScene->mRootNode)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
aiMatrix4x4 m;
|
|
|
|
CalculateBounds(g_pcAsset->pcScene->mRootNode,aiVecs,m);
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
aiVector3D vDelta = aiVecs[1]-aiVecs[0];
|
|
|
|
aiVector3D vHalf = aiVecs[0] + (vDelta / 2.0f);
|
|
|
|
float fScale = 10.0f / vDelta.Length();
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
g_mWorld = aiMatrix4x4(
|
2008-05-13 23:26:52 +00:00
|
|
|
1.0f,0.0f,0.0f,0.0f,
|
|
|
|
0.0f,1.0f,0.0f,0.0f,
|
|
|
|
0.0f,0.0f,1.0f,0.0f,
|
|
|
|
-vHalf.x,-vHalf.y,-vHalf.z,1.0f) *
|
2008-05-05 12:36:31 +00:00
|
|
|
aiMatrix4x4(
|
2008-05-13 23:26:52 +00:00
|
|
|
fScale,0.0f,0.0f,0.0f,
|
|
|
|
0.0f,fScale,0.0f,0.0f,
|
|
|
|
0.0f,0.0f,fScale,0.0f,
|
|
|
|
0.0f,0.0f,0.0f,1.0f);
|
2008-05-05 12:36:31 +00:00
|
|
|
return 1;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
// Generate a vertex buffer which holds the normals of the asset as
|
|
|
|
// a list of unconnected lines
|
|
|
|
// pcMesh Input mesh
|
|
|
|
// pcSource Source mesh from ASSIMP
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int GenerateNormalsAsLineList(AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSource)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != pcMesh);
|
|
|
|
ai_assert(NULL != pcSource);
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
if (!pcSource->mNormals)return 0;
|
|
|
|
|
|
|
|
// create vertex buffer
|
|
|
|
if(FAILED( g_piDevice->CreateVertexBuffer(sizeof(AssetHelper::LineVertex) *
|
|
|
|
pcSource->mNumVertices * 2,
|
|
|
|
D3DUSAGE_WRITEONLY,
|
|
|
|
AssetHelper::LineVertex::GetFVF(),
|
|
|
|
D3DPOOL_DEFAULT, &pcMesh->piVBNormals,NULL)))
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
|
|
|
CLogDisplay::Instance().AddEntry("Failed to create vertex buffer for the normal list",
|
|
|
|
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
|
2008-05-05 12:36:31 +00:00
|
|
|
return 2;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
// now fill the vertex buffer with data
|
2008-05-05 12:36:31 +00:00
|
|
|
AssetHelper::LineVertex* pbData2;
|
|
|
|
pcMesh->piVBNormals->Lock(0,0,(void**)&pbData2,0);
|
|
|
|
for (unsigned int x = 0; x < pcSource->mNumVertices;++x)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
pbData2->vPosition = pcSource->mVertices[x];
|
|
|
|
|
|
|
|
++pbData2;
|
|
|
|
|
|
|
|
aiVector3D vNormal = pcSource->mNormals[x];
|
|
|
|
vNormal.Normalize();
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
// scalo with the inverse of the world scaling to make sure
|
|
|
|
// the normals have equal length in each case
|
|
|
|
// TODO: Check whether this works in every case, I don't think so
|
2008-05-05 12:36:31 +00:00
|
|
|
vNormal.x /= g_mWorld.a1*4;
|
|
|
|
vNormal.y /= g_mWorld.b2*4;
|
|
|
|
vNormal.z /= g_mWorld.c3*4;
|
|
|
|
|
|
|
|
pbData2->vPosition = pcSource->mVertices[x] + vNormal;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
++pbData2;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
pcMesh->piVBNormals->Unlock();
|
2008-05-09 17:24:28 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
// Create the native D3D representation of the asset: vertex buffers,
|
|
|
|
// index buffers, materials ...
|
2008-05-09 17:24:28 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
int CreateAssetData()
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
if (!g_pcAsset)return 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
// reset all subsystems
|
|
|
|
CMaterialManager::Instance().Reset();
|
|
|
|
CDisplay::Instance().Reset();
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-10-29 17:08:03 +00:00
|
|
|
const aiMesh* mesh = g_pcAsset->pcScene->mMeshes[i];
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
// create the material for the mesh
|
2009-02-15 20:29:07 +00:00
|
|
|
if (!g_pcAsset->apcMeshes[i]->piEffect) {
|
2008-05-13 23:26:52 +00:00
|
|
|
CMaterialManager::Instance().CreateMaterial(
|
2008-10-29 17:08:03 +00:00
|
|
|
g_pcAsset->apcMeshes[i],mesh);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// create vertex buffer
|
|
|
|
if(FAILED( g_piDevice->CreateVertexBuffer(sizeof(AssetHelper::Vertex) *
|
2008-10-29 17:08:03 +00:00
|
|
|
mesh->mNumVertices,
|
2008-05-05 12:36:31 +00:00
|
|
|
D3DUSAGE_WRITEONLY,
|
2008-10-29 17:08:03 +00:00
|
|
|
0,
|
2009-02-15 20:29:07 +00:00
|
|
|
D3DPOOL_DEFAULT, &g_pcAsset->apcMeshes[i]->piVB,NULL))) {
|
2008-05-05 12:36:31 +00:00
|
|
|
MessageBox(g_hDlg,"Failed to create vertex buffer",
|
|
|
|
"ASSIMP Viewer Utility",MB_OK);
|
|
|
|
return 2;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
DWORD dwUsage = 0;
|
|
|
|
if (g_pcAsset->apcMeshes[i]->piOpacityTexture || 1.0f != g_pcAsset->apcMeshes[i]->fOpacity)
|
|
|
|
dwUsage |= D3DUSAGE_DYNAMIC;
|
|
|
|
|
2009-02-15 20:29:07 +00:00
|
|
|
unsigned int nidx;
|
|
|
|
switch (mesh->mPrimitiveTypes) {
|
|
|
|
case aiPrimitiveType_POINT:
|
|
|
|
nidx = 1;break;
|
|
|
|
case aiPrimitiveType_LINE:
|
|
|
|
nidx = 2;break;
|
|
|
|
case aiPrimitiveType_TRIANGLE:
|
|
|
|
nidx = 3;break;
|
|
|
|
default: assert(false);
|
|
|
|
};
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// check whether we can use 16 bit indices
|
2009-02-15 20:29:07 +00:00
|
|
|
if (mesh->mNumFaces * 3 >= 65536) {
|
2008-05-09 17:24:28 +00:00
|
|
|
// create 32 bit index buffer
|
|
|
|
if(FAILED( g_piDevice->CreateIndexBuffer( 4 *
|
2009-02-15 20:29:07 +00:00
|
|
|
mesh->mNumFaces * nidx,
|
2008-05-13 23:26:52 +00:00
|
|
|
D3DUSAGE_WRITEONLY | dwUsage,
|
2008-05-09 17:24:28 +00:00
|
|
|
D3DFMT_INDEX32,
|
2008-05-13 23:26:52 +00:00
|
|
|
D3DPOOL_DEFAULT,
|
|
|
|
&g_pcAsset->apcMeshes[i]->piIB,
|
|
|
|
NULL)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
MessageBox(g_hDlg,"Failed to create 32 Bit index buffer",
|
|
|
|
"ASSIMP Viewer Utility",MB_OK);
|
|
|
|
return 2;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// now fill the index buffer
|
|
|
|
unsigned int* pbData;
|
|
|
|
g_pcAsset->apcMeshes[i]->piIB->Lock(0,0,(void**)&pbData,0);
|
2008-10-29 17:08:03 +00:00
|
|
|
for (unsigned int x = 0; x < mesh->mNumFaces;++x)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2009-02-15 20:29:07 +00:00
|
|
|
for (unsigned int a = 0; a < nidx;++a)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-10-29 17:08:03 +00:00
|
|
|
*pbData++ = mesh->mFaces[x].mIndices[a];
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-15 20:29:07 +00:00
|
|
|
else {
|
2008-05-09 17:24:28 +00:00
|
|
|
// create 16 bit index buffer
|
|
|
|
if(FAILED( g_piDevice->CreateIndexBuffer( 2 *
|
2009-02-15 20:29:07 +00:00
|
|
|
mesh->mNumFaces * nidx,
|
2008-05-13 23:26:52 +00:00
|
|
|
D3DUSAGE_WRITEONLY | dwUsage,
|
2008-05-09 17:24:28 +00:00
|
|
|
D3DFMT_INDEX16,
|
2008-05-13 23:26:52 +00:00
|
|
|
D3DPOOL_DEFAULT,
|
|
|
|
&g_pcAsset->apcMeshes[i]->piIB,
|
|
|
|
NULL)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
MessageBox(g_hDlg,"Failed to create 16 Bit index buffer",
|
|
|
|
"ASSIMP Viewer Utility",MB_OK);
|
|
|
|
return 2;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// now fill the index buffer
|
|
|
|
uint16_t* pbData;
|
|
|
|
g_pcAsset->apcMeshes[i]->piIB->Lock(0,0,(void**)&pbData,0);
|
2008-10-29 17:08:03 +00:00
|
|
|
for (unsigned int x = 0; x < mesh->mNumFaces;++x)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2009-02-15 20:29:07 +00:00
|
|
|
for (unsigned int a = 0; a < nidx;++a)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-29 17:08:03 +00:00
|
|
|
*pbData++ = (uint16_t)mesh->mFaces[x].mIndices[a];
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
g_pcAsset->apcMeshes[i]->piIB->Unlock();
|
|
|
|
|
2008-10-29 17:08:03 +00:00
|
|
|
// collect weights on all vertices. Quick and careless
|
|
|
|
std::vector<std::vector<aiVertexWeight> > weightsPerVertex( mesh->mNumVertices);
|
2009-02-15 20:29:07 +00:00
|
|
|
for( unsigned int a = 0; a < mesh->mNumBones; a++) {
|
2008-10-29 17:08:03 +00:00
|
|
|
const aiBone* bone = mesh->mBones[a];
|
|
|
|
for( unsigned int b = 0; b < bone->mNumWeights; b++)
|
|
|
|
weightsPerVertex[bone->mWeights[b].mVertexId].push_back( aiVertexWeight( a, bone->mWeights[b].mWeight));
|
|
|
|
}
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// now fill the vertex buffer
|
|
|
|
AssetHelper::Vertex* pbData2;
|
|
|
|
g_pcAsset->apcMeshes[i]->piVB->Lock(0,0,(void**)&pbData2,0);
|
2008-10-29 17:08:03 +00:00
|
|
|
for (unsigned int x = 0; x < mesh->mNumVertices;++x)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-10-29 17:08:03 +00:00
|
|
|
pbData2->vPosition = mesh->mVertices[x];
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-29 17:08:03 +00:00
|
|
|
if (NULL == mesh->mNormals)
|
2008-05-05 12:36:31 +00:00
|
|
|
pbData2->vNormal = aiVector3D(0.0f,0.0f,0.0f);
|
2008-10-29 17:08:03 +00:00
|
|
|
else pbData2->vNormal = mesh->mNormals[x];
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2009-02-15 20:29:07 +00:00
|
|
|
if (NULL == mesh->mTangents) {
|
2008-05-05 12:36:31 +00:00
|
|
|
pbData2->vTangent = aiVector3D(0.0f,0.0f,0.0f);
|
|
|
|
pbData2->vBitangent = aiVector3D(0.0f,0.0f,0.0f);
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2009-02-15 20:29:07 +00:00
|
|
|
else {
|
2008-10-29 17:08:03 +00:00
|
|
|
pbData2->vTangent = mesh->mTangents[x];
|
|
|
|
pbData2->vBitangent = mesh->mBitangents[x];
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2009-02-15 20:29:07 +00:00
|
|
|
if (mesh->HasVertexColors( 0)) {
|
2008-05-05 12:36:31 +00:00
|
|
|
pbData2->dColorDiffuse = D3DCOLOR_ARGB(
|
2008-10-29 17:08:03 +00:00
|
|
|
((unsigned char)std::max( std::min( mesh->mColors[0][x].a * 255.0f, 255.0f),0.0f)),
|
|
|
|
((unsigned char)std::max( std::min( mesh->mColors[0][x].r * 255.0f, 255.0f),0.0f)),
|
|
|
|
((unsigned char)std::max( std::min( mesh->mColors[0][x].g * 255.0f, 255.0f),0.0f)),
|
|
|
|
((unsigned char)std::max( std::min( mesh->mColors[0][x].b * 255.0f, 255.0f),0.0f)));
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-10-31 19:32:00 +00:00
|
|
|
else pbData2->dColorDiffuse = D3DCOLOR_ARGB(0xFF,0xff,0xff,0xff);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// ignore a third texture coordinate component
|
2009-02-15 20:29:07 +00:00
|
|
|
if (mesh->HasTextureCoords( 0)) {
|
2008-05-05 12:36:31 +00:00
|
|
|
pbData2->vTextureUV = aiVector2D(
|
2008-10-29 17:08:03 +00:00
|
|
|
mesh->mTextureCoords[0][x].x,
|
|
|
|
mesh->mTextureCoords[0][x].y);
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-10-31 19:32:00 +00:00
|
|
|
else pbData2->vTextureUV = aiVector2D(0.5f,0.5f);
|
2008-10-29 17:08:03 +00:00
|
|
|
|
2009-02-15 20:29:07 +00:00
|
|
|
if (mesh->HasTextureCoords( 1)) {
|
2008-11-05 12:26:11 +00:00
|
|
|
pbData2->vTextureUV2 = aiVector2D(
|
|
|
|
mesh->mTextureCoords[1][x].x,
|
|
|
|
mesh->mTextureCoords[1][x].y);
|
|
|
|
}
|
|
|
|
else pbData2->vTextureUV2 = aiVector2D(0.5f,0.5f);
|
|
|
|
|
2008-10-29 17:08:03 +00:00
|
|
|
// Bone indices and weights
|
2009-02-15 20:29:07 +00:00
|
|
|
if( mesh->HasBones()) {
|
2008-10-29 17:08:03 +00:00
|
|
|
unsigned char boneIndices[4] = { 0, 0, 0, 0 };
|
|
|
|
unsigned char boneWeights[4] = { 0, 0, 0, 0 };
|
2008-10-30 19:51:01 +00:00
|
|
|
ai_assert( weightsPerVertex[x].size() <= 4);
|
2008-10-29 17:08:03 +00:00
|
|
|
for( unsigned int a = 0; a < weightsPerVertex[x].size(); a++)
|
|
|
|
{
|
|
|
|
boneIndices[a] = weightsPerVertex[x][a].mVertexId;
|
|
|
|
boneWeights[a] = (unsigned char) (weightsPerVertex[x][a].mWeight * 255.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy( pbData2->mBoneIndices, boneIndices, sizeof( boneIndices));
|
|
|
|
memcpy( pbData2->mBoneWeights, boneWeights, sizeof( boneWeights));
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
memset( pbData2->mBoneIndices, 0, sizeof( pbData2->mBoneIndices));
|
|
|
|
memset( pbData2->mBoneWeights, 0, sizeof( pbData2->mBoneWeights));
|
|
|
|
}
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
++pbData2;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
g_pcAsset->apcMeshes[i]->piVB->Unlock();
|
|
|
|
|
|
|
|
// now generate the second vertex buffer, holding all normals
|
2009-02-15 20:29:07 +00:00
|
|
|
if (!g_pcAsset->apcMeshes[i]->piVBNormals) {
|
2008-10-29 17:08:03 +00:00
|
|
|
GenerateNormalsAsLineList(g_pcAsset->apcMeshes[i],mesh);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
// Delete all effects, textures, vertex buffers ... associated with
|
|
|
|
// an asset
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
int DeleteAssetData(bool bNoMaterials)
|
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
if (!g_pcAsset)return 0;
|
|
|
|
|
|
|
|
// TODO: Move this to a proper destructor
|
|
|
|
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
if(g_pcAsset->apcMeshes[i]->piVB)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
g_pcAsset->apcMeshes[i]->piVB->Release();
|
|
|
|
g_pcAsset->apcMeshes[i]->piVB = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
if(g_pcAsset->apcMeshes[i]->piVBNormals)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
g_pcAsset->apcMeshes[i]->piVBNormals->Release();
|
|
|
|
g_pcAsset->apcMeshes[i]->piVBNormals = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
if(g_pcAsset->apcMeshes[i]->piIB)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
g_pcAsset->apcMeshes[i]->piIB->Release();
|
|
|
|
g_pcAsset->apcMeshes[i]->piIB = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
|
|
|
|
2008-05-25 22:29:05 +00:00
|
|
|
// TODO ... unfixed memory leak
|
|
|
|
// delete storage eventually allocated to hold a copy
|
|
|
|
// of the original vertex normals
|
|
|
|
//if (g_pcAsset->apcMeshes[i]->pvOriginalNormals)
|
2008-05-13 23:26:52 +00:00
|
|
|
//{
|
|
|
|
// delete[] g_pcAsset->apcMeshes[i]->pvOriginalNormals;
|
|
|
|
//}
|
|
|
|
|
|
|
|
if (!bNoMaterials)
|
|
|
|
{
|
|
|
|
if(g_pcAsset->apcMeshes[i]->piEffect)
|
|
|
|
{
|
|
|
|
g_pcAsset->apcMeshes[i]->piEffect->Release();
|
|
|
|
g_pcAsset->apcMeshes[i]->piEffect = NULL;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
if(g_pcAsset->apcMeshes[i]->piDiffuseTexture)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
g_pcAsset->apcMeshes[i]->piDiffuseTexture->Release();
|
|
|
|
g_pcAsset->apcMeshes[i]->piDiffuseTexture = NULL;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
if(g_pcAsset->apcMeshes[i]->piNormalTexture)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
g_pcAsset->apcMeshes[i]->piNormalTexture->Release();
|
|
|
|
g_pcAsset->apcMeshes[i]->piNormalTexture = NULL;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
if(g_pcAsset->apcMeshes[i]->piSpecularTexture)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
g_pcAsset->apcMeshes[i]->piSpecularTexture->Release();
|
|
|
|
g_pcAsset->apcMeshes[i]->piSpecularTexture = NULL;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
if(g_pcAsset->apcMeshes[i]->piAmbientTexture)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
g_pcAsset->apcMeshes[i]->piAmbientTexture->Release();
|
|
|
|
g_pcAsset->apcMeshes[i]->piAmbientTexture = NULL;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
if(g_pcAsset->apcMeshes[i]->piEmissiveTexture)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
g_pcAsset->apcMeshes[i]->piEmissiveTexture->Release();
|
|
|
|
g_pcAsset->apcMeshes[i]->piEmissiveTexture = NULL;
|
2008-05-25 22:29:05 +00:00
|
|
|
}
|
|
|
|
if(g_pcAsset->apcMeshes[i]->piOpacityTexture)
|
|
|
|
{
|
|
|
|
g_pcAsset->apcMeshes[i]->piOpacityTexture->Release();
|
|
|
|
g_pcAsset->apcMeshes[i]->piOpacityTexture = NULL;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
if(g_pcAsset->apcMeshes[i]->piShininessTexture)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
g_pcAsset->apcMeshes[i]->piShininessTexture->Release();
|
|
|
|
g_pcAsset->apcMeshes[i]->piShininessTexture = NULL;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
// Switch beetween zoom/rotate view and the standatd FPS view
|
|
|
|
// g_bFPSView specifies the view mode to setup
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int SetupFPSView()
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
if (!g_bFPSView)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
g_sCamera.vPos = aiVector3D(0.0f,0.0f,g_fWheelPos);
|
|
|
|
g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f);
|
|
|
|
g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f);
|
|
|
|
g_sCamera.vRight = aiVector3D(0.0f,1.0f,0.0f);
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
else
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
g_fWheelPos = g_sCamera.vPos.z;
|
|
|
|
g_sCamera.vPos = aiVector3D(0.0f,0.0f,-10.0f);
|
|
|
|
g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f);
|
|
|
|
g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f);
|
|
|
|
g_sCamera.vRight = aiVector3D(0.0f,1.0f,0.0f);
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
// Initialize the IDIrect3D interface
|
|
|
|
// Called by the WinMain
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int InitD3D(void)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
if (NULL == g_piD3D)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
g_piD3D = Direct3DCreate9(D3D_SDK_VERSION);
|
|
|
|
if (NULL == g_piD3D)return 0;
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
// Release the IDirect3D interface.
|
|
|
|
// NOTE: Assumes that the device has already been deleted
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int ShutdownD3D(void)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
ShutdownDevice();
|
|
|
|
if (NULL != g_piD3D)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
g_piD3D->Release();
|
|
|
|
g_piD3D = NULL;
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
// Shutdown the D3D devie object and all resources associated with it
|
|
|
|
// NOTE: Assumes that the asset has already been deleted
|
2008-05-05 12:36:31 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int ShutdownDevice(void)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
|
|
|
// release other subsystems
|
|
|
|
CBackgroundPainter::Instance().ReleaseNativeResource();
|
|
|
|
CLogDisplay::Instance().ReleaseNativeResource();
|
|
|
|
|
|
|
|
// release global shaders that have been allocazed
|
2008-05-05 12:36:31 +00:00
|
|
|
if (NULL != g_piDefaultEffect)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
g_piDefaultEffect->Release();
|
|
|
|
g_piDefaultEffect = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
if (NULL != g_piNormalsEffect)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
g_piNormalsEffect->Release();
|
|
|
|
g_piNormalsEffect = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
if (NULL != g_piPassThroughEffect)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
g_piPassThroughEffect->Release();
|
|
|
|
g_piPassThroughEffect = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
|
|
|
if (NULL != g_piPatternEffect)
|
|
|
|
{
|
|
|
|
g_piPatternEffect->Release();
|
|
|
|
g_piPatternEffect = NULL;
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
if (NULL != g_pcTexture)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
g_pcTexture->Release();
|
|
|
|
g_pcTexture = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-29 17:08:03 +00:00
|
|
|
if( NULL != gDefaultVertexDecl)
|
|
|
|
{
|
|
|
|
gDefaultVertexDecl->Release();
|
|
|
|
gDefaultVertexDecl = NULL;
|
|
|
|
}
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
// delete the main D3D device object
|
|
|
|
if (NULL != g_piDevice)
|
|
|
|
{
|
|
|
|
g_piDevice->Release();
|
|
|
|
g_piDevice = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// deleted the one channel image allocated to hold the HUD mask
|
2008-05-05 12:36:31 +00:00
|
|
|
delete[] g_szImageMask;
|
|
|
|
g_szImageMask = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
return 1;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int CreateHUDTexture()
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
// lock the memory resource ourselves
|
|
|
|
HRSRC res = FindResource(NULL,MAKEINTRESOURCE(IDR_HUD),RT_RCDATA);
|
|
|
|
HGLOBAL hg = LoadResource(NULL,res);
|
|
|
|
void* pData = LockResource(hg);
|
|
|
|
|
|
|
|
if(FAILED(D3DXCreateTextureFromFileInMemoryEx(g_piDevice,
|
|
|
|
pData,SizeofResource(NULL,res),
|
|
|
|
D3DX_DEFAULT_NONPOW2,
|
|
|
|
D3DX_DEFAULT_NONPOW2,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
D3DFMT_A8R8G8B8,
|
|
|
|
D3DPOOL_MANAGED,
|
|
|
|
D3DX_DEFAULT,
|
|
|
|
D3DX_DEFAULT,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&g_pcTexture)))
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
CLogDisplay::Instance().AddEntry("[ERROR] Unable to load HUD texture",
|
|
|
|
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
|
|
|
|
|
|
|
|
g_pcTexture = NULL;
|
|
|
|
g_szImageMask = NULL;
|
|
|
|
|
|
|
|
UnlockResource(hg);
|
|
|
|
FreeResource(hg);
|
|
|
|
return 0;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
UnlockResource(hg);
|
|
|
|
FreeResource(hg);
|
|
|
|
|
|
|
|
D3DSURFACE_DESC sDesc;
|
|
|
|
g_pcTexture->GetLevelDesc(0,&sDesc);
|
|
|
|
|
|
|
|
|
|
|
|
// lock the memory resource ourselves
|
|
|
|
res = FindResource(NULL,MAKEINTRESOURCE(IDR_HUDMASK),RT_RCDATA);
|
|
|
|
hg = LoadResource(NULL,res);
|
|
|
|
pData = LockResource(hg);
|
|
|
|
|
|
|
|
IDirect3DTexture9* pcTex;
|
|
|
|
if(FAILED(D3DXCreateTextureFromFileInMemoryEx(g_piDevice,
|
|
|
|
pData,SizeofResource(NULL,res),
|
|
|
|
sDesc.Width,
|
|
|
|
sDesc.Height,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
D3DFMT_L8,
|
|
|
|
D3DPOOL_MANAGED, // unnecessary
|
|
|
|
D3DX_DEFAULT,
|
|
|
|
D3DX_DEFAULT,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&pcTex)))
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
CLogDisplay::Instance().AddEntry("[ERROR] Unable to load HUD mask texture",
|
|
|
|
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
|
|
|
|
g_szImageMask = NULL;
|
|
|
|
|
|
|
|
UnlockResource(hg);
|
|
|
|
FreeResource(hg);
|
|
|
|
return 0;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
UnlockResource(hg);
|
|
|
|
FreeResource(hg);
|
|
|
|
|
|
|
|
// lock the texture and copy it to get a pointer
|
|
|
|
D3DLOCKED_RECT sRect;
|
|
|
|
pcTex->LockRect(0,&sRect,NULL,D3DLOCK_READONLY);
|
|
|
|
|
|
|
|
unsigned char* szOut = new unsigned char[sDesc.Width * sDesc.Height];
|
|
|
|
unsigned char* _szOut = szOut;
|
|
|
|
|
|
|
|
unsigned char* szCur = (unsigned char*) sRect.pBits;
|
|
|
|
for (unsigned int y = 0; y < sDesc.Height;++y)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
memcpy(_szOut,szCur,sDesc.Width);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
szCur += sRect.Pitch;
|
|
|
|
_szOut += sDesc.Width;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
pcTex->UnlockRect(0);
|
|
|
|
pcTex->Release();
|
|
|
|
|
|
|
|
g_szImageMask = szOut;
|
|
|
|
return 1;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int CreateDevice (bool p_bMultiSample,bool p_bSuperSample,bool bHW /*= true*/)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
D3DDEVTYPE eType = bHW ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// get the client rectangle of the window.
|
2008-05-05 12:36:31 +00:00
|
|
|
RECT sRect;
|
|
|
|
GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
|
|
|
|
sRect.right -= sRect.left;
|
|
|
|
sRect.bottom -= sRect.top;
|
|
|
|
|
|
|
|
D3DPRESENT_PARAMETERS sParams;
|
|
|
|
memset(&sParams,0,sizeof(D3DPRESENT_PARAMETERS));
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// get the current display mode
|
2008-05-05 12:36:31 +00:00
|
|
|
D3DDISPLAYMODE sMode;
|
|
|
|
g_piD3D->GetAdapterDisplayMode(0,&sMode);
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// fill the presentation parameter structure
|
|
|
|
sParams.Windowed = TRUE;
|
|
|
|
sParams.hDeviceWindow = GetDlgItem( g_hDlg, IDC_RT );
|
|
|
|
sParams.EnableAutoDepthStencil = TRUE;
|
|
|
|
sParams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
|
|
|
|
sParams.BackBufferWidth = (UINT)sRect.right;
|
|
|
|
sParams.BackBufferHeight = (UINT)sRect.bottom;
|
|
|
|
sParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
2008-07-22 22:52:16 +00:00
|
|
|
sParams.BackBufferCount = 1;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// check whether we can use a D32 depth buffer format
|
|
|
|
if (SUCCEEDED ( g_piD3D->CheckDepthStencilMatch(0,eType,
|
|
|
|
D3DFMT_X8R8G8B8,D3DFMT_X8R8G8B8,D3DFMT_D32)))
|
|
|
|
{
|
|
|
|
sParams.AutoDepthStencilFormat = D3DFMT_D32;
|
|
|
|
}
|
|
|
|
else sParams.AutoDepthStencilFormat = D3DFMT_D24X8;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// find the highest multisample type available on this device
|
|
|
|
D3DMULTISAMPLE_TYPE sMS = D3DMULTISAMPLE_2_SAMPLES;
|
|
|
|
D3DMULTISAMPLE_TYPE sMSOut = D3DMULTISAMPLE_NONE;
|
|
|
|
DWORD dwQuality = 0;
|
|
|
|
if (p_bMultiSample)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
while ((D3DMULTISAMPLE_TYPE)(D3DMULTISAMPLE_16_SAMPLES + 1) !=
|
2008-05-13 23:26:52 +00:00
|
|
|
(sMS = (D3DMULTISAMPLE_TYPE)(sMS + 1)))
|
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
if(SUCCEEDED( g_piD3D->CheckDeviceMultiSampleType(0,eType,
|
|
|
|
sMode.Format,TRUE,sMS,&dwQuality)))
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
sMSOut = sMS;
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
if (0 != dwQuality)dwQuality -= 1;
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
sParams.MultiSampleQuality = dwQuality;
|
|
|
|
sParams.MultiSampleType = sMSOut;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-29 17:08:03 +00:00
|
|
|
// preget the device capabilities. If the hardware vertex shader is too old, we prefer software vertex processing
|
|
|
|
g_piD3D->GetDeviceCaps( 0, D3DDEVTYPE_HAL, &g_sCaps);
|
|
|
|
DWORD creationFlags = D3DCREATE_MULTITHREADED;
|
|
|
|
if( g_sCaps.VertexShaderVersion >= D3DVS_VERSION( 2, 0))
|
|
|
|
creationFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
|
|
|
|
else
|
|
|
|
creationFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
|
2008-10-13 15:50:12 +00:00
|
|
|
|
|
|
|
// create the D3D9 device object. with software-vertexprocessing if VS2.0 isn`t supported in hardware
|
|
|
|
if(FAILED(g_piD3D->CreateDevice(0,eType, g_hDlg, creationFlags ,&sParams,&g_piDevice)))
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-10-13 15:50:12 +00:00
|
|
|
// if hardware fails use software rendering instead
|
|
|
|
if (bHW)return CreateDevice(p_bMultiSample,p_bSuperSample,false);
|
|
|
|
return 0;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-10-29 17:08:03 +00:00
|
|
|
|
|
|
|
// create a vertex declaration to match the vertex
|
|
|
|
D3DVERTEXELEMENT9* vdecl = AssetHelper::Vertex::GetDeclarationElements();
|
|
|
|
if( FAILED( g_piDevice->CreateVertexDeclaration( vdecl, &gDefaultVertexDecl)))
|
|
|
|
{
|
|
|
|
MessageBox( g_hDlg, "Failed to create vertex declaration", "Init", MB_OK);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
g_piDevice->SetVertexDeclaration( gDefaultVertexDecl);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-09 21:18:59 +00:00
|
|
|
// get the capabilities of the device object
|
|
|
|
g_piDevice->GetDeviceCaps(&g_sCaps);
|
|
|
|
if(g_sCaps.PixelShaderVersion < D3DPS_VERSION(3,0))
|
|
|
|
{
|
|
|
|
EnableWindow(GetDlgItem(g_hDlg,IDC_LOWQUALITY),FALSE);
|
|
|
|
}
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// compile the default material shader (gray gouraud/phong)
|
2008-05-05 12:36:31 +00:00
|
|
|
ID3DXBuffer* piBuffer = NULL;
|
|
|
|
if(FAILED( D3DXCreateEffect(g_piDevice,
|
|
|
|
g_szDefaultShader.c_str(),
|
|
|
|
(UINT)g_szDefaultShader.length(),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
AI_SHADER_COMPILE_FLAGS,
|
2008-05-05 12:36:31 +00:00
|
|
|
NULL,
|
|
|
|
&g_piDefaultEffect,&piBuffer)))
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
if( piBuffer)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK);
|
|
|
|
piBuffer->Release();
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
if( piBuffer)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
piBuffer->Release();
|
|
|
|
piBuffer = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-29 17:08:03 +00:00
|
|
|
// use Fixed Function effect when working with shaderless cards
|
|
|
|
if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
|
|
|
|
g_piDefaultEffect->SetTechnique( "DefaultFXSpecular_FF");
|
2008-10-09 21:18:59 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// create the shader used to draw the HUD
|
2008-05-05 12:36:31 +00:00
|
|
|
if(FAILED( D3DXCreateEffect(g_piDevice,
|
|
|
|
g_szPassThroughShader.c_str(),(UINT)g_szPassThroughShader.length(),
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
NULL,NULL,AI_SHADER_COMPILE_FLAGS,NULL,&g_piPassThroughEffect,&piBuffer)))
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
if( piBuffer)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-10-09 20:17:46 +00:00
|
|
|
MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK);
|
2008-05-05 12:36:31 +00:00
|
|
|
piBuffer->Release();
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
if( piBuffer)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
piBuffer->Release();
|
|
|
|
piBuffer = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-10-29 17:08:03 +00:00
|
|
|
// use Fixed Function effect when working with shaderless cards
|
|
|
|
if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
|
|
|
|
g_piPassThroughEffect->SetTechnique( "PassThrough_FF");
|
2008-10-09 21:18:59 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// create the shader used to visualize normal vectors
|
2008-05-05 12:36:31 +00:00
|
|
|
if(FAILED( D3DXCreateEffect(g_piDevice,
|
|
|
|
g_szNormalsShader.c_str(),(UINT)g_szNormalsShader.length(),
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
NULL,NULL,AI_SHADER_COMPILE_FLAGS,NULL,&g_piNormalsEffect, &piBuffer)))
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
if( piBuffer)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-10-09 20:17:46 +00:00
|
|
|
MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK);
|
2008-05-05 12:36:31 +00:00
|
|
|
piBuffer->Release();
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
if( piBuffer)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
piBuffer->Release();
|
|
|
|
piBuffer = NULL;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
//MessageBox( g_hDlg, "Failed to create vertex declaration", "Init", MB_OK);
|
|
|
|
|
2008-10-29 17:08:03 +00:00
|
|
|
// use Fixed Function effect when working with shaderless cards
|
|
|
|
if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
|
|
|
|
g_piNormalsEffect->SetTechnique( "RenderNormals_FF");
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2010-01-28 21:17:25 +00:00
|
|
|
g_piDevice->SetRenderState(D3DRS_DITHERENABLE,TRUE);
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// create the texture for the HUD
|
|
|
|
CreateHUDTexture();
|
|
|
|
CBackgroundPainter::Instance().RecreateNativeResource();
|
|
|
|
CLogDisplay::Instance().RecreateNativeResource();
|
|
|
|
|
|
|
|
g_piPassThroughEffect->SetTexture("TEXTURE_2D",g_pcTexture);
|
|
|
|
return 1;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int CreateDevice (void)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
return CreateDevice(g_sOptions.bMultiSample,
|
|
|
|
g_sOptions.bSuperSample);
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
int GetProjectionMatrix (aiMatrix4x4& p_mOut)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
const float fFarPlane = 100.0f;
|
|
|
|
const float fNearPlane = 0.1f;
|
|
|
|
const float fFOV = (float)(45.0 * 0.0174532925);
|
|
|
|
|
|
|
|
const float s = 1.0f / tanf(fFOV * 0.5f);
|
2008-05-13 23:26:52 +00:00
|
|
|
const float Q = fFarPlane / (fFarPlane - fNearPlane);
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
RECT sRect;
|
|
|
|
GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
|
|
|
|
sRect.right -= sRect.left;
|
|
|
|
sRect.bottom -= sRect.top;
|
|
|
|
const float fAspect = (float)sRect.right / (float)sRect.bottom;
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
p_mOut = aiMatrix4x4(
|
2008-05-05 12:36:31 +00:00
|
|
|
s / fAspect, 0.0f, 0.0f, 0.0f,
|
2008-05-13 23:26:52 +00:00
|
|
|
0.0f, s, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, Q, 1.0f,
|
|
|
|
0.0f, 0.0f, -Q * fNearPlane, 0.0f);
|
2008-05-05 12:36:31 +00:00
|
|
|
return 1;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
aiVector3D GetCameraMatrix (aiMatrix4x4& p_mOut)
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-05-05 12:36:31 +00:00
|
|
|
D3DXMATRIX view;
|
|
|
|
D3DXMatrixIdentity( &view );
|
|
|
|
|
|
|
|
D3DXVec3Normalize( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)&g_sCamera.vLookAt );
|
|
|
|
D3DXVec3Cross( (D3DXVECTOR3*)&g_sCamera.vRight, (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vLookAt );
|
|
|
|
D3DXVec3Normalize( (D3DXVECTOR3*)&g_sCamera.vRight, (D3DXVECTOR3*)&g_sCamera.vRight );
|
|
|
|
D3DXVec3Cross( (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)&g_sCamera.vRight );
|
|
|
|
D3DXVec3Normalize( (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vUp );
|
|
|
|
|
|
|
|
view._11 = g_sCamera.vRight.x;
|
|
|
|
view._12 = g_sCamera.vUp.x;
|
|
|
|
view._13 = g_sCamera.vLookAt.x;
|
|
|
|
view._14 = 0.0f;
|
|
|
|
|
|
|
|
view._21 = g_sCamera.vRight.y;
|
|
|
|
view._22 = g_sCamera.vUp.y;
|
|
|
|
view._23 = g_sCamera.vLookAt.y;
|
|
|
|
view._24 = 0.0f;
|
|
|
|
|
|
|
|
view._31 = g_sCamera.vRight.z;
|
|
|
|
view._32 = g_sCamera.vUp.z;
|
|
|
|
view._33 = g_sCamera.vLookAt.z;
|
|
|
|
view._34 = 0.0f;
|
|
|
|
|
|
|
|
view._41 = -D3DXVec3Dot( (D3DXVECTOR3*)&g_sCamera.vPos, (D3DXVECTOR3*)&g_sCamera.vRight );
|
|
|
|
view._42 = -D3DXVec3Dot( (D3DXVECTOR3*)&g_sCamera.vPos, (D3DXVECTOR3*)&g_sCamera.vUp );
|
|
|
|
view._43 = -D3DXVec3Dot( (D3DXVECTOR3*)&g_sCamera.vPos, (D3DXVECTOR3*)&g_sCamera.vLookAt );
|
|
|
|
view._44 = 1.0f;
|
|
|
|
|
|
|
|
memcpy(&p_mOut,&view,sizeof(aiMatrix4x4));
|
|
|
|
|
|
|
|
return g_sCamera.vPos;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|