Jump to content

  • Log In with Google      Sign In   
  • Create Account


how do i know the vertex coordinate of the mesh


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 tcige   Members   -  Reputation: 206

Like
1Likes
Like

Posted 13 June 2013 - 08:25 AM

i test using D3DXCreateTeapot, but can not find any info about its vertex coordinate



Sponsor:

#2 DwarvesH   Members   -  Reputation: 433

Like
2Likes
Like

Posted 13 June 2013 - 08:34 AM

Well D3DXCreateTeapot returns a ID3DXMesh  object. You can call GetVertexBuffer on it. Don't forget to lock it before editing. You also need to figure out the vertex stride of the buffer. You can use D3DXGetFVFVertexSize:
D3DXGetFVFVertexSize(teapot->GetFVF())


#3 BornToCode   Members   -  Reputation: 901

Like
1Likes
Like

Posted 13 June 2013 - 10:36 AM

you can grab the the fvf and & D3DFVF_XYZ to see if the FVF have vertex information .If it does then that data is usually resides at the beginning of the vertex memory block when you lock it for access.



#4 belfegor   Crossbones+   -  Reputation: 2359

Like
1Likes
Like

Posted 13 June 2013 - 12:42 PM

Might do better with vertex declaration since that way have more control, for example it can give you bytes offset to some element.

Here is example chopped from my old project:

D3DVERTEXELEMENT9 decl[MAX_FVF_DECL_SIZE];
hr = dxMesh->GetDeclaration(decl);
if(FAILED(hr))
    ...// handle error
bool havePosition  = false;
        bool haveNormal    = false;
        bool haveTexCoord0 = false;
        bool haveTexCoord1 = false;
        bool haveTangent   = false;
        bool haveBinormal  = false;

        WORD offsetToPosition  = 0;
        WORD offsetToNormal    = 0;
        WORD offsetToTexCoord0 = 0;
        WORD offsetToTexCoord1 = 0;
        WORD offsetToTangent   = 0;
        WORD offsetToBinormal  = 0;

        for(UINT i = 0; i < MAX_FVF_DECL_SIZE; ++i)
        {
            if(decl[i].Stream == 0xFF || decl[i].Stream != 0)
            {
                break;
            }

            if(decl[i].Usage == D3DDECLUSAGE_POSITION)
            {
                offsetToPosition = decl[i].Offset;
                havePosition      = true;
                continue;
            }

            if(decl[i].Usage == D3DDECLUSAGE_NORMAL)
            {
                offsetToNormal = decl[i].Offset;
                haveNormal      = true;
                continue;
            }

            if(decl[i].Usage == D3DDECLUSAGE_TEXCOORD && decl[i].UsageIndex == 0)
            {
                offsetToTexCoord0 = decl[i].Offset;
                haveTexCoord0      = true;
                continue;
            }

            if(decl[i].Usage == D3DDECLUSAGE_TEXCOORD && decl[i].UsageIndex == 1)
            {
                offsetToTexCoord1 = decl[i].Offset;
                haveTexCoord1      = true;
                continue;
            }

            if(decl[i].Usage == D3DDECLUSAGE_TANGENT)
            {
                offsetToTangent = decl[i].Offset;
                haveTangent      = true;
                continue;
            }

            if(decl[i].Usage == D3DDECLUSAGE_BINORMAL)
            {
                offsetToBinormal = decl[i].Offset;
                haveBinormal      = true;
                continue;
            }
            ...// add more what you need
        }
   

Then you lock and access what you need:

auto stride = dxMesh->GetNumBytesPerVertex();
BYTE* pVerts;
dxMesh->LockVertexBuffer(0, reinterpret_cast<LPVOID*>(&pVerts));
...
if(havePosition)
{
    for(DWORD i = 0; i < numVertices; ++i)
    {
        // assume that position is vec3
        // you can check vertex declaration for that also
        D3DXVECTOR3 pos = *reinterpret_cast<D3DXVECTOR3*>((i * stride) + pVerts + offsetToPosition);
    }
}

Edited by belfegor, 13 June 2013 - 12:44 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS