1#include "Foundation/Logging/Logger.h"
3#include "Systems/Core/TransformSystem.h"
5#include "Resources/MaterialManager.h"
9#include "HighlightRegionSystem.h"
10#include "HighlightRegionBounds.h"
11#include "HighlightRegionPicker.h"
12#include "HighlightRegionRenderer.h"
22 if (!material || !material->isActive())
return;
27 bool update = regionComp.hasChanged();
29 if (!data.materialInstance) {
30 data.materialInstance =
context->materialInstanceManager->createMaterialInstance(material);
31 if (
VariableKey key = material->getTextureKey(
"offscreenDepth"); key != NoProperty) {
38 data.worldMatrix =
context->transformSystem->getLocalToWorld(trComp);
42 data.materialInstance->setVariant(
"DebugForceVisible", regionComp.debugForceVisible);
43 data.materialInstance->setVariant(
"DebugShowTriangles", regionComp.debugShowTriangles);
44 data.materialInstance->setVariant(
"DebugDiscardBehindNearNotEye", regionComp.debugDiscardBehindNearNotEye);
46 data.debugForceNoSplit = regionComp.debugForceNoSplit;
47 data.materialInstance->setVariant(
"SplitCube", !data.debugForceNoSplit);
49 size_t instanceCount = std::min(regionComp.id.size(),
50 std::min(std::min(regionComp.position.size(),
51 regionComp.rotation.size()),
52 std::min(regionComp.scale.size(),
53 regionComp.color.size())));
54 const float alpha = regionComp.alpha;
55 constexpr float sqrt3 = 1.74f;
56 data.instanceData.resize(instanceCount);
57 glm::vec3 boundsMin = glm::vec3(std::numeric_limits<float>::max());
58 glm::vec3 boundsMax = glm::vec3(-std::numeric_limits<float>::max());
59 for (
size_t i = 0; i < instanceCount; i++) {
60 const glm::quat& r = regionComp.rotation[i];
61 const glm::vec3& p = regionComp.position[i];
62 const glm::vec3& s = regionComp.scale[i];
63 const glm::vec4& c = regionComp.color[i];
65 float radius = sqrt3 * std::max(s.x, std::max(s.y, s.z));
66 boundsMin = glm::min(boundsMin, p - glm::vec3(radius));
67 boundsMax = glm::max(boundsMax, p + glm::vec3(radius));
70 const glm::mat3 R = glm::mat3_cast(r);
72 data.instanceData[i].data0 = glm::mat4(R[0][0], R[1][0], R[2][0], p.x,
73 R[0][1], R[1][1], R[2][1], p.y,
74 R[0][2], R[1][2], R[2][2], p.z,
75 c.r, c.g, c.b, c.a * alpha);
77 data.instanceData[i].data1 = glm::mat4(s.x, s.y, s.z, 0.f,
82 data.boundsMin = boundsMin;
83 data.boundsMax = boundsMax;
84 data.instanceDataUpdated =
true;
92 if (pool.size() == 0) {
94 material = context->materialManager->loadMaterial(
"HighlightRegionMaterial.material");
97 assert(bounds ==
nullptr);
99 context->bounds->addBoundsExtension(bounds);
101 assert(picker ==
nullptr);
103 context->rayPicking->addPickable(picker);
106 context->renderer->registerExtension(renderer);
108 LOG_DEBUG(logger,
"Registered bounds, picker, and renderer extensions");
117 if (pool.size() == 0) {
119 context->bounds->removeBoundsExtension(bounds);
124 context->rayPicking->removePickable(picker);
129 context->renderer->unregisterExtension(renderer);
133 LOG_DEBUG(logger,
"Unregistered bounds, picker, and renderer extensions");
ComponentType * getComponent() const
virtual ComponentHandle createComponent()
Create a new component instance.
Context * context
Pointer to the Context instance the system lives in.
virtual void destroyComponent(ComponentHandle)
Destroy the component held by the given handle.
void update()
Updates the system state to that of the current frame.
ComponentPool< ComponentType > pool
Pool of components managed by the system.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Log implementation class.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
uint16_t VariableKey
Used to lookup material properties.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Handle to a Component instance.
void destroyComponent(ComponentHandle component) override
ComponentHandle createComponent() override
@ MinMagMipPoint
Point sampling for both minification and magnification.