Sign in to follow this  

Drawing Lines

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

I have not tested this but it should work. Basically it loads an X file, computes the normals, the runs through each vertex and puts it's normal into the vector.


D3DVERTEXELEMENT9 decl[]=
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
{0, 20, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
D3DDECL_END()
};

//This will hold all the vertices
std::vector<D3DXVECTOR3> Vertices;

ID3DXMesh* Mesh;
ID3DXMesh* TempMesh;

D3DXLoadMeshFromX("somefile.X", D3DXMESH_MANAGED, D3DDevice, NULL, NULL, NULL, NULL, &TempMesh);

TempMesh->CloneMesh(D3DXMESH_MANAGED, decl, D3DDevice, &Mesh);

D3DXComputeNormals(Mesh, NULL);

TempMesh->Release();

typedef struct {
D3DXVECTOR3 VertexPos;
D3DXVECTOR2 TexCoord;
D3DXVECTOR3 Normal;
} Mesh_FVF;

int NumVerticies = Mesh->GetNumVertices();
int NumTris = Mesh->GetNumFaces();
DWORD FVFSize = D3DXGetFVFVertexSize(Mesh->GetFVF());

char *MeshPtr;
Mesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&MeshPtr);
for(int NumVerts = 0; NumVerts < NumVerticies; NumVerts++)
{
Mesh_FVF *MeshFVF = (Mesh_FVF*)MeshPtr;

MeshFVF->VertexPos;
MeshFVF->TexCoord;
Vertices.push_back(MeshFVF->Normal);

MeshPtr += FVFSize;
}
Mesh->UnlockVertexBuffer();



Share this post


Link to post
Share on other sites

This topic is 4017 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this