3
\$\begingroup\$

I have a COLLADA(.dae) file exported from Blender, also I have program that read all data from structure generated with Assimp and I want to translate all data in more readable format. Problem appears when I want to read aiBone structure from aiMesh from aiNode from aiScene: my program shows wrong number of bones. It's only a simple figure with few bones, without animation. I don't know where is problem. In my program logic or Assimp or Blender...

  • Assimp 3.3.1
  • OpenGL 4.0.
  • Blender 2.78c

My code

void start(){
    Importer importer;
    unsigned int flags = 0;// aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_FlipUVs;
    const aiScene* scene = importer.ReadFile(filePath, flags);
    if (!scene || scene->mFlags&& AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
        cout << "Model::'" << filePath << "':" << importer.GetErrorString() << endl;
        system("pause");
        return;
    }
    cout << "Model loaded" << endl;
    showHierarchy(scene, scene->mRootNode);
}

void showHierarchy(const aiScene* scene, aiNode* currNode) {
        string boneName = currNode->mName.C_Str();
        aiNode* parent = currNode->mParent;
        string parentName = parent == NULL ? "NO ROOT" : parent->mName.C_Str();

        unsigned int* meshesIndexes = currNode->mMeshes;
        cout << "Num. meshes: " << currNode->mNumMeshes << endl;

        for (int nrMesh = 0; nrMesh < currNode->mNumMeshes; ++nrMesh) {
            aiMesh* mesh = scene->mMeshes[meshesIndexes[nrMesh]];
            if (mesh->mNumBones > 0) {
                cout << "Num. bones: " << mesh->mNumBones << endl;
                aiBone** bones = mesh->mBones;
                for (int nrBone = 0; nrBone < mesh->mNumBones; ++nrBone) {
                    aiBone* bone = bones[nrBone];                   
                    cout << "Bone "<<nrBone<<": " << bone->mName.C_Str() << endl;
                }
            }
        }

        //for each child do the same operations
        for (int nrChild = 0; nrChild < currNode->mNumChildren; ++nrChild) {
            showHierarchy(scene, currNode->mChildren[nrChild]);
        }
}

Maybe will help

