mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 17:46:48 +01:00
feat(editor): a part of an EU07M model taken out with what it draws
"Remove this part" (Del) in the Models mode takes out any part without parts under it which nothing else in the model points at (an animation, a light slot, a skin): with its components, its transform and its own mesh. eu07m::remove_node now takes such a node with its geometry: its primitives go, and their vertices and indices leave the streams where no other primitive shares them. The primitives after them move back, and so do the meshes, the vertex groups and the references to the geometry store. A part whose mesh another node draws too, or whose mesh has vertex groups, stays. Ctrl+Z puts the part back and picks it again. So the flat glowing patch under a lamp post of E3D (placek) is taken out and a real light source put in the lamp instead. Unit tests take out a part with geometry, check the streams and the primitive moved into its place, write and read the model back, and keep a part whose mesh is shared.
This commit is contained in:
@@ -1608,9 +1608,8 @@ void eu07m_model_panel::render_selection()
|
||||
render_light_settings(*light);
|
||||
}
|
||||
render_place(index);
|
||||
if (light && eu07m::node_removable(m_model, index) && ImGui::Button(STR_C("Remove this light (Del)")))
|
||||
if (render_remove(index, light.has_value()))
|
||||
{
|
||||
remove_selected();
|
||||
ImGui::PopItemWidth();
|
||||
return;
|
||||
}
|
||||
@@ -1618,6 +1617,22 @@ void eu07m_model_panel::render_selection()
|
||||
ImGui::PopItemWidth();
|
||||
}
|
||||
|
||||
bool eu07m_model_panel::render_remove(std::uint32_t const Index, bool const Light)
|
||||
{
|
||||
auto const *target{submodel(Index)};
|
||||
auto const removable{(target != nullptr) && (target->Parent != nullptr) && eu07m::node_removable(m_model, Index)};
|
||||
ImGui::Separator();
|
||||
ImGui::BeginDisabled(false == removable);
|
||||
auto const clicked{ImGui::Button(Light ? STR_C("Remove this light (Del)") : STR_C("Remove this part (Del)"))};
|
||||
ImGui::EndDisabled();
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
|
||||
{
|
||||
ImGui::SetTooltip("%s", removable ? STR_C("Takes it out of the model, with what it draws; Ctrl+Z brings it back")
|
||||
: STR_C("This part can't be taken out: it has parts under it, or something else in the model points at it (an animation, a light slot, a skin)"));
|
||||
}
|
||||
return clicked && remove_selected();
|
||||
}
|
||||
|
||||
void eu07m_model_panel::render_light_settings(std::uint32_t const Component)
|
||||
{
|
||||
auto const &record{m_model.components[Component]};
|
||||
@@ -2166,6 +2181,8 @@ void eu07m_model_panel::apply_tree(tree_change const &Change, bool const Forward
|
||||
m_source->LinkEditorSubmodel(*Change.submodel, *Change.parent, Change.previous);
|
||||
m_submodels.insert(m_submodels.begin() + Change.index, Change.submodel);
|
||||
m_boxes.insert(m_boxes.begin() + Change.index, node_box(m_model, Change.index));
|
||||
// the part back is picked again, as it was when it was taken out
|
||||
m_pick_after = Change.index;
|
||||
return;
|
||||
}
|
||||
if (Change.index >= m_submodels.size())
|
||||
@@ -2175,6 +2192,10 @@ void eu07m_model_panel::apply_tree(tree_change const &Change, bool const Forward
|
||||
m_source->UnlinkEditorSubmodel(*Change.submodel);
|
||||
m_submodels.erase(m_submodels.begin() + Change.index);
|
||||
m_boxes.erase(m_boxes.begin() + Change.index);
|
||||
if (m_selected == static_cast<std::int64_t>(Change.index))
|
||||
{
|
||||
m_selected = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void eu07m_model_panel::push_change(snapshot Snapshot)
|
||||
@@ -2238,6 +2259,11 @@ void eu07m_model_panel::settled()
|
||||
{
|
||||
m_selected = -1;
|
||||
}
|
||||
if (auto const part{std::exchange(m_pick_after, std::nullopt)}; part && (*part < m_model.nodes.size()))
|
||||
{
|
||||
select(*part);
|
||||
m_scrolltoselected = true;
|
||||
}
|
||||
}
|
||||
|
||||
void eu07m_model_panel::add_light(std::uint32_t const Parent, glm::vec3 const &Position, glm::quat const &Rotation, bool const Spot)
|
||||
@@ -2353,13 +2379,14 @@ bool eu07m_model_panel::remove_selected()
|
||||
}
|
||||
auto const index{static_cast<std::uint32_t>(m_selected)};
|
||||
auto *target{submodel(index)};
|
||||
if ((false == light_of(index).has_value()) || (target == nullptr) || (target->Parent == nullptr) || (false == eu07m::node_removable(m_model, index)))
|
||||
if ((target == nullptr) || (target->Parent == nullptr) || (false == eu07m::node_removable(m_model, index)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
auto before{take(true)};
|
||||
auto *parent{target->Parent};
|
||||
auto const name{part_name(index)};
|
||||
auto const light{light_of(index).has_value()};
|
||||
if (false == eu07m::remove_node(m_model, index))
|
||||
{
|
||||
return false;
|
||||
@@ -2371,7 +2398,8 @@ bool eu07m_model_panel::remove_selected()
|
||||
push_change(std::move(before));
|
||||
m_before = take(false);
|
||||
m_selected = -1;
|
||||
m_message = std::vformat(STR("Removed the light {}. Ctrl+Z brings it back"), std::make_format_args(name));
|
||||
m_message = light ? std::vformat(STR("Removed the light {}. Ctrl+Z brings it back"), std::make_format_args(name))
|
||||
: std::vformat(STR("Removed {}. Ctrl+Z brings it back"), std::make_format_args(name));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user