19EntityHierarchy::EntityHierarchy(
const string&
id): id(id)
31 for (
auto entity:
entities)
delete entity;
50 if (entityHierarchyLevel ==
nullptr || entityHierarchyLevel->parent ==
nullptr)
return nullptr;
51 return entityHierarchyLevel->entity;
56 if (_entity == entity) {
57 Console::println(
"EntityHierarchy::addEntity(): " + entity->
getId() +
": entity already added!");
77 if (parentEntityHierarchyLevel ==
nullptr) {
78 Console::println(
"EntityHierarchy::addEntity(): parent '" + parentId +
"': not found");
82 childEntityHierarchyLevel.
id = entity->
getId();
83 childEntityHierarchyLevel.
parent = parentEntityHierarchyLevel;
84 childEntityHierarchyLevel.
entity = entity;
85 parentEntityHierarchyLevel->children[entity->
getId()] = childEntityHierarchyLevel;
94 if (entityHierarchyLevel ==
nullptr || entityHierarchyLevel->parent ==
nullptr) {
99 vector<string> children;
100 for (
auto& childIt: entityHierarchyLevel->children) children.push_back(childIt.first);
104 auto entity = entityHierarchyLevel->entity;
106 entityHierarchyLevel->parent->children.erase(
id);
119 if (parentEntityHierarchyLevel ==
nullptr) {
122 for (
auto entityIt: parentEntityHierarchyLevel->children) {
123 entities.push_back(entityIt.second.entity);
129 for (
auto entityIt: entityHierarchyLevel.
children) {
130 auto entity = entityIt.second.entity;
132 if (firstEntity ==
true) {
138 entity->applyParentTransformations(parentTransformations);
140 for (
auto& childIt: entityHierarchyLevel.
children) {
141 updateHierarchy(childIt.second.entity->getTransformations(), childIt.second, depth + 1, firstEntity);
156 auto firstEntity =
true;
164 auto firstEntity =
true;
171 if (this->enabled ==
enabled)
return;
194 if (this->frustumCulling ==
true) {
212 for (
auto entity:
entities) entity->dispose();
220 for (
auto entity:
entities) entity->initialize();
void deregisterEntity(Entity *entity)
Removes a entity from internal lists, those entities can also be sub entities from entity hierarchy o...
void removeEntityFromLists(Entity *entity)
Remove entity.
void registerEntity(Entity *entity)
Adds a entity to internal lists, those entities can also be sub entities from entity hierarchy or par...
Entity hierarchy to be used with engine class.
BoundingBox boundingBoxTransformed
void dispose() override
Dispose this object 3d.
void initialize() override
Initiates this object 3d.
void update() override
Update transformations.
void addEntity(Entity *entity, const string &parentId=string())
Adds a entity to the hierarchy.
void fromTransformations(const Transformations &transformations) override
Set up this transformations from given transformations.
EntityHierarchyLevel entityRoot
vector< Entity * > entities
EntityHierarchyLevel * getEntityHierarchyLevel(const string &id)
Get entity hierarchy level by given entity id.
const vector< Entity * > query(const string &parentId=string())
Query direct sub entities for given parent entity id.
void removeEntity(const string &id)
Removes a entity from hierarchy by given unique entity id.
void setFrustumCulling(bool frustumCulling) override
Set frustum culling.
void setEngine(Engine *engine) override
Set up engine.
void setEnabled(bool enabled) override
Enable/disable rendering.
Entity * getEntity(const string &id)
bool isFrustumCulling() override
virtual ~EntityHierarchy()
Destructor.
void updateHierarchy(const Transformations &parentTransformations, EntityHierarchyLevel &entityHierarchyLevel, int depth, bool &firstEntity)
Update hierarchy from given entity hierarchy level ongoing.
void setRenderer(Renderer *renderer) override
Set up renderer.
virtual void setRenderer(Renderer *renderer)=0
Set up renderer.
virtual const string & getId()=0
virtual void setEngine(Engine *engine)=0
Set up engine.
virtual void setEffectColorMul(const Color4 &effectColorMul)=0
Set effect color that will be multiplied with fragment color.
virtual void initialize()=0
Initiates this object 3d.
virtual void setContributesShadows(bool contributesShadows)=0
Enable/disable contributes shadows.
virtual void setPickable(bool pickable)=0
Set this object pickable.
virtual void setReceivesShadows(bool receivesShadows)=0
Enable/disable receives shadows.
virtual void setEffectColorAdd(const Color4 &effectColorAdd)=0
Set effect color that will be added to fragment color.
virtual void setParentEntity(Entity *entity)=0
Set parent entity, needs to be called before adding to engine.
Object 3D to be used with engine class.
void set(const array< float, 4 > &color)
Set up color.
void fromBoundingVolumeWithTransformations(BoundingBox *original, const Transformations &transformations)
Create bounding volume from given original(of same type) with applied transformations.
void extend(BoundingBox *boundingBox)
Extend bounding box with given bounding box.
void update()
Updates this bounding box.
map< string, EntityHierarchyLevel > children
EntityHierarchyLevel * parent
virtual void updateEntity(Entity *entity)=0
Updates a entity.
virtual void addEntity(Entity *entity)=0
Adds a entity.
virtual void removeEntity(Entity *entity)=0
Removes a entity.