From 07b902d034daec343a89fbd6274d0ac24efe438b Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Sun, 29 Nov 2026 15:18:35 +0100 Subject: [PATCH] feat(editor): a window to see and edit the components of an EU07M model Selecting a scenery model loaded from an .eu07m file opens the "EU07M model" window: the tree of the nodes with their transforms and the components aimed at each of them, then the components of the model. - The fields of SOCK, JOIN, CHNL (with its bindings), LGHT, LSLT, EMIT, COLL and MREF are edited; the other components are shown by size. - The clip flags are edited, and a time slider holds the instance at a pose (time stands still in the editor); TAnimModel::play_clip takes the second to start from. - Channel sliders try the channels on the instance without changing the file. - "Save the model" validates the model and writes the file through a temporary one; the family store is kept. "Read it again" drops the changes. The geometry, the mapping and the materials aren't edited. The Polish texts of the window are added to lang/editor_pl.po. --- CMakeLists.txt | 1 + application/editoruilayer.cpp | 1 + application/editoruilayer.h | 2 + application/editoruimodel.cpp | 526 ++++++++++++++++++++++++++++++++++ application/editoruimodel.h | 51 ++++ docs/eu07m-format.md | 15 + lang/editor_pl.po | 204 +++++++++++++ model/AnimModel.cpp | 6 +- model/AnimModel.h | 7 +- 9 files changed, 808 insertions(+), 5 deletions(-) create mode 100644 application/editoruimodel.cpp create mode 100644 application/editoruimodel.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b6ea75106..69a7de615 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -331,6 +331,7 @@ set(SOURCES "application/scriptedinput.cpp" "input/editormouseinput.cpp" "application/editoruilayer.cpp" +"application/editoruimodel.cpp" "application/editoruipanels.cpp" "application/scenarioloadermode.cpp" "application/scenarioloaderuilayer.cpp" diff --git a/application/editoruilayer.cpp b/application/editoruilayer.cpp index 42a3d6289..4abaabc18 100644 --- a/application/editoruilayer.cpp +++ b/application/editoruilayer.cpp @@ -637,6 +637,7 @@ void editor_ui::render_() render_tool_options(); render_inspector(); render_scene(); + m_modelpanel.render(m_node); // status bar: the outcome of the last operation, and the selected node if (ImGui::BeginViewportSideBar("##editorstatusbar", viewport, ImGuiDir_Down, ImGui::GetFrameHeight(), flags)) { diff --git a/application/editoruilayer.h b/application/editoruilayer.h index d7fc890e1..2b9c990b8 100644 --- a/application/editoruilayer.h +++ b/application/editoruilayer.h @@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/. #include "application/uilayer.h" #include "application/editoruipanels.h" +#include "application/editoruimodel.h" namespace scene { @@ -268,6 +269,7 @@ class editor_ui : public ui_layer std::function m_bendoptions; bool m_bendexpand{false}; scene::basic_node *m_node{nullptr}; // currently bound scene node, if any + eu07m_model_panel m_modelpanel; // the EU07M model of the selected instance, its components bool m_track{false}; // windows of an unpinned dock, and the edge they're hidden at struct autohide_group diff --git a/application/editoruimodel.cpp b/application/editoruimodel.cpp new file mode 100644 index 000000000..590835d95 --- /dev/null +++ b/application/editoruimodel.cpp @@ -0,0 +1,526 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#include "stdafx.h" +#include "application/editoruimodel.h" + +#include "model/AnimModel.h" +#include "model/Model3d.h" +#include "model/eu07m/eu07m_dump.h" +#include "model/eu07m/eu07m_io.h" +#include "model/eu07m/eu07m_store.h" +#include "scene/scenenode.h" +#include "utilities/Globals.h" +#include "utilities/translation.h" +#include "utilities/utilities.h" + +#include +#include +#include +#include +#include + +namespace +{ + +namespace payload = eu07m::payload; + +// the nodes of a model the panel shows open at once +constexpr std::size_t small_model{32}; + +// the name of a component type, its four characters +std::string fourcc_text(std::uint32_t const Type) +{ + std::string result(4, ' '); + for (std::size_t idx = 0; idx < 4; ++idx) + { + result[idx] = static_cast((Type >> (8 * idx)) & 0xFF); + } + return result; +} + +// a string of the model edited by its text; an empty text is no string +bool edit_string(char const *Label, eu07m::model &Model, std::uint32_t &Id) +{ + std::array buffer{}; + auto const text{Model.string(Id)}; + std::memcpy(buffer.data(), text.data(), std::min(text.size(), buffer.size() - 1)); + ImGui::InputText(Label, buffer.data(), buffer.size()); + if (false == ImGui::IsItemDeactivatedAfterEdit()) + { + return false; + } + std::string_view const edited{buffer.data()}; + Id = edited.empty() ? eu07m::no_index : Model.intern(edited); + return true; +} + +// an enumeration of the format picked from the names of its values +template bool edit_enum(char const *Label, Enum_ &Value, std::initializer_list Names) +{ + std::vector const names{Names}; + auto index{static_cast(Value)}; + if (false == ImGui::Combo(Label, &index, names.data(), static_cast(names.size()))) + { + return false; + } + Value = static_cast(index); + return true; +} + +bool edit_flag(char const *Label, std::uint8_t &Flags, std::uint8_t const Bit) +{ + auto set{(Flags & Bit) != 0}; + if (false == ImGui::Checkbox(Label, &set)) + { + return false; + } + Flags = static_cast(set ? (Flags | Bit) : (Flags & ~Bit)); + return true; +} + +// a rotation as a quaternion x y z w, kept of unit length +bool edit_rotation(char const *Label, std::array &Rotation) +{ + if (false == ImGui::DragFloat4(Label, Rotation.data(), 0.01f, -1.f, 1.f, "%.3f")) + { + return false; + } + auto const length{std::sqrt(Rotation[0] * Rotation[0] + Rotation[1] * Rotation[1] + Rotation[2] * Rotation[2] + Rotation[3] * Rotation[3])}; + if (length > 0.f) + { + for (auto &component : Rotation) + { + component /= length; + } + } + return true; +} + +// the payload of the component at Offset of its data, edited by Edit; written back when it changed +template bool edit_payload(eu07m::model &Model, std::uint32_t const Index, std::size_t const Offset, Edit_ &&Edit) +{ + auto const &record{Model.components[Index]}; + auto const at{std::size_t{record.data_offset} + Offset}; + if ((Offset + sizeof(Payload_) > record.data_size) || (at + sizeof(Payload_) > Model.component_data.size())) + { + ImGui::TextDisabled("%s", STR_C("The data of the component is cut short")); + return false; + } + Payload_ value; + std::memcpy(&value, Model.component_data.data() + at, sizeof(value)); + if (false == Edit(value)) + { + return false; + } + std::memcpy(Model.component_data.data() + at, &value, sizeof(value)); + return true; +} + +bool edit_socket(eu07m::model &Model, payload::socket &Socket) +{ + auto changed{edit_string(STR_C("Role"), Model, Socket.role)}; + changed |= edit_enum(STR_C("End of the vehicle"), Socket.end, {STR_C("none"), STR_C("front"), STR_C("rear")}); + changed |= ImGui::InputScalar(STR_C("Index"), ImGuiDataType_U16, &Socket.index); + changed |= ImGui::DragFloat3(STR_C("Position"), Socket.position.data(), 0.001f, 0.f, 0.f, "%.4f"); + changed |= edit_rotation(STR_C("Rotation"), Socket.rotation); + return changed; +} + +bool edit_joint(eu07m::model &Model, payload::joint &Joint) +{ + auto changed{edit_enum(STR_C("Kind"), Joint.kind, {STR_C("fixed"), STR_C("hinge"), STR_C("ball"), STR_C("slider"), STR_C("screw")})}; + auto limited{Joint.limited != 0}; + if (ImGui::Checkbox(STR_C("Limited"), &limited)) + { + Joint.limited = limited ? 1 : 0; + changed = true; + } + changed |= edit_string(STR_C("Role"), Model, Joint.role); + changed |= ImGui::DragFloat3(STR_C("Axis"), Joint.axis.data(), 0.01f, -1.f, 1.f, "%.3f"); + changed |= ImGui::DragFloat(STR_C("Minimum"), &Joint.minimum, 0.01f); + changed |= ImGui::DragFloat(STR_C("Maximum"), &Joint.maximum, 0.01f); + changed |= ImGui::DragFloat(STR_C("Rest"), &Joint.rest, 0.01f); + if (Joint.kind == payload::joint_kind::screw) + { + changed |= ImGui::DragFloat(STR_C("Pitch, m a turn"), &Joint.pitch, 0.0005f, 0.f, 1.f, "%.4f"); + } + return changed; +} + +bool edit_channel(eu07m::model &Model, payload::channel &Channel) +{ + auto changed{edit_string(STR_C("Name"), Model, Channel.name)}; + changed |= ImGui::DragFloat(STR_C("Minimum"), &Channel.minimum, 0.01f); + changed |= ImGui::DragFloat(STR_C("Maximum"), &Channel.maximum, 0.01f); + changed |= ImGui::DragFloat(STR_C("Initial value"), &Channel.initial, 0.01f); + return changed; +} + +bool edit_binding(payload::channel_binding &Binding) +{ + auto changed{edit_enum(STR_C("Bound to"), Binding.kind, {STR_C("joint"), STR_C("clip"), STR_C("variants"), STR_C("light slot")})}; + auto target{Binding.target == eu07m::no_index ? -1 : static_cast(Binding.target)}; + if (ImGui::InputInt(STR_C("Target (component or clip, -1 none)"), &target)) + { + Binding.target = target < 0 ? eu07m::no_index : static_cast(target); + changed = true; + } + changed |= ImGui::DragFloat(STR_C("Scale"), &Binding.scale, 0.01f); + changed |= ImGui::DragFloat(STR_C("Offset"), &Binding.offset, 0.01f); + return changed; +} + +bool edit_light(payload::light &Light) +{ + auto changed{edit_enum(STR_C("Kind"), Light.kind, {STR_C("point"), STR_C("spot")})}; + changed |= edit_flag(STR_C("Lights itself"), Light.flags, payload::light_flags::shade_self); + changed |= edit_flag(STR_C("No shadows"), Light.flags, payload::light_flags::no_shadows); + changed |= edit_flag(STR_C("Soft falloff"), Light.flags, payload::light_flags::soft_falloff); + changed |= edit_flag(STR_C("Light only"), Light.flags, payload::light_flags::light_only); + changed |= ImGui::ColorEdit4(STR_C("Colour"), Light.color.data()); + changed |= ImGui::DragFloat(STR_C("Intensity"), &Light.hotspot_power, 0.01f, 0.f, 100.f); + changed |= ImGui::DragFloat(STR_C("Radius"), &Light.radius, 0.1f, 0.f, 10000.f); + changed |= ImGui::DragFloat(STR_C("Cosine of the cone"), &Light.cos_falloff, 0.005f, -1.f, 1.f); + changed |= ImGui::DragFloat(STR_C("Cosine of the hotspot"), &Light.cos_hotspot, 0.005f, -1.f, 1.f); + return changed; +} + +bool edit_light_slot(payload::light_slot &Slot) +{ + auto changed{ImGui::InputScalar(STR_C("Slot"), ImGuiDataType_U16, &Slot.slot)}; + changed |= ImGui::DragFloat(STR_C("Initial state"), &Slot.initial, 0.01f, 0.f, 10.f); + changed |= ImGui::ColorEdit3(STR_C("Colour (negative: of the sources)"), Slot.color.data(), ImGuiColorEditFlags_Float | ImGuiColorEditFlags_HDR); + return changed; +} + +bool edit_emitter(payload::emitter &Emitter) +{ + auto changed{edit_enum(STR_C("Kind"), Emitter.kind, {STR_C("smoke"), STR_C("steam"), STR_C("sparks")})}; + changed |= ImGui::DragFloat3(STR_C("Direction"), Emitter.direction.data(), 0.01f, -1.f, 1.f, "%.3f"); + return changed; +} + +bool edit_collision(eu07m::model &Model, payload::collision &Collision) +{ + auto changed{edit_enum(STR_C("Shape"), Collision.kind, {STR_C("box"), STR_C("sphere"), STR_C("capsule")})}; + changed |= edit_string(STR_C("Role"), Model, Collision.role); + changed |= ImGui::DragFloat3(STR_C("Centre"), Collision.centre.data(), 0.001f, 0.f, 0.f, "%.4f"); + changed |= edit_rotation(STR_C("Rotation"), Collision.rotation); + changed |= ImGui::DragFloat3(STR_C("Half extents"), Collision.size.data(), 0.001f, 0.f, 1000.f, "%.4f"); + return changed; +} + +bool edit_reference(eu07m::model &Model, payload::model_reference &Reference) +{ + auto changed{edit_string(STR_C("Model path"), Model, Reference.path)}; + changed |= edit_string(STR_C("Skin"), Model, Reference.skin); + return changed; +} + +// the components the panel edits field by field; the others are shown by their size +bool edit_component(eu07m::model &Model, std::uint32_t const Index) +{ + namespace component = eu07m::component; + auto const type{Model.components[Index].type}; + if (type == component::socket) + return edit_payload(Model, Index, 0, [&Model](payload::socket &Value) { return edit_socket(Model, Value); }); + if (type == component::joint) + return edit_payload(Model, Index, 0, [&Model](payload::joint &Value) { return edit_joint(Model, Value); }); + if (type == component::light) + return edit_payload(Model, Index, 0, [](payload::light &Value) { return edit_light(Value); }); + if (type == component::light_slot) + return edit_payload(Model, Index, 0, [](payload::light_slot &Value) { return edit_light_slot(Value); }); + if (type == component::emitter) + return edit_payload(Model, Index, 0, [](payload::emitter &Value) { return edit_emitter(Value); }); + if (type == component::collision) + return edit_payload(Model, Index, 0, [&Model](payload::collision &Value) { return edit_collision(Model, Value); }); + if (type == component::model_reference) + return edit_payload(Model, Index, 0, [&Model](payload::model_reference &Value) { return edit_reference(Model, Value); }); + if (type != component::channel) + { + ImGui::TextDisabled("%s", std::vformat(STR("{} bytes, not edited here"), std::make_format_args(Model.components[Index].data_size)).c_str()); + return false; + } + payload::channel channel; + auto changed{edit_payload(Model, Index, 0, [&Model, &channel](payload::channel &Value) { + auto const result{edit_channel(Model, Value)}; + channel = Value; + return result; + })}; + for (std::uint32_t binding = 0; binding < channel.binding_count; ++binding) + { + ImGui::PushID(static_cast(binding)); + ImGui::SeparatorText(std::vformat(STR("Binding {}"), std::make_format_args(binding)).c_str()); + changed |= edit_payload(Model, Index, sizeof(payload::channel) + binding * sizeof(payload::channel_binding), [](payload::channel_binding &Value) { return edit_binding(Value); }); + ImGui::PopID(); + } + return changed; +} + +} // namespace + +bool eu07m_model_panel::load(TAnimModel &Instance) +{ + m_instance = &Instance; + m_path.clear(); + m_model = eu07m::model{}; + m_dirty = false; + m_message.clear(); + m_open = true; + if ((Instance.pModel == nullptr) || (false == Global.modelformat_eu07m)) + { + return false; + } + auto const path{FileCased(Instance.pModel->NameGet() + ".eu07m")}; + if (path.empty()) + { + return false; + } + std::ifstream file{path, std::ios::binary | std::ios::ate}; + std::vector data(file.good() ? static_cast(file.tellg()) : 0); + file.seekg(0); + file.read(reinterpret_cast(data.data()), static_cast(data.size())); + eu07m::read_options options; + options.blocks = eu07m::store_source(eu07m::family_store(path)); + if (auto const result{eu07m::read(data, m_model, options)}; false == result.ok) + { + m_message = result.error; + return false; + } + m_path = path; + m_cliptimes.assign(m_model.clips.size(), 0.f); + m_channels.clear(); + for (auto const &channel : Instance.pModel->channels()) + { + m_channels.push_back(channel.initial); + } + return true; +} + +void eu07m_model_panel::render(scene::basic_node *Node) +{ + auto *instance{dynamic_cast(Node)}; + if (instance == nullptr) + { + m_instance = nullptr; + return; + } + if (instance != m_instance) + { + load(*instance); + } + if (m_path.empty() || (false == m_open)) + { + return; + } + // beside the inspector, over the right of the view, and opaque: the settings of the interface may make the windows see-through + auto const *viewport{ImGui::GetMainViewport()}; + ImGui::SetNextWindowPos(ImVec2(viewport->WorkPos.x + viewport->WorkSize.x - 900.f, viewport->WorkPos.y + 120.f), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSize(ImVec2(440, 560), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowBgAlpha(0.97f); + if (ImGui::Begin((std::string(STR_C("EU07M model")) + "###eu07mmodel").c_str(), &m_open, ImGuiWindowFlags_NoFocusOnAppearing)) + { + render_file(); + if (ImGui::CollapsingHeader(STR_C("Nodes and their components"), ImGuiTreeNodeFlags_DefaultOpen)) + { + for (std::uint32_t idx = 0; idx < m_model.nodes.size(); idx = m_model.nodes[idx].subtree_end) + { + render_node(idx); + } + } + render_model_components(); + render_clips(*instance); + render_channels(*instance); + } + ImGui::End(); +} + +void eu07m_model_panel::render_file() +{ + ImGui::TextWrapped("%s", m_path.c_str()); + auto const nodes{m_model.nodes.size()}; + auto const components{m_model.components.size()}; + auto const clips{m_model.clips.size()}; + auto const vertices{m_model.vertex_count()}; + ImGui::TextDisabled("%s", std::vformat(STR("{} nodes, {} components, {} clips, {} vertices"), std::make_format_args(nodes, components, clips, vertices)).c_str()); + ImGui::BeginDisabled(false == m_dirty); + if (ImGui::Button(STR_C("Save the model"))) + { + save(); + } + ImGui::EndDisabled(); + ImGui::SameLine(); + if (ImGui::Button(STR_C("Read it again")) && (m_instance != nullptr)) + { + load(*const_cast(m_instance)); + } + if (false == m_message.empty()) + { + ImGui::TextWrapped("%s", m_message.c_str()); + } +} + +void eu07m_model_panel::render_node(std::uint32_t const Index) +{ + auto const &node{m_model.nodes[Index]}; + auto const name{m_model.string(node.name)}; + // the components aimed at the node, whether its range lists them or not + std::vector components; + for (std::uint32_t idx = 0; idx < m_model.components.size(); ++idx) + { + if ((m_model.components[idx].kind == eu07m::target_kind::node) && (m_model.components[idx].target == Index)) + { + components.push_back(idx); + } + } + auto const leaf{(node.subtree_end == Index + 1) && components.empty()}; + auto label{name.empty() ? std::string{STR_C("(no name)")} : std::string{name}}; + if (false == components.empty()) + { + auto const count{components.size()}; + label += std::vformat(STR(" [{} components]"), std::make_format_args(count)); + } + label += "##node" + std::to_string(Index); + // a small model shows its whole tree at once + auto const open{m_model.nodes.size() <= small_model ? ImGuiTreeNodeFlags_DefaultOpen : ImGuiTreeNodeFlags_None}; + if (false == ImGui::TreeNodeEx(label.c_str(), leaf ? ImGuiTreeNodeFlags_Leaf : open)) + { + return; + } + ImGui::TextDisabled("t %.3f %.3f %.3f r %.3f %.3f %.3f %.3f s %.3f %.3f %.3f", node.translation[0], node.translation[1], node.translation[2], node.rotation[0], node.rotation[1], + node.rotation[2], node.rotation[3], node.scale[0], node.scale[1], node.scale[2]); + for (auto const component : components) + { + render_component(component); + } + for (auto child = Index + 1; child < node.subtree_end; child = m_model.nodes[child].subtree_end) + { + render_node(child); + } + ImGui::TreePop(); +} + +void eu07m_model_panel::render_component(std::uint32_t const Index) +{ + auto const label{std::format("{} [{}]##component{}", fourcc_text(m_model.components[Index].type), Index, Index)}; + auto const open{m_model.components.size() <= small_model / 4 ? ImGuiTreeNodeFlags_DefaultOpen : ImGuiTreeNodeFlags_None}; + if (false == ImGui::TreeNodeEx(label.c_str(), open)) + { + return; + } + ImGui::PushID(static_cast(Index)); + if (edit_component(m_model, Index)) + { + m_dirty = true; + } + ImGui::PopID(); + ImGui::TreePop(); +} + +void eu07m_model_panel::render_model_components() +{ + auto const count{std::ranges::count(m_model.components, eu07m::target_kind::model, &eu07m::component_record::kind)}; + if (count == 0) + { + return; + } + if (ImGui::CollapsingHeader(STR_C("Components of the model"), m_model.nodes.size() <= small_model ? ImGuiTreeNodeFlags_DefaultOpen : ImGuiTreeNodeFlags_None)) + { + for (std::uint32_t idx = 0; idx < m_model.components.size(); ++idx) + { + if (m_model.components[idx].kind == eu07m::target_kind::model) + { + render_component(idx); + } + } + } +} + +void eu07m_model_panel::render_clips(TAnimModel &Instance) +{ + if (m_model.clips.empty() || (false == ImGui::CollapsingHeader(STR_C("Animation clips")))) + { + return; + } + for (std::size_t idx = 0; idx < m_model.clips.size(); ++idx) + { + auto &clip{m_model.clips[idx]}; + ImGui::PushID(static_cast(idx)); + auto const name{std::string{m_model.string(clip.name)}}; + ImGui::SeparatorText(name.c_str()); + auto looped{(clip.flags & eu07m::clip_flags::loop) != 0}; + auto autoplay{(clip.flags & eu07m::clip_flags::autoplay) != 0}; + if (ImGui::Checkbox(STR_C("Looped"), &looped) | ImGui::Checkbox(STR_C("Plays on its own"), &autoplay)) + { + clip.flags = (looped ? eu07m::clip_flags::loop : 0u) | (autoplay ? eu07m::clip_flags::autoplay : 0u); + m_dirty = true; + } + // the editor stops the time: the clip is held at the time picked + if (ImGui::SliderFloat(STR_C("Time, s"), &m_cliptimes[idx], 0.f, std::max(clip.duration, 0.001f), "%.2f")) + { + Instance.play_clip(name, 1.f, m_cliptimes[idx]); + } + ImGui::PopID(); + } + if (ImGui::Button(STR_C("Stop the clips"))) + { + Instance.stop_clips(); + } +} + +void eu07m_model_panel::render_channels(TAnimModel &Instance) +{ + if ((Instance.pModel == nullptr) || Instance.pModel->channels().empty() || (false == ImGui::CollapsingHeader(STR_C("Channels")))) + { + return; + } + auto const &channels{Instance.pModel->channels()}; + m_channels.resize(channels.size(), 0.f); + for (std::size_t idx = 0; idx < channels.size(); ++idx) + { + auto const &channel{channels[idx]}; + ImGui::PushID(static_cast(idx)); + if (ImGui::SliderFloat(channel.name.c_str(), &m_channels[idx], std::min(channel.minimum, channel.maximum), std::max(channel.minimum, channel.maximum), "%.3f")) + { + Instance.set_channel(channel.name, m_channels[idx]); + } + ImGui::PopID(); + } + ImGui::TextDisabled("%s", STR_C("The channels and the clips are tried on the instance; the model as the file had it when it was loaded")); +} + +void eu07m_model_panel::save() +{ + if (auto const faults{eu07m::validate(m_model, 1)}; false == faults.empty()) + { + m_message = std::vformat(STR("Not saved: {}"), std::make_format_args(faults.front())); + return; + } + auto const data{eu07m::write(m_model)}; + auto const temporary{m_path + ".tmp"}; + { + std::ofstream file{temporary, std::ios::binary}; + file.write(reinterpret_cast(data.data()), static_cast(data.size())); + if (false == file.good()) + { + m_message = STR("Not saved: the file can't be written"); + return; + } + } + std::error_code error; + std::filesystem::rename(temporary, m_path, error); + if (error) + { + m_message = STR("Not saved: the file can't be written"); + return; + } + m_dirty = false; + m_message = STR("Saved. The game uses the change once it loads the model again"); +} diff --git a/application/editoruimodel.h b/application/editoruimodel.h new file mode 100644 index 000000000..22d24bab6 --- /dev/null +++ b/application/editoruimodel.h @@ -0,0 +1,51 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#pragma once + +#include "model/eu07m/eu07m_model.h" + +#include +#include +#include + +class TAnimModel; +namespace scene +{ +class basic_node; +} + +// the window of the EU07M model of the scenery instance selected in the editor: the tree of its nodes with their components, the fields +// of the common components to edit and save to the file, and the clips and the channels of the model to try on the instance. the +// geometry, the mapping and the materials aren't edited here +class eu07m_model_panel +{ + public: + // shown while the selected node is a model instance loaded from an EU07M file + void render(scene::basic_node *Node); + + private: + bool load(TAnimModel &Instance); + void render_file(); + void render_node(std::uint32_t Index); + void render_component(std::uint32_t Index); + void render_model_components(); + void render_clips(TAnimModel &Instance); + void render_channels(TAnimModel &Instance); + void save(); + + bool m_open{true}; + TAnimModel const *m_instance{nullptr}; + std::string m_path; // of the .eu07m file, empty when the model has none + eu07m::model m_model; + bool m_dirty{false}; + std::string m_message; + std::vector m_cliptimes; // the times the clips are held at, seconds + std::vector m_channels; // the values the channels were set to +}; diff --git a/docs/eu07m-format.md b/docs/eu07m-format.md index d750f4890..be99933b4 100644 --- a/docs/eu07m-format.md +++ b/docs/eu07m-format.md @@ -284,6 +284,21 @@ With `modelformat eu07m` in `eu07.ini`, a model with an `.eu07m` file beside its - A node with `range_max_sq` 0 has no distance limit; before, such a node (of a model made anew, not converted from E3D) wasn't drawn at all. +### In the editor + +Selecting a scenery model loaded from an `.eu07m` file opens the "EU07M model" window (`application/editoruimodel.cpp`): + +- the file, and the tree of the nodes with their transforms and the components aimed at each of them, then the components of the + model; +- the fields of the common components to edit: `SOCK`, `JOIN`, `CHNL` with its bindings, `LGHT`, `LSLT`, `EMIT`, `COLL`, `MREF`; + the others are shown by their size. Strings are edited by their text; +- the clips, with their flags to edit and a time to hold the instance at (the time stands still in the editor), and the channels of + the model, set on the instance with a slider, which tries them without changing the file; +- "Save the model" checks the model and writes the file again (the store of the family is kept); the game uses the change once it + loads the model again. "Read it again" drops the changes. + +The geometry, the mapping and the materials aren't edited there; that is the work of the exporter. + ### Animation clips A clip (`ACLP`) is a set of tracks (`ATRK`), each of which sets one part of the TRS of a node: translation, rotation or scale. The diff --git a/lang/editor_pl.po b/lang/editor_pl.po index 4e845d709..0eb29e1ab 100644 --- a/lang/editor_pl.po +++ b/lang/editor_pl.po @@ -16334,3 +16334,207 @@ msgstr "Nie udało się zapisać terenu: %s. Pliki sieci trakcyjnej są już zap msgid "Files of the terrain or of the catenary may be written already, the scenery files aren't: save again once it's fixed" msgstr "Pliki terenu lub sieci trakcyjnej mogą być już zapisane, pliki scenerii nie: zapisz ponownie po usunięciu przyczyny" + +msgid "The data of the component is cut short" +msgstr "Dane komponentu są ucięte" + +msgid "Role" +msgstr "Rola" + +msgid "End of the vehicle" +msgstr "Koniec pojazdu" + +msgid "front" +msgstr "przód" + +msgid "rear" +msgstr "tył" + +msgid "Index" +msgstr "Indeks" + +msgid "Position" +msgstr "Położenie" + +msgid "hinge" +msgstr "zawias" + +msgid "ball" +msgstr "kulisty" + +msgid "slider" +msgstr "przesuw" + +msgid "screw" +msgstr "śruba" + +msgid "Limited" +msgstr "Ograniczony" + +msgid "Axis" +msgstr "Oś" + +msgid "Minimum" +msgstr "Minimum" + +msgid "Maximum" +msgstr "Maksimum" + +msgid "Rest" +msgstr "Spoczynek" + +msgid "Pitch, m a turn" +msgstr "Skok, m na obrót" + +msgid "Initial value" +msgstr "Wartość początkowa" + +msgid "Bound to" +msgstr "Powiązany z" + +msgid "joint" +msgstr "joint" + +msgid "clip" +msgstr "klip" + +msgid "variants" +msgstr "warianty" + +msgid "light slot" +msgstr "slot światła" + +msgid "Target (component or clip, -1 none)" +msgstr "Cel (komponent albo klip, -1 brak)" + +msgid "Offset" +msgstr "Przesunięcie" + +msgid "point" +msgstr "punkt" + +msgid "spot" +msgstr "reflektor" + +msgid "Lights itself" +msgstr "Oświetla siebie" + +msgid "No shadows" +msgstr "Bez cieni" + +msgid "Soft falloff" +msgstr "Miękkie wygaszanie" + +msgid "Light only" +msgstr "Tylko oświetlenie" + +msgid "Colour" +msgstr "Kolor" + +msgid "Intensity" +msgstr "Natężenie" + +msgid "Cosine of the cone" +msgstr "Cosinus stożka" + +msgid "Cosine of the hotspot" +msgstr "Cosinus plamy" + +msgid "Slot" +msgstr "Slot" + +msgid "Initial state" +msgstr "Stan początkowy" + +msgid "Colour (negative: of the sources)" +msgstr "Kolor (ujemny: kolor źródeł)" + +msgid "smoke" +msgstr "dym" + +msgid "steam" +msgstr "para" + +msgid "sparks" +msgstr "iskry" + +msgid "Direction" +msgstr "Kierunek" + +msgid "Shape" +msgstr "Kształt" + +msgid "box" +msgstr "prostopadłościan" + +msgid "sphere" +msgstr "kula" + +msgid "capsule" +msgstr "kapsuła" + +msgid "Centre" +msgstr "Środek" + +msgid "Half extents" +msgstr "Połowy wymiarów" + +msgid "Model path" +msgstr "Ścieżka modelu" + +msgid "{} bytes, not edited here" +msgstr "{} B, nie edytowane tutaj" + +msgid "Binding {}" +msgstr "Powiązanie {}" + +msgid "EU07M model" +msgstr "Model EU07M" + +msgid "Nodes and their components" +msgstr "Węzły i ich komponenty" + +msgid "{} nodes, {} components, {} clips, {} vertices" +msgstr "węzły: {}, komponenty: {}, klipy: {}, wierzchołki: {}" + +msgid "Save the model" +msgstr "Zapisz model" + +msgid "Read it again" +msgstr "Wczytaj ponownie" + +msgid " [{} components]" +msgstr " [komponenty: {}]" + +msgid "Components of the model" +msgstr "Komponenty modelu" + +msgid "Animation clips" +msgstr "Klipy animacji" + +msgid "Looped" +msgstr "Zapętlony" + +msgid "Plays on its own" +msgstr "Gra sam" + +msgid "Time, s" +msgstr "Czas, s" + +msgid "Stop the clips" +msgstr "Zatrzymaj klipy" + +msgid "Channels" +msgstr "Kanały" + +msgid "The channels and the clips are tried on the instance; the model as the file had it when it was loaded" +msgstr "Kanały i klipy są próbowane na egzemplarzu, w modelu takim, jaki plik miał przy wczytaniu" + +msgid "Not saved: {}" +msgstr "Nie zapisano: {}" + +msgid "Not saved: the file can't be written" +msgstr "Nie zapisano: nie można zapisać pliku" + +msgid "Saved. The game uses the change once it loads the model again" +msgstr "Zapisano. Gra użyje zmiany, gdy wczyta model ponownie" diff --git a/model/AnimModel.cpp b/model/AnimModel.cpp index 22fa34c39..974339fdb 100644 --- a/model/AnimModel.cpp +++ b/model/AnimModel.cpp @@ -802,7 +802,7 @@ void TAnimModel::light_parts_shown( int const Light, bool &Lit, bool &Dark ) con } } -bool TAnimModel::play_clip( std::string_view const Name, float const Speed ) { +bool TAnimModel::play_clip( std::string_view const Name, float const Speed, float const From ) { if( pModel == nullptr ) { return false; } auto const &clips { pModel->clips() }; @@ -810,7 +810,9 @@ bool TAnimModel::play_clip( std::string_view const Name, float const Speed ) { if( found == clips.end() ) { return false; } auto const index { static_cast( std::distance( clips.begin(), found ) ) }; std::erase_if( m_clips, [ index ]( clip_playing const &Playing ) { return Playing.clip == index; } ); - m_clips.push_back( { index, Timer::GetTime(), Speed } ); + // started as long before now as From takes at the pace + auto const pace { std::max( Speed, 1e-3f ) }; + m_clips.push_back( { index, Timer::GetTime() - static_cast( From / pace ), pace } ); m_autoplaystarted = true; return true; } diff --git a/model/AnimModel.h b/model/AnimModel.h index a5567679d..c1920e19b 100644 --- a/model/AnimModel.h +++ b/model/AnimModel.h @@ -189,9 +189,10 @@ public: // rotation and scale of the instance as a matrix: rotate y * rotate x * rotate z * scale glm::mat4 const &rotation_scale(); void RaAnimate( unsigned int const Framestamp ); // przeliczenie animacji egzemplarza - // starts the animation clip of the model (EU07M) with the name from its beginning, at Speed times its pace; a clip already playing - // starts over. false when the model has no clip of the name - bool play_clip( std::string_view Name, float Speed = 1.f ); + // starts the animation clip of the model (EU07M) with the name at From seconds of it (its beginning by default), at Speed times its + // pace; a clip already playing starts over. with the time stopped (the editor) it holds the pose of From. false when the model has + // no clip of the name + bool play_clip( std::string_view Name, float Speed = 1.f, float From = 0.f ); // stops the clips playing, the nodes they moved stay where they were last put till the next clip moves them void stop_clips(); // sets the channel of the model (EU07M) with the name to Value, kept within its range; the joints and the clips it's bound to