Skip to content

Commit

Permalink
Traktor: Implemented support for entity state in InstanceMeshComponen…
Browse files Browse the repository at this point in the history
…t so we can hide/show in editor properly.
  • Loading branch information
apistol78 committed May 27, 2024
1 parent 912a5d7 commit d4ed6d2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
25 changes: 23 additions & 2 deletions code/Mesh/Instance/InstanceMeshComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ void InstanceMeshComponent::destroy()
void InstanceMeshComponent::setWorld(world::World* world)
{
// Remove from last world.
if (m_world != nullptr)
if (m_world != nullptr && m_cullingInstance != nullptr)
{
T_FATAL_ASSERT(m_cullingInstance != nullptr);
world::CullingComponent* culling = m_world->getComponent< world::CullingComponent >();
culling->releaseInstance(m_cullingInstance);
}
Expand All @@ -60,6 +59,28 @@ void InstanceMeshComponent::setWorld(world::World* world)
m_world = world;
}

void InstanceMeshComponent::setState(const world::EntityState& state, const world::EntityState& mask)
{
const bool visible = (state.visible && mask.visible);
if (visible)
{
if (!m_cullingInstance)
{
world::CullingComponent* culling = m_world->getComponent< world::CullingComponent >();
m_cullingInstance = culling->allocateInstance(this, (intptr_t)m_mesh.getResource());
m_cullingInstance->setTransform(m_transform.get0());
}
}
else
{
if (m_cullingInstance)
{
world::CullingComponent* culling = m_world->getComponent< world::CullingComponent >();
culling->releaseInstance(m_cullingInstance);
}
}
}

void InstanceMeshComponent::setTransform(const Transform& transform)
{
MeshComponent::setTransform(transform);
Expand Down
2 changes: 2 additions & 0 deletions code/Mesh/Instance/InstanceMeshComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class T_DLLCLASS InstanceMeshComponent

virtual void setWorld(world::World* world) override final;

virtual void setState(const world::EntityState& state, const world::EntityState& mask) override final;

virtual void setTransform(const Transform& transform) override final;

virtual Aabb3 getBoundingBox() const override final;
Expand Down
2 changes: 2 additions & 0 deletions code/World/Entity/CullingComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ void CullingComponent::releaseInstance(Instance*& instance)
{
T_FATAL_ASSERT(instance->owner == this);
auto it = std::find(m_instances.begin(), m_instances.end(), instance);
T_FATAL_ASSERT(it != m_instances.end());
m_instances.erase(it);
delete instance;
instance = nullptr;
m_instanceBufferDirty = true;
}

void CullingComponent::Instance::setTransform(const Transform& transform)
Expand Down

0 comments on commit d4ed6d2

Please sign in to comment.