#include "assimp_view.h"
#include "AnimEvaluator.h"
#include "SceneAnimator.h"
#include "StringUtils.h"
#include <commdlg.h>
namespace AssimpView {
using namespace Assimp;
extern std::string g_szCheckerBackgroundShader;
struct SVertex
{
float x,y,z,w,u,v;
};
CDisplay CDisplay::s_cInstance;
extern COLORREF g_aclCustomColors[16] ;
extern HKEY g_hRegistry;
extern float g_fLoadTime;
D3DXVECTOR4 g_aclNormalColors[14] =
{
D3DXVECTOR4(0xFF / 255.0f,0xFF / 255.0f,0xFF / 255.0f, 1.0f),
D3DXVECTOR4(0xFF / 255.0f,0x00 / 255.0f,0x00 / 255.0f,1.0f), D3DXVECTOR4(0x00 / 255.0f,0xFF / 255.0f,0x00 / 255.0f,1.0f), D3DXVECTOR4(0x00 / 255.0f,0x00 / 255.0f,0xFF / 255.0f,1.0f),
D3DXVECTOR4(0xFF / 255.0f,0xFF / 255.0f,0x00 / 255.0f,1.0f), D3DXVECTOR4(0xFF / 255.0f,0x00 / 255.0f,0xFF / 255.0f,1.0f), D3DXVECTOR4(0x00 / 255.0f,0xFF / 255.0f,0xFF / 255.0f,1.0f),
D3DXVECTOR4(0xFF / 255.0f,0x60 / 255.0f,0x60 / 255.0f,1.0f), D3DXVECTOR4(0x60 / 255.0f,0xFF / 255.0f,0x60 / 255.0f,1.0f), D3DXVECTOR4(0x60 / 255.0f,0x60 / 255.0f,0xFF / 255.0f,1.0f),
D3DXVECTOR4(0xA0 / 255.0f,0x00 / 255.0f,0x00 / 255.0f,1.0f), D3DXVECTOR4(0x00 / 255.0f,0xA0 / 255.0f,0x00 / 255.0f,1.0f), D3DXVECTOR4(0x00 / 255.0f,0x00 / 255.0f,0xA0 / 255.0f,1.0f),
D3DXVECTOR4(0x88 / 255.0f,0x88 / 255.0f,0x88 / 255.0f, 1.0f) };
void GetNodeCount(aiNode* pcNode, unsigned int* piCnt)
{
*piCnt = *piCnt+1;
for (unsigned int i = 0; i < pcNode->mNumChildren;++i)
GetNodeCount(pcNode->mChildren[i],piCnt);
}
int CDisplay::EnableAnimTools(BOOL hm)
{
EnableWindow(GetDlgItem(g_hDlg,IDC_PLAY),hm);
EnableWindow(GetDlgItem(g_hDlg,IDC_SLIDERANIM),hm);
return 1;
}
int CDisplay::FillAnimList(void)
{
if (0 != g_pcAsset->pcScene->mNumAnimations)
{
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumAnimations;++i) {
SendDlgItemMessage(g_hDlg,IDC_COMBO1,CB_ADDSTRING,0,
( LPARAM ) g_pcAsset->pcScene->mAnimations[i]->mName.data);
}
SendDlgItemMessage(g_hDlg,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM)"none");
SendDlgItemMessage(g_hDlg,IDC_COMBO1,CB_SETCURSEL,0,0);
EnableAnimTools(TRUE);
}
else EnableAnimTools(FALSE);
return 1;
}
int CDisplay::ClearAnimList(void)
{
SendDlgItemMessage(g_hDlg,IDC_COMBO1,CB_RESETCONTENT,0,0);
return 1;
}
int CDisplay::ClearDisplayList(void)
{
TreeView_DeleteAllItems(GetDlgItem(g_hDlg,IDC_TREE1));
this->Reset();
return 1;
}
int CDisplay::AddNodeToDisplayList(
unsigned int iIndex,
unsigned int iDepth,
aiNode* pcNode,
HTREEITEM hRoot)
{
ai_assert(NULL != pcNode);
ai_assert(NULL != hRoot);
char chTemp[MAXLEN];
if(0 == pcNode->mName.length) {
if (iIndex >= 100) {
iIndex += iDepth * 1000;
}
else if (iIndex >= 10)
{
iIndex += iDepth * 100;
}
else
iIndex += iDepth * 10;
ai_snprintf(chTemp, MAXLEN,"Node %u",iIndex);
}
else {
ai_snprintf(chTemp, MAXLEN,"%s",pcNode->mName.data);
}
ai_snprintf(chTemp+strlen(chTemp), MAXLEN- strlen(chTemp), iIndex ? " (%i)" : " (%i meshes)",pcNode->mNumMeshes);
TVITEMEXW tvi;
TVINSERTSTRUCTW sNew;
wchar_t tmp[512];
int t = MultiByteToWideChar(CP_UTF8,0,chTemp,-1,tmp,512);
tvi.pszText = tmp;
tvi.cchTextMax = (int)t;
tvi.mask = TVIF_TEXT | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_HANDLE | TVIF_PARAM;
tvi.iImage = this->m_aiImageList[AI_VIEW_IMGLIST_NODE];
tvi.iSelectedImage = this->m_aiImageList[AI_VIEW_IMGLIST_NODE];
tvi.lParam = (LPARAM)5;
sNew.itemex = tvi;
sNew.hInsertAfter = TVI_LAST;
sNew.hParent = hRoot;
HTREEITEM hTexture = (HTREEITEM)SendMessage(GetDlgItem(g_hDlg,IDC_TREE1),
TVM_INSERTITEMW,
0,
(LPARAM)(LPTVINSERTSTRUCT)&sNew);
++iDepth;
for (unsigned int i = 0; i< pcNode->mNumChildren;++i){
AddNodeToDisplayList(i,iDepth,pcNode->mChildren[i],hTexture);
}
NodeInfo info;
info.hTreeItem = hTexture;
info.psNode = pcNode;
this->AddNode(info);
return 1;
}
int CDisplay::AddMeshToDisplayList(unsigned int iIndex, HTREEITEM hRoot)
{
aiMesh* pcMesh = g_pcAsset->pcScene->mMeshes[iIndex];
char chTemp[MAXLEN];
if(0 == pcMesh->mName.length) {
ai_snprintf(chTemp,MAXLEN,"Mesh %u",iIndex);
}
else {
ai_snprintf(chTemp,MAXLEN,"%s",pcMesh->mName.data);
}
ai_snprintf(chTemp+strlen(chTemp),MAXLEN-strlen(chTemp), iIndex ? " (%i)" : " (%i faces)",pcMesh->mNumFaces);
TVITEMEXW tvi;
TVINSERTSTRUCTW sNew;
wchar_t tmp[512];
int t = MultiByteToWideChar(CP_UTF8,0,chTemp,-1,tmp,512);
tvi.pszText = tmp;
tvi.cchTextMax = (int)t;
tvi.mask = TVIF_TEXT | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_HANDLE | TVIF_PARAM;
tvi.iImage = this->m_aiImageList[AI_VIEW_IMGLIST_NODE];
tvi.iSelectedImage = this->m_aiImageList[AI_VIEW_IMGLIST_NODE];
tvi.lParam = (LPARAM)5;
sNew.itemex = tvi;
sNew.hInsertAfter = TVI_LAST;
sNew.hParent = hRoot;
HTREEITEM hTexture = (HTREEITEM)SendMessage(GetDlgItem(g_hDlg,IDC_TREE1),
TVM_INSERTITEMW,
0,
(LPARAM)(LPTVINSERTSTRUCT)&sNew);
MeshInfo info;
info.hTreeItem = hTexture;
info.psMesh = pcMesh;
AddMesh(info);
return 1;
}
int CDisplay::ReplaceCurrentTexture(const char* szPath)
{
ai_assert(NULL != szPath);
IDirect3DTexture9* piTexture = NULL;
aiString szString;
strcpy(szString.data,szPath);
szString.length = strlen(szPath);
CMaterialManager::Instance().LoadTexture(&piTexture,&szString);
if (!piTexture) {
CLogDisplay::Instance().AddEntry("[ERROR] Unable to load this texture",
D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
return 0;
}
TVITEMEX tvi;
tvi.mask = TVIF_SELECTEDIMAGE | TVIF_IMAGE;
tvi.iImage = m_aiImageList[AI_VIEW_IMGLIST_MATERIAL];
tvi.iSelectedImage = m_aiImageList[AI_VIEW_IMGLIST_MATERIAL];
TreeView_SetItem(GetDlgItem(g_hDlg,IDC_TREE1),
m_pcCurrentTexture->hTreeItem);
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (this->m_pcCurrentTexture->iMatIndex != g_pcAsset->pcScene->mMeshes[i]->mMaterialIndex)
continue;
AssetHelper::MeshHelper* pcMesh = g_pcAsset->apcMeshes[i];
IDirect3DTexture9** tex = NULL;
const char* tex_string = NULL;
switch (this->m_pcCurrentTexture->iType)
{
case aiTextureType_DIFFUSE:
tex = &pcMesh->piDiffuseTexture;
tex_string = "DIFFUSE_TEXTURE";
break;
case aiTextureType_AMBIENT:
tex = &pcMesh->piAmbientTexture;
tex_string = "AMBIENT_TEXTURE";
break;
case aiTextureType_SPECULAR:
tex = &pcMesh->piSpecularTexture;
tex_string = "SPECULAR_TEXTURE";
break;
case aiTextureType_EMISSIVE:
tex = &pcMesh->piEmissiveTexture;
tex_string = "EMISSIVE_TEXTURE";
break;
case aiTextureType_LIGHTMAP:
tex = &pcMesh->piLightmapTexture;
tex_string = "LIGHTMAP_TEXTURE";
break;
case aiTextureType_DISPLACEMENT:
case aiTextureType_REFLECTION:
case aiTextureType_UNKNOWN:
break;
case aiTextureType_SHININESS:
tex = &pcMesh->piShininessTexture;
tex_string = "SHININESS_TEXTURE";
break;
case aiTextureType_NORMALS:
case aiTextureType_HEIGHT:
if (pcMesh->piNormalTexture && pcMesh->piNormalTexture != piTexture) {
piTexture->AddRef();
pcMesh->piNormalTexture->Release();
pcMesh->piNormalTexture = piTexture;
CMaterialManager::Instance().HMtoNMIfNecessary(pcMesh->piNormalTexture,&pcMesh->piNormalTexture,true);
m_pcCurrentTexture->piTexture = &pcMesh->piNormalTexture;
if (!pcMesh->bSharedFX) {
pcMesh->piEffect->SetTexture("NORMAL_TEXTURE",piTexture);
}
}
break;
default:
tex = &pcMesh->piOpacityTexture;
tex_string = "OPACITY_TEXTURE";
break;
};
if (tex && *tex && *tex != piTexture)
{
(**tex).Release();
*tex = piTexture;
m_pcCurrentTexture->piTexture = tex;
pcMesh->piEffect->SetTexture(tex_string,piTexture);
}
}
return 1;
}
int CDisplay::AddTextureToDisplayList(unsigned int iType,
unsigned int iIndex,
const aiString* szPath,
HTREEITEM hFX,
unsigned int iUVIndex ,
const float fBlendFactor ,
aiTextureOp eTextureOp ,
unsigned int iMesh )
{
ai_assert(NULL != szPath);
char chTemp[512];
char chTempEmb[256];
const char* sz = strrchr(szPath->data,'\\');
if (!sz)sz = strrchr(szPath->data,'/');
if (!sz)
{
if ('*' == *szPath->data)
{
int iIndex = atoi(szPath->data+1);
ai_snprintf(chTempEmb,256,"Embedded #%i",iIndex);
sz = chTempEmb;
}
else
{
sz = szPath->data;
}
}
bool bIsExtraOpacity = 0 != (iType & 0x40000000);
const char* szType;
IDirect3DTexture9** piTexture;
switch (iType)
{
case aiTextureType_DIFFUSE:
piTexture = &g_pcAsset->apcMeshes[iMesh]->piDiffuseTexture;
szType = "Diffuse";
break;
case aiTextureType_SPECULAR:
piTexture = &g_pcAsset->apcMeshes[iMesh]->piSpecularTexture;
szType = "Specular";
break;
case aiTextureType_AMBIENT:
piTexture = &g_pcAsset->apcMeshes[iMesh]->piAmbientTexture;
szType = "Ambient";
break;
case aiTextureType_EMISSIVE:
piTexture = &g_pcAsset->apcMeshes[iMesh]->piEmissiveTexture;
szType = "Emissive";
break;
case aiTextureType_HEIGHT:
piTexture = &g_pcAsset->apcMeshes[iMesh]->piNormalTexture;
szType = "Heightmap";
break;
case aiTextureType_NORMALS:
piTexture = &g_pcAsset->apcMeshes[iMesh]->piNormalTexture;
szType = "Normalmap";
break;
case aiTextureType_SHININESS:
piTexture = &g_pcAsset->apcMeshes[iMesh]->piShininessTexture;
szType = "Shininess";
break;
case aiTextureType_LIGHTMAP:
piTexture = &g_pcAsset->apcMeshes[iMesh]->piLightmapTexture;
szType = "Lightmap";
break;
case aiTextureType_DISPLACEMENT:
piTexture = NULL;
szType = "Displacement";
break;
case aiTextureType_REFLECTION:
piTexture = NULL;
szType = "Reflection";
break;
case aiTextureType_UNKNOWN:
piTexture = NULL;
szType = "Unknown";
break;
default: piTexture = &g_pcAsset->apcMeshes[iMesh]->piOpacityTexture;
szType = "Opacity";
break;
};
if (bIsExtraOpacity) {
ai_snprintf(chTemp,512,"%s %i (<copy of diffuse #1>)",szType,iIndex+1);
}
else
ai_snprintf(chTemp,512,"%s %i (%s)",szType,iIndex+1,sz);
TVITEMEX tvi;
TVINSERTSTRUCT sNew;
tvi.pszText = chTemp;
tvi.cchTextMax = (int)strlen(chTemp);
tvi.mask = TVIF_TEXT | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_HANDLE | TVIF_HANDLE;
tvi.lParam = (LPARAM)20;
if (piTexture && *piTexture) {
static const GUID guidPrivateData =
{ 0x9785da94, 0x1d96, 0x426b,
{ 0xb3, 0xcb, 0xba, 0xdc, 0x36, 0x34, 0x7f, 0x5e } };
uint32_t iData = 0;
DWORD dwSize = 4;
(*piTexture)->GetPrivateData(guidPrivateData,&iData,&dwSize);
if (0xFFFFFFFF == iData)
{
tvi.iImage = m_aiImageList[AI_VIEW_IMGLIST_TEXTURE_INVALID];
tvi.iSelectedImage = m_aiImageList[AI_VIEW_IMGLIST_TEXTURE_INVALID];
}
else
{
tvi.iImage = m_aiImageList[AI_VIEW_IMGLIST_TEXTURE];
tvi.iSelectedImage = m_aiImageList[AI_VIEW_IMGLIST_TEXTURE];
}
}
else
{
tvi.iImage = m_aiImageList[AI_VIEW_IMGLIST_TEXTURE_INVALID];
tvi.iSelectedImage = m_aiImageList[AI_VIEW_IMGLIST_TEXTURE_INVALID];
}
sNew.itemex = tvi;
sNew.hInsertAfter = TVI_LAST;
sNew.hParent = hFX;
HTREEITEM hTexture = (HTREEITEM)SendMessage(GetDlgItem(g_hDlg,IDC_TREE1),
TVM_INSERTITEM,
0,
(LPARAM)(LPTVINSERTSTRUCT)&sNew);
CDisplay::TextureInfo sInfo;
sInfo.iUV = iUVIndex;
sInfo.fBlend = fBlendFactor;
sInfo.eOp = eTextureOp;
sInfo.szPath = szPath->data;
sInfo.hTreeItem = hTexture;
sInfo.piTexture = piTexture;
sInfo.iType = iType;
sInfo.iMatIndex = g_pcAsset->pcScene->mMeshes[iMesh]->mMaterialIndex;
AddTexture(sInfo);
return 1;
}
int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot,
unsigned int iIndex)
{
ai_assert(NULL != hRoot);
aiMaterial* pcMat = g_pcAsset->pcScene->mMaterials[iIndex];
unsigned int iMesh = 0;
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (iIndex == g_pcAsset->pcScene->mMeshes[i]->mMaterialIndex)
{
iMesh = i;
break;
}
}
char chTemp[512];
aiString szOut;
if (AI_SUCCESS != aiGetMaterialString(pcMat,AI_MATKEY_NAME,&szOut))
{
ai_snprintf(chTemp,512,"Material %i",iIndex+1);
}
else
{
ai_snprintf(chTemp,512,"%s (%i)",szOut.data,iIndex+1);
}
TVITEMEXW tvi;
TVINSERTSTRUCTW sNew;
wchar_t tmp[512];
int t = MultiByteToWideChar(CP_UTF8,0,chTemp,-1,tmp,512);
tvi.pszText = tmp;
tvi.cchTextMax = (int)t;
tvi.mask = TVIF_TEXT | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_HANDLE | TVIF_PARAM ;
tvi.iImage = m_aiImageList[AI_VIEW_IMGLIST_MATERIAL];
tvi.iSelectedImage = m_aiImageList[AI_VIEW_IMGLIST_MATERIAL];
tvi.lParam = (LPARAM)10;
sNew.itemex = tvi;
sNew.hInsertAfter = TVI_LAST;
sNew.hParent = hRoot;
HTREEITEM hTexture = (HTREEITEM)SendMessage(GetDlgItem(g_hDlg,IDC_TREE1),
TVM_INSERTITEMW,
0,
(LPARAM)(LPTVINSERTSTRUCT)&sNew);
unsigned int iUV;
float fBlend;
aiTextureOp eOp;
aiString szPath;
bool bNoOpacity = true;
for (unsigned int i = 0; i <= AI_TEXTURE_TYPE_MAX;++i)
{
unsigned int iNum = 0;
while (true)
{
if (AI_SUCCESS != aiGetMaterialTexture(pcMat,(aiTextureType)i,iNum,
&szPath,NULL, &iUV,&fBlend,&eOp))
{
break;
}
if (aiTextureType_OPACITY == i)bNoOpacity = false;
AddTextureToDisplayList(i,iNum,&szPath,hTexture,iUV,fBlend,eOp,iMesh);
++iNum;
}
}
AssetHelper::MeshHelper* pcMesh = g_pcAsset->apcMeshes[iMesh];
if (pcMesh->piDiffuseTexture && pcMesh->piDiffuseTexture == pcMesh->piOpacityTexture && bNoOpacity)
{
static const GUID guidPrivateData =
{ 0x9785da94, 0x1d96, 0x426b,
{ 0xb3, 0xcb, 0xba, 0xdc, 0x36, 0x34, 0x7f, 0x5e } };
uint32_t iData = 0;
DWORD dwSize = 4;
if(FAILED( pcMesh->piDiffuseTexture->GetPrivateData(guidPrivateData,&iData,&dwSize) ||
0xffffffff == iData))
{
AddTextureToDisplayList(aiTextureType_OPACITY | 0x40000000,
0,&szPath,hTexture,iUV,fBlend,eOp,iMesh);
}
}
MaterialInfo info;
info.hTreeItem = hTexture;
info.psMaterial = pcMat;
info.iIndex = iIndex;
info.piEffect = g_pcAsset->apcMeshes[iMesh]->piEffect;
this->AddMaterial(info);
return 1;
}
int CDisplay::ExpandTree()
{
for (std::vector< MaterialInfo >::iterator
i = m_asMaterials.begin();
i != m_asMaterials.end();++i)
{
TreeView_Expand(GetDlgItem(g_hDlg,IDC_TREE1),(*i).hTreeItem,TVE_EXPAND);
}
for (std::vector< NodeInfo >::iterator
i = m_asNodes.begin();
i != m_asNodes.end();++i)
{
TreeView_Expand(GetDlgItem(g_hDlg,IDC_TREE1),(*i).hTreeItem,TVE_EXPAND);
}
TreeView_Expand(GetDlgItem(g_hDlg,IDC_TREE1),m_hRoot,TVE_EXPAND);
return 1;
}
int CDisplay::LoadImageList(void)
{
if (!m_hImageList)
{
HIMAGELIST hIml = ImageList_Create( 16,16,ILC_COLOR24, 5, 0 );
HBITMAP hBmp = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_BFX));
m_aiImageList[AI_VIEW_IMGLIST_MATERIAL] = ImageList_Add(hIml, hBmp, NULL);
DeleteObject(hBmp);
hBmp = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_BNODE));
m_aiImageList[AI_VIEW_IMGLIST_NODE] = ImageList_Add(hIml, hBmp, NULL);
DeleteObject(hBmp);
hBmp = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_BTX));
m_aiImageList[AI_VIEW_IMGLIST_TEXTURE] = ImageList_Add(hIml, hBmp, NULL);
DeleteObject(hBmp);
hBmp = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_BTXI));
m_aiImageList[AI_VIEW_IMGLIST_TEXTURE_INVALID] = ImageList_Add(hIml, hBmp, NULL);
DeleteObject(hBmp);
hBmp = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_BROOT));
m_aiImageList[AI_VIEW_IMGLIST_MODEL] = ImageList_Add(hIml, hBmp, NULL);
DeleteObject(hBmp);
TreeView_SetImageList(GetDlgItem(g_hDlg,IDC_TREE1), hIml, TVSIL_NORMAL);
m_hImageList = hIml;
}
return 1;
}
int CDisplay::FillDisplayList(void)
{
LoadImageList();
TVITEMEX tvi;
TVINSERTSTRUCT sNew;
tvi.pszText = (char*) "Model";
tvi.cchTextMax = (int)strlen(tvi.pszText);
tvi.mask = TVIF_TEXT | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_HANDLE | TVIF_STATE;
tvi.state = TVIS_EXPANDED;
tvi.iImage = m_aiImageList[AI_VIEW_IMGLIST_MODEL];
tvi.iSelectedImage = m_aiImageList[AI_VIEW_IMGLIST_MODEL];
tvi.lParam = (LPARAM)0;
sNew.itemex = tvi;
sNew.hInsertAfter = TVI_ROOT;
sNew.hParent = 0;
m_hRoot = (HTREEITEM)SendMessage(GetDlgItem(g_hDlg,IDC_TREE1),
TVM_INSERTITEM,
0,
(LPARAM)(LPTVINSERTSTRUCT)&sNew);
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMaterials;++i)
AddMaterialToDisplayList(m_hRoot,i);
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
AddMeshToDisplayList(i,m_hRoot);
AddNodeToDisplayList(0,0,g_pcAsset->pcScene->mRootNode,m_hRoot);
ExpandTree();
UpdateWindow(g_hDlg);
return 1;
}
int CDisplay::OnRender()
{
if( g_pcAsset)
{
static double lastPlaying = 0.;
ai_assert( g_pcAsset->mAnimator);
if (g_bPlay) {
g_dCurrent += clock()/ double( CLOCKS_PER_SEC) -lastPlaying;
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))));
}
g_pcAsset->mAnimator->Calculate( time );
lastPlaying = g_dCurrent;
}
}
g_piDevice->BeginScene();
switch (m_iViewMode)
{
case VIEWMODE_FULL:
case VIEWMODE_NODE:
RenderFullScene();
break;
case VIEWMODE_MATERIAL:
RenderMaterialView();
break;
case VIEWMODE_TEXTURE:
RenderTextureView();
break;
};
CLogDisplay::Instance().OnRender();
g_piDevice->EndScene();
g_piDevice->Present(NULL,NULL,NULL,NULL);
Sleep(10);
return 1;
}
void UpdateColorFieldsInUI()
{
InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR1),NULL,TRUE);
InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR2),NULL,TRUE);
InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR3),NULL,TRUE);
UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR1));
UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR2));
UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR3));
}
int CDisplay::FillDefaultStatistics(void)
{
if (!g_pcAsset)
{
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_ESHADER,"0");
SetDlgItemText(g_hDlg,IDC_ETEX,"0");
return 1;
}
unsigned int iNumVert = 0;
unsigned int iNumFaces = 0;
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
iNumVert += g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
iNumFaces += g_pcAsset->pcScene->mMeshes[i]->mNumFaces;
}
char szOut[1024];
ai_snprintf(szOut,1024,"%i",(int)iNumVert);
SetDlgItemText(g_hDlg,IDC_EVERT,szOut);
ai_snprintf(szOut, 1024,"%i",(int)iNumFaces);
SetDlgItemText(g_hDlg,IDC_EFACE,szOut);
ai_snprintf(szOut, 1024,"%i",(int)g_pcAsset->pcScene->mNumMaterials);
SetDlgItemText(g_hDlg,IDC_EMAT,szOut);
ai_snprintf(szOut, 1024,"%i",(int)g_pcAsset->pcScene->mNumMeshes);
SetDlgItemText(g_hDlg,IDC_EMESH,szOut);
iNumVert = 0;
GetNodeCount(g_pcAsset->pcScene->mRootNode,&iNumVert);
ai_snprintf(szOut, 1024,"%i",(int)iNumVert);
SetDlgItemText(g_hDlg,IDC_ENODEWND,szOut);
ai_snprintf(szOut, 1024,"%i", CMaterialManager::Instance().GetShaderCount());
SetDlgItemText(g_hDlg,IDC_ESHADER,szOut);
sprintf(szOut,"%.5f",(float)g_fLoadTime);
SetDlgItemText(g_hDlg,IDC_ELOAD,szOut);
UpdateColorFieldsInUI();
UpdateWindow(g_hDlg);
return 1;
}
int CDisplay::Reset(void)
{
m_asMaterials.clear();
m_asTextures.clear();
m_asNodes.clear();
m_asMeshes.clear();
m_hRoot = NULL;
return OnSetupNormalView();
}
void ShowNormalUIComponents()
{
ShowWindow(GetDlgItem(g_hDlg,IDC_NUMNODES),SW_SHOW);
ShowWindow(GetDlgItem(g_hDlg,IDC_ENODEWND),SW_SHOW);
ShowWindow(GetDlgItem(g_hDlg,IDC_NUMSHADERS),SW_SHOW);
ShowWindow(GetDlgItem(g_hDlg,IDC_LOADTIME),SW_SHOW);
ShowWindow(GetDlgItem(g_hDlg,IDC_ESHADER),SW_SHOW);
ShowWindow(GetDlgItem(g_hDlg,IDC_ELOAD),SW_SHOW);
ShowWindow(GetDlgItem(g_hDlg,IDC_VIEWMATRIX),SW_HIDE);
}
int CDisplay::OnSetupNormalView()
{
if (VIEWMODE_NODE == m_iViewMode)
{
ShowNormalUIComponents();
}
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMVERTS),"Vertices:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMNODES),"Nodes:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMFACES),"Faces:");
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:");
FillDefaultStatistics();
SetViewMode(VIEWMODE_FULL);
m_pcCurrentMaterial = NULL;
m_pcCurrentTexture = NULL;
m_pcCurrentNode = NULL;
UpdateColorFieldsInUI();
UpdateWindow(g_hDlg);
return 1;
}
int CDisplay::OnSetupNodeView(NodeInfo* pcNew)
{
ai_assert(NULL != pcNew);
if (m_pcCurrentNode == pcNew)return 2;
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMVERTS),"Vertices:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMFACES),"Faces:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMMATS),"Materials:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMMESHES),"Meshes:");
ShowWindow(GetDlgItem(g_hDlg,IDC_NUMNODES),SW_HIDE);
ShowWindow(GetDlgItem(g_hDlg,IDC_ENODEWND),SW_HIDE);
ShowWindow(GetDlgItem(g_hDlg,IDC_NUMSHADERS),SW_HIDE);
ShowWindow(GetDlgItem(g_hDlg,IDC_LOADTIME),SW_HIDE);
ShowWindow(GetDlgItem(g_hDlg,IDC_ESHADER),SW_HIDE);
ShowWindow(GetDlgItem(g_hDlg,IDC_ELOAD),SW_HIDE);
ShowWindow(GetDlgItem(g_hDlg,IDC_VIEWMATRIX),SW_SHOW);
char szTemp[1024];
sprintf(szTemp,
"%.2f %.2f %.2f\r\n"
"%.2f %.2f %.2f\r\n"
"%.2f %.2f %.2f\r\n"
"%.2f %.2f %.2f\r\n",
pcNew->psNode->mTransformation.a1,
pcNew->psNode->mTransformation.b1,
pcNew->psNode->mTransformation.c1,
pcNew->psNode->mTransformation.a2,
pcNew->psNode->mTransformation.b2,
pcNew->psNode->mTransformation.c2,
pcNew->psNode->mTransformation.a3,
pcNew->psNode->mTransformation.b3,
pcNew->psNode->mTransformation.c3,
pcNew->psNode->mTransformation.a4,
pcNew->psNode->mTransformation.b4,
pcNew->psNode->mTransformation.c4);
SetWindowText(GetDlgItem(g_hDlg,IDC_VIEWMATRIX),szTemp);
m_pcCurrentNode = pcNew;
SetViewMode(VIEWMODE_NODE);
return 1;
}
int CDisplay::OnSetupMaterialView(MaterialInfo* pcNew)
{
ai_assert(NULL != pcNew);
if (m_pcCurrentMaterial == pcNew)return 2;
if (VIEWMODE_NODE == m_iViewMode)
ShowNormalUIComponents();
m_pcCurrentMaterial = pcNew;
SetViewMode(VIEWMODE_MATERIAL);
UpdateColorFieldsInUI();
UpdateWindow(g_hDlg);
return 1;
}
int CDisplay::OnSetupTextureView(TextureInfo* pcNew)
{
ai_assert(NULL != pcNew);
if (this->m_pcCurrentTexture == pcNew)return 2;
if (VIEWMODE_NODE == this->m_iViewMode)
{
ShowNormalUIComponents();
}
if ((aiTextureType_OPACITY | 0x40000000) == pcNew->iType)
{
CLogDisplay::Instance().AddEntry("[INFO] This texture is not existing in the "
"original mesh",D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
CLogDisplay::Instance().AddEntry("It is a copy of the alpha channel of the first "
"diffuse texture",D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
}
if (g_sCaps.PixelShaderVersion < D3DPS_VERSION(3,0))
{
CLogDisplay::Instance().AddEntry("[WARN] The background shader won't work "
"on your system, it required PS 3.0 hardware. A default color is used ...",
D3DCOLOR_ARGB(0xFF,0xFF,0x00,0));
}
this->m_fTextureZoom = 1000.0f;
this->m_vTextureOffset.x = this->m_vTextureOffset.y = 0.0f;
this->m_pcCurrentTexture = pcNew;
this->SetViewMode(VIEWMODE_TEXTURE);
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMVERTS),"Width:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMNODES),"Height:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMFACES),"Format:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMSHADERS),"MIPs:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMMATS),"UV:");
SetWindowText(GetDlgItem(g_hDlg,IDC_NUMMESHES),"Blend:");
SetWindowText(GetDlgItem(g_hDlg,IDC_LOADTIME),"Op:");
D3DSURFACE_DESC sDesc;
if (pcNew->piTexture && *pcNew->piTexture) {
(*pcNew->piTexture)->GetLevelDesc(0,&sDesc);
char szTemp[128];
sprintf(szTemp,"%i",sDesc.Width);
SetWindowText(GetDlgItem(g_hDlg,IDC_EVERT),szTemp);
sprintf(szTemp,"%i",sDesc.Height);
SetWindowText(GetDlgItem(g_hDlg,IDC_ENODEWND),szTemp);
sprintf(szTemp,"%i",(*pcNew->piTexture)->GetLevelCount());
SetWindowText(GetDlgItem(g_hDlg,IDC_ESHADER),szTemp);
sprintf(szTemp,"%u",pcNew->iUV);
SetWindowText(GetDlgItem(g_hDlg,IDC_EMAT),szTemp);
sprintf(szTemp,"%f",pcNew->fBlend);
SetWindowText(GetDlgItem(g_hDlg,IDC_EMESH),szTemp);
const char* szOp;
switch (pcNew->eOp)
{
case aiTextureOp_Add:
szOp = "add";break;
case aiTextureOp_Subtract:
szOp = "sub";break;
case aiTextureOp_Divide:
szOp = "div";break;
case aiTextureOp_SignedAdd:
szOp = "addsign";break;
case aiTextureOp_SmoothAdd:
szOp = "addsmooth";break;
default: szOp = "mul";
};
SetWindowText(GetDlgItem(g_hDlg,IDC_ELOAD),szOp);
SetWindowText(GetDlgItem(g_hDlg,IDC_EFACE),"ARGB8");
if (pcNew->piTexture)
{
static const GUID guidPrivateData =
{ 0x9785da94, 0x1d96, 0x426b,
{ 0xb3, 0xcb, 0xba, 0xdc, 0x36, 0x34, 0x7f, 0x5e } };
uint32_t iData = 0;
DWORD dwSize = 4;
(*pcNew->piTexture)->GetPrivateData(guidPrivateData,&iData,&dwSize);
if (0xFFFFFFFF == iData)
{
CLogDisplay::Instance().AddEntry("[ERROR] Texture could not be loaded. "
"The displayed texture is a default texture",
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
return 0;
}
}
}
UpdateColorFieldsInUI();
UpdateWindow(g_hDlg);
return 1;
}
int CDisplay::OnSetup(HTREEITEM p_hTreeItem)
{
union {
TextureInfo* pcNew;
NodeInfo* pcNew2;
MaterialInfo* pcNew3;
};
pcNew = NULL;
for (std::vector<TextureInfo>::iterator i = m_asTextures.begin();i != m_asTextures.end();++i){
if (p_hTreeItem == (*i).hTreeItem) {
pcNew = &(*i);
break;
}
}
if (pcNew) {
return OnSetupTextureView(pcNew);
}
for (std::vector<NodeInfo>::iterator i = m_asNodes.begin(); i != m_asNodes.end();++i){
if (p_hTreeItem == (*i).hTreeItem) {
pcNew2 = &(*i);
break;
}
}
if (pcNew2) {
return OnSetupNodeView(pcNew2);
}
for (std::vector<MaterialInfo>::iterator i = m_asMaterials.begin();i != m_asMaterials.end();++i){
if (p_hTreeItem == (*i).hTreeItem){
pcNew3 = &(*i);
break;
}
}
if (pcNew3) {
return OnSetupMaterialView(pcNew3);
}
return OnSetupNormalView();
}
int CDisplay::ShowTreeViewContextMenu(HTREEITEM hItem)
{
ai_assert(NULL != hItem);
HMENU hDisplay = NULL;
TextureInfo* pcNew = NULL;
for (std::vector<TextureInfo>::iterator
i = m_asTextures.begin();
i != m_asTextures.end();++i)
{
if (hItem == (*i).hTreeItem) {
pcNew = &(*i);
break;
}
}
if (pcNew)
{
HMENU hMenu = LoadMenu(g_hInstance,MAKEINTRESOURCE(IDR_TXPOPUP));
hDisplay = GetSubMenu(hMenu,0);
}
MaterialInfo* pcNew2 = NULL;
for (std::vector<MaterialInfo>::iterator
i = m_asMaterials.begin();
i != m_asMaterials.end();++i)
{
if (hItem == (*i).hTreeItem) {
pcNew2 = &(*i);
break;
}
}
if (pcNew2)
{
HMENU hMenu = LoadMenu(g_hInstance,MAKEINTRESOURCE(IDR_MATPOPUP));
hDisplay = GetSubMenu(hMenu,0);
}
if (NULL != hDisplay)
{
TreeView_Select(GetDlgItem(g_hDlg,IDC_TREE1),hItem,TVGN_CARET);
OnRender();
POINT sPoint;
GetCursorPos(&sPoint);
TrackPopupMenu(hDisplay, TPM_LEFTALIGN, sPoint.x, sPoint.y, 0,
g_hDlg,NULL);
}
return 1;
}
int CDisplay::HandleTreeViewPopup(WPARAM wParam,LPARAM lParam)
{
std::vector<Info> apclrOut;
const char* szMatKey = "";
switch (LOWORD(wParam))
{
case ID_SOLONG_CLEARDIFFUSECOLOR:
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (this->m_pcCurrentMaterial->iIndex == g_pcAsset->pcScene->mMeshes[i]->mMaterialIndex)
{
apclrOut.push_back( Info( &g_pcAsset->apcMeshes[i]->vDiffuseColor,
g_pcAsset->apcMeshes[i],"DIFFUSE_COLOR"));
}
}
szMatKey = "$clr.diffuse";
break;
case ID_SOLONG_CLEARSPECULARCOLOR:
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (this->m_pcCurrentMaterial->iIndex == g_pcAsset->pcScene->mMeshes[i]->mMaterialIndex)
{
apclrOut.push_back( Info( &g_pcAsset->apcMeshes[i]->vSpecularColor,
g_pcAsset->apcMeshes[i],"SPECULAR_COLOR"));
}
}
szMatKey = "$clr.specular";
break;
case ID_SOLONG_CLEARAMBIENTCOLOR:
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (this->m_pcCurrentMaterial->iIndex == g_pcAsset->pcScene->mMeshes[i]->mMaterialIndex)
{
apclrOut.push_back( Info( &g_pcAsset->apcMeshes[i]->vAmbientColor,
g_pcAsset->apcMeshes[i],"AMBIENT_COLOR"));
}
}
szMatKey = "$clr.ambient";
break;
case ID_SOLONG_CLEAREMISSIVECOLOR:
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (this->m_pcCurrentMaterial->iIndex == g_pcAsset->pcScene->mMeshes[i]->mMaterialIndex)
{
apclrOut.push_back( Info( &g_pcAsset->apcMeshes[i]->vEmissiveColor,
g_pcAsset->apcMeshes[i],"EMISSIVE_COLOR"));
}
}
szMatKey = "$clr.emissive";
break;
default:
HandleTreeViewPopup2(wParam,lParam);
};
if (!apclrOut.empty())
{
aiColor4D clrOld = *((aiColor4D*)(apclrOut.front().pclrColor));
CHOOSECOLOR clr;
clr.lStructSize = sizeof(CHOOSECOLOR);
clr.hwndOwner = g_hDlg;
clr.Flags = CC_RGBINIT | CC_FULLOPEN;
clr.rgbResult = RGB(
clamp<unsigned char>(clrOld.r * 255.0f),
clamp<unsigned char>(clrOld.g * 255.0f),
clamp<unsigned char>(clrOld.b * 255.0f));
clr.lpCustColors = g_aclCustomColors;
clr.lpfnHook = NULL;
clr.lpTemplateName = NULL;
clr.lCustData = 0;
ChooseColor(&clr);
clrOld.r = (float)(((unsigned int)clr.rgbResult) & 0xFF) / 255.0f;
clrOld.g = (float)(((unsigned int)clr.rgbResult >> 8) & 0xFF) / 255.0f;
clrOld.b = (float)(((unsigned int)clr.rgbResult >> 16) & 0xFF) / 255.0f;
for (std::vector<Info>::iterator
i = apclrOut.begin();
i != apclrOut.end();++i)
{
*((*i).pclrColor) = *((D3DXVECTOR4*)&clrOld);
if (!(*i).pMesh->bSharedFX)
{
(*i).pMesh->piEffect->SetVector((*i).szShaderParam,(*i).pclrColor);
}
}
aiMaterial* pcMat = (aiMaterial*)g_pcAsset->pcScene->mMaterials[
this->m_pcCurrentMaterial->iIndex];
pcMat->AddProperty<aiColor4D>(&clrOld,1,szMatKey,0,0);
if (ID_SOLONG_CLEARSPECULARCOLOR == LOWORD(wParam) &&
aiShadingMode_Gouraud == apclrOut.front().pMesh->eShadingMode)
{
CLogDisplay::Instance().AddEntry("[INFO] You have just changed the specular "
"material color",D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
CLogDisplay::Instance().AddEntry(
"This is great, especially since there is currently no specular shading",
D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
}
}
return 1;
}
int CALLBACK TreeViewCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
if (lParamSort == lParam1)return -1;
if (lParamSort == lParam2)return 1;
return 0;
}
int CDisplay::HandleTreeViewPopup2(WPARAM wParam,LPARAM lParam)
{
char szFileName[MAX_PATH];
DWORD dwTemp = MAX_PATH;
switch (LOWORD(wParam))
{
case ID_HEY_REPLACE:
{
if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"ReplaceTextureSrc",NULL,NULL,
(BYTE*)szFileName,&dwTemp))
{
strcpy(szFileName,"");
}
else
{
char* sz = strrchr(szFileName,'\\');
if (!sz)
sz = strrchr(szFileName,'/');
if (sz)
*sz = 0;
}
OPENFILENAME sFilename1 = {
sizeof(OPENFILENAME),
g_hDlg,GetModuleHandle(NULL),
"Textures\0*.png;*.dds;*.tga;*.bmp;*.tif;*.ppm;*.ppx;*.jpg;*.jpeg;*.exr\0*.*\0",
NULL, 0, 1,
szFileName, MAX_PATH, NULL, 0, NULL,
"Replace this texture",
OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
0, 1, ".jpg", 0, NULL, NULL
};
if(GetOpenFileName(&sFilename1) == 0) return 0;
RegSetValueExA(g_hRegistry,"ReplaceTextureSrc",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
this->ReplaceCurrentTexture(szFileName);
}
return 1;
case ID_HEY_EXPORT:
{
if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"TextureExportDest",NULL,NULL,
(BYTE*)szFileName,&dwTemp))
{
strcpy(szFileName,"");
}
else
{
char* sz = strrchr(szFileName,'\\');
if (!sz)
sz = strrchr(szFileName,'/');
if (sz)
*sz = 0;
}
OPENFILENAME sFilename1 = {
sizeof(OPENFILENAME),
g_hDlg,GetModuleHandle(NULL),
"Textures\0*.png;*.dds;*.bmp;*.tif;*.pfm;*.jpg;*.jpeg;*.hdr\0*.*\0", NULL, 0, 1,
szFileName, MAX_PATH, NULL, 0, NULL,
"Export texture to file",
OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
0, 1, ".png", 0, NULL, NULL
};
if(GetSaveFileName(&sFilename1) == 0) return 0;
RegSetValueExA(g_hRegistry,"TextureExportDest",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
D3DXIMAGE_FILEFORMAT eFormat = D3DXIFF_PNG;
const char* sz = strrchr(szFileName,'.');
if (sz)
{
++sz;
if (0 == Assimp::ASSIMP_stricmp(sz,"pfm"))eFormat = D3DXIFF_PFM;
else if (0 == Assimp::ASSIMP_stricmp(sz,"dds"))eFormat = D3DXIFF_DDS;
else if (0 == Assimp::ASSIMP_stricmp(sz,"jpg"))eFormat = D3DXIFF_JPG;
else if (0 == Assimp::ASSIMP_stricmp(sz,"jpeg"))eFormat = D3DXIFF_JPG;
else if (0 == Assimp::ASSIMP_stricmp(sz,"hdr"))eFormat = D3DXIFF_HDR;
else if (0 == Assimp::ASSIMP_stricmp(sz,"bmp"))eFormat = D3DXIFF_BMP;
}
IDirect3DSurface9* pi = NULL;
(*this->m_pcCurrentTexture->piTexture)->GetSurfaceLevel(0,&pi);
if(!pi || FAILED(D3DXSaveSurfaceToFile(szFileName,eFormat,pi,NULL,NULL)))
{
CLogDisplay::Instance().AddEntry("[ERROR] Unable to export texture",
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
}
else
{
CLogDisplay::Instance().AddEntry("[INFO] The texture has been exported",
D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
}
if(pi)pi->Release();
}
return 1;
case ID_HEY_REMOVE:
{
if(IDYES != MessageBox(g_hDlg,"To recover the texture you need to reload the model. Do you wish to continue?",
"Remove texture",MB_YESNO)) {
return 1;
}
aiMaterial* pcMat = (aiMaterial*)g_pcAsset->pcScene->mMaterials[
m_pcCurrentTexture->iMatIndex];
unsigned int s;
if (m_pcCurrentTexture->iType == (aiTextureType_OPACITY | 0x40000000))
{
int iVal = 1;
pcMat->AddProperty<int>(&iVal,1,"no_a_from_d",0,0);
s = aiTextureType_OPACITY;
}
else s = m_pcCurrentTexture->iType;
pcMat->RemoveProperty(AI_MATKEY_TEXTURE(m_pcCurrentTexture->iType,0));
for (unsigned int i = 0;i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (m_pcCurrentTexture->iMatIndex == g_pcAsset->pcScene->mMeshes[i]->mMaterialIndex)
{
CMaterialManager::Instance().DeleteMaterial(g_pcAsset->apcMeshes[i]);
CMaterialManager::Instance().CreateMaterial(g_pcAsset->apcMeshes[i],g_pcAsset->pcScene->mMeshes[i]);
}
}
const unsigned int iMatIndex = m_pcCurrentTexture->iMatIndex;
for (std::vector<MaterialInfo>::iterator
a = m_asMaterials.begin();
a != m_asMaterials.end();++a)
{
if (iMatIndex == (*a).iIndex)
{
for (std::vector<TextureInfo>::iterator
n = m_asTextures.begin();
n != m_asTextures.end();++n)
{
if ((*n).iMatIndex == iMatIndex)
{
n = m_asTextures.erase(n);
if (m_asTextures.end() == n)break;
}
}
TreeView_DeleteItem(GetDlgItem(g_hDlg,IDC_TREE1),(*a).hTreeItem);
this->m_asMaterials.erase(a);
break;
}
}
AddMaterialToDisplayList(m_hRoot,iMatIndex);
HTREEITEM hNewItem = m_asMaterials.back().hTreeItem;
TreeView_Expand(GetDlgItem(g_hDlg,IDC_TREE1),hNewItem,TVE_EXPAND);
TVSORTCB sSort;
sSort.hParent = m_hRoot;
sSort.lParam = 10;
sSort.lpfnCompare = &TreeViewCompareFunc;
TreeView_SortChildrenCB(GetDlgItem(g_hDlg,IDC_TREE1),&sSort,0);
TreeView_Select(GetDlgItem(g_hDlg,IDC_TREE1),m_hRoot,TVGN_CARET);
return 1;
}
}
return 0;
}
int CDisplay::SetupStereoView()
{
if (NULL != g_pcAsset && NULL != g_pcAsset->pcScene->mRootNode)
{
g_piDevice->SetRenderState(D3DRS_COLORWRITEENABLE,
D3DCOLORWRITEENABLE_RED |
D3DCOLORWRITEENABLE_ALPHA |
D3DCOLORWRITEENABLE_GREEN);
g_sCamera.vPos -= g_sCamera.vRight * 0.03f;
}
return 1;
}
int CDisplay::RenderStereoView(const aiMatrix4x4& m)
{
if (NULL != g_pcAsset && NULL != g_pcAsset->pcScene->mRootNode)
{
g_piDevice->SetRenderState(D3DRS_COLORWRITEENABLE,
D3DCOLORWRITEENABLE_GREEN |
D3DCOLORWRITEENABLE_ALPHA |
D3DCOLORWRITEENABLE_BLUE);
g_piDevice->Clear(0,NULL,D3DCLEAR_ZBUFFER,0,1.0f,0);
g_sCamera.vPos += g_sCamera.vRight * 0.06f;
RenderNode(g_pcAsset->pcScene->mRootNode,m,false);
g_piDevice->SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
RenderNode(g_pcAsset->pcScene->mRootNode,m,true);
g_piDevice->SetRenderState(D3DRS_ZWRITEENABLE,TRUE);
g_sCamera.vPos -= g_sCamera.vRight * 0.03f;
g_piDevice->SetRenderState(D3DRS_COLORWRITEENABLE,
D3DCOLORWRITEENABLE_RED |
D3DCOLORWRITEENABLE_GREEN |
D3DCOLORWRITEENABLE_ALPHA |
D3DCOLORWRITEENABLE_BLUE);
}
return 1;
}
int CDisplay::HandleInputTextureView()
{
HandleMouseInputTextureView();
HandleKeyboardInputTextureView();
return 1;
}
int CDisplay::HandleInput()
{
if(CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode())
HandleMouseInputSkyBox();
HandleMouseInputLightRotate();
HandleMouseInputLightIntensityAndColor();
if(g_bFPSView)
{
HandleMouseInputFPS();
HandleKeyboardInputFPS();
}
else HandleMouseInputLocal();
if (g_sOptions.bRotate)
{
aiMatrix4x4 mMat;
D3DXMatrixRotationYawPitchRoll((D3DXMATRIX*)&mMat,
g_vRotateSpeed.x * g_fElpasedTime,
g_vRotateSpeed.y * g_fElpasedTime,
g_vRotateSpeed.z * g_fElpasedTime);
g_mWorldRotate = g_mWorldRotate * mMat;
}
if (g_sOptions.bLightRotate)
{
aiMatrix4x4 mMat;
D3DXMatrixRotationYawPitchRoll((D3DXMATRIX*)&mMat,
g_vRotateSpeed.x * g_fElpasedTime * 0.5f,
g_vRotateSpeed.y * g_fElpasedTime * 0.5f,
g_vRotateSpeed.z * g_fElpasedTime * 0.5f);
D3DXVec3TransformNormal((D3DXVECTOR3*)&g_avLightDirs[0],
(D3DXVECTOR3*)&g_avLightDirs[0],(D3DXMATRIX*)&mMat);
g_avLightDirs[0].Normalize();
}
return 1;
}
int CDisplay::HandleInputEmptyScene()
{
if(CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode())
{
if (g_bFPSView)
{
HandleMouseInputFPS();
HandleKeyboardInputFPS();
}
HandleMouseInputSkyBox();
if (!g_bFPSView)
{
g_LastmousePos.x = g_mousePos.x;
g_LastmousePos.y = g_mousePos.y;
}
}
return 1;
}
int CDisplay::DrawHUD()
{
if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
return 1;
RECT sRect;
GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
sRect.right -= sRect.left;
sRect.bottom -= sRect.top;
g_piPassThroughEffect->SetTexture("TEXTURE_2D",g_pcTexture);
if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
g_piPassThroughEffect->SetTechnique( "PassThrough_FF");
else
g_piPassThroughEffect->SetTechnique("PassThrough");
UINT dw;
g_piPassThroughEffect->Begin(&dw,0);
g_piPassThroughEffect->BeginPass(0);
D3DSURFACE_DESC sDesc;
g_pcTexture->GetLevelDesc(0,&sDesc);
SVertex as[4];
float fHalfX = ((float)sRect.right-(float)sDesc.Width) / 2.0f;
float fHalfY = ((float)sRect.bottom-(float)sDesc.Height) / 2.0f;
as[1].x = fHalfX;
as[1].y = fHalfY;
as[1].z = 0.2f;
as[1].w = 1.0f;
as[1].u = 0.0f;
as[1].v = 0.0f;
as[3].x = (float)sRect.right-fHalfX;
as[3].y = fHalfY;
as[3].z = 0.2f;
as[3].w = 1.0f;
as[3].u = 1.0f;
as[3].v = 0.0f;
as[0].x = fHalfX;
as[0].y = (float)sRect.bottom-fHalfY;
as[0].z = 0.2f;
as[0].w = 1.0f;
as[0].u = 0.0f;
as[0].v = 1.0f;
as[2].x = (float)sRect.right-fHalfX;
as[2].y = (float)sRect.bottom-fHalfY;
as[2].z = 0.2f;
as[2].w = 1.0f;
as[2].u = 1.0f;
as[2].v = 1.0f;
as[0].x -= 0.5f;as[1].x -= 0.5f;as[2].x -= 0.5f;as[3].x -= 0.5f;
as[0].y -= 0.5f;as[1].y -= 0.5f;as[2].y -= 0.5f;as[3].y -= 0.5f;
g_piDevice->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR);
g_piDevice->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_LINEAR);
DWORD dw2;g_piDevice->GetFVF(&dw2);
g_piDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
g_piDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,
&as,sizeof(SVertex));
g_piPassThroughEffect->EndPass();
g_piPassThroughEffect->End();
g_piDevice->SetFVF(dw2);
return 1;
}
int CDisplay::RenderFullScene()
{
g_iCurrentColor = 0;
aiMatrix4x4 pcProj;
GetProjectionMatrix(pcProj);
vPos = GetCameraMatrix(mViewProjection);
mViewProjection = mViewProjection * pcProj;
if (g_sOptions.eDrawMode == RenderOptions::WIREFRAME)
g_piDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
else g_piDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
if (g_sOptions.bCulling)
g_piDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
else g_piDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
if (g_sOptions.bLowQuality) {
for (DWORD d = 0; d < 8;++d) {
g_piDevice->SetSamplerState(d,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR);
g_piDevice->SetSamplerState(d,D3DSAMP_MINFILTER,D3DTEXF_LINEAR);
g_piDevice->SetSamplerState(d,D3DSAMP_MIPFILTER,D3DTEXF_LINEAR);
}
}
else {
for (DWORD d = 0; d < 8;++d) {
g_piDevice->SetSamplerState(d,D3DSAMP_MAGFILTER,D3DTEXF_ANISOTROPIC);
g_piDevice->SetSamplerState(d,D3DSAMP_MINFILTER,D3DTEXF_ANISOTROPIC);
g_piDevice->SetSamplerState(d,D3DSAMP_MIPFILTER,D3DTEXF_LINEAR);
g_piDevice->SetSamplerState(d,D3DSAMP_MAXANISOTROPY,g_sCaps.MaxAnisotropy);
}
}
CBackgroundPainter::Instance().OnPreRender();
if (g_sOptions.bStereoView)
SetupStereoView();
aiMatrix4x4 m;
if (NULL != g_pcAsset && NULL != g_pcAsset->pcScene->mRootNode)
{
HandleInput();
m = g_mWorld * g_mWorldRotate;
RenderNode(g_pcAsset->pcScene->mRootNode,m,false);
}
HandleInputEmptyScene();
CBackgroundPainter::Instance().OnPostRender();
if (NULL != g_pcAsset && NULL != g_pcAsset->pcScene->mRootNode)
{
if (!g_sOptions.bNoAlphaBlending) {
g_piDevice->SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
}
RenderNode(g_pcAsset->pcScene->mRootNode,m,true);
if (!g_sOptions.bNoAlphaBlending) {
g_piDevice->SetRenderState(D3DRS_ZWRITEENABLE,TRUE);
}
}
if (g_sOptions.bStereoView)
RenderStereoView(m);
if (g_sOptions.bSkeleton && NULL != g_pcAsset && NULL != g_pcAsset->pcScene->mRootNode) {
g_piDevice->SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
if (g_sOptions.eDrawMode != RenderOptions::WIREFRAME) {
g_piDevice->SetRenderState(D3DRS_ZENABLE,FALSE);
}
g_piDevice->SetVertexDeclaration( gDefaultVertexDecl);
ID3DXEffect* piEnd = g_piNormalsEffect;
aiMatrix4x4 pcProj = m * mViewProjection;
D3DXVECTOR4 vVector(1.f,0.f,0.f,1.f);
piEnd->SetVector("OUTPUT_COLOR",&vVector);
piEnd->SetMatrix("WorldViewProjection", (const D3DXMATRIX*)&pcProj);
UINT dwPasses = 0;
piEnd->Begin(&dwPasses,0);
piEnd->BeginPass(0);
RenderSkeleton(g_pcAsset->pcScene->mRootNode,m,m);
piEnd->EndPass();piEnd->End();
g_piDevice->SetRenderState(D3DRS_ZWRITEENABLE,TRUE);
g_piDevice->SetRenderState(D3DRS_ZENABLE,TRUE);
}
if (!g_bFPSView && g_pcAsset && g_pcTexture)
DrawHUD();
return 1;
}
int CDisplay::RenderMaterialView()
{
return 1;
}
int CDisplay::RenderSkeleton (aiNode* piNode,const aiMatrix4x4& piMatrix, const aiMatrix4x4& parent)
{
aiMatrix4x4 me = g_pcAsset->mAnimator->GetGlobalTransform( piNode);
me.Transpose();
if (piNode->mParent) {
AssetHelper::LineVertex data[2];
data[0].dColorDiffuse = data[1].dColorDiffuse = D3DCOLOR_ARGB(0xff,0xff,0,0);
data[0].vPosition.x = parent.d1;
data[0].vPosition.y = parent.d2;
data[0].vPosition.z = parent.d3;
data[1].vPosition.x = me.d1;
data[1].vPosition.y = me.d2;
data[1].vPosition.z = me.d3;
g_piDevice->DrawPrimitiveUP(D3DPT_LINELIST,1,&data,sizeof(AssetHelper::LineVertex));
}
for (unsigned int i = 0; i < piNode->mNumChildren;++i)
RenderSkeleton(piNode->mChildren[i],piMatrix, me );
return 1;
}
int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
bool bAlpha )
{
aiMatrix4x4 aiMe = g_pcAsset->mAnimator->GetGlobalTransform( piNode);
aiMe.Transpose();
aiMe *= piMatrix;
bool bChangedVM = false;
if (VIEWMODE_NODE == m_iViewMode && m_pcCurrentNode)
{
if (piNode != m_pcCurrentNode->psNode)
{
for (unsigned int i = 0; i < piNode->mNumChildren;++i)
RenderNode(piNode->mChildren[i],piMatrix,bAlpha );
return 1;
}
m_iViewMode = VIEWMODE_FULL;
bChangedVM = true;
}
aiMatrix4x4 pcProj = aiMe * mViewProjection;
aiMatrix4x4 pcCam = aiMe;
pcCam.Inverse().Transpose();
if (!g_sOptions.bRenderMats && !bAlpha)
{
ID3DXEffect* piEnd = g_piDefaultEffect;
piEnd->SetMatrix("WorldViewProjection",
(const D3DXMATRIX*)&pcProj);
piEnd->SetMatrix("World",(const D3DXMATRIX*)&aiMe);
piEnd->SetMatrix("WorldInverseTranspose",
(const D3DXMATRIX*)&pcCam);
if ( CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode())
{
pcCam = pcCam * pcProj;
piEnd->SetMatrix("ViewProj",(const D3DXMATRIX*)&pcCam);
pcCam.Inverse();
piEnd->SetMatrix("InvViewProj",(const D3DXMATRIX*)&pcCam);
}
D3DXVECTOR4 apcVec[5];
apcVec[0].x = g_avLightDirs[0].x;
apcVec[0].y = g_avLightDirs[0].y;
apcVec[0].z = g_avLightDirs[0].z;
apcVec[0].w = 0.0f;
apcVec[1].x = g_avLightDirs[0].x * -1.0f;
apcVec[1].y = g_avLightDirs[0].y * -1.0f;
apcVec[1].z = g_avLightDirs[0].z * -1.0f;
apcVec[1].w = 0.0f;
D3DXVec4Normalize(&apcVec[0],&apcVec[0]);
D3DXVec4Normalize(&apcVec[1],&apcVec[1]);
piEnd->SetVectorArray("afLightDir",apcVec,5);
apcVec[0].x = ((g_avLightColors[0] >> 16) & 0xFF) / 255.0f;
apcVec[0].y = ((g_avLightColors[0] >> 8) & 0xFF) / 255.0f;
apcVec[0].z = ((g_avLightColors[0]) & 0xFF) / 255.0f;
apcVec[0].w = 1.0f;
if( g_sOptions.b3Lights)
{
apcVec[1].x = ((g_avLightColors[1] >> 16) & 0xFF) / 255.0f;
apcVec[1].y = ((g_avLightColors[1] >> 8) & 0xFF) / 255.0f;
apcVec[1].z = ((g_avLightColors[1]) & 0xFF) / 255.0f;
apcVec[1].w = 0.0f;
} else
{
apcVec[1].x = 0.0f;
apcVec[1].y = 0.0f;
apcVec[1].z = 0.0f;
apcVec[1].w = 0.0f;
}
apcVec[0] *= g_fLightIntensity;
apcVec[1] *= g_fLightIntensity;
piEnd->SetVectorArray("afLightColor",apcVec,5);
apcVec[0].x = vPos.x;
apcVec[0].y = vPos.y;
apcVec[0].z = vPos.z;
piEnd->SetVector( "vCameraPos",&apcVec[0]);
if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
{
g_piDefaultEffect->SetTechnique( "DefaultFXSpecular_FF");
} else
if (g_sCaps.PixelShaderVersion < D3DPS_VERSION(3,0) || g_sOptions.bLowQuality)
{
if (g_sOptions.b3Lights)
piEnd->SetTechnique("DefaultFXSpecular_PS20_D2");
else piEnd->SetTechnique("DefaultFXSpecular_PS20_D1");
}
else
{
if (g_sOptions.b3Lights)
piEnd->SetTechnique("DefaultFXSpecular_D2");
else piEnd->SetTechnique("DefaultFXSpecular_D1");
}
UINT dwPasses = 0;
piEnd->Begin(&dwPasses,0);
piEnd->BeginPass(0);
}
D3DXVECTOR4 vVector = g_aclNormalColors[g_iCurrentColor];
if (++g_iCurrentColor == 14)
{
g_iCurrentColor = 0;
}
if (! (!g_sOptions.bRenderMats && bAlpha ))
{
for (unsigned int i = 0; i < piNode->mNumMeshes;++i)
{
const aiMesh* mesh = g_pcAsset->pcScene->mMeshes[piNode->mMeshes[i]];
AssetHelper::MeshHelper* helper = g_pcAsset->apcMeshes[piNode->mMeshes[i]];
if (g_sOptions.bRenderMats && (helper->piOpacityTexture || helper->fOpacity != 1.0f) && !mesh->HasBones())
{
if (!bAlpha)continue;
}
else if (bAlpha)continue;
if( mesh->HasBones())
{
if( helper->piEffect)
{
static float matrices[4*4*60];
float* tempmat = matrices;
const std::vector<aiMatrix4x4>& boneMats = g_pcAsset->mAnimator->GetBoneMatrices( piNode, i);
ai_assert( boneMats.size() == mesh->mNumBones);
for( unsigned int a = 0; a < mesh->mNumBones; a++)
{
const aiMatrix4x4& mat = boneMats[a];
*tempmat++ = mat.a1; *tempmat++ = mat.a2; *tempmat++ = mat.a3; *tempmat++ = mat.a4;
*tempmat++ = mat.b1; *tempmat++ = mat.b2; *tempmat++ = mat.b3; *tempmat++ = mat.b4;
*tempmat++ = mat.c1; *tempmat++ = mat.c2; *tempmat++ = mat.c3; *tempmat++ = mat.c4;
*tempmat++ = mat.d1; *tempmat++ = mat.d2; *tempmat++ = mat.d3; *tempmat++ = mat.d4;
}
if( g_sOptions.bRenderMats)
{
helper->piEffect->SetMatrixTransposeArray( "gBoneMatrix", (D3DXMATRIX*)matrices, 60);
} else
{
g_piDefaultEffect->SetMatrixTransposeArray( "gBoneMatrix", (D3DXMATRIX*)matrices, 60);
g_piDefaultEffect->CommitChanges();
}
}
} else
{
if( !g_sOptions.bRenderMats)
{
D3DXMATRIX identity( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
g_piDefaultEffect->SetMatrixTransposeArray( "gBoneMatrix", &identity, 1);
g_piDefaultEffect->CommitChanges();
}
}
if (g_sOptions.bRenderMats)
{
CMaterialManager::Instance().SetupMaterial( helper, pcProj, aiMe, pcCam, vPos);
}
g_piDevice->SetVertexDeclaration( gDefaultVertexDecl);
if (g_sOptions.bNoAlphaBlending) {
g_piDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
}
if (bAlpha)CMeshRenderer::Instance().DrawSorted(piNode->mMeshes[i],aiMe);
else CMeshRenderer::Instance().DrawUnsorted(piNode->mMeshes[i]);
if (g_sOptions.bRenderMats)
{
CMaterialManager::Instance().EndMaterial( helper);
}
if (g_sOptions.bRenderNormals && helper->piVBNormals)
{
ID3DXEffect* piEnd = g_piNormalsEffect;
piEnd->SetVector("OUTPUT_COLOR",&vVector);
piEnd->SetMatrix("WorldViewProjection", (const D3DXMATRIX*)&pcProj);
UINT dwPasses = 0;
piEnd->Begin(&dwPasses,0);
piEnd->BeginPass(0);
g_piDevice->SetStreamSource(0, helper->piVBNormals, 0, sizeof(AssetHelper::LineVertex));
g_piDevice->DrawPrimitive(D3DPT_LINELIST,0, g_pcAsset->pcScene->mMeshes[piNode->mMeshes[i]]->mNumVertices);
piEnd->EndPass();
piEnd->End();
}
}
if (!g_sOptions.bRenderMats)
{
g_piDefaultEffect->EndPass();
g_piDefaultEffect->End();
}
}
for (unsigned int i = 0; i < piNode->mNumChildren;++i)
RenderNode(piNode->mChildren[i],piMatrix,bAlpha );
if (bChangedVM)
m_iViewMode = VIEWMODE_NODE;
return 1;
}
int CDisplay::RenderPatternBG()
{
if (!g_piPatternEffect)
{
if (g_sCaps.PixelShaderVersion >= D3DPS_VERSION(3,0))
{
ID3DXBuffer* piBuffer = NULL;
if(FAILED( D3DXCreateEffect(g_piDevice,
g_szCheckerBackgroundShader.c_str(),
(UINT)g_szCheckerBackgroundShader.length(),
NULL,
NULL,
D3DXSHADER_USE_LEGACY_D3DX9_31_DLL,
NULL,
&g_piPatternEffect,&piBuffer)))
{
if( piBuffer)
{
MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK);
piBuffer->Release();
}
return 0;
}
if( piBuffer)
{
piBuffer->Release();
piBuffer = NULL;
}
}
else
{
g_piDevice->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB(0xFF,0xFF,0,0xFF), 1.0f,0 );
return 1;
}
}
g_piDevice->Clear(0,NULL,D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB(0xFF,0xFF,0,0xFF), 1.0f,0 );
g_piPatternEffect->SetVector("COLOR_ONE",&m_avCheckerColors[0]);
g_piPatternEffect->SetVector("COLOR_TWO",&m_avCheckerColors[1]);
UINT dw;
g_piPatternEffect->Begin(&dw,0);
g_piPatternEffect->BeginPass(0);
RECT sRect;
GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
sRect.right -= sRect.left;
sRect.bottom -= sRect.top;
struct SVertex
{
float x,y,z,w;
};
SVertex as[4];
as[1].x = 0.0f;
as[1].y = 0.0f;
as[1].z = 0.2f;
as[3].x = (float)sRect.right;
as[3].y = 0.0f;
as[3].z = 0.2f;
as[0].x = 0.0f;
as[0].y = (float)sRect.bottom;
as[0].z = 0.2f;
as[2].x = (float)sRect.right;
as[2].y = (float)sRect.bottom;
as[2].z = 0.2f;
as[0].w = 1.0f;
as[1].w = 1.0f;
as[2].w = 1.0f;
as[3].w = 1.0f;
as[0].x -= 0.5f;as[1].x -= 0.5f;as[2].x -= 0.5f;as[3].x -= 0.5f;
as[0].y -= 0.5f;as[1].y -= 0.5f;as[2].y -= 0.5f;as[3].y -= 0.5f;
DWORD dw2;g_piDevice->GetFVF(&dw2);
g_piDevice->SetFVF(D3DFVF_XYZRHW);
g_piDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,
&as,sizeof(SVertex));
g_piDevice->SetFVF(dw2);
g_piPatternEffect->EndPass();
g_piPatternEffect->End();
return 1;
}
int CDisplay::RenderTextureView()
{
if (!g_pcAsset || !g_pcAsset->pcScene)return 0;
this->HandleInputTextureView();
RenderPatternBG();
if (!m_pcCurrentTexture->piTexture)
{
return 0;
}
RECT sRect;
GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
sRect.right -= sRect.left;
sRect.bottom -= sRect.top;
g_piPassThroughEffect->SetTexture("TEXTURE_2D",*m_pcCurrentTexture->piTexture);
if (aiTextureType_OPACITY == m_pcCurrentTexture->iType)
{
g_piPassThroughEffect->SetTechnique("PassThroughAlphaFromR");
}
else if ((aiTextureType_OPACITY | 0x40000000) == m_pcCurrentTexture->iType)
{
g_piPassThroughEffect->SetTechnique("PassThroughAlphaFromA");
}
else if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
g_piPassThroughEffect->SetTechnique( "PassThrough_FF");
else
g_piPassThroughEffect->SetTechnique("PassThrough");
UINT dw;
g_piPassThroughEffect->Begin(&dw,0);
g_piPassThroughEffect->BeginPass(0);
if (aiTextureType_HEIGHT == m_pcCurrentTexture->iType ||
aiTextureType_NORMALS == m_pcCurrentTexture->iType || g_sOptions.bNoAlphaBlending)
{
g_piDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
}
D3DSURFACE_DESC sDesc;
if ( m_pcCurrentTexture->piTexture && *m_pcCurrentTexture->piTexture) {
(*m_pcCurrentTexture->piTexture)->GetLevelDesc(0,&sDesc);
struct SVertex{float x,y,z,w,u,v;};
SVertex as[4];
const float nx = (float)sRect.right;
const float ny = (float)sRect.bottom;
const float x = (float)sDesc.Width;
const float y = (float)sDesc.Height;
float f = min((nx-30) / x,(ny-30) / y) * (m_fTextureZoom/1000.0f);
float fHalfX = (nx - (f * x)) / 2.0f;
float fHalfY = (ny - (f * y)) / 2.0f;
as[1].x = fHalfX + m_vTextureOffset.x;
as[1].y = fHalfY + m_vTextureOffset.y;
as[1].z = 0.2f;
as[1].w = 1.0f;
as[1].u = 0.0f;
as[1].v = 0.0f;
as[3].x = nx-fHalfX + m_vTextureOffset.x;
as[3].y = fHalfY + m_vTextureOffset.y;
as[3].z = 0.2f;
as[3].w = 1.0f;
as[3].u = 1.0f;
as[3].v = 0.0f;
as[0].x = fHalfX + m_vTextureOffset.x;
as[0].y = ny-fHalfY + m_vTextureOffset.y;
as[0].z = 0.2f;
as[0].w = 1.0f;
as[0].u = 0.0f;
as[0].v = 1.0f;
as[2].x = nx-fHalfX + m_vTextureOffset.x;
as[2].y = ny-fHalfY + m_vTextureOffset.y;
as[2].z = 0.2f;
as[2].w = 1.0f;
as[2].u = 1.0f;
as[2].v = 1.0f;
as[0].x -= 0.5f;as[1].x -= 0.5f;as[2].x -= 0.5f;as[3].x -= 0.5f;
as[0].y -= 0.5f;as[1].y -= 0.5f;as[2].y -= 0.5f;as[3].y -= 0.5f;
DWORD dw2;g_piDevice->GetFVF(&dw2);
g_piDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
g_piDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,
&as,sizeof(SVertex));
g_piDevice->SetFVF(dw2);
}
g_piPassThroughEffect->EndPass();
g_piPassThroughEffect->End();
return 1;
}
};