1#include "MeshGeneratorSystem.h"
3#include "Foundation/Logging/Logger.h"
5#include "Components/Core/MeshComponent.h"
6#include "Components/Core/CameraComponent.h"
7#include "Components/Core/TransformComponent.h"
8#include "Components/Core/LodComponent.h"
10#include "Systems/Core/TransformSystem.h"
11#include "Systems/Core/CameraSystem.h"
12#include "Systems/Core/LodSystem.h"
16#include "Utilities/TessellationPredicates.h"
18#include "Services/Services.h"
20#include "Generators/MeshGenerator.h"
33 auto camComp =
context->cameraSystem->getMainCamera();
34 for (
auto & component :
pool) {
35 auto & data = getData(&component);
40 const auto & lodData =
context->lodSystem->getData<
LodData>(lodComp);
43 glm::vec4 screenReferencePoint = lodData.localToClip * glm::vec4(0.f, 0.f, 0.f, 1.f);
45 float minSamples = 3.f;
46 float maxSamples = 4.f * float(component.samples);
47 float epsilon = lodComp->geometricTolerance;
49 screenReferencePoint, 1.f);
52 float nonIntegerSamples = 0.f;
53 switch (
context->lodSystem->geometricErrorKind) {
54 case GeometricErrorKind::AreaBased:
55 nonIntegerSamples = sphereSectorGeometricAreaPredicate(rr, camComp->viewportSize,
56 epsilon*epsilon, minSamples, maxSamples);
58 case GeometricErrorKind::DistanceBased:
59 nonIntegerSamples = sphereSectorGeometricDistancePredicate(rr, camComp->viewportSize,
60 epsilon, minSamples, maxSamples);
63 int samples =
static_cast<int>(std::ceil(nonIntegerSamples));
64 if (samples == data.currentSamples && !component.hasChanged()) {
67 data.currentSamples = samples;
70 if (!component.hasChanged() ||
71 (data.currentType == component.shape &&
72 data.currentSamples == component.samples &&
73 data.currentSize == component.size &&
74 data.arcStart == component.arcStart &&
75 data.arcEnd == component.arcEnd)) {
79 data.currentSamples = component.samples;
80 data.currentSize = component.size;
83 data.currentType = component.shape;
84 data.arcStart = component.arcStart;
85 data.arcEnd = component.arcEnd;
89 assert(meshComponent &&
"No mesh component found to assign generated mesh.");
91 meshComponent->meshHandle = meshGenerator->getMesh(data.currentType, data.currentSamples, component.size, data.arcStart, data.arcEnd);
92 meshComponent->setChanged();
Context * context
Pointer to the Context instance the system lives in.
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.
std::unique_ptr< class Services > services
Services.
Contains data describing level of detail behavior for the entity the component belongs to.
Contains a handle to a Mesh resource to use when rendering using the MeshRenderComponent.
Log implementation class.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
COGSCORE_DLL_API glm::vec2 localSphereRadiusInScreenSpace(const glm::mat4 &localToClip, const glm::mat4 &clipToLocal, const glm::vec4 &clipPosition, const float localRadius)
Given a screen space reference position and a local space radius, find the corresponding screen space...
@ GeometricTolerance
Use a geometric error bound to determine how refined geometry needs to be at its current position.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Defines level of detail data calculated by the LodSystem.