X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fobject.cpp;h=637af62a3753becb9407e346fb471bad9213f94a;hb=27fe0982fc18d1f5f9efe942e18c42f508268f34;hp=6bc872a198553eb38aa65ae67052b32ace758597;hpb=72790b3aba8ddc1a6d020646fb7312959729777b;p=libs%2Fgl.git diff --git a/source/object.cpp b/source/object.cpp index 6bc872a1..637af62a 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); } @@ -129,9 +157,11 @@ 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() +{ + obj.update_bounding_sphere(); } void Object::Loader::mesh_inline()