Jump to content
  • Advertisement
Sign in to follow this  
Hunter_Ex

D3DX Mesh Shapes problem SOLVED

This topic is 4898 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

hey ive wanna add a skybox to my terrain and the box is rendered and created but the textures on the box seems to be 0,0 att every vertex couse the "SetTexture(0,texture);" is set but i only get a single solid color from the first pixel in the texture ?? how can i see the Texture coords of the created mesh using D3DXCreateBox(graphDevice,2000,500,2000,&DeviceMesh[0],NULL))) or is the problem my own?? hunter_ex [Edited by - Hunter_Ex on July 21, 2005 8:41:40 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sadly, the built-in D3DX mesh creation functions don't UV map the meshes they create. Take a look for some kind of tutorial about creating your own box mesh - it's not that hard, and you'll get some experience working with directly manipulating meshes :) Heck, you might even be able to UV map the box mesh after D3DX creates it. You could just kind of fiddle with the UV coords until you get them right. Make sure your vertex format has at least one set of UV coords, of course.

Share this post


Link to post
Share on other sites
hm to what use is the mesh creation then :S

its sound overmake if u need to copy the vertices in a new buffer and then delete the mesh

??

Share this post


Link to post
Share on other sites
Quote:

its sound overmake if u need to copy the vertices in a new buffer and then delete the mesh


Ehh..! What? Syntax error! Sentence does not make sense at line 3.

You can modify the buffer in place, if that's what you're asking. Just use the ID3DXMesh::LockVertexBuffer, edit the data that it returns, and call ID3DXMesh::UnlockVertexBuffer.

Hopefully you have defined somewhere in your code the structure that represents the vertex format, which is usually accompanied by either an FVF Code definition or a Vertex Declaration definition. It might look something like this:

struct CustomVertex
{
float x, y, z;
float nx, ny, nz;
float u, v;
}


Find that struct, post it here, and I'll show you what to do.

Share this post


Link to post
Share on other sites
Quote:
Original post by Drakex
Quote:

its sound overmake if u need to copy the vertices in a new buffer and then delete the mesh


Ehh..! What? Syntax error! Sentence does not make sense at line 3.

You can modify the buffer in place, if that's what you're asking. Just use the ID3DXMesh::LockVertexBuffer, edit the data that it returns, and call ID3DXMesh::UnlockVertexBuffer.

This won't work, because the mesh generation functions in D3DX (D3DXCreate*) do not use a vertex structure with texture coordinates, only position and normal (as said in the "Remarks" section in their documentation). You have to clone the created mesh first int an ID3DXMesh with an FVF that contains texture coordinates, then lock it and generate the coordinates.

Share this post


Link to post
Share on other sites
I had this exact problem and still have the solution ;p

The answer has already been given to you in the desciption of the peeps that replied so i will give the code to do it!

#define boxFVF (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_TEX1)
struct BoxVertex
{
D3DXVECTOR3 pos;
D3DXVECTOR3 norm;
D3DCOLOR color;
FLOAT tu, tv;
};

//the mesh
LPD3DXMESH pTempMesh = NULL;
HRESULT hr;
LPDIRECT3DVERTEXBUFFER8 tempVertexBuffer = NULL;
BoxVertex* pVerts = NULL;

D3DXCreateBox( pd3dDevice, 2.0f, 2.0f, 2.0f, &pTempMesh, NULL );

//check FVF format
if( pTempMesh->GetFVF() != boxFVF )
{
pTempMesh->CloneMeshFVF( D3DXMESH_MANAGED, boxFVF, pd3dDevice, &m_pMesh );
pTempMesh->Release();
}
else
m_pMesh = pTempMesh;

//set tex coords
m_pMesh->GetVertexBuffer( &tempVertexBuffer );
tempVertexBuffer->Lock( 0, m_pMesh->GetNumVertices() * sizeof(BoxVertex),
(BYTE **)&pVerts, 0);
for( int i=0; i<(int)m_pMesh->GetNumVertices(); i++ )
{
pVerts.color = 0x88888888;

//x faces
if( i<4 || ( i>7 && i<12 ))
{
pVerts.tu = (float)(pVerts.pos[1]);
pVerts.tv = (float)(pVerts.pos[2]);
}
//z faces
else if( i<24 && i >15 )
{
pVerts.tu = (float)(pVerts.pos[0]);
pVerts.tv = (float)(pVerts.pos[1]);
}
//y faces
else
{
pVerts.tu = (float)(pVerts.pos[0]);
pVerts.tv = (float)(pVerts.pos[2]);
}
//dont want negative tex coords
if( pVerts.tu < 1.0f )
pVerts.tu = 0.0f;
if( pVerts.tv < 1.0f )
pVerts.tv = 0.0f;
}
tempVertexBuffer->Unlock();
tempVertexBuffer->Release();
D3DXCreateTextureFromFile( pd3dDevice, TextureFileName, m_pTex );

Share this post


Link to post
Share on other sites
well i maked my own skybox instead much cleaner...

so now its working but now i know how to clone also ; )

thx all

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!