X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fobject.cpp;h=283894501e29a0aec9b3694d47b9730154d56c60;hb=84269f7b598673b06757313d70934a1747045b69;hp=fe1690d267ee3e2a433d832dc388e72ae15f66e9;hpb=5b532dcb2a4a2d15d0b6607374284c979ece36a8;p=libs%2Fgl.git diff --git a/source/object.cpp b/source/object.cpp index fe1690d2..28389450 100644 --- a/source/object.cpp +++ b/source/object.cpp @@ -68,7 +68,7 @@ void Object::update_bounding_sphere() vector points; for(vector::const_iterator i=lods.begin(); i!=lods.end(); ++i) { - if(!i->mesh) + if(!i->mesh || !i->mesh->is_loaded()) continue; const VertexArray &vertices = i->mesh->get_vertices(); @@ -92,6 +92,11 @@ void Object::update_bounding_sphere() } } + /* Don't touch the bounding sphere if we had no vertices to avoid + overwriting a possible hint. */ + if(points.empty()) + return; + bounding_sphere = Geometry::BoundingSphere::from_point_cloud(points.begin(), points.end()); } @@ -195,6 +200,7 @@ Object::Loader::Loader(Object &o, Collection &c): void Object::Loader::init() { + add("bounding_sphere_hint", &Loader::bounding_sphere_hint); add("level_of_detail", &Loader::level_of_detail); } @@ -203,6 +209,11 @@ void Object::Loader::finish() obj.update_bounding_sphere(); } +void Object::Loader::bounding_sphere_hint(float x, float y, float z, float r) +{ + obj.bounding_sphere = Geometry::BoundingSphere(Vector3(x, y, z), r); +} + void Object::Loader::level_of_detail(unsigned i) { LodLoader ldr(obj, i, coll);