2
// C++ Interface: ModelDefinition
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2004
8
// Copyright (c) 2005 The Cataclysmos Team
10
// This program is free software; you can redistribute it and/or modify
11
// it under the terms of the GNU General Public License as published by
12
// the Free Software Foundation; either version 2 of the License, or
13
// (at your option) any later version.
15
// This program is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU General Public License for more details.
20
// You should have received a copy of the GNU General Public License
21
// along with this program; if not, write to the Free Software
22
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
24
#ifndef EMBEROGREMODELDEFINITION_H
25
#define EMBEROGREMODELDEFINITION_H
27
#include "components/ogre/EmberOgrePrerequisites.h"
28
//#include <ext/hash_map>
36
class SubModelDefinition;
37
class ModelDefinition;
38
class SubEntityDefinition;
40
class ActionDefinition;
41
struct SoundDefinition;
42
class AnimationDefinition;
43
struct AnimationPartDefinition;
44
struct AttachPointDefinition;
45
struct ViewDefinition;
47
typedef std::map<std::string, Model*> ModelInstanceStore;
49
typedef std::vector<SubModelDefinition*> SubModelDefinitionsStore;
50
typedef std::vector<PartDefinition*> PartDefinitionsStore;
51
typedef std::vector<SubEntityDefinition*> SubEntityDefinitionsStore;
52
typedef std::vector<AnimationDefinition*> AnimationDefinitionsStore;
53
typedef std::vector<AnimationPartDefinition*> AnimationPartDefinitionsStore;
54
typedef std::vector<SoundDefinition*> SoundDefinitionsStore;
55
typedef std::vector<ActionDefinition*> ActionDefinitionsStore;
56
typedef std::vector<AttachPointDefinition> AttachPointDefinitionStore;
57
typedef std::map<std::string, ViewDefinition*> ViewDefinitionStore;
58
typedef std::map<std::string, std::string> StringParamStore;
61
A rendering definition. This allows you to specify a different render method than the default one (regular Model).
62
All of this requires that you create functionality for implementing the different schemes that might be specified.
64
class RenderingDefinition
66
friend class XMLModelDefinitionSerializer;
70
* Gets the scheme which will be used.
73
const std::string& getScheme() const;
78
void setScheme(const std::string& scheme);
80
* Gets a collection of parameters for the rendering scheme.
83
const StringParamStore& getParameters() const;
86
StringParamStore mParams;
90
class SubEntityDefinition
92
friend class PartDefinition;
94
const std::string& getSubEntityName() const;
95
unsigned int getSubEntityIndex() const;
96
//void setSubEntityName(const std::string&);
98
const std::string& getMaterialName() const;
99
void setMaterialName(const std::string& materialName);
101
PartDefinition& getPartDefinition();
104
SubEntityDefinition(const std::string& subEntityName, PartDefinition& partdef);
105
SubEntityDefinition(unsigned int subEntityIndex, PartDefinition& partdef);
106
std::string mSubEntityName;
107
std::string mMaterialName;
108
unsigned int mSubEntityIndex;
109
PartDefinition& mPartDef;
115
friend class SubModelDefinition;
119
void setName(const std::string& name);
120
const std::string& getName() const;
122
void setGroup(const std::string& group);
123
const std::string& getGroup() const;
125
void setShow(bool show);
126
bool getShow() const;
128
SubEntityDefinition* createSubEntityDefinition(const std::string& subEntityName);
129
SubEntityDefinition* createSubEntityDefinition(unsigned int subEntityIndex);
130
const SubEntityDefinitionsStore& getSubEntityDefinitions();
131
void removeSubEntityDefinition(SubEntityDefinition* def);
133
SubModelDefinition& getSubModelDefinition();
136
PartDefinition(const std::string& name, SubModelDefinition& subModelDef);
140
SubEntityDefinitionsStore mSubEntities;
141
SubModelDefinition& mSubModelDef;
145
class SubModelDefinition
147
friend class ModelDefinition;
149
~SubModelDefinition();
151
const std::string& getMeshName() const;
153
PartDefinition* createPartDefinition(const std::string& partname);
154
const PartDefinitionsStore& getPartDefinitions();
155
void removePartDefinition(PartDefinition* def);
157
ModelDefinition& getModelDefinition();
160
SubModelDefinition(const std::string& meshname, ModelDefinition& modelDef);
161
std::string mMeshName;
162
PartDefinitionsStore mParts;
163
ModelDefinition& mModelDef;
167
A simple struct for defining a certain view of the Model. These settings needs to be applied to the camera rendering the Model.
169
struct ViewDefinition
172
The name of the view.
177
The rotation of the camera related to the Model.
179
Ogre::Quaternion Rotation;
182
The distance of the camera from the Model.
187
struct AttachPointDefinition
190
std::string BoneName;
191
Ogre::Quaternion Rotation;
194
struct AnimationPartDefinition
200
class AnimationDefinition
202
friend class ActionDefinition;
204
~AnimationDefinition();
205
AnimationPartDefinition* createAnimationPartDefinition(const std::string& ogreAnimationName, Ogre::Real weight = 1);
206
const AnimationPartDefinitionsStore& getAnimationPartDefinitions();
207
void removeAnimationPartDefinition(AnimationPartDefinition* def);
209
const std::string& getName() const;
210
int getIterations() const;
213
AnimationDefinition(int iterations);
215
AnimationPartDefinitionsStore mAnimationParts;
220
struct SoundDefinition
222
std::string groupName;
223
unsigned int playOrder;
226
class ActionDefinition
228
friend class ModelDefinition;
232
AnimationDefinition* createAnimationDefinition(int iterations = 1);
233
const AnimationDefinitionsStore& getAnimationDefinitions();
234
void removeAnimationDefinition(AnimationDefinition* def);
236
SoundDefinition* createSoundDefinition(const std::string& groupName, unsigned int play);
238
const SoundDefinitionsStore& getSoundDefinitions();
239
void removeSoundDefinition(SoundDefinition* def);
241
const std::string& getName() const;
242
Ogre::Real getAnimationSpeed() const { return mAnimationSpeed; }
243
void setAnimationSpeed(Ogre::Real speed) { mAnimationSpeed = speed; }
246
ActionDefinition(const std::string& name);
250
AnimationDefinitionsStore mAnimations;
251
SoundDefinitionsStore mSounds;
252
Ogre::Real mAnimationSpeed;
257
@author Erik Hjortsberg
259
class ModelDefinition : public Ogre::Resource {
261
friend class XMLModelDefinitionSerializer;
267
whether to use a certain axis for scaling
268
for example, if you use a model of a human you probably want to scale according to the height
269
this might mean that width and depths aren't correct though
280
//th ModelDefinition(const Ogre::String& name, const Ogre::String& path);
282
ModelDefinition(Ogre::ResourceManager* creator, const Ogre::String& name, Ogre::ResourceHandle handle,
283
const Ogre::String& group, bool isManual = false, Ogre::ManualResourceLoader* loader = 0);
285
virtual ~ModelDefinition();
288
void setValid(bool valid);
290
//Ogre resource virtual functions
293
void unloadImpl(void);
295
size_t calculateSize(void) const;
297
//Model* createModel(Ogre::String name, Ogre::SceneManager* sceneManager);
300
* Gets the amount of scale that needs to be applied to derived Models.
303
Ogre::Real getScale() const;
304
void setScale(Ogre::Real scale);
307
* Gets how derived Models needs to be scaled.
311
const UseScaleOf getUseScaleOf() const;
312
void setUseScaleOf(const UseScaleOf useScale);
315
* Gets an optional translation vector which should be applied to derived Models.
318
const Ogre::Vector3& getTranslate() const;
319
void setTranslate(const Ogre::Vector3 translate);
322
* Whether contained entities should be shown or not.
324
* @return true if contained entities should be shown, else false
326
bool getShowContained() const;
327
void getShowContained(bool show);
330
* If set to something else than 0, all models beyond this distance won't be shown.
333
float getRenderingDistance() const;
334
void setRenderingDistance(float distance);
337
* Returns a vector defining how much, if ever, contained entities should be offset.
338
* If they shouldn't, Ogre::Vector3::ZERO will be returned.
339
* @return A offset vector.
341
const Ogre::Vector3& getContentOffset() const;
342
void setContentOffset(const Ogre::Vector3&);
345
* Gets the rotation of the model.
348
const Ogre::Quaternion& getRotation() const;
351
* Sets the rotation of the model.
354
void setRotation(const Ogre::Quaternion rotation);
358
* Gets a path to an icon resource, if defined.
359
* @return a path to an image which can be used as an icon for the model
361
const std::string& getIconPath() const;
365
* Creates and returns a new sub model definition for the supplied mesh name.
366
* @param meshname The name of the mesh to base the new sub model on. Must be a valid mesh.
369
SubModelDefinition* createSubModelDefinition(const std::string& meshname);
372
* Returns all SubModelDefinitions defined.
373
* @return The SubModelDefinitions store.
375
const SubModelDefinitionsStore& getSubModelDefinitions();
378
* Removes a certain SubModelDefinition.
379
* @param def The definition to remove.
381
void removeSubModelDefinition(SubModelDefinition* def);
384
* Creates and returns a new ActionDefintion with the given name.
385
* @param actionname The name of the new ActionDefinition.
386
* @return A pointer to the new ActionDefinition.
388
ActionDefinition* createActionDefinition(const std::string& actionname);
391
* Returns all ActionDefinitions defined.
394
const ActionDefinitionsStore& getActionDefinitions();
397
* Removes a certain ActionDefinition.
398
* @param def The definition to remove.
400
void removeActionDefinition(ActionDefinition* def);
402
const AttachPointDefinitionStore& getAttachPointsDefinitions();
405
Creates and returns a new ViewDefinition with the supplied name.
406
@param viewname The name of the view
407
@return A pointer to the new view.
409
ViewDefinition* createViewDefinition(const std::string& viewname);
412
* Returns all views defined.
415
const ViewDefinitionStore& getViewDefinitions();
418
* Removed a named view. If no view can be found, no exception will be thrown.
419
* @param name The name of the view to to remove.
421
void removeViewDefinition(const std::string name);
425
* Utility method for removing a defintion from a non-associative stores (vector, list etc.)
426
* @param def The defintion to remove.
427
* @param store The store to remove from.
429
template <typename T, typename T1>
430
static void removeDefinition(T* def, T1& store);
434
* Reloads all the Model instances that uses this definition.
436
void reloadAllInstances();
439
* Gets a pointer to the rendering scheme definition, or null if none specified.
442
const RenderingDefinition* getRenderingDefinition() const;
447
struct BindingDefinition
449
std::string EmitterVar;
450
std::string AtlasAttribute;
453
typedef std::vector<BindingDefinition> BindingSet;
455
struct ParticleSystemDefinition
461
typedef std::vector<ParticleSystemDefinition> ParticleSystemSet;
463
struct LightDefinition
465
Ogre::Light::LightTypes type;
466
Ogre::ColourValue diffuseColour, specularColour;
467
Ogre::Real range, constant, linear, quadratic;
468
Ogre::Vector3 position;
471
typedef std::vector<LightDefinition> LightSet;
476
* Adds a model instance to the internal store of instances. This method should be called from the class Model when a new Model is created.
479
void addModelInstance(Model*);
481
* Removed a model instance from the internal store of instances. This method should be called from the class Model when a new Model is removed.
484
void removeModelInstance(Model*);
487
A store of all model instances of this definition.
488
This can be used to update all instances at once.
490
ModelInstanceStore mModelInstances;
494
The minimum distance at which the model will be shown.
496
float mRenderingDistance;
498
SubModelDefinitionsStore mSubModels;
499
ActionDefinitionsStore mActions;
500
ParticleSystemSet mParticleSystems;
503
AttachPointDefinitionStore mAttachPoints;
505
UseScaleOf mUseScaleOf;
507
Ogre::Quaternion mRotation;
508
// const Ogre::String mPath;
511
Defines how much contained entities should be offset. ZERO if not.
513
Ogre::Vector3 mContentOffset;
516
Whether contained entities should be shown or not.
522
How, if any, to transform the model from the base position.
523
Defaults to a zeroed vector.
525
Ogre::Vector3 mTranslate;
529
ViewDefinitionStore mViews;
532
A path to an image resource which can be shown as an icon for the model.
534
std::string mIconPath;
536
RenderingDefinition* mRenderingDef;
540
/** Specialisation of SharedPtr to allow SharedPtr to be assigned to ModelDefnPtr
541
@note Has to be a subclass since we need operator=.
542
We could templatise this instead of repeating per Resource subclass,
543
except to do so requires a form VC6 does not support i.e.
544
ResourceSubclassPtr<T> : public SharedPtr<T>
546
class ModelDefnPtr : public Ogre::SharedPtr<ModelDefinition>
549
ModelDefnPtr() : Ogre::SharedPtr<ModelDefinition>() {}
550
explicit ModelDefnPtr(ModelDefinition* rep) : Ogre::SharedPtr<ModelDefinition>(rep) {}
551
ModelDefnPtr(const ModelDefnPtr& r) : Ogre::SharedPtr<ModelDefinition>(r) {}
552
ModelDefnPtr(const Ogre::ResourcePtr& r);
553
/// Operator used to convert a ResourcePtr to a ModelDefnPtr
554
ModelDefnPtr& operator=(const Ogre::ResourcePtr& r);
556
/// Override destroy since we need to delete Mesh after fully defined
557
// void destroy(void);
560
typedef ModelDefnPtr ModelDefinitionPtr;
565
inline const Ogre::Vector3& ModelDefinition::getContentOffset() const
567
return mContentOffset;
569
inline void ModelDefinition::setContentOffset(const Ogre::Vector3& offset)
571
mContentOffset = offset;
574
inline void ModelDefinition::setValid(bool valid)
579
inline size_t ModelDefinition::calculateSize(void) const
581
//TODO:implement this
585
inline Ogre::Real ModelDefinition::getScale() const
589
inline void ModelDefinition::setScale(Ogre::Real scale)
594
inline const ModelDefinition::UseScaleOf ModelDefinition::getUseScaleOf() const
598
inline void ModelDefinition::setUseScaleOf(const UseScaleOf useScale)
600
mUseScaleOf = useScale;
603
inline float ModelDefinition::getRenderingDistance() const
605
return mRenderingDistance;
608
inline void ModelDefinition::setRenderingDistance(float distance)
610
mRenderingDistance = distance;
613
inline const std::string& ModelDefinition::getIconPath() const
618
inline int AnimationDefinition::getIterations() const