mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 03:59:19 +02:00
feat(editor): edit parameters of a placed include
This commit is contained in:
@@ -497,6 +497,51 @@ std::pair<int, int> state_manager::preview_include(std::string const &Directive,
|
||||
return m_serializer.preview_include(Directive, Context, Layer, Instance);
|
||||
}
|
||||
|
||||
std::pair<int, int> state_manager::rebuild_include(scene::instance_handle const Instance, std::vector<TAnimModel *> &Retired) {
|
||||
if (false == scene::Layers.tracked(Instance)) {
|
||||
return { 0, 0 };
|
||||
}
|
||||
auto const &included { scene::Layers.instance(Instance) };
|
||||
// the models the include was loaded with don't match it anymore.
|
||||
// NOTE: done ahead of retiring the models made by the editor, which are told from the loaded ones by their preview flag
|
||||
scene::Layers.rebuilt(Instance);
|
||||
for (auto *model : Instances.sequence()) {
|
||||
if (model == nullptr || model->m_instance != Instance || false == model->m_preview) {
|
||||
continue;
|
||||
}
|
||||
if (false == included.removed) {
|
||||
scene::Layers.count(model->layer(), scene::layer_item::model, -1);
|
||||
}
|
||||
Region->erase(model);
|
||||
scene::Hierarchy.erase(model->uuid.to_string());
|
||||
model->visible(false);
|
||||
model->m_preview = false;
|
||||
Retired.emplace_back(model);
|
||||
}
|
||||
if (included.dead) {
|
||||
return { 0, 0 };
|
||||
}
|
||||
auto const layer { scene::Layers.resolve(included.layer) };
|
||||
auto const result { m_serializer.preview_include(scene::Layers.directive(Instance), included.context, layer, Instance) };
|
||||
// what's shown for an include which is out of sight at the moment goes out of sight as well
|
||||
auto const layerhidden { scene::Layers.valid(layer) && false == scene::Layers.layer(layer).visible };
|
||||
if (included.removed || layerhidden) {
|
||||
for (auto *model : Instances.sequence()) {
|
||||
if (model == nullptr || model->m_instance != Instance || false == model->m_preview) {
|
||||
continue;
|
||||
}
|
||||
if (included.removed) {
|
||||
scene::Layers.count(model->layer(), scene::layer_item::model, -1);
|
||||
}
|
||||
if (model->visible()) {
|
||||
model->visible(false);
|
||||
model->m_layerhidden = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void state_manager::delete_model(TAnimModel *model) {
|
||||
scene::Layers.count(model->layer(), scene::layer_item::model, -1);
|
||||
scene::Layers.forget(model);
|
||||
|
||||
@@ -46,6 +46,11 @@ public:
|
||||
// creates model instances defined by an include directive placed in the scenery editor
|
||||
std::pair<int, int>
|
||||
preview_include(std::string const &Directive, scene::layer_context const &Context, scene::layer_handle Layer, scene::instance_handle Instance);
|
||||
// replaces models shown for specified include with the ones defined by its current directive. Retired: receives
|
||||
// the replaced models made by the editor. they're out of the scene already, but the renderer can still hold on
|
||||
// to them for a few frames; pass them to Instances.purge() afterwards
|
||||
std::pair<int, int>
|
||||
rebuild_include(scene::instance_handle Instance, std::vector<TAnimModel *> &Retired);
|
||||
// delete TAnimModel instance
|
||||
void
|
||||
delete_model(TAnimModel *model);
|
||||
|
||||
@@ -1451,12 +1451,9 @@ std::pair<int, int> state_serializer::preview_include(std::string const &Directi
|
||||
nodedata.instance = Instance;
|
||||
auto *instance { (nodedata.type == "model" && nodedata.range_min >= 0.0) ? deserialize_model(parser, scratch, nodedata) : nullptr };
|
||||
if (instance != nullptr) {
|
||||
// same as for a model loaded with the scenery
|
||||
if (instance->Model() != nullptr) {
|
||||
for (auto const &smokesource : instance->Model()->smoke_sources()) {
|
||||
Particles.insert(smokesource.first, instance, smokesource.second);
|
||||
}
|
||||
}
|
||||
// NOTE: unlike for a model loaded with the scenery, smoke sources of the model aren't set up.
|
||||
// they'd be left with a dangling owner when the model is replaced after a change of the include
|
||||
instance->m_preview = true;
|
||||
simulation::Instances.insert(instance);
|
||||
simulation::Region->insert(instance);
|
||||
scene::Hierarchy[instance->uuid.to_string()] = instance;
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
TAnimModel * create_model(std::string const &src, std::string const &name, const glm::dvec3 &position);
|
||||
// create new eventlauncher from node stirng
|
||||
TEventLauncher * create_eventlauncher(std::string const &src, std::string const &name, const glm::dvec3 &position);
|
||||
// creates model instances defined by an include directive placed in the scenery editor, to show what was placed.
|
||||
// creates model instances defined by an include directive placed or changed in the scenery editor, to show the outcome.
|
||||
// everything else the included template defines is left out, and takes effect when the saved scenery is loaded.
|
||||
// Context: placement in effect at the location of the directive. returns: number of created models and of skipped statements
|
||||
std::pair<int, int> preview_include(std::string const &Directive, scene::layer_context const &Context, scene::layer_handle Layer, scene::instance_handle Instance);
|
||||
|
||||
Reference in New Issue
Block a user