]> git.tdb.fi Git - libs/gl.git/blobdiff - source/object.cpp
Allow bounding sphere hints for objects and export such from Blender
[libs/gl.git] / source / object.cpp
index fe1690d267ee3e2a433d832dc388e72ae15f66e9..283894501e29a0aec9b3694d47b9730154d56c60 100644 (file)
@@ -68,7 +68,7 @@ void Object::update_bounding_sphere()
        vector<Vector3> points;
        for(vector<LevelOfDetail>::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<float, 3>::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<float, 3>(Vector3(x, y, z), r);
+}
+
 void Object::Loader::level_of_detail(unsigned i)
 {
        LodLoader ldr(obj, i, coll);