BlenderLoader: don't output diffuse color if it is all black. Seems to be Blenders way of telling us there is no diffuse color.

AssimpView: add 'no transparency' option in UI and implement underlying logic.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@811 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2010-08-31 17:24:04 +00:00
parent 400086e19f
commit 693a3a039d
9 changed files with 82 additions and 21 deletions

View File

@ -554,7 +554,12 @@ void BlenderImporter::BuildMaterials(ConversionData& conv_data)
// basic material colors
aiColor3D col(mat->r,mat->g,mat->b);
mout->AddProperty(&col,1,AI_MATKEY_COLOR_DIFFUSE);
if (mat->r || mat->g || mat->b ) {
// Usually, zero diffuse color means no diffuse color at all in the equation - seemingly.
// So we ommit this member to express this intent.
mout->AddProperty(&col,1,AI_MATKEY_COLOR_DIFFUSE);
}
col = aiColor3D(mat->specr,mat->specg,mat->specb);
mout->AddProperty(&col,1,AI_MATKEY_COLOR_SPECULAR);
@ -681,7 +686,10 @@ void BlenderImporter::ConvertMesh(const Scene& in, const Object* obj, const Mesh
aiVector3D* vn = out->mNormals + out->mNumVertices;
// XXX we can't fold this easily, because we are restricted
// to the member names from the BLEND file (v1,v2,v3,v4) ..
// to the member names from the BLEND file (v1,v2,v3,v4)
// which are assigned by the genblenddna.py script and
// cannot be changed without breaking the entire
// import process.
if (mf.v1 >= mesh->totvert) {
ThrowException("Vertex index v1 out of range");

View File

@ -1778,9 +1778,14 @@ int CDisplay::RenderFullScene()
if (NULL != g_pcAsset && NULL != g_pcAsset->pcScene->mRootNode)
{
// disable the z-buffer
g_piDevice->SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
if (!g_sOptions.bNoAlphaBlending) {
g_piDevice->SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
}
RenderNode(g_pcAsset->pcScene->mRootNode,m,true);
g_piDevice->SetRenderState(D3DRS_ZWRITEENABLE,TRUE);
if (!g_sOptions.bNoAlphaBlending) {
g_piDevice->SetRenderState(D3DRS_ZWRITEENABLE,TRUE);
}
}
// setup the stereo view if necessary
@ -2042,6 +2047,11 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
}
g_piDevice->SetVertexDeclaration( gDefaultVertexDecl);
if (g_sOptions.bNoAlphaBlending) {
// manually disable alphablending
g_piDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
}
if (bAlpha)CMeshRenderer::Instance().DrawSorted(piNode->mMeshes[i],aiMe);
else CMeshRenderer::Instance().DrawUnsorted(piNode->mMeshes[i]);
@ -2235,7 +2245,7 @@ int CDisplay::RenderTextureView()
g_piPassThroughEffect->BeginPass(0);
if (aiTextureType_HEIGHT == m_pcCurrentTexture->iType ||
aiTextureType_NORMALS == m_pcCurrentTexture->iType)
aiTextureType_NORMALS == m_pcCurrentTexture->iType || g_sOptions.bNoAlphaBlending)
{
// manually disable alpha blending
g_piDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);

View File

