28 using std::make_unique;
32 using std::unique_ptr;
54 Scene::Scene(
const string& name,
const string& description):
BaseProperties(name, description)
59 library = make_unique<SceneLibrary>(
this);
64 if (defaultShaderParameter ==
nullptr)
continue;
75 auto haveDimension =
false;
76 auto levelLeft = 0.0f;
77 auto levelRight = 0.0f;
78 auto levelNear = 0.0f;
81 auto levelBottom = 0.0f;
82 Vector3 sideVector(1.0f, 0.0f, 0.0f);
83 Vector3 upVector(0.0f, 1.0f, 0.0f);
84 Vector3 forwardVector(0.0f, 0.0f, 1.0f);
88 for (
const auto& sceneEntity:
entities) {
91 if (sceneEntity->getPrototype()->getType() == Prototype_Type::MODEL) {
103 bbDimension.
scale(0.5f);
105 bbMin.
sub(bbDimension);
107 bbMax.
add(bbDimension);
108 auto entityLeft = bbMin.
getX();
109 auto entityRight = bbMax.
getX();
110 auto entityNear = bbMin.
getZ();
111 auto entityFar = bbMax.
getZ();
112 auto entityBottom = bbMin.
getY();
113 auto entityTop = bbMax.
getY();
114 if (haveDimension ==
false) {
115 levelLeft = entityLeft;
116 levelRight = entityRight;
117 levelNear = entityNear;
118 levelFar = entityFar;
119 levelTop = entityTop;
120 levelBottom = entityBottom;
121 haveDimension =
true;
123 if (entityLeft < levelLeft) levelLeft = entityLeft;
124 if (entityRight > levelRight) levelRight = entityRight;
125 if (entityNear < levelNear) levelNear = entityNear;
126 if (entityFar > levelFar) levelFar = entityFar;
127 if (entityTop > levelTop) levelTop = entityTop;
128 if (entityBottom < levelBottom) levelBottom = entityBottom;
131 for (
auto prototype:
library->getPrototypes()) {
132 if (prototype->getType() != Prototype_Type::TERRAIN)
continue;
133 auto terrain = prototype->getTerrain();
134 auto entityLeft = 0.0f;
135 auto entityRight = terrain->getWidth();
136 auto entityNear = 0.0f;
137 auto entityFar = terrain->getDepth();
138 if (entityLeft < levelLeft) levelLeft = entityLeft;
139 if (entityRight > levelRight) levelRight = entityRight;
140 if (entityNear < levelNear) levelNear = entityNear;
141 if (entityFar > levelFar) levelFar = entityFar;
142 for (
auto terrainHeight: terrain->getHeightVector()) {
143 auto entityTop = terrainHeight;
144 auto entityBottom = terrainHeight;
145 if (entityTop > levelTop) levelTop = entityTop;
146 if (entityBottom < levelBottom) levelBottom = entityBottom;
173 for (
const auto& entity:
entities) {
174 if (entity->getPrototype()->getId() == prototypeId) {
175 entitiesByPrototypeId.push_back(entity->getId());
182 vector<string> entitiesToRemove;
184 for (
const auto& entityId: entitiesToRemove) {
192 if (replaceEntity ==
nullptr)
195 for (
const auto& entity:
entities) {
196 if (entity->getPrototype()->getId() == searchPrototypeId) {
197 entity->setPrototype(replaceEntity);
205 if (_entity !=
nullptr) {
208 "Scene::addEntity():: entity with id '" +
210 "' already exists. Removing it!"
214 entities.push_back(unique_ptr<SceneEntity>(entity));
222 auto entity = entityByIdIt->second;
223 for (
auto i = 0; i <
entities.size(); i++) {
230 if (entity->getPrototype()->getType() == Prototype_Type::ENVIRONMENTMAPPING)
environmentMappingIds.erase(entity->getId());
238 if (
id == newId)
return true;
239 if (
getEntity(newId) !=
nullptr)
return false;
242 auto entity = entityByIdIt->second;
244 if (entity->getPrototype()->getType() == Prototype_Type::ENVIRONMENTMAPPING)
environmentMappingIds.erase(entity->getId());
245 entity->setName(newId);
247 if (entity->getPrototype()->getType() == Prototype_Type::ENVIRONMENTMAPPING)
environmentMappingIds.insert(entity->getId());
258 return entityByIdIt->second;
Color 4 definition class.
static const Shader::ParameterDefaults * getDefaultShaderParameter(const string &shaderId, const string ¶meterName)
Returns shader parameter default value for given shader id and parameter name.
static const vector< string > getShaderParameterNames(const string &shaderId)
Returns shader parameter names of shader with given id.
TDME2 engine entity shader parameters.
void setShaderParameter(const string ¶meterName, const ShaderParameter ¶meterValue)
Set shader parameter for given parameter name.
void setShader(const string &shaderId)
Set shader.
Representation of a 3D model.
Represents rotation orders of a model.
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
const Vector3 & getCenter() const
void fromBoundingVolumeWithTransform(BoundingBox *original, const Transform &transform)
Create bounding volume from given original(of same type) with applied transform.
const Vector3 & getDimensions() const
void update()
Updates this bounding box.
Bounding volume interface.
Prototype terrain definition.
Prototype_Type * getType()
Prototype * getPrototype()
Scene prototype library definition.
Prototype * getPrototype(int id)
Get a prototype by given id.
map< string, SceneEntity * > entitiesById
bool removeEntity(const string &id)
Removes an entity from scene.
void replacePrototypeByIds(int searchPrototypeId, int newPrototypeId)
Replace prototype of given search prototype with new prototype.
virtual ~Scene()
Destructor.
void removeEntitiesByPrototypeId(int prototypeId)
Remove entities with given prototype id.
EntityShaderParameters skyShaderParameters
void getEntitiesByPrototypeId(int prototypeId, vector< string > &entitiesByPrototypeId)
Get entities with given prototype id.
RotationOrder * rotationOrder
unique_ptr< SceneLibrary > library
bool renameEntity(const string &id, const string &newId)
Rename an entity from scene.
SceneEntity * getEntity(const string &id)
Returns scene entity by id.
void addEntity(SceneEntity *entity)
Adds an entity to scene.
set< string > environmentMappingIds
string applicationRootPathName
SceneLibrary * getLibrary()
void update()
Update scene dimension, bounding box, center.
vector< unique_ptr< SceneEntity > > entities
void clearEntities()
Clears all scene entities.
void computeBoundingBox()
Computes scene bounding box.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Vector3 & setX(float x)
Sets x component.
Vector3 & add(float scalar)
Adds a scalar.
Vector3 & setY(float y)
Sets y component.
Vector3 clone() const
Clones this vector3.
Vector3 & sub(float scalar)
Subtracts a scalar.
Vector3 & scale(float scalar)
Scales by scalar.
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
Vector3 & setZ(float z)
Sets z component.
Vector4 class representing vector4 mathematical structure and operations with x, y,...