- further works on the viewer's way to animation country. Now really fucked up, but Aramis is going to help me fix it.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@206 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
ulfjorensen 2008-10-30 12:49:28 +00:00
parent cfeb8b2b2a
commit 9f92c7098e
4 changed files with 73 additions and 67 deletions

View File

@ -67,6 +67,9 @@ void AnimEvaluator::Evaluate( double pTime)
if( mAnim->mDuration > 0.0)
time = fmod( pTime, mAnim->mDuration);
if( mTransforms.size() != mAnim->mNumChannels)
mTransforms.resize( mAnim->mNumChannels);
// calculate the transformations for each animation channel
for( unsigned int a = 0; a < mAnim->mNumChannels; a++)
{

View File

@ -737,6 +737,12 @@ int CDisplay::FillDisplayList(void)
//-------------------------------------------------------------------------------
int CDisplay::OnRender()
{
// update possible animation
if( g_pcAsset)
{
assert( g_pcAsset->mAnimator);
g_pcAsset->mAnimator->Calculate( double( clock()) / double( CLOCKS_PER_SEC));
}
// begin the frame
g_piDevice->BeginScene();
@ -1884,11 +1890,11 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
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[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;
apcVec[1].w = 0.0f;
D3DXVec4Normalize(&apcVec[0],&apcVec[0]);
D3DXVec4Normalize(&apcVec[1],&apcVec[1]);
@ -1899,19 +1905,19 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
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;
}
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;
@ -1923,10 +1929,10 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
piEnd->SetVector( "vCameraPos",&apcVec[0]);
// setup the best technique
if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
{
g_piDefaultEffect->SetTechnique( "DefaultFXSpecular_FF");
} else
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)
@ -1954,14 +1960,15 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
{
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]];
// fix: Render triangle meshes only
if (g_pcAsset->pcScene->mMeshes[piNode->mMeshes[i]]->mPrimitiveTypes != aiPrimitiveType_TRIANGLE)
if (mesh->mPrimitiveTypes != aiPrimitiveType_TRIANGLE)
continue;
// don't render the mesh if the render pass is incorrect
if (g_sOptions.bRenderMats && (
g_pcAsset->apcMeshes[piNode->mMeshes[i]]->piOpacityTexture ||
g_pcAsset->apcMeshes[piNode->mMeshes[i]]->fOpacity != 1.0f))
if (g_sOptions.bRenderMats && (helper->piOpacityTexture || helper->fOpacity != 1.0f))
{
if (!bAlpha)continue;
}
@ -1970,8 +1977,25 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
// now setup the material
if (g_sOptions.bRenderMats)
{
CMaterialManager::Instance().SetupMaterial(
g_pcAsset->apcMeshes[piNode->mMeshes[i]],pcProj,aiMe,pcCam,vPos);
CMaterialManager::Instance().SetupMaterial( helper, pcProj, aiMe, pcCam, vPos);
}
// Upload bone matrices. This maybe is the wrong place to do it, but for the heck of it I don't understand this code flow
if( mesh->HasBones())
{
static float matrices[4*3*60];
float* tempmat = matrices;
const std::vector<aiMatrix4x4>& boneMats = g_pcAsset->mAnimator->GetBoneMatrices( piNode, i);
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;
}
helper->piEffect->SetFloatArray( "gBoneMatrix", matrices, 3*60*4);
}
if (bAlpha)CMeshRenderer::Instance().DrawSorted(piNode->mMeshes[i],aiMe);
@ -1980,31 +2004,25 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
// now end the material
if (g_sOptions.bRenderMats)
{
CMaterialManager::Instance().EndMaterial(
g_pcAsset->apcMeshes[piNode->mMeshes[i]]);
CMaterialManager::Instance().EndMaterial( helper);
}
// render normal vectors?
if (g_sOptions.bRenderNormals && g_pcAsset->apcMeshes[piNode->mMeshes[i]]->piVBNormals)
if (g_sOptions.bRenderNormals && helper->piVBNormals)
{
// this is very similar to the code in SetupMaterial()
ID3DXEffect* piEnd = g_piNormalsEffect;
piEnd->SetVector("OUTPUT_COLOR",&vVector);
piEnd->SetMatrix("WorldViewProjection",
(const D3DXMATRIX*)&pcProj);
piEnd->SetMatrix("WorldViewProjection", (const D3DXMATRIX*)&pcProj);
UINT dwPasses = 0;
piEnd->Begin(&dwPasses,0);
piEnd->BeginPass(0);
g_piDevice->SetStreamSource(0,
g_pcAsset->apcMeshes[piNode->mMeshes[i]]->piVBNormals,0,
sizeof(AssetHelper::LineVertex));
g_piDevice->DrawPrimitive(D3DPT_LINELIST,0,
g_pcAsset->pcScene->mMeshes[piNode->mMeshes[i]]->mNumVertices);
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();

View File

@ -1140,11 +1140,11 @@ int CMaterialManager::SetupMaterial (
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[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;
apcVec[1].w = 0.0f;
D3DXVec4Normalize(&apcVec[0],&apcVec[0]);
D3DXVec4Normalize(&apcVec[1],&apcVec[1]);
piEnd->SetVectorArray("afLightDir",apcVec,5);
@ -1154,19 +1154,19 @@ int CMaterialManager::SetupMaterial (
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;
}
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;
@ -1232,22 +1232,6 @@ int CMaterialManager::SetupMaterial (
}
}
// setup bones if neccessary
// if( pcMesh->HasBones())
{
static float matrices[4*3*60];
float* tempmat = matrices;
for( unsigned int a = 0; a < 60; a++)
{
// HACK: (thom) set identity matrices for all bones for the moment so that you see something
*tempmat++ = 1.0f; *tempmat++ = 0.0f; *tempmat++ = 0.0f; *tempmat++ = 0.0f;
*tempmat++ = 0.0f; *tempmat++ = 1.0f; *tempmat++ = 0.0f; *tempmat++ = 0.0f;
*tempmat++ = 0.0f; *tempmat++ = 0.0f; *tempmat++ = 1.0f; *tempmat++ = 0.0f;
}
pcMesh->piEffect->SetVectorArray( "gBoneMatrix", (const D3DXVECTOR4*) matrices, 3*60);
}
// setup the correct shader technique to be used for drawing
if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
{

View File

@ -34,6 +34,7 @@
#include <memory.h>
#include <tchar.h>
#include <stdio.h>
#include <time.h>
// D3D9 includes