Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libgui|ModelDrawable: Set up bounds at load time
The bounding box of the model can be determined at load time from vertex
positions.
  • Loading branch information
skyjake committed Apr 7, 2014
1 parent 9a3ed78 commit dd398d5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion doomsday/libgui/include/de/graphics/modeldrawable.h
Expand Up @@ -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.
Expand Down
68 changes: 32 additions & 36 deletions doomsday/libgui/src/graphics/modeldrawable.cpp
Expand Up @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -820,9 +815,10 @@ void ModelDrawable::setAnimationTime(TimeDelta const &time)
d->animTime = time;
}

void ModelDrawable::draw()
void ModelDrawable::draw() const
{
glInit();
const_cast<ModelDrawable *>(this)->glInit();

if(isReady() && d->program && d->atlas)
{
d->draw();
Expand Down

0 comments on commit dd398d5

Please sign in to comment.