Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


What is the quickest way to render a LPD3DXMESH?


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
5 replies to this topic

#1 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 20 July 2014 - 05:37 PM

I'd like to render a LPD3DXMESH quickly.. Do I still need to lock index/vertex buffers? Or there is a way to accomplish this on the fly? Thanks Jack

Sponsor:

#2 Promit   Moderators   -  Reputation: 7344

Like
0Likes
Like

Posted 20 July 2014 - 06:07 PM

I am not sure why you think you need to do anything beyond DrawSubset.



#3 Buckeye   Crossbones+   -  Reputation: 5730

Like
0Likes
Like

Posted 20 July 2014 - 06:07 PM

Can you describe why mesh->DrawSubset() doesn't work for you?

 

Ninja'd ph34r.png


Edited by Buckeye, 20 July 2014 - 06:08 PM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#4 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 21 July 2014 - 04:04 AM

Actually I just have a little problem that I don't have access to the material buffer to loop with

I want to render the m_dxDebugMesh on the screen.

Thanks

Jack

 

bool NavMesher::buildDebugMesh(rcPolyMeshDetail* dmesh)
{
    if(dmesh->nmeshes == 0)
    {
        MessageBox(0,"getMeshDataFromPolyMeshDetail(): dmesh->nmeshes == 0\n", 0,0);
        return false;
    }

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

    if(FAILED(D3DXCreateMesh(dmesh->ntris, dmesh->nverts, D3DXMESH_MANAGED, vertexElements, m_d3d9device, &m_dxDebugMesh)))
    {
        MessageBox(0, "Failed to create dx mesh!", 0, 0);
        return false;
    }

    struct VERTEX
    {
        D3DXVECTOR3 p;
        D3DXVECTOR3 n;
        D3DXVECTOR2 t;
    };
    WORD* pInd;
    VERTEX* pVert;

    m_dxDebugMesh->LockVertexBuffer(0, (LPVOID*)&pVert);
    m_dxDebugMesh->LockIndexBuffer(0, (LPVOID*)&pInd);

    const D3DXVECTOR3* verts = (const D3DXVECTOR3*)dmesh->verts;
    for(int i = 0; i < dmesh->nverts; ++i)
    {
        pVert[i].p = verts[i];
        pVert[i].n = D3DXVECTOR3(0.f,0.0f,0.0f); // temp
        pVert[i].t = D3DXVECTOR2(0.0f,0.0f); // temp
    }

    // does not work like this!
    /*const unsigned char* tris = dmesh->tris;
    for(int i = 0; i < dmesh->ntris * 3; ++i)
    {
        pInd[i] = tris[i];
    }*/
    
    // this is piece of code for indices found on Irrlicht forum
    int cnt = 0;
    int tri_offset = 0;
    int old_nverts = 0;
    for (int p = 0; p < dmesh->nmeshes; ++p)
    {
        unsigned int* m = &(dmesh->meshes[p * 4]);
        const unsigned short bverts = m[0]; // `b' means "beginning of"!!
        const unsigned short nverts = m[1];
        const unsigned short btris  = m[2];
        const unsigned short ntris  = m[3];
        const unsigned char* tris   = &(dmesh->tris[btris * 4]);

        tri_offset += old_nverts;

        for(int n = 0; n < ntris; ++n)
        {
            for(int k = 0; k < 3; ++k)
            {
                int tri = tris[n * 4 + k] + tri_offset;
                pInd[cnt] = tri;
                cnt++;
            }
        }
        old_nverts = nverts;
    }

    m_dxDebugMesh->UnlockVertexBuffer();
    m_dxDebugMesh->UnlockIndexBuffer();

    return true;
}


#5 belfegor   Crossbones+   -  Reputation: 2692

Like
0Likes
Like

Posted 21 July 2014 - 03:43 PM

You mean like D3DMATERIAL9? It is not part of the mesh, you might be confused as your framework that you are using is usually loading X from file, with functions that can obtain that information, like D3DXLoadMeshFromX.

 

You can create material yourself:

D3DMATERIAL9 mat;
memset(&mat, 0, sizeof(mat));
mat.diffuse.b = 0xff;
...
device->SetMaterial(mat);
m_dxDebugMesh->DrawSubset(0);

 

or better yet draw it with a shader.

 

navmesh.jpg

 

If you want to draw outlines with lines, like they did in Recast/Detour demo, you can use mesh adjacency info, here is piece of code that i used with dx9:

DWORD numFaces = navDebugMesh->GetNumFaces();
    DWORD* meshAdj = new DWORD[numFaces * 3];
    hr = navDebugMesh->GenerateAdjacency(0.001f, meshAdj);
    if (FAILED(hr))
    {
        MessageBox(....);
    }

    const D3DXVECTOR3 outlineColor(0.0f, 0.0f, 0.0f);
    const D3DXVECTOR3 innerColor(0.85f, 0.85f, 0.85f);

    struct MeshVertex
    {
        D3DXVECTOR3 p;
        D3DXVECTOR3 n;
        D3DXVECTOR2 t;
    };
    WORD* pInd;
    MeshVertex* pVert;
    navDebugMesh->LockVertexBuffer(0, (LPVOID*)&pVert);
    navDebugMesh->LockIndexBuffer(0, (LPVOID*)&pInd);

    for (DWORD i = 0; i < numFaces; ++i)
    {
        if (0xFFFFFFFF == meshAdj[i * 3 + 0])
        {
            Line line;
            line.start = pVert[pInd[i * 3 + 0]].p;
            line.end = pVert[pInd[i * 3 + 1]].p;
            line.color = outlineColor;
            lRenderer->addLine(line);
        }
        else
        {
            Line line;
            line.start = pVert[pInd[i * 3 + 0]].p;
            line.end = pVert[pInd[i * 3 + 1]].p;
            line.color = innerColor;
            lRenderer->addLine(line);
        }

        if (0xFFFFFFFF == meshAdj[i * 3 + 1])
        {
            Line line;
            line.start = pVert[pInd[i * 3 + 1]].p;
            line.end = pVert[pInd[i * 3 + 2]].p;
            line.color = outlineColor;
            lRenderer->addLine(line);
        }
        else
        {
            Line line;
            line.start = pVert[pInd[i * 3 + 1]].p;
            line.end = pVert[pInd[i * 3 + 2]].p;
            line.color = innerColor;
            lRenderer->addLine(line);
        }

        if (0xFFFFFFFF == meshAdj[i * 3 + 2])
        {
            Line line;
            line.start = pVert[pInd[i * 3 + 2]].p;
            line.end = pVert[pInd[i * 3 + 0]].p;
            line.color = outlineColor;
            lRenderer->addLine(line);
        }
        else
        {
            Line line;
            line.start = pVert[pInd[i * 3 + 2]].p;
            line.end = pVert[pInd[i * 3 + 0]].p;
            line.color = innerColor;
            lRenderer->addLine(line);
        }
    }

    navDebugMesh->UnlockVertexBuffer();
    navDebugMesh->UnlockIndexBuffer();


#6 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 21 July 2014 - 11:20 PM

Lovely, I'll try that out today... Thanks Jack




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