X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fobject.cpp;h=9aba5466e3e1cf548674b61f2a4b70f156eb8a93;hb=946266e823c07025f115b5e4f5523b496dcb393e;hp=d35517bf3adeb43773760cc2d6648d65f05a1c06;hpb=46921b54c8252bb535a3b2cb7be97eb38e66eaed;p=libs%2Fgl.git diff --git a/source/object.cpp b/source/object.cpp index d35517bf..9aba5466 100644 --- a/source/object.cpp +++ b/source/object.cpp @@ -7,6 +7,7 @@ #include "program.h" #include "programdata.h" #include "renderer.h" +#include "resourcemanager.h" #include "technique.h" #include "texturing.h" @@ -27,7 +28,11 @@ Object::Object(const Mesh *m, const Technique *t) // Avoid synthesizing ~RefPtr in files including object.h Object::~Object() -{ } +{ + if(meshes[0]) + if(ResourceManager *rm = meshes[0]->get_manager()) + rm->unwatch_resource(*meshes[0], *this); +} void Object::set_mesh(unsigned i, const Mesh *m) { @@ -37,8 +42,19 @@ void Object::set_mesh(unsigned i, const Mesh *m) if(i==meshes.size()) meshes.push_back(m); else + { + if(i==0 && meshes[i]) + if(ResourceManager *rm = meshes[i]->get_manager()) + rm->unwatch_resource(*meshes[i], *this); meshes[i] = m; + } meshes[i].keep(); + + if(i==0 && m) + if(ResourceManager *rm = m->get_manager()) + rm->watch_resource(*m, *this); + + update_bounding_sphere(); } void Object::update_bounding_sphere() @@ -47,12 +63,15 @@ void Object::update_bounding_sphere() for(vector >::const_iterator i=meshes.begin(); i!=meshes.end(); ++i) { const VertexArray &vertices = (*i)->get_vertices(); + int offset = vertices.get_format().offset(VERTEX3); + bool three = true; if(offset<0) { - // TODO Handle two-dimensional meshes - bounding_sphere = Geometry::BoundingSphere(); - return; + offset = vertices.get_format().offset(VERTEX2); + three = false; + if(offset<0) + continue; } unsigned n_vertices = vertices.size(); @@ -60,7 +79,7 @@ void Object::update_bounding_sphere() for(unsigned j=0; jget_pass(tag); } +void Object::resource_loaded(Resource &res) +{ + if(!meshes.empty() && &res==meshes.front().get() && bounding_sphere.is_empty()) + update_bounding_sphere(); +} + Object::Loader::Loader(Object &o): DataFile::CollectionObjectLoader(o, 0) @@ -157,9 +182,6 @@ void Object::Loader::init() add("mesh", &Loader::mesh_lod); add("technique", &Loader::technique_inline); add("technique", &Loader::technique); - - // Deprecated alias, will be removed - add("lod_mesh", &Loader::mesh_lod); } void Object::Loader::finish()