1 #ifndef MSP_GL_OBJECT_H_
2 #define MSP_GL_OBJECT_H_
5 #include "renderable.h"
6 #include "rendermethod.h"
7 #include "resourceobserver.h"
17 Combines a Mesh with a Technique for a complete model.
19 An object does not have a model matrix and will be rendered at origin if used
20 by itself. The ObjectInstance class provides a way to position objects in a
21 scene and customize them in other ways.
23 Objects can have multiple levels of detail, with different resources. The most
24 detailed level has index 0, with increasing indices having less detail. When
25 rendering an instance, the instance's get_level_of_detail method is called to
26 determine which LoD to use.
28 An Object can be rendered with any tag its Technique supports. Unknown tags
31 class Object: public Renderable, private ResourceObserver
36 class LodLoader: public DataFile::CollectionObjectLoader<Object>
43 LodLoader(Object &, unsigned, Collection &);
46 void mesh(const std::string &);
48 void technique(const std::string &);
49 void technique_inline();
53 class Loader: public LodLoader
56 Loader(Object &, Collection &);
58 virtual void finish();
60 void bounding_sphere_hint(float, float, float, float);
61 void level_of_detail(unsigned);
68 const Technique *technique;
71 std::vector<LevelOfDetail> lods;
72 Geometry::BoundingSphere<float, 3> bounding_sphere;
73 bool lod0_watched = false;
75 static const Matrix identity_matrix;
79 Object(const Mesh *, const Technique *);
83 LevelOfDetail &get_lod(unsigned, const char *);
86 /** Sets the mesh for the highest level of detail (index 0). */
87 void set_mesh(const Mesh *m) { set_mesh(0, m); }
89 /** Sets the mesh for a specific level of detail. LoDs must be defined in
90 order, without gaps. If this call creates a new LoD, technique is copied
91 from the previous one. */
92 void set_mesh(unsigned, const Mesh *);
95 void update_bounding_sphere();
97 const Mesh *get_mesh(unsigned = 0) const;
99 /** Sets the technique for the highest level of detail (index 0). */
100 void set_technique(const Technique *t) { set_technique(0, t); }
102 /** Sets the technique for a specific level of detail. LoDs must be defined
103 in order, without gaps. If this call creates a new LoD, mesh is copied from
105 void set_technique(unsigned, const Technique *);
107 const Technique *get_technique(unsigned = 0) const;
108 unsigned get_n_lods() const { return lods.size(); }
110 virtual const Matrix *get_matrix() const { return &identity_matrix; }
111 virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return &bounding_sphere; }
113 virtual void render(Renderer &, Tag = Tag()) const;
115 /** Renders an instance of the object. The instance's hook functions are
116 called before and after drawing the mesh. */
117 virtual void render(Renderer &, const ObjectInstance &, Tag = Tag()) const;
120 virtual void setup_render(Renderer &, Tag) const { }
121 virtual void finish_render(Renderer &, Tag) const { }
124 const RenderMethod *get_method(Tag, unsigned) const;
126 virtual void resource_loaded(Resource &);
127 virtual void resource_removed(Resource &);