Improved preloadtexture script command so it loads model textures as well as the geometry.

sensor-dev
Chris Laurel 2009-09-15 04:55:03 +00:00
parent 02fc9009b9
commit f177424e43
3 changed files with 33 additions and 1 deletions

View File

@ -9,6 +9,7 @@
#include "model.h"
#include "rendcontext.h"
#include "texmanager.h"
#include <cassert>
#include <functional>
#include <algorithm>
@ -465,3 +466,23 @@ Model::sortMeshes(const MeshComparator& comparator)
// Sort the meshes so that completely opaque ones are first
sort(meshes.begin(), meshes.end(), MeshComparatorAdapter(comparator));
}
void
Model::loadTextures()
{
for (vector<const Mesh::Material*>::const_iterator iter = materials.begin();
iter != materials.end(); iter++)
{
const Mesh::Material* m = *iter;
if (m->maps[Mesh::DiffuseMap] != InvalidResource)
GetTextureManager()->find(m->maps[Mesh::DiffuseMap]);
if (m->maps[Mesh::NormalMap] != InvalidResource)
GetTextureManager()->find(m->maps[Mesh::NormalMap]);
if (m->maps[Mesh::SpecularMap] != InvalidResource)
GetTextureManager()->find(m->maps[Mesh::SpecularMap]);
if (m->maps[Mesh::EmissiveMap] != InvalidResource)
GetTextureManager()->find(m->maps[Mesh::EmissiveMap]);
}
}

View File

@ -43,6 +43,11 @@ public:
{
return false;
}
/*! Load all textures used by the model. */
virtual void loadTextures()
{
}
};
@ -146,6 +151,8 @@ class Model : public Geometry
/*! Optimize the model by eliminating all duplicated materials */
void uniquifyMaterials();
void loadTextures();
/*! This comparator will roughly sort the model's meshes by
* opacity so that transparent meshes are rendered last. It's far
* from perfect, but covers a lot of cases. A better method of

View File

@ -10361,7 +10361,11 @@ void Renderer::loadTextures(Body* body)
if (body->getGeometry() != InvalidResource)
{
GetGeometryManager()->find(body->getGeometry());
Geometry* geometry = GetGeometryManager()->find(body->getGeometry());
if (geometry)
{
geometry->loadTextures();
}
}
}