<node id="Armature" name="Armature" type="NODE">
        <translate sid="location">-1.290625 0.08518557 -3.139279</translate>
        <rotate sid="rotationZ">0 0 1 0</rotate>
        <rotate sid="rotationY">0 1 0 0</rotate>
        <rotate sid="rotationX">1 0 0 0</rotate>
        <scale sid="scale">2.297401 2.297401 2.297401</scale>
        <node id="Bone" name="Bone" sid="Bone" type="JOINT">
          <matrix sid="transform">1 0 2.38419e-7 0.5586469 2.38419e-7 0 -1 -0.01256594 0 1 0 0.9420496 0 0 0 1</matrix>
          <node id="Bone_001" name="Bone.001" sid="Bone_001" type="JOINT">
            <matrix sid="transform">1 6.41312e-9 -7.15169e-7 0 1.28262e-8 0.9996382 0.02689855 0.48549 7.15083e-7 -0.02689855 0.9996381 0 0 0 0 1</matrix>
            <node id="Bone_002" name="Bone.002" sid="Bone_002" type="JOINT">
              <matrix sid="transform">1 -3.70967e-8 2.378e-7 0 1.85446e-8 0.9997111 0.02403316 0.3515059 -2.38796e-7 -0.02403316 0.9997112 3.72529e-9 0 0 0 1</matrix>
              <node id="Bone_006" name="Bone.006" sid="Bone_006" type="JOINT">
                <matrix sid="transform">1 1.94806e-7 2.73368e-6 0 2.50534e-6 -0.4732692 -0.8809178 0.5466702 1.11965e-6 0.880918 -0.4732695 0 0 0 0 1</matrix>
                <node id="Bone_007" name="Bone.007" sid="Bone_007" type="JOINT">
                  <matrix sid="transform">-0.9999999 -2.50612e-6 4.84192e-6 0 3.08088e-6 0.4735363 0.8807744 0.3267682 -4.50835e-6 0.8807743 -0.4735363 0 0 0 0 1</matrix>
                  <node id="Bone_008" name="Bone.008" sid="Bone_008" type="JOINT">
                    <matrix sid="transform">1 -4.58268e-7 3.0653e-6 0 2.77133e-8 0.9891911 0.1466312 0.3368657 -3.1009e-6 -0.1466312 0.9891911 -5.96046e-8 0 0 0 1</matrix>
                    <extra>
                      <technique profile="blender">
                        <connect>1</connect>
                        <layer>0</layer>
                        <roll>3.141592</roll>
                        <tip_x>0</tip_x>
                        <tip_y>0.0444796</tip_y>
                        <tip_z>-0.4622855</tip_z>
                      </technique>
                    </extra>
                  </node>
                  <extra>
                    <technique profile="blender">
                      <connect>1</connect>
                      <layer>0</layer>
                      <roll>-3.141596</roll>
                    </technique>
                  </extra>
                </node>
                <extra>
                  <technique profile="blender">
                    <connect>1</connect>
                    <layer>0</layer>
                    <roll>2.86102e-6</roll>
                  </technique>
                </extra>
              </node>
              <node id="Bone_003" name="Bone.003" sid="Bone_003" type="JOINT">
                <matrix sid="transform">1 -2.14772e-7 -9.97458e-8 0 -1.29403e-8 -0.4887015 0.8724509 0.5466702 -2.38636e-7 -0.872451 -0.4887016 0 0 0 0 1</matrix>
                <node id="Bone_004" name="Bone.004" sid="Bone_004" type="JOINT">
                  <matrix sid="transform">1 -2.70245e-8 -2.22184e-7 0 1.97028e-7 0.6096119 0.7927001 0.2557451 1.34571e-7 -0.7927002 0.6096118 0 0 0 0 1</matrix>
                  <node id="Bone_005" name="Bone.005" sid="Bone_005" type="JOINT">
                    <matrix sid="transform">1 -3.3895e-8 -4.78732e-7 0 1.69833e-7 0.9634752 0.2677974 0.4389689 4.5297e-7 -0.2677974 0.9634753 0 0 0 0 1</matrix>
                    <extra>
                      <technique profile="blender">
                        <connect>1</connect>
                        <layer>0</layer>
                        <roll>-7.15256e-7</roll>
                        <tip_x>0</tip_x>
                        <tip_y>-0.08205157</tip_y>
                        <tip_z>-0.4585228</tip_z>
                      </technique>
                    </extra>
                  </node>
                  <extra>
                    <technique profile="blender">
                      <connect>1</connect>
                      <layer>0</layer>
                      <roll>-2.38419e-7</roll>
                    </technique>
                  </extra>
                </node>
                <extra>
                  <technique profile="blender">
                    <connect>1</connect>
                    <layer>0</layer>
                  </technique>
                </extra>
              </node>
              <extra>
                <technique profile="blender">
                  <connect>1</connect>
                  <layer>0</layer>
                  <roll>-2.38419e-7</roll>
                </technique>
              </extra>
            </node>
            <extra>
              <technique profile="blender">
                <connect>1</connect>
                <layer>0</layer>
                <roll>-4.76837e-7</roll>
              </technique>
            </extra>
          </node>
          <extra>
            <technique profile="blender">
              <layer>0</layer>
              <roll>2.38419e-7</roll>
            </technique>
          </extra>
        </node>
      </node>
\$\endgroup\$
2
  • \$\begingroup\$ Assimp has a standalone viewer. Can you compare the number of bones in the viewer with the number in Blender? \$\endgroup\$
    – Jay
    Jan 23, 2018 at 2:11
  • \$\begingroup\$ Yes. I have these bones in Blender: Bone, Bone.001, Bone.002, Bone.006, Bone.007, Bone.008, Bone.003, Bone.004, Bone.005 but in program Num. bones: 5 Bone0: Bone.003 Bone1: Bone.002 Bone2: Bone.006 Bone3: Bone.008 Bone4: Bone.004 \$\endgroup\$
    – Romeon0
    Jan 23, 2018 at 7:30

1 Answer 1

3
\$\begingroup\$

Finally I found the solution. Problem was in vertices. aiBone structure contain, among other things, vertices weights. My 3D model has too few weights and exists bones that don't affect vertices, so Assimp didn't loaded bones that affected 0 vertices.

\$\endgroup\$
2
  • \$\begingroup\$ Can you tell me more information about this please? Was it a problem in Blender or in the Code, and how did you fix it in Blender if it was there? \$\endgroup\$ Nov 29, 2020 at 22:30
  • \$\begingroup\$ apparently my issue was the flag aiProcess_PreTransformVertices like explained here: stackoverflow.com/questions/58561457/… \$\endgroup\$ Nov 29, 2020 at 23:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .