3#include "LoadRvmCommand.h"
6#include "EditorState.h"
7#include "Resources/ModelManager.h"
8#include "Components/Core/ModelComponent.h"
9#include "Commands/EditorCommand.h"
10#include "Foundation/Platform/IO.h"
11#include "Foundation/Logging/Logger.h"
18Cogs::Core::LoadRvmCommand::LoadRvmCommand(EditorState* state,
const StringView& path,
bool openInRoot,
bool synchronous) :
19 ModalEditorCommand(state), pathStr(path), openInRoot(openInRoot), synchronous(synchronous)
21 fileName = Cogs::IO::fileName(pathStr);
24 createOption<bool>(rvmMdb2,
"rvm.mdb2",
true);
25 createOption<bool>(rvmMdb2GuessHierarchy,
"rvm.mdb2.guessHierarchy",
true);
26 createOption<bool>(rvmInheritAttributes,
"rvm.inheritAttributes",
false);
27 createOption<float>(rvmTessellateTolerance,
"rvm.tessellate.tolerance", 0.01f);
28 createOption<float>(rvmTessellateFeatureAngle,
"rvm.tessellate.featureAngle", 0.7f);
29 createOption<float>(rvmTessellateCullDiameter,
"rvm.tessellate.cullDiameter", -1.f);
30 createOption<bool>(rvmParseColorize,
"rvm.parse.colorize",
true);
31 createOption<bool>(rvmParseIgnoreAttributeIndentation,
"rvm.parse.ignoreAttributeIndentation",
true);
32 createOption<bool>(rvmParseIgnoreAttributeHierarchy,
"rvm.parse.ignoreAttributeHierarchy",
false);
33 createOption<bool>(rvmParseAllowReparent,
"rvm.parse.allowReparent",
true);
34 createOption<bool>(rvmVueExperimental,
"rvm.vue.experimental",
false);
46 ImGui::OpenPopup(
"Rvmparser file options");
47 if (ImGui::BeginPopupModal(
"Rvmparser file options",
nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
49 ImGui::Text(
"File: %s", fileName.c_str());
51 ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.4f);
53 ImGui::Checkbox(rvmMdb2.key.data(), &rvmMdb2.value);
54 ImGui::Checkbox(rvmMdb2GuessHierarchy.key.data(), &rvmMdb2GuessHierarchy.value);
55 ImGui::Checkbox(rvmInheritAttributes.key.data(), &rvmInheritAttributes.value);
57 ImGui::InputFloat(rvmTessellateTolerance.key.data(), &rvmTessellateTolerance.value);
58 ImGui::InputFloat(rvmTessellateFeatureAngle.key.data(), &rvmTessellateFeatureAngle.value);
59 ImGui::InputFloat(rvmTessellateCullDiameter.key.data(), &rvmTessellateCullDiameter.value);
61 ImGui::Checkbox(rvmParseColorize.key.data(), &rvmParseColorize.value);
62 ImGui::Checkbox(rvmParseIgnoreAttributeIndentation.key.data(), &rvmParseIgnoreAttributeIndentation.value);
63 ImGui::Checkbox(rvmParseIgnoreAttributeHierarchy.key.data(), &rvmParseIgnoreAttributeHierarchy.value);
64 ImGui::Checkbox(rvmParseAllowReparent.key.data(), &rvmParseAllowReparent.value);
66 ImGui::Checkbox(rvmVueExperimental.key.data(), &rvmVueExperimental.value);
69 ImGui::PopItemWidth();
71 ImGui::SetItemDefaultFocus();
72 if (ImGui::Button(
"OK", ImVec2(120, 0))) {
75 ImGui::CloseCurrentPopup();
78 if (ImGui::Button(
"Cancel", ImVec2(120, 0))) {
80 ImGui::CloseCurrentPopup();
91void Cogs::Core::LoadRvmCommand::loadFile()
93 std::string name = Cogs::IO::stem(pathStr);
94 std::unique_ptr<CreateEntityCommand> newCommand = std::make_unique<CreateEntityCommand>(state,
"ModelEntity", name, openInRoot);
95 EditorCommand* createCommand = state->editor->doApply(std::move(newCommand));
100 LOG_ERROR(logger,
"Could not create Entity ModelEntity");
104 ModelComponent* modelComponent = selected->
getComponent<ModelComponent>();
106 ModelLoadInfo* loadInfo = context->modelManager->createLoadInfo();
108 loadInfo->resourceId = NoResourceId;
109 loadInfo->resourcePath = pathStr;
112 loadInfo->modelFlags = flags;
113 if (context->variables->get(
"resources.models.autoReload",
false)) {
114 loadInfo->loadFlags |= ResourceLoadFlags::AutoReload;
117 loadInfo->properties = std::make_unique<PropertyStore>();
118 for (RvmparserOptionBase* option : allOptions) {
119 option->addPropertyTo(loadInfo->properties.get());
123 modelComponent->model = context->modelManager->loadResource(loadInfo);
124 modelComponent->waitForSubresources =
false;
125 modelComponent->setChanged();
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.
Log implementation class.
ModelLoadFlags
Model loading flags. May be combined with resource loading flags.
@ ForceSynchronous
Force loading the resource synchronously.
ResourceLoadFlags
Flags for describing how to load a resource.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Base class for Cogs Editor commands.
bool permanentUndo
True if cannot Redo after Undo.
void showGui() override
Display custom ImGUI.
bool continueModal() override
Shall return true while the GUI should still be shown. False when.
void beginModal() override
Called when the command is initiated.