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 *);
80 Object(const Object &);
85 LevelOfDetail &get_lod(unsigned, const char *);
89 /** Sets the mesh for the highest level of detail (index 0). */
90 void set_mesh(const Mesh *m) { set_mesh(0, m); }
92 /** Sets the mesh for a specific level of detail. LoDs must be defined in
93 order, without gaps. If this call creates a new LoD, technique is copied
94 from the previous one. */
95 void set_mesh(unsigned, const Mesh *);
98 void update_bounding_sphere();
100 const Mesh *get_mesh(unsigned = 0) const;
102 /** Sets the technique for the highest level of detail (index 0). */
103 void set_technique(const Technique *t) { set_technique(0, t); }
105 /** Sets the technique for a specific level of detail. LoDs must be defined
106 in order, without gaps. If this call creates a new LoD, mesh is copied from
108 void set_technique(unsigned, const Technique *);
110 const Technique *get_technique(unsigned = 0) const;
111 unsigned get_n_lods() const { return lods.size(); }
113 virtual const Matrix *get_matrix() const { return &identity_matrix; }
114 virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return &bounding_sphere; }
116 virtual void render(Renderer &, Tag = Tag()) const;
118 /** Renders an instance of the object. The instance's hook functions are
119 called before and after drawing the mesh. */
120 virtual void render(Renderer &, const ObjectInstance &, Tag = Tag()) const;
123 virtual void setup_render(Renderer &, Tag) const { }
124 virtual void finish_render(Renderer &, Tag) const { }
127 const RenderMethod *get_method(Tag, unsigned) const;
129 virtual void resource_loaded(Resource &);
130 virtual void resource_removed(Resource &);