Jump to content
  • Advertisement
Sign in to follow this  
EvilWeebl

Loading/Rendering/Creating .x files

This topic is 3160 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi people I really need help because I think iv tried everything but cant figure this out and its driving me crazy! So Im just doing the basic D3DXLoadMeshFromX() for just basic models. I can render the directX samples like the 'tiger.x' and 'airplane 2.x' files but cant seem to render my own. Now im not an artist and im working in a group and the artists are exporting the models in 3ds max with the panda exporter. At first they weren't doing it properly but I thought they had nailed it because when opening these in the directx viewer it shows absolutely fine, but when I come to render it in my game its not there at all?! I dont mean its there but its white or black which would mean a texture or material locating problem I mean it must be invisible or something? This code is near enough the same as directx tutorials render functions so cant figure where the problem is. Oh and I also altered the directx 'Meshes_2008' tutorial code to load my .x file instead and still no show. Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
You could try tweaking the view and projection matrices. Maybe the model wasn't modeled around the origin or something. And try to disable backface culling.

Also, this might help.

Share this post


Link to post
Share on other sites
I can guarantee they are certainly not invisible vertices :)

Likely you have a render/camera mismatch. In other words, you render to some off-in-the weeds position in world space and have your camera looking at a completely different location, and no matter how you rotate your camera you can never get the model into the frustum (or maybe it does get in there but its just a single pixel).

There are many ways to bring this under control:

1. Capture a frame using Pix, find your DrawPrimitive() call and trace back a single vertex as it gets transformed by world view and projection, this should give you insight into why the model isn't in the view frustum (i.e. on the screen).

2. Create a test camera for yourself that can quickly rotate and move through a *LOT* of 3-D space and then go searching for your rendered triangles (a bit amateurish actually).

3. Pick a single vertex of your model and then force your view matrix to look-at that vertex, while keeping the model's world at identity and the view and projection matrix the same between camera and model.

I'm sure you can think of other little hackish ways to figure this out. If you are truly afraid that a draw primitive call is rendering "nothing", you could try enabling wireframe and disabling culling (all via renderstates).

Even if you were using fixed function pipeline/lighting and forgot to enable/disable lighting, you should still see black triangles if the object is in your view frustum. Even if all your vertices were 100% transparent and you were doing the correct alpha blends/tests, if I remember correctly you would still get some shimmering artifacts. I suppose its possible that all your alpha is outside the range of some alpha test you set up (but again unlikely).

Quite simply put: chances are the object is not in your camera's view frustum.

Share this post


Link to post
Share on other sites
It had occurred to me that the camera might be pointing at the wrong place but alas I havn't got round to making a proper camera so for now its hard coded as such:


// Set view matrix
D3DXVECTOR3 vEyePt( 0.0f, 5.0f,-5.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
gD3dDevice->SetTransform( D3DTS_VIEW, &matView );

// Set projection matrix
D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 1.0f, 1.0f, 1000.0f );
gD3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );



As you can see its set a little back and a little up and as I say when loading the directx tiger its absolutely fine and I can see it. The first model I tried was a racing track and so thought that maybe my camera was looking in the middle so not seeing it but I upped the far plane to 1000.0f and even positioned the camera to look down on it and still nothing. To make sure this wasnt the problem another model was made of a cube with cardboard textures and its origin is still (0,0,0) but nope still nothing. Do you think it could be the artists fault with the way its being exported? If that was the case then why would it show up fine in the directx viewer?

I havnt progressed much with this project yet as this is pinning me down so let me know if there is any code/screenprints you need.

Share this post


Link to post
Share on other sites
To answer your question of why it might show up fine in the directX viewer but not with your camera: because they compute the center of the frame hierarchy with D3DXFrameCalculateBoundingSphere() and then re-position their camera to look at the freshly compute model's center set a certain percentage back from its bounding radius (i.e. a model viewer)

Share this post


Link to post
Share on other sites
Ok so I might have two ideas but am too new at this stuff to tell what's right or wrong. The following is my D3D initialisation code:-


//Initialises Direct3D
bool InitialiseDirect3D(HWND hWnd)
{

// Create the D3D object.
if( NULL == ( gD3dObject = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return false;

// Fill out the parameters for the required device
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

// Create the D3DDevice
if( FAILED( gD3dObject->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &gD3dDevice ) ) )
{
//If a hardware vertex processing device is not available fallback to a software one
if( FAILED( gD3dObject->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &gD3dDevice ) ) )
{
return false;
}
}

// Turn on the zbuffer
gD3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );

// Turn on ambient lighting
gD3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff );

return true;

}



Now I need to know if the parameters are suitable and if I should set any more render states other than turning on zbuffer and also is only having ambient lighting sufficient?

So here's theory number two:

As advised in the directx tutorials when loading the mesh I set the materials ambient values to their diffuse values. As such:-

// Set the ambient color for the material (D3DX does not do this)
materials.Ambient = materials.Diffuse;



now when I run with the dircetx test models like the tiger or airplane these are very specific (i.e 'r','g' and 'b' are 0.69411 with 'a' being 1) while when I use my own meshes these values are all set to '1'. Could this mean that all ambient light is reflected making it appear not there or taking in all light or something along these lines?

That's me grasping at straws, feel free to shoot these down or provide alternative idea's or even a solution would be nice :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!