Multiple Layers/Textures Lightwave Object -> .X Troubles
Hello,
I''ve been going at game programming for a bit now, but now I''ve hit a little snag.
I just made a house in Lightwave 7.5, and exported it to a .X file in Deep Exploration. When I loaded it into my .X viewer, only the brick walls were textured (1st layer in Lightwave, too),
I checked the .X file out in Deep Exploration, and it gave me this frame heirachy
Frm
`object7
`Frm6
`object6
`Frm3
`object4
`Frm1
`object2
I''m basically using the DirectX 8.1 SDK source to load the .X file in [see below]
Any help would be much appreciated.
#include "global.h"
#include "core.h"
DWORD End;
float theta = -15.0f;
float alpha = 1.0f;
float beta = 150.0f;
LPD3DXMESH g_pMesh = NULL; // Our mesh object in sysmem
D3DMATERIAL8* g_pMeshMaterials = NULL; // Materials for our mesh
LPDIRECT3DTEXTURE8* g_pMeshTextures = NULL; // Textures for our mesh
DWORD g_dwNumMaterials = 0L; // Number of mesh materials
LPD3DXBUFFER pD3DXMtrlBuffer;
struct CUSTOMVERTEX
{
FLOAT x, y, z; // The untransformed position for the vertex.
DWORD color; // The vertex color.
};
void Frame();
void LoadMesh(char* Filename);
cApplication App;
cGraphics Graphics;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iShowCmd)
{
App.m_hInst = hInstance;
App.Run();
Graphics.Init(App, App.m_hWnd);
LoadMesh();
while(App.msg.message != WM_QUIT)
{
if(PeekMessage(&App.msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&App.msg);
DispatchMessage(&App.msg);
}
Frame();
End = GetTickCount();
//while((GetTickCount() - End) < 33);
}
return(0);
}
void Frame()
{
Graphics.GetDeviceCOM()->SetRenderState( D3DRS_AMBIENT, 0xffffffff );
if(KEY_DOWN(VK_UP))
theta+=0.1f;
else if(KEY_DOWN(VK_DOWN))
theta-=0.1f;
else if(KEY_DOWN(VK_LEFT))
beta+=0.1f;
else if(KEY_DOWN(VK_RIGHT))
beta-=0.1f;
else if(KEY_DOWN(VK_INSERT))
alpha+=0.1f;
else if(KEY_DOWN(VK_DELETE))
alpha-=0.1f;
else
return;
D3DXMATRIX matWorld;
D3DXMATRIX matView;
D3DXMATRIX matProj;
D3DXMatrixRotationY(&matWorld, beta);
D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3( 0.0f, 3.0f, theta), &D3DXVECTOR3(0.0f, alpha, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.0f, 1.0f, 1000.0f);
Graphics.BeginScene();
Graphics.ClearZ();
for( DWORD i=0; iSetMaterial( &g_pMeshMaterials );
Graphics.GetDeviceCOM()->SetTexture( 0, g_pMeshTextures );
// Draw the mesh subset
g_pMesh->DrawSubset( i );
}
Graphics.GetDeviceCOM()->SetTransform(D3DTS_WORLD, &matWorld);
Graphics.GetDeviceCOM()->SetTransform( D3DTS_VIEW, &matView );
Graphics.GetDeviceCOM()->SetTransform( D3DTS_PROJECTION, &matProj );
Graphics.EndScene();
Graphics.Display();
}
void LoadMesh(char* Filename)
{
if(FAILED(D3DXLoadMeshFromX(Filename, D3DXMESH_SYSTEMMEM, Graphics.GetDeviceCOM(), NULL, &pD3DXMtrlBuffer, &g_dwNumMaterials, &g_pMesh)))
PostQuitMessage(0);
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
g_pMeshMaterials = new D3DMATERIAL8[g_dwNumMaterials];
g_pMeshTextures = new LPDIRECT3DTEXTURE8[g_dwNumMaterials];
for( DWORD i=0; i<g_dwNumMaterials; i++ )
{
// Copy the material
g_pMeshMaterials = d3dxMaterials.MatD3D;
// Set the ambient color for the material (D3DX does not do this)
g_pMeshMaterials.Ambient = g_pMeshMaterials.Diffuse;
// Create the texture
if( FAILED( D3DXCreateTextureFromFile( Graphics.GetDeviceCOM(),
d3dxMaterials.pTextureFilename,
&g_pMeshTextures ) ) )
{
g_pMeshTextures = NULL;
}
}
pD3DXMtrlBuffer->Release();
} </i>
I''''m a signature virus, copy me into your signature and help me spread!
First off, have you tried your .X file in the DX SDK mesh viewer? If it shows up OK there, then this indicates a problem with your loader code.
---
[[ Gaping Wolf Software ]] [[ GameGenesis Forums ]]
---
[[ Gaping Wolf Software ]] [[ GameGenesis Forums ]]
Thanks,
It looked OK in their mesh viewer, and I just copied some of their source from their Enhanced Mesh sample and now i''m slowly getting there. At least now everything is textured, but albiet with the wrong texture... all brick.bmp.
Oh well... thanks anyway
I''''m a signature virus, copy me into your signature and help me spread!
It looked OK in their mesh viewer, and I just copied some of their source from their Enhanced Mesh sample and now i''m slowly getting there. At least now everything is textured, but albiet with the wrong texture... all brick.bmp.
Oh well... thanks anyway
I''''m a signature virus, copy me into your signature and help me spread!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement