diff --git a/application/editormode.cpp b/application/editormode.cpp index 8f6316371..d9b1d4311 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -5879,14 +5879,14 @@ bool editor_mode::enter_cab(TDynamicObject &Vehicle) return true; } -void editor_mode::place_model_file(std::string const &File) +void editor_mode::place_model_file(std::string const &File, std::string const &Parameters) { // on the ground some way ahead of the camera, as far as Insert would put it by a click there auto const view{GfxRenderer->Camera_View_Matrix()}; glm::dvec3 ahead{-view[0][2], 0.0, -view[2][2]}; ahead = glm::length(ahead) > 1e-6 ? glm::normalize(ahead) : glm::dvec3{0.0, 0.0, 1.0}; auto const where{placement_on_ground(Camera.Pos + ahead * 12.0)}; - auto *placed{simulation::State.create_model("node -1 0 none model 0 0 0 0 " + File + " none endmodel", "editor_", where)}; + auto *placed{simulation::State.create_model("node -1 0 none model 0 0 0 0 " + File + " none " + (Parameters.empty() ? std::string{} : Parameters + " ") + "endmodel", "editor_", where)}; if (placed == nullptr) { ui()->set_status(format(STR_C("The model %s couldn't be put in, the log says why"), File.c_str()), true); diff --git a/application/editormode.h b/application/editormode.h index d87249484..0b6620e1b 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -873,7 +873,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri void capture_terrain(); bool m_terrain_open{false}; // the terrain is the field of work, chosen in the toolbar bool m_models_open{false}; // the models are the field of work, chosen in the toolbar - void place_model_file(std::string const &File); // a model of the folder of the models put in the scenery and selected + // a model of the folder of the models put in the scenery and selected; Parameters go after its skin, such as "lights 3" + void place_model_file(std::string const &File, std::string const &Parameters = {}); bool enter_cab(TDynamicObject &Vehicle); // the cab of the vehicle loaded as by getting in, the camera in the seat of the driver bool m_cabview{false}; // the cab of the vehicle driven is drawn, as from the seat of the driver float m_terrain_spacing{2.0f}; // point spacing of the chunks made and of the spacing tool diff --git a/application/editormodeselftestscene.cpp b/application/editormodeselftestscene.cpp index 8f2d754ec..bf3419574 100644 --- a/application/editormodeselftestscene.cpp +++ b/application/editormodeselftestscene.cpp @@ -394,10 +394,12 @@ editor_mode::selftest_result editor_mode::selftest_scene(std::string const &comm } if (command == "modelplace") { - // a model of the folder of the models put in front of the camera + // a model of the folder of the models put in front of the camera, with the parameters of the node after its skin std::string file; words >> file; - place_model_file(file); + std::string parameters; + std::getline(words >> std::ws, parameters); + place_model_file(file, parameters); WriteLog("SELFTEST modelplace " + file + (m_node != nullptr ? "" : ": not placed")); return selftest_result::handled; } @@ -411,6 +413,20 @@ editor_mode::selftest_result editor_mode::selftest_scene(std::string const &comm WriteLog("SELFTEST modelvehicle " + name + " " + part + (picked ? "" : ": no such vehicle")); return selftest_result::handled; } + if (command == "modelsave") + { + auto const saved{ui()->model_panel().save_model()}; + WriteLog(std::string{"SELFTEST modelsave"} + (saved ? "" : ": not saved")); + return selftest_result::handled; + } + if (command == "modelbrightness") + { + float brightness{1.f}; + words >> brightness; + auto const set{ui()->model_panel().set_brightness(brightness)}; + WriteLog("SELFTEST modelbrightness " + std::to_string(brightness) + (set ? "" : ": no light picked")); + return selftest_result::handled; + } if (command == "modelimport") { auto const imported{ui()->model_panel().import_model()}; diff --git a/application/editoruimodel.cpp b/application/editoruimodel.cpp index ee16d2d53..e7204bcc5 100644 --- a/application/editoruimodel.cpp +++ b/application/editoruimodel.cpp @@ -1789,6 +1789,37 @@ bool eu07m_model_panel::pick_vehicle(std::string_view const Name, int const Part return true; } +bool eu07m_model_panel::save_model() +{ + if (m_path.empty()) + { + return false; + } + save(); + return false == m_dirty; +} + +bool eu07m_model_panel::set_brightness(float const Brightness) +{ + auto const light{m_selected >= 0 ? light_of(static_cast(m_selected)) : std::nullopt}; + if (false == light.has_value()) + { + return false; + } + auto const &record{m_model.components[*light]}; + if (std::size_t{record.data_offset} + sizeof(payload::light) > m_model.component_data.size()) + { + return false; + } + payload::light value; + std::memcpy(&value, m_model.component_data.data() + record.data_offset, sizeof(value)); + value.hotspot_power = Brightness; + std::memcpy(m_model.component_data.data() + record.data_offset, &value, sizeof(value)); + changed(); + show_change(*light); + return true; +} + bool eu07m_model_panel::select_node(std::string_view const Name) { auto const nodes{eu07m::find_nodes(m_model, Name)}; diff --git a/application/editoruimodel.h b/application/editoruimodel.h index abeb98f11..5f4a4b545 100644 --- a/application/editoruimodel.h +++ b/application/editoruimodel.h @@ -107,6 +107,10 @@ class eu07m_model_panel bool pick_vehicle(std::string_view Name, int Part); // the cab of the vehicle shown, loaded when it isn't yet, as the button does bool open_cab(); + // the model written to its file, as Save the changes does; false when it isn't (the self-test of the editor) + bool save_model(); + // the brightness of the light source picked, as its slider sets it; false when no light is picked (the self-test of the editor) + bool set_brightness(float Brightness); private: enum class gizmo : int diff --git a/docs/eu07m-format.md b/docs/eu07m-format.md index e647b5188..e43c028ad 100644 --- a/docs/eu07m-format.md +++ b/docs/eu07m-format.md @@ -285,6 +285,9 @@ With `modelformat eu07m` in `eu07.ini`, a model with an `.eu07m` file beside its - The code of the game which reads the vertices of a model (pantograph, bounds, picking, the editor) gets them as `gfx::basic_vertex`, made from the streams the first time they are read. - The stars (`STAR`) keep their colour in the normal, so they go as `gfx::basic_vertex` in Vulkan too. +- A `LGHT` node without an `LMAT` (a light made in the editor or exported anew) shines whenever its node is shown: its threshold of + self-illumination is that of `selfillum: true` of a `.t3d`. Before, such a light never lit anything. The converter gives every + light of E3D an `LMAT` with the threshold it had, so the converted models don't change. - 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. diff --git a/model/eu07m/eu07m_load.cpp b/model/eu07m/eu07m_load.cpp index ba8f45765..593dddc63 100644 --- a/model/eu07m/eu07m_load.cpp +++ b/model/eu07m/eu07m_load.cpp @@ -43,6 +43,9 @@ static_assert(sizeof(eu07m::attributes) == sizeof(gfx::compact_attributes)); static_assert(offsetof(eu07m::attributes, qtangent) == offsetof(gfx::compact_attributes, qtangent)); static_assert(offsetof(eu07m::attributes, uv) == offsetof(gfx::compact_attributes, texture)); +// the threshold of the self-illumination of a light source without the material of E3D: always lit, as "selfillum: true" of a .t3d +constexpr float light_always_lit{2.f}; + // what E3D keeps in the submodel and EU07M in the components of the node struct legacy_parts { std::optional light; @@ -162,6 +165,10 @@ void submodel_builder::build(std::uint32_t const Index, TSubModel &Submodel) { if (parts.light) { Submodel.eType = TP_FREESPOTLIGHT; light(*parts.light, Submodel); + // a light source without the material of E3D (made in the editor or exported anew) shines whenever its node is shown, as a + // light of a .t3d with "selfillum: true"; the converter gives every light of E3D its material, with the threshold it had + if (parts.material == eu07m::no_index) + Submodel.fLight = light_always_lit; } if (node.mesh >= 0) { auto const &mesh{m_model.meshes[node.mesh]}; @@ -602,6 +609,8 @@ TSubModel &TModel3d::AddEditorLight(TSubModel &Parent, std::string const &Name, submodel.iFlags = Flags; submodel.pName = Name; submodel_builder::light(Light, submodel); + // it has no material of E3D: it shines whenever its node is shown, as the loader has it + submodel.fLight = light_always_lit; submodel.Parent = &Parent; // the last child, as the node is the last child of its parent in the file if (Parent.Child == nullptr) {