Sync editor rendering and UI workspace updates
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "ComponentEditors/MeshRendererComponentEditor.h"
|
||||
#include "ComponentEditors/ScriptComponentEditor.h"
|
||||
#include "ComponentEditors/TransformComponentEditor.h"
|
||||
#include "ComponentEditors/VolumeRendererComponentEditor.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
@@ -21,6 +22,7 @@ ComponentEditorRegistry::ComponentEditorRegistry() {
|
||||
RegisterEditor(std::make_unique<LightComponentEditor>());
|
||||
RegisterEditor(std::make_unique<MeshFilterComponentEditor>());
|
||||
RegisterEditor(std::make_unique<MeshRendererComponentEditor>());
|
||||
RegisterEditor(std::make_unique<VolumeRendererComponentEditor>());
|
||||
RegisterEditor(std::make_unique<ScriptComponentEditor>());
|
||||
}
|
||||
|
||||
|
||||
122
editor/src/ComponentEditors/VolumeRendererComponentEditor.h
Normal file
122
editor/src/ComponentEditors/VolumeRendererComponentEditor.h
Normal file
@@ -0,0 +1,122 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetReferenceEditorUtils.h"
|
||||
#include "IComponentEditor.h"
|
||||
#include "Core/IUndoManager.h"
|
||||
#include "UI/UI.h"
|
||||
|
||||
#include <XCEngine/Components/VolumeRendererComponent.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
|
||||
class VolumeRendererComponentEditor : public IComponentEditor {
|
||||
public:
|
||||
const char* GetComponentTypeName() const override {
|
||||
return "VolumeRenderer";
|
||||
}
|
||||
|
||||
const char* GetDisplayName() const override {
|
||||
return "Volume Renderer";
|
||||
}
|
||||
|
||||
bool Render(::XCEngine::Components::Component* component, IUndoManager* undoManager) override {
|
||||
auto* volumeRenderer = dynamic_cast<::XCEngine::Components::VolumeRendererComponent*>(component);
|
||||
if (!volumeRenderer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr const char* kUndoLabel = "Modify Volume Renderer";
|
||||
|
||||
bool changed = false;
|
||||
|
||||
const ComponentEditorAssetUI::AssetReferenceInteraction volumeFieldInteraction =
|
||||
ComponentEditorAssetUI::DrawAssetReferenceProperty(
|
||||
"Volume Field",
|
||||
volumeRenderer->GetVolumeFieldPath(),
|
||||
"Drop Volume Asset",
|
||||
{ ".nvdb" });
|
||||
|
||||
changed |= UI::ApplyPropertyChange(
|
||||
volumeFieldInteraction.clearRequested && !volumeRenderer->GetVolumeFieldPath().empty(),
|
||||
undoManager,
|
||||
kUndoLabel,
|
||||
[volumeRenderer]() {
|
||||
volumeRenderer->ClearVolumeField();
|
||||
});
|
||||
changed |= UI::ApplyPropertyChange(
|
||||
!volumeFieldInteraction.assignedPath.empty() &&
|
||||
volumeFieldInteraction.assignedPath != volumeRenderer->GetVolumeFieldPath(),
|
||||
undoManager,
|
||||
kUndoLabel,
|
||||
[volumeRenderer, assignedPath = volumeFieldInteraction.assignedPath]() {
|
||||
volumeRenderer->SetVolumeFieldPath(assignedPath);
|
||||
});
|
||||
|
||||
const ComponentEditorAssetUI::AssetReferenceInteraction materialInteraction =
|
||||
ComponentEditorAssetUI::DrawAssetReferenceProperty(
|
||||
"Material",
|
||||
volumeRenderer->GetMaterialPath(),
|
||||
"Drop Material Asset",
|
||||
{ ".mat" });
|
||||
|
||||
changed |= UI::ApplyPropertyChange(
|
||||
materialInteraction.clearRequested && !volumeRenderer->GetMaterialPath().empty(),
|
||||
undoManager,
|
||||
kUndoLabel,
|
||||
[volumeRenderer]() {
|
||||
volumeRenderer->ClearMaterial();
|
||||
});
|
||||
changed |= UI::ApplyPropertyChange(
|
||||
!materialInteraction.assignedPath.empty() &&
|
||||
materialInteraction.assignedPath != volumeRenderer->GetMaterialPath(),
|
||||
undoManager,
|
||||
kUndoLabel,
|
||||
[volumeRenderer, assignedPath = materialInteraction.assignedPath]() {
|
||||
volumeRenderer->SetMaterialPath(assignedPath);
|
||||
});
|
||||
|
||||
bool castShadows = volumeRenderer->GetCastShadows();
|
||||
changed |= UI::ApplyPropertyChange(
|
||||
UI::DrawPropertyBool("Cast Shadows", castShadows),
|
||||
undoManager,
|
||||
kUndoLabel,
|
||||
[volumeRenderer, castShadows]() {
|
||||
volumeRenderer->SetCastShadows(castShadows);
|
||||
});
|
||||
|
||||
bool receiveShadows = volumeRenderer->GetReceiveShadows();
|
||||
changed |= UI::ApplyPropertyChange(
|
||||
UI::DrawPropertyBool("Receive Shadows", receiveShadows),
|
||||
undoManager,
|
||||
kUndoLabel,
|
||||
[volumeRenderer, receiveShadows]() {
|
||||
volumeRenderer->SetReceiveShadows(receiveShadows);
|
||||
});
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool CanAddTo(::XCEngine::Components::GameObject* gameObject) const override {
|
||||
return gameObject && !gameObject->GetComponent<::XCEngine::Components::VolumeRendererComponent>();
|
||||
}
|
||||
|
||||
const char* GetAddDisabledReason(::XCEngine::Components::GameObject* gameObject) const override {
|
||||
if (!gameObject) {
|
||||
return "Invalid";
|
||||
}
|
||||
|
||||
return gameObject->GetComponent<::XCEngine::Components::VolumeRendererComponent>()
|
||||
? "Already Added"
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
bool CanRemove(::XCEngine::Components::Component* component) const override {
|
||||
return CanEdit(component);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user