1#include "ExtensionRegistry.h"
3#include "Components/Core/DynamicComponent.h"
4#include "Components/Core/TransformComponent.h"
5#include "Components/Core/MeshRenderComponent.h"
6#include "Components/Core/SceneComponent.h"
9#include "EntityStore.h"
11#include "Renderer/Renderer.h"
12#include "Renderer/RenderPipelineManager.h"
13#include "Renderer/Tasks/RenderTaskFactory.h"
15#include "Resources/ResourceStore.h"
16#include "Resources/MaterialInstance.h"
20#include "Services/Services.h"
22#include "AnnotationComponent.h"
23#include "RationalReducerComponent.h"
24#include "MeshReductionManager.h"
25#include "RRSimplifyCommand.h"
26#include "RRMultiSimplifyCommand.h"
27#include "RRSaveAllLodCommand.h"
29#include "Foundation/ComponentModel/Entity.h"
30#include "Foundation/Logging/Logger.h"
48 for (
auto & child : sceneComp->children) {
49 populateMeshItems(items, child.get());
54 items.emplace_back(
MeshItem{meshComp, meshRenderComp->material });
67 LOG_DEBUG(logger,
"done\n");
73 auto entity = state->getSelected();
76 std::vector<MeshItem> items;
77 populateMeshItems(items, entity);
79 if (items.empty())
return;
81 std::vector<Mesh *> meshes;
82 std::vector<MaterialInstance *> mats;
83 for (
auto & item : items) {
84 meshes.push_back(item.meshComp->meshHandle.resolve());
85 mats.push_back(item.mat.resolve());
88 float reductionPercent = 90.f;
89 float reductionEpsilon = 0.05f;
93 auto reducedMeshes = manager->reduce(meshes, mats, std::clamp(reductionPercent, 0.0f, 100.0f), reductionEpsilon);
95 if (reducedMeshes.size() != items.size()) {
96 LOG_ERROR(logger,
"Expected %zu meshes from reduce, got %zu.", items.size(), reducedMeshes.size());
99 for (
size_t i = 0; i < items.size(); i++) {
100 items[i].meshComp->meshHandle = reducedMeshes[i];
101 items[i].meshComp->setChanged();
103 LOG_DEBUG(logger,
"Simplified %zu meshes", items.size());
119 namespace RationalReducerExtension
132 RationalReducerComponent::registerType();
133 AnnotationComponent::registerType();
134 TypeDatabase::createType<MeshReductionManager>();
136 Editor::registerExtensionItem(
"RRSimplify",
"RR Simplify Mesh");
138 Editor::registerExtensionItem(
"RRMultiSimplify",
"RR create LOD levels");
140 Editor::registerExtensionItem(
"RRSaveAllLod",
"RR save LODs in separate files");
152 context->
resourceStore->addSearchPath(
"../Extensions/RationalReducer/Data/");
168 } rationalReducerExtensionInstance;
Container for components, providing composition of dynamic entities.
T * getComponent() const
Get a pointer to the first component implementing the given type in the entity.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
std::unique_ptr< class Services > services
Services.
void registerDynamicComponentType(const StringView &typeName)
Register a dynamic component type with the given typeName.
std::unique_ptr< class ResourceStore > resourceStore
ResourceStore service instance.
static void add(Extension *extension, StringView version)
Adds the given extension to the registry, ensuring the initialization methods are called at appropria...
Contains a handle to a Mesh resource to use when rendering using the MeshRenderComponent.
MeshHandle meshHandle
Handle to a Mesh resource to use when rendering.
Renders the contents of a MeshComponent using the given materials.
MaterialInstanceHandle material
Material used to render the mesh.
Contains information on how the entity behaves in the scene.
Log implementation class.
Interface to Rational Reducer for reducing meshes.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Contains reflection support.
Contains all Cogs related functionality.
Base class for Cogs Editor commands.
virtual void apply()=0
Run the command.
Defines an extension to Cogs.Core and provides methods to override in order to initialize extension c...
Task id struct used to identify unique Task instances.
virtual bool initialize(Context *context) override
Initialize extension for the given context.
virtual void cleanup(Context *context) override
Cleanup context bound extension content.
virtual const char * getExtensionKey() const override
Get the extensions unique key, used to check for extension presence and retrieve extension specific d...
virtual bool initializeStatic() override
Initialize extension statically.