From dd398d53171d511303fec0c7a87646b988105ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Mon, 7 Apr 2014 14:37:15 +0300 Subject: [PATCH] libgui|ModelDrawable: Set up bounds at load time The bounding box of the model can be determined at load time from vertex positions. --- .../include/de/graphics/modeldrawable.h | 2 +- .../libgui/src/graphics/modeldrawable.cpp | 68 +++++++++---------- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/doomsday/libgui/include/de/graphics/modeldrawable.h b/doomsday/libgui/include/de/graphics/modeldrawable.h index 9430017e68..761d7f0402 100644 --- a/doomsday/libgui/include/de/graphics/modeldrawable.h +++ b/doomsday/libgui/include/de/graphics/modeldrawable.h @@ -97,7 +97,7 @@ class ModelDrawable : public AssetGroup void setAnimationTime(TimeDelta const &time); - void draw(); + void draw() const; /** * Dimensions of the default pose, in model space. diff --git a/doomsday/libgui/src/graphics/modeldrawable.cpp b/doomsday/libgui/src/graphics/modeldrawable.cpp index 0684a88a53..3f5723f231 100644 --- a/doomsday/libgui/src/graphics/modeldrawable.cpp +++ b/doomsday/libgui/src/graphics/modeldrawable.cpp @@ -270,6 +270,30 @@ DENG2_PIMPL(ModelDrawable) scene = importer.GetScene(); initBones(); + + globalInverse = convertMatrix(scene->mRootNode->mTransformation).inverse(); + maxPoint = Vector3f(1.0e-9, 1.0e-9, 1.0e-9); + minPoint = Vector3f(1.0e9, 1.0e9, 1.0e9); + + // Determine the total bounding box. + for(duint i = 0; i < scene->mNumMeshes; ++i) + { + aiMesh const &mesh = *scene->mMeshes[i]; + for(duint i = 0; i < mesh.mNumVertices; ++i) + { + addToBounds(Vector3f(&mesh.mVertices[i].x)); + } + } + + // Print some information. + qDebug() << "total bones:" << boneCount(); + + // Animations. + qDebug() << "animations:" << scene->mNumAnimations; + for(duint i = 0; i < scene->mNumAnimations; ++i) + { + qDebug() << " anim #" << i << "name:" << scene->mAnimations[i]->mName.C_Str(); + } } /// Release all loaded model data. @@ -296,7 +320,11 @@ DENG2_PIMPL(ModelDrawable) // Has a scene been imported successfully? if(!scene) return; - initFromScene(); + // Materials. + initTextures(); + + // Initialize all meshes in the scene into a single GL buffer. + makeBuffer(); // Ready to go! modelAsset.setState(Ready); @@ -327,39 +355,6 @@ DENG2_PIMPL(ModelDrawable) materialTexIds.clear(); } - void initFromScene() - { - globalInverse = convertMatrix(scene->mRootNode->mTransformation).inverse(); - maxPoint = Vector3f(1.0e-9, 1.0e-9, 1.0e-9); - minPoint = Vector3f(1.0e9, 1.0e9, 1.0e9); - - // Determine the total bounding box. - for(duint i = 0; i < scene->mNumMeshes; ++i) - { - aiMesh const &mesh = *scene->mMeshes[i]; - for(duint i = 0; i < mesh.mNumVertices; ++i) - { - addToBounds(Vector3f(&mesh.mVertices[i].x)); - } - } - - // Print some information. - qDebug() << "total bones:" << boneCount(); - - // Animations. - qDebug() << "animations:" << scene->mNumAnimations; - for(duint i = 0; i < scene->mNumAnimations; ++i) - { - qDebug() << " anim #" << i << "name:" << scene->mAnimations[i]->mName.C_Str(); - } - - // Materials. - initTextures(); - - // Initialize all meshes in the scene into a single GL buffer. - makeBuffer(); - } - void addToBounds(Vector3f const &point) { minPoint = minPoint.min(point); @@ -820,9 +815,10 @@ void ModelDrawable::setAnimationTime(TimeDelta const &time) d->animTime = time; } -void ModelDrawable::draw() +void ModelDrawable::draw() const { - glInit(); + const_cast(this)->glInit(); + if(isReady() && d->program && d->atlas) { d->draw();