Cogs.Core
VolumetricExtension.cpp
1#include "ExtensionRegistry.h"
2
3#include "Resources/ResourceStore.h"
4#include "Serialization/EntityReader.h"
5#include "Services/Variables.h"
6
7#include "Components/PointDataComponent.h"
8#include "Components/DensityFieldComponent.h"
9#include "Components/PointVisualizationComponent.h"
10#include "Components/OctComponent.h"
11
12#include "Systems/DensityFieldSystem.h"
13#include "Systems/PointVisualizationSystem.h"
14#include "Systems/OctSystem.h"
15#include "Systems/OctDummyProviderSystem.h"
16
17#include "../Extensions/IsoSurfaces/IsoSurfaces.h"
18
19#include "Foundation/Reflection/TypeDatabase.h"
20
21namespace Cogs::Core::Volumetric
22{
24 {
25 VolumetricExtension() { ExtensionRegistry::add(this, COGS_CORE_VERSION_STRING); }
26
27 bool initializeStatic() override;
28 bool initialize(Context * context) override;
29 const char * getExtensionKey() const override { return "Volumetric"; }
30
31 } volumetricExtension;
32}
33
35{
36 PointDataComponent::registerType();
37 PointVisualizationComponent::registerType();
38 DensityFieldComponent::registerType();
39 OctComponent::registerType();
40 VolOctDummyProviderComponent::registerType();
41 return true;
42}
43
45{
46 context->resourceStore->addResourceArchive("Cogs.Core.Extensions.Volumetric.zip");
47
48 context->resourceStore->addSearchPath("../Extensions/Volumetric/Data/Materials/");
49 context->resourceStore->addSearchPath("../Extensions/Volumetric/Data/Shaders/");
50
51 context->registerDynamicComponentType("VolPointDataComponent");
52
53 context->variables->set("Volumetric.IsoSurfaces.AVX2", false);
54
55
56 readEntityDefinition(R"(
57{ "name": "VolPointData",
58 "components" : [
59 "VolPointDataComponent",
60 "TransformComponent",
61 "SceneComponent",
62 ]
63})"
64, context->store);
65
66 readEntityDefinition(R"(
67{ "name": "VolPointVisualization",
68 "components": [
69 "VolPointVisualizationComponent",
70 "TransformComponent",
71 "SceneComponent",
72 "MeshComponent",
73 "MeshRenderComponent"
74 ],
75 "defaults": [
76 { "VolPointVisualizationComponent": { "material": "DefaultMaterial" }},
77 ],
78})"
79, context->store);
80
81 readEntityDefinition(R"(
82{ "name": "VolDensityField",
83 "components": [
84 "VolDensityFieldComponent",
85 "TransformComponent",
86 "SceneComponent",
87 "MeshComponent",
88 "SubMeshRenderComponent"
89 ],
90 "defaults": [
91 { "VolDensityFieldComponent": { "material": "DefaultMaterial" }},
92 ],
93})"
94, context->store);
95
96 readEntityDefinition(R"(
97{ "name": "VolOctDummy",
98 "components" : [
99 "VolOctComponent",
100 "VolOctDummyProviderComponent",
101 "TransformComponent",
102 "SceneComponent"
103 ]
104})"
105, context->store);
106
107 ExtensionRegistry::registerExtensionSystem<DensityFieldSystem>(context, SystemPriority::Geometry, 4);
108 ExtensionRegistry::registerExtensionSystem<PointVisualizationSystem>(context, SystemPriority::Geometry, 4);
109 ExtensionRegistry::registerExtensionSystem<OctSystem>(context, SystemPriority::PostView, 4);
110 ExtensionRegistry::registerExtensionSystem<OctDummyProviderSystem>(context, SystemPriority::PreGeometry, 4);
111
112 return true;
113}
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
void registerDynamicComponentType(const StringView &typeName)
Register a dynamic component type with the given typeName.
Definition: Context.cpp:380
class EntityStore * store
Entity store.
Definition: Context.h:231
std::unique_ptr< class Variables > variables
Variables service instance.
Definition: Context.h:180
std::unique_ptr< class ResourceStore > resourceStore
ResourceStore service instance.
Definition: Context.h:210
static void add(Extension *extension, StringView version)
Adds the given extension to the registry, ensuring the initialization methods are called at appropria...
Defines an extension to Cogs.Core and provides methods to override in order to initialize extension c...
@ PostView
Run after view data has been updated. Anything after this is appropriate for geometry depending on e....
Definition: Engine.h:66
@ Geometry
Run at the time geometry data is updated.
Definition: Engine.h:70
@ PreGeometry
Run before geometry updates are performed.
Definition: Engine.h:68
bool initialize(Context *context) override
Initialize extension for the given context.
bool initializeStatic() override
Initialize extension statically.
const char * getExtensionKey() const override
Get the extensions unique key, used to check for extension presence and retrieve extension specific d...