@ -333,19 +333,20 @@ int CMaterialManager::LoadTexture(IDirect3DTexture9** p_ppiOut,aiString* szPath)
{
// it is an embedded file ... don't need the file format hint,
// simply let D3DX load the file
D3DXIMAGE_INFO info;
if (FAILED(D3DXCreateTextureFromFileInMemoryEx(g_piDevice,
g_pcAsset->pcScene->mTextures[iIndex]->pcData,
g_pcAsset->pcScene->mTextures[iIndex]->mWidth,
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
1,
D3DUSAGE_AUTOGENMIPMAP,
D3DFMT_UNKNOWN,
D3DPOOL_MANAGED,
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
NULL,
&info,
NULL,
p_ppiOut)))
{

View File

@ -88,11 +88,10 @@ int CMeshRenderer::DrawSorted(unsigned int iIndex,const aiMatrix4x4& mWorld)
if (!pcHelper || !pcMesh || !pcHelper->piIB)
return -5;
if (pcMesh->mPrimitiveTypes != aiPrimitiveType_TRIANGLE)
return DrawUnsorted(iIndex);
if (pcMesh->HasBones())
if (pcMesh->mPrimitiveTypes != aiPrimitiveType_TRIANGLE || pcMesh->HasBones() || g_sOptions.bNoAlphaBlending)
return DrawUnsorted(iIndex);
// compute the position of the camera in worldspace
aiMatrix4x4 mWorldInverse = mWorld;
mWorldInverse.Inverse();

View File

@ -272,6 +272,19 @@ void ToggleLightRotate()
RegSetValueExA(g_hRegistry,"LightRotate",0,REG_DWORD,(const BYTE*)&dwValue,4);
}
//-------------------------------------------------------------------------------
// Toggle the "NoTransparency" state
//-------------------------------------------------------------------------------
void ToggleTransparency()
{
g_sOptions.bNoAlphaBlending = !g_sOptions.bNoAlphaBlending;
// store this in the registry, too
DWORD dwValue = 0;
if (g_sOptions.bNoAlphaBlending)dwValue = 1;
RegSetValueExA(g_hRegistry,"NoTransparency",0,REG_DWORD,(const BYTE*)&dwValue,4);
}
//-------------------------------------------------------------------------------
// Toggle the "LowQuality" state
//-------------------------------------------------------------------------------
@ -777,13 +790,13 @@ void DisplayMemoryConsumption()
char szOut[2048];
sprintf(szOut,
"(1 KB = 1024 Byte)\n\n"
"ASSIMP Import Data: \t%i KB\n"
"Texture data:\t\t%i KB\n"
"Vertex buffers:\t\t%i KB\n"
"Index buffers:\t\t%i KB\n"
"Video Memory:\t\t%i KB\n\n"
"Total: \t\t\t%i KB",
"(1 KiB = 1024 bytes)\n\n"
"ASSIMP Import Data: \t%i KiB\n"
"Texture data:\t\t%i KiB\n"
"Vertex buffers:\t\t%i KiB\n"
"Index buffers:\t\t%i KiB\n"
"Video Memory:\t\t%i KiB\n\n"
"Total: \t\t\t%i KiB",
iScene / 1024,iTexture / 1024,iVB / 1024,iIB / 1024,iVRAM / 1024,
(iScene + iTexture + iVB + iIB + iVRAM) / 1024);
MessageBox(g_hDlg,szOut,"Memory consumption",MB_OK);
@ -1106,6 +1119,20 @@ void InitUI()
CheckDlgButton(g_hDlg,IDC_LOWQUALITY,BST_CHECKED);
}
// LowQuality
if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"NoTransparency",NULL,NULL,
(BYTE*)&dwValue,&dwTemp))dwValue = 0;
if (0 == dwValue)
{
g_sOptions.bNoAlphaBlending = false;
CheckDlgButton(g_hDlg,IDC_NOAB,BST_UNCHECKED);
}
else
{
g_sOptions.bNoAlphaBlending = true;
CheckDlgButton(g_hDlg,IDC_NOAB,BST_CHECKED);
}
// DisplayNormals
if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"RenderNormals",NULL,NULL,
(BYTE*)&dwValue,&dwTemp))dwValue = 0;
@ -2020,6 +2047,10 @@ INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg,
{
ToggleSpecular();
}
else if (IDC_NOAB == LOWORD(wParam))
{
ToggleTransparency();
}
else if (IDC_ZOOM == LOWORD(wParam))
{
ToggleFPSView();

View File

@ -37,7 +37,10 @@ class RenderOptions
bNoSpecular (false),
bStereoView (false),
bCulling (false),
bSkeleton (false) {}
bSkeleton (false),
bNoAlphaBlending(false)
{}
bool bMultiSample;
@ -68,6 +71,8 @@ class RenderOptions
// enable stereo view
bool bStereoView;
bool bNoAlphaBlending;
// wireframe or solid rendering?
DrawMode eDrawMode;

View File

@ -15,7 +15,7 @@
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Deutsch (Deutschland) resources
// German (Germany) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU)
#ifdef _WIN32
@ -95,7 +95,7 @@ BEGIN
COMBOBOX IDC_COMBO1,317,373,112,30,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
LTEXT "Nodes:",IDC_NUMNODES,221,413,28,9
EDITTEXT IDC_ENODEWND,253,411,37,14,ES_AUTOHSCROLL | ES_READONLY
CONTROL "",IDC_TREE1,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP,474,0,141,484
CONTROL "",IDC_TREE1,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,474,0,141,484
LTEXT "Mesh:",IDC_NUMMESHES,295,428,23,9
EDITTEXT IDC_EMESH,322,426,34,14,ES_AUTOHSCROLL | ES_READONLY
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDVERT,100,392,1,87
@ -117,6 +117,7 @@ BEGIN
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDVERT,472,0,1,484
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDVERT,365,392,1,70
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,1,367,471,1
CONTROL "No transparency",IDC_NOAB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,109,439,68,12
END
IDD_LOADDIALOG DIALOGEX 0, 0, 143, 60
@ -442,7 +443,7 @@ IDR_TEXT1 TEXT "text1.bin"
IDR_HUD RCDATA "HUD.png"
IDR_HUDMASK RCDATA "HUDMask.png"
#endif // Deutsch (Deutschland) resources
#endif // German (Germany) resources
/////////////////////////////////////////////////////////////////////////////

View File

@ -79,6 +79,8 @@
#define IDC_CHECK9 1024
#define IDC_NOSPECULAR 1024
#define IDC_PLAYANIM 1025
#define IDC_3LIGHTS2 1025
#define IDC_NOAB 1025
#define IDC_SPEED 1026
#define IDC_COMBO1 1027
#define IDC_PINORDER 1028

View File

@ -1563,6 +1563,10 @@
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File
RelativePath="..\..\tools\shared\assimp_tools_icon.ico"
>
</File>
<File
RelativePath="..\..\tools\assimp_view\assimp_view.ico"
>