Domanda

I was looking on the internet for some Assimp sample but without success.

I have the following struct:

struct VertexTextureNormal
{
    XMFLOAT3 Position;
    XMFLOAT2 TexCoord;
    XMFLOAT3 Normal;
};

Can anyone please post actual code that fills an array of vertex and indices?

È stato utile?

Soluzione

        DWORD nIndices;
        DWORD *pIndices;

        if (pAIMesh->HasFaces())
        {
            aiFace *pAIFaces;

            pAIFaces = pAIMesh->mFaces;
            nIndices = pAIMesh->mNumFaces * 3;

            pIndices = new DWORD[nIndices];

            for (DWORD i = 0; i < pAIMesh->mNumFaces; i++)
            {
                if (pAIFaces[i].mNumIndices != 3)
                {
                    aiReleaseImport(pScene);
                    delete[] pIndices;
                    return E_FAIL;
                }

                for (DWORD j = 0; j < 3; j++)
                {
                    pIndices[i * 3 + j] = pAIFaces[i].mIndices[j];
                }
            }
        }

        if (pAIMesh->HasPositions())
        {
            DWORD nVertices;
            CVertex *pVertices;

            nVertices = pAIMesh->mNumVertices;

            pVertices = new CVertex[nVertices];

            for (DWORD i = 0; i < nVertices; i++)
            {
                pVertices[i].vPos = XMFLOAT3(pAIMesh->mVertices[i].x, pAIMesh->mVertices[i].y, pAIMesh->mVertices[i].z);

                XMStoreFloat3(&pVertices[i].vPos, XMVector3TransformCoord(XMLoadFloat3(&pVertices[i].vPos), mLocalWorld));
            }

            if (pAIMesh->HasNormals())
            {
                for (DWORD i = 0; i < nVertices; i++)
                {
                    XMVECTOR xvNormal = XMLoadFloat3((XMFLOAT3 *)&pAIMesh->mNormals[i]);

                    xvNormal = XMVector3Normalize(xvNormal);

                    XMStoreFloat3(&pVertices[i].vNormal, xvNormal);
                }
            }

            if (pAIMesh->HasTextureCoords(0))
            {
                for (DWORD i = 0; i < nVertices; i++)
                {
                    pVertices[i].vTexCoords = XMFLOAT2(pAIMesh->mTextureCoords[0][i].x, pAIMesh->mTextureCoords[0][i].y);
                }
            }

            pMesh->m_pVertices = pVertices;
            pMesh->m_dwNumVertices = nVertices;
        }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top