1#include "ExtensionRegistry.h"
2#include "Resources/MeshManager.h"
3#include "Resources/MaterialManager.h"
4#include "Components/Core/MeshComponent.h"
5#include "Components/Core/SubMeshRenderComponent.h"
6#include "Components/Core/SceneComponent.h"
9#include "Components/PointDataComponent.h"
11#include "../Tasks/DensityFieldTask.h"
12#include "DensityFieldSystem.h"
14#include "Foundation/ComponentModel/Entity.h"
18 for (
auto & fieldComp :
pool) {
19 if(!fieldComp.pointData)
continue;
21 auto & fieldData = getData(&fieldComp);
23 if (!fieldData.persistentData) fieldData.persistentData = std::make_shared<DensityFieldTaskData>();
26 if (!pointComp)
continue;
31 if (pointComp->hasChanged()
32 || (fieldData.pointPositionGeneration != pointComp->positions.getGeneration())
33 || (fieldData.pointDataGeneration != pointComp->data.getGeneration())
36 fieldData.needsUpdate =
true;
39 if (fieldComp.hasChanged()) {
40 if (glm::any(glm::notEqual(fieldData.resolution, fieldComp.resolution))) {
41 fieldData.resolution = fieldComp.resolution;
42 fieldData.needsUpdate =
true;
46 if (!pointComp->positions) {
47 meshComp->meshHandle = {};
53 if (fieldData.persistentData.use_count() == 1) {
56 if (fieldData.persistentData->context !=
nullptr) {
57 fieldData.persistentData->context =
nullptr;
59 meshComp->meshHandle = fieldData.persistentData->mesh;
63 meshRenderComp->
materials.resize(fieldData.persistentData->thresholds.size());
65 for (
size_t i = 0; i < fieldData.persistentData->thresholds.size(); i++) {
66 if (!meshRenderComp->materials[i]) {
67 meshRenderComp->materials[i] =
context->materialInstanceManager->createMaterialInstance(
context->materialManager->getDefaultMaterial());
70 if (fieldComp.innerLayerOpaque && i == 0) {
71 meshRenderComp->materials[i]->setOpaque();
73 meshRenderComp->materials[i]->setTransparent();
75 meshRenderComp->materials[i]->clone(fieldComp.material.resolve());
77 if (meshRenderComp->materials[i]->isDefaultMaterial()) {
78 meshRenderComp->materials[i]->setPermutation(
"Default");
79 meshRenderComp->materials[i]->setVariant(
"Textured",
true);
80 meshRenderComp->materials[i]->setVariant(
"EnableLighting",
true);
83 meshRenderComp->materials[i]->setTransparent();
84 meshRenderComp->materials[i]->options.depthBiasEnabled =
true;
85 meshRenderComp->materials[i]->options.depthBias.slope = 0.f;
86 meshRenderComp->materials[i]->options.depthBias.constant = i*fieldComp.layerDepthBiasStep;
87 meshRenderComp->materials[i]->options.depthBias.clamp = 100000.f;
89 meshRenderComp->setChanged();
93 if (fieldData.needsUpdate) {
94 auto r = fieldData.resolution;
96 fieldData.pointPositionGeneration = pointComp->positions.getGeneration();
97 if (pointComp->data) {
98 fieldData.pointDataGeneration = pointComp->data.getGeneration();
101 if (fieldComp.thresholds.empty()
102 || pointComp->positions.empty()
103 || (std::min(std::min(r.x, r.y), r.z) == 0)
104 || !sceneComp->visible)
112 fieldData.persistentData->update(
context,
115 pointComp->positions,
void setChanged()
Sets the component to the ComponentFlags::Changed state with carry.
ComponentType * getComponent() const
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 TaskManager > taskManager
TaskManager service instance.
Contains a handle to a Mesh resource to use when rendering using the MeshRenderComponent.
Contains information on how the entity behaves in the scene.
bool visible
If the entity this component is a member of should be visible.
Renders a mesh with flexible submesh usage.
std::vector< MaterialInstanceHandle > materials
Materials used to render individual sub-meshes.
static const ResourceHandle_t NoHandle
Handle representing a default (or none if default not present) resource.