Sign in to follow this  
lucky6969b

The relationship between attribute groups and materials

Recommended Posts

Does each attribute group contain multiple materials? So this would pose some problems?

BTW, what does attribute group in direct3d correspond to in 3ds max?

 

 

    //Copy materials and load textures (just like with a static mesh)

    for(int i=0;i<(int)NumMaterials;i++)

    {

        D3DXMATERIAL mtrl;

        memcpy(&mtrl, &pMaterials[i], sizeof(D3DXMATERIAL));

        boneMesh->materials.push_back(mtrl.MatD3D);

        IDirect3DTexture9* newTexture = NULL;



        if(mtrl.pTextureFilename != NULL)

        {

            char textureFname[200];

            strcpy(textureFname, "resources/meshes/");

            strcat(textureFname, mtrl.pTextureFilename);



            //Load texture

            D3DXCreateTextureFromFile(g_pDevice, textureFname, &newTexture);

        }



        boneMesh->textures.push_back(newTexture);

    }



    if(pSkinInfo != NULL)

    {

        //Get Skin Info

        boneMesh->pSkinInfo = pSkinInfo;

        pSkinInfo->AddRef();    //Add reference so that the SkinInfo isnt deallocated



        DWORD maxVertInfluences = 0;

        DWORD numBoneComboEntries = 0;

        ID3DXBuffer* boneComboTable = 0;



        pSkinInfo->ConvertToIndexedBlendedMesh(pMeshData->pMesh,

                                                D3DXMESH_MANAGED | D3DXMESH_WRITEONLY,  

                                                30,

                                                0, // ignore adjacency in

                                                0, // ignore adjacency out

                                                0, // ignore face remap

                                                0, // ignore vertex remap

                                                &maxVertInfluences,

                                                &numBoneComboEntries,

                                                &boneComboTable,

                                                &boneMesh->MeshData.pMesh);



        if(boneComboTable != NULL)

            boneComboTable->Release();



        //Get Attribute Table

        boneMesh->MeshData.pMesh->GetAttributeTable(NULL, &boneMesh->NumAttributeGroups);

        boneMesh->attributeTable = new D3DXATTRIBUTERANGE[boneMesh->NumAttributeGroups];

        boneMesh->MeshData.pMesh->GetAttributeTable(boneMesh->attributeTable, NULL);



        //Create bone offset and current matrices

        int NumBones = pSkinInfo->GetNumBones();

        boneMesh->boneOffsetMatrices = new D3DXMATRIX[NumBones];        

        boneMesh->currentBoneMatrices = new D3DXMATRIX[NumBones];



        //Get bone offset matrices

        for(int i=0;i < NumBones;i++)

            boneMesh->boneOffsetMatrices[i] = *(boneMesh->pSkinInfo->GetBoneOffsetMatrix(i));

    }
Edited by lucky6969b

Share this post


Link to post
Share on other sites

Attributes are used to divide the faces of a mesh into groups. Each group can be rendered separately by calling DrawSubset with the group's attribute as an id.

It's up to you what you're using the groups for. However, it's common to create a separate group for each material a mesh uses.

From the Direct3D 9 documentation: 

 

An attribute table is used to identify areas of the mesh that need to be drawn with different textures, render states, materials, and so on. In addition, the application can use the attribute table to hide portions of a mesh by not drawing a given attribute identifier (AttribId) when drawing the frame.

 

Share this post


Link to post
Share on other sites

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