[SOLVED] Loading File to the World

[SOLVED] Loading File to the World


I am trying to load a hkt file into my scene (actually i am just trying to load any resource file from the demo resources directory). Whenever I add an entity to my world, it crashes and provides me with this error : Insufficient capacity to store child shape AABBs.

I am not sure if I really have a capacity problem (I dont know what to do if it is the case) or if my code is just plain wrong. Anyone could explain me how I could load an havok mesh into the world? I tried looking at many of the examples, but they none seemed to load what I wanted into the world.

hkRootLevelContainer* container = hkSerializeUtil::loadObject<hkRootLevelContainer>(

    hkxScene* scene =

reinterpret_cast<hkxScene*>( container->findObjectByType( hkxSceneClass.getName() ));

if(scene == HK_NULL || (scene->m_rootNode == HK_NULL) )

"No scene data (or scene data root hkxNode) found. Can't continue.");

    hkAabb meshAabb;
    hkArray<hkRefPtr<hkxNode>> nodes;
    hkxSceneUtils::findAllMeshNodes(scene, scene->m_rootNode, nodes);
    scene->getWorldFromNodeTransform(nodes[0], worldTransform_);
    hkpPhysicsData* physics =

reinterpret_cast<hkpPhysicsData*>( container->findObjectByType( hkpPhysicsDataClass.getName() ));
    HavokCore& core = HavokCore::GetInstance();
    hkpWorld* w = core.GetWorld();

for(intnMesh = 0; nMesh < scene->m_meshes.getSize(); nMesh++ )
        hkxMesh* originalMesh = scene->m_meshes[nMesh];

for(intnSection = 0; nSection < originalMesh->m_sections.getSize(); nSection++ )
            hkxMeshSection* section = originalMesh->m_sections[nSection];
            hkArray<hkVector4> verticesTemp;

for(intv=0; v<verticesTemp.getSize(); v++)
                hkVector4 tempV;
                worldTransform_.multiplyVector(verticesTemp[v], tempV);
    hkGeometry geo;
    hkpExtendedMeshShape* extendedMeshShape =


//for(int i = 0; i < 1/*sections_.getSize()*/; ++i)
        hkpExtendedMeshShape::TrianglesSubpart part;

// set vertices
        part.m_numVertices = geo.m_vertices.getSize();
        part.m_vertexBase  = &geo.m_vertices.begin()[0](0);
        part.m_vertexStriding =


// set triangles
        part.m_indexBase = geo.m_triangles.begin();
        part.m_numTriangleShapes = geo.m_triangles.getSize();
        part.m_indexStriding =

        part.m_stridingType = hkpExtendedMeshShape::INDICES_INT32;

//part.m_numTriangleShapes = sections_[0]->getNumTriangles();

//part.m_numVertices = sections_[0]->m_vertexBuffer->getNumVertices();

//part.m_vertexBase = reinterpret_cast<hkReal*>(&sections_[0]->m_vertexBuffer->);

//part.m_vertexStriding = sizeof(hkVector4);//sizeof(hkReal) * 4;

//part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16;

//part.m_indexBase = sections_[0].//reinterpret_cast<void*>(&sections_[0]->m_indexBuffers);

//part.m_indexStriding = sizeof(hkpExtendedMeshShape::TrianglesSubpart);//sizeof( hkUint8 ) * 4;

/*part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16;
        part.m_vertexStriding = sizeof(hkReal) * 4;
        part.m_indexBase = &m_indices[0];
        part.m_indexStriding = sizeof( hkUint16 ) * 4;*/
        extendedMeshShape->addTrianglesSubpart( part );
    hkVector4 v = hkVector4(0,0,0);
    hkpRigidBodyCinfo info;
    info.m_shape = extendedMeshShape;
    info.m_position = v;
    info.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo( 0, 1 );
    info.m_motionType = hkpMotion::MOTION_FIXED;
    hkpRigidBody* body =


5 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

Hi Stephane,

How you load your hkt/hkx file will most likely depend on what is in it. Have you looked at Common->Api->Mesh->DebugDisplayMeshDemo? This demo loads a file with a hkxScene object and uses that to populate the scene. Physics->Api->Dynamics->World->WorldSnapshot also uses a hkpPhysicsData (which your code seems to use) to create a world with hkpPhysicsData::createWorld().

If you're trying to load a particular type of object from the file the Common->Api->Mesh->DebugDisplaySkinnedMeshDemo shows how you could load a skeleton, bindings, and skin individually from different files using hkRootLevelContainer::findObjectBytype(...) but of course we must be sure that each file contains the data we are trying to load from it. On the other hand if you're looking for a specifically named object in the file you can also find it by name using hkRootLevelContainer::findObjectByName(...).

In short, you'll need to know what you're trying to load into the world in order to load it appropriately. Hopefully this puts you on the right track. If you've any more questions just let me know.

Amy Developer Support Engineer Havok www.havok.com

Thanks for the replay. I do not have either of these 2 demos that you suggested. The only one in the mesh section is MeshSimplification. I also tried to look elsewhere but did not found them. Is there a specific version I need to use? I am currently using 2012-1 no SIMD.



I was able to successfully load a hkx file doing the following:

hkRootLevelContainer* container = hkSerializeUtil::loadObject<hkRootLevelContainer>(

    hkpPhysicsData* physicsData =

    HK_ASSERT2(0x27343635, physicsData,

"No physics loaded");
    hkpWorld* w = HavokCore::GetInstance().GetWorld();

for(inti = 0; i < physicsData->getPhysicsSystems().getSize(); ++i)

Hi Stephane,

Very sorry my mistake, it looks like the two mesh demos aren't in the free PC version. Glad to hear you got it sorted anyway. Although if you are still looking for examples of loading a hkxScene many of the animation demos load data from hkxScene objects. If you've any other problems just let us know.

Amy Developer Support Engineer Havok www.havok.com

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen