X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fobject.cpp;h=d48b0843fb9f3b73591588631429ce09e2709a8c;hb=fcb9b3bdb1746f5a5c4b564857c0a2a66fd55765;hp=637af62a3753becb9407e346fb471bad9213f94a;hpb=e042e093a4761f1227d4dd80d695e01642e17ffd;p=libs%2Fgl.git diff --git a/source/object.cpp b/source/object.cpp index 637af62a..d48b0843 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() @@ -46,13 +62,19 @@ void Object::update_bounding_sphere() vector points; for(vector >::const_iterator i=meshes.begin(); i!=meshes.end(); ++i) { + if(!*i) + continue; + 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 +82,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)