I am working on a project where I take an unrigged closed mesh, import it using ASSIMP, auto-rig it using the algorithm provided by Ilya Baran and Jovan Popovic and again export it using ASSIMP. I have the following code that updates the aiScene structure created by assimp inserting the new skeleton data into it. I does not seem to be working, it throws weird exceptions. Can anyone check whether I am updating the data correctly...

Update Code:

void setSkeleton()
    //Number of bones is 20
    const int num_bones = 20;
    string names[num_bones] = { "hip_center", "spine", "shoulder_center", "head"
        , "shoulder_left", "elbow_left", "wrist_left", "hand_left"
        , "shoulder_right", "elbow_right", "wrist_right", "hand_right"
        , "hip_left", "knee_left", "ankle_left", "foot_left"
        , "hip_right", "knee_right", "ankle_right", "foot_right" };

    //define nodes
    aiNode* nodes[num_bones];
    for (int i = 0; i < num_bones; i++) {
        nodes[i] = new aiNode(names[i]);

    //define parents
    nodes[0]->mParent = NULL;
    nodes[1]->mParent = nodes[0];
    nodes[2]->mParent = nodes[1];
    nodes[3]->mParent = nodes[2];
    nodes[4]->mParent = nodes[2];
    nodes[5]->mParent = nodes[4];
    nodes[6]->mParent = nodes[5];
    nodes[7]->mParent = nodes[6];
    nodes[8]->mParent = nodes[2];
    nodes[9]->mParent = nodes[8];
    nodes[10]->mParent = nodes[9];
    nodes[11]->mParent = nodes[10];
    nodes[12]->mParent = nodes[0];
    nodes[13]->mParent = nodes[12];
    nodes[14]->mParent = nodes[13];
    nodes[15]->mParent = nodes[14];
    nodes[16]->mParent = nodes[0];
    nodes[17]->mParent = nodes[16];
    nodes[18]->mParent = nodes[17];
    nodes[19]->mParent = nodes[18];

    //set root node reference in the aiScene object
    aiscene->mRootNode = nodes[0];

    //create bones for the 0th mesh in the scene(assuming there is only one mesh)
    aiMesh* aimesh = aiscene->mMeshes[0];
    aimesh->mNumBones = 20;
    aiBone* bones[20];
    aimesh->mBones = bones;

    vector<aiVertexWeight> weightsOfBone[20];
    //This loop creates vertexWeight objects for all the vertices affected by each bone in the above array
    int numVertices = rigOut.attachment->getNumVertices();
    for (int i = 0; i < numVertices; i++) {
        vector<pair<int, double>> weights = rigOut.attachment->getNZWeights(i);
        int s = weights.size();
        for (int j = 0; j < s; j++){
            aiVertexWeight wght(i, weights[j].second);

    //define bones
    for (int i = 0; i < num_bones; i++)
        bones[i] = new aiBone();
        bones[i]->mName = names[i];
        const int numWeights = weightsOfBone[i].size();
        bones[i]->mNumWeights = numWeights;
        if (numWeights == 0) return;
        aiVertexWeight* weights = (aiVertexWeight *)malloc(numWeights * sizeof(aiVertexWeight));
        for (int j = 0; j < numWeights; j++) {
            weights[i] = weightsOfBone[i][j];
        bones[i]->mWeights = weights;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.