X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fobject.cpp;h=d35517bf3adeb43773760cc2d6648d65f05a1c06;hb=46921b54c8252bb535a3b2cb7be97eb38e66eaed;hp=6bc872a198553eb38aa65ae67052b32ace758597;hpb=72790b3aba8ddc1a6d020646fb7312959729777b;p=libs%2Fgl.git diff --git a/source/object.cpp b/source/object.cpp index 6bc872a1..d35517bf 100644 --- a/source/object.cpp +++ b/source/object.cpp @@ -41,6 +41,32 @@ void Object::set_mesh(unsigned i, const Mesh *m) meshes[i].keep(); } +void Object::update_bounding_sphere() +{ + vector points; + for(vector >::const_iterator i=meshes.begin(); i!=meshes.end(); ++i) + { + const VertexArray &vertices = (*i)->get_vertices(); + int offset = vertices.get_format().offset(VERTEX3); + if(offset<0) + { + // TODO Handle two-dimensional meshes + bounding_sphere = Geometry::BoundingSphere(); + return; + } + + unsigned n_vertices = vertices.size(); + points.reserve(points.size()+n_vertices); + for(unsigned j=0; j::from_point_cloud(points.begin(), points.end()); +} + const Mesh *Object::get_mesh(unsigned i) const { if(i>=meshes.size()) @@ -103,7 +129,9 @@ void Object::render(Renderer &renderer, const ObjectInstance &inst, const Tag &t const RenderPass *Object::get_pass(const Tag &tag) const { - if(!technique || !technique->has_pass(tag)) + if(!technique) + throw logic_error("!technique"); + if(!technique->has_pass(tag)) return 0; return &technique->get_pass(tag); } @@ -134,6 +162,11 @@ void Object::Loader::init() add("lod_mesh", &Loader::mesh_lod); } +void Object::Loader::finish() +{ + obj.update_bounding_sphere(); +} + void Object::Loader::mesh_inline() { RefPtr msh = new Mesh;