X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fobject.cpp;h=f043f614ac84f80e549381b003b3202f8231c02f;hb=b345b919f572b35042d7c50291422f2f917e5a08;hp=fe1690d267ee3e2a433d832dc388e72ae15f66e9;hpb=5b532dcb2a4a2d15d0b6607374284c979ece36a8;p=libs%2Fgl.git diff --git a/source/object.cpp b/source/object.cpp index fe1690d2..f043f614 100644 --- a/source/object.cpp +++ b/source/object.cpp @@ -21,7 +21,8 @@ Object::Object(): lods(1) { } -Object::Object(const Mesh *m, const Technique *t) +Object::Object(const Mesh *m, const Technique *t): + lods(1) { set_mesh(m); set_technique(t); @@ -68,7 +69,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 +93,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 +201,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 +210,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);