mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 17:46:48 +01:00
42e0884606
The cab of a vehicle is loaded only by getting in. "Get in the cab" in the Models mode does what the simulation does then: it makes the train of the vehicle (TTrain::Init loads the cab, its controls and its sounds), makes it the vehicle driven, and puts the camera in the seat of the driver. While the cab is edited the editor draws it as from that seat: FreeFlyModeFlag is off and the vehicle owns the camera, which moves with it by its offset (the sounds read the owner of the camera then). With the body picked, or in another field of work, the view is free again. A new self-test command, modelvehicle <name> [cab], picks a vehicle and gets in its cab. Tested on the EU07-424 (303e-tv) with a light added to its cab.
243 lines
11 KiB
C++
243 lines
11 KiB
C++
/*
|
|
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 <glm/gtc/quaternion.hpp>
|
|
#include <glm/mat4x4.hpp>
|
|
#include <glm/vec3.hpp>
|
|
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
class TAnimModel;
|
|
class TDynamicObject;
|
|
class TModel3d;
|
|
class TSubModel;
|
|
namespace scene
|
|
{
|
|
class basic_node;
|
|
}
|
|
|
|
// the field of work of the models in the editor: an EU07M model of a scenery model or of a vehicle, edited by someone who doesn't
|
|
// know the format. the window of the node bank says what is edited and lets a vehicle be picked, the tool options hold the page of
|
|
// the tool chosen in the toolbar (the lights, the parts of the vehicle, all the parts of the model, the animations), the inspector
|
|
// the settings of the part picked. a click on the model picks its part, a light is put where the model is clicked, and the part
|
|
// picked is moved with a gizmo in the 3d view. what is edited shows on the model at once and is taken back with Ctrl+Z; the file
|
|
// is written on Save. the geometry, the mapping and the materials aren't edited here
|
|
class eu07m_model_panel
|
|
{
|
|
public:
|
|
enum class tool : int
|
|
{
|
|
lights,
|
|
parts,
|
|
elements,
|
|
animations
|
|
};
|
|
|
|
// once a frame, after the windows: the model of the scenery node selected, of the vehicle picked or of the vehicle driven. Active:
|
|
// the field of work of the models is the one in use; only then is the model shown changed, and the 3d view drawn over
|
|
void update(scene::basic_node *Selected, bool Active);
|
|
// what is edited, and the vehicles to pick from: in the window of the node bank
|
|
void render_bank();
|
|
// the page of the tool chosen: in the tool options window
|
|
void render_tools();
|
|
// the settings of the part picked: in the inspector
|
|
void render_selection();
|
|
// the left button in the 3d view came down on Picked (none: nothing of the scenery, or a vehicle). true when the press picked a
|
|
// part of the model shown or put a light on it, then it doesn't select anything in the scenery
|
|
bool pick(scene::basic_node const *Picked);
|
|
// the last change of the model taken back, or made again; false when there's none
|
|
bool undo();
|
|
bool redo();
|
|
// the part picked taken out, when it's a light source that can be (Del)
|
|
bool remove_selected();
|
|
// a scenery model has a file of the format to edit
|
|
bool editable(scene::basic_node const *Node) const;
|
|
|
|
tool current_tool() const { return m_tool; }
|
|
void choose_tool(tool Tool);
|
|
bool has_vehicle() const { return m_target.vehicle != nullptr; }
|
|
bool has_animations() const;
|
|
bool marks_shown() const { return m_marks; }
|
|
void show_marks(bool Shown) { m_marks = Shown; }
|
|
bool turning() const { return m_gizmo == gizmo::turn; }
|
|
void set_turning(bool Turning) { m_gizmo = Turning ? gizmo::turn : gizmo::move; }
|
|
|
|
// moves the camera to look at a point of the world, framing a sphere of the radius given
|
|
std::function<void(glm::dvec3 const &, double)> focus;
|
|
// puts a model of the file (relative to the folder of the models) in the scenery, in front of the camera, and selects it
|
|
std::function<void(std::string const &)> place_model;
|
|
// takes the editor to the tool which puts a vehicle on a track
|
|
std::function<void()> place_vehicle;
|
|
// loads the cab of the vehicle the way the game does when someone gets in, and puts the camera in the seat of the driver;
|
|
// false when the vehicle has no cab of its own
|
|
std::function<bool(TDynamicObject &)> enter_cab;
|
|
// the cab of the vehicle shown is edited: the editor draws it, the camera may be in it
|
|
bool shows_cab() const { return m_active && (m_target.vehicle != nullptr) && (m_target.part == 1); }
|
|
TDynamicObject *vehicle() const { return m_target.vehicle; }
|
|
// the model as a whole is moved with the gizmo of the editor, in place of its part picked
|
|
bool moves_whole() const { return m_whole && (m_target.instance != nullptr); }
|
|
void set_whole(bool Whole) { m_whole = Whole; }
|
|
// the gizmo of the part picked is shown in the 3d view, in place of the one of the editor
|
|
bool gizmo_shown() const { return m_gizmoshown; }
|
|
// the last press of the left button in the 3d view went to the gizmo or to a mark of a light, not to picking a node
|
|
bool took_press() const { return m_tookpress; }
|
|
// picks the first node of the name in the model shown; false when it has none (the self-test of the editor)
|
|
bool select_node(std::string_view Name);
|
|
// a light added in the middle of the part picked, as a click there adds it (the self-test of the editor)
|
|
bool add_test_light(bool Spot);
|
|
// the model shown, without a file of the format, given one made of it as the game has it; false when it can't be
|
|
bool import_model();
|
|
// the vehicle of the name picked, its body (0) or its cab (1), as a click in the list picks it (the self-test of the editor)
|
|
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();
|
|
|
|
private:
|
|
enum class gizmo : int
|
|
{
|
|
move,
|
|
turn
|
|
};
|
|
using box = std::pair<glm::vec3, glm::vec3>;
|
|
// what is edited: a scenery model, or the body or the cab of a vehicle
|
|
struct target
|
|
{
|
|
TAnimModel *instance{nullptr};
|
|
TDynamicObject *vehicle{nullptr};
|
|
int part{0}; // of the vehicle: 0 the body, 1 the cab
|
|
bool operator==(target const &) const = default;
|
|
};
|
|
// a change of the tree of the nodes: a light added or taken out, as the model the game has is to follow it
|
|
struct tree_change
|
|
{
|
|
enum class kind : int
|
|
{
|
|
none,
|
|
added,
|
|
removed
|
|
};
|
|
kind what{kind::none};
|
|
std::uint32_t index{0}; // of the node
|
|
TSubModel *submodel{nullptr};
|
|
TSubModel *parent{nullptr};
|
|
TSubModel *previous{nullptr}; // the child of the parent before it, none when it's the first
|
|
};
|
|
// the model as it was before a change: the nodes and the components, or the whole of it when the tree changed
|
|
struct snapshot
|
|
{
|
|
std::vector<eu07m::node_record> nodes;
|
|
std::vector<eu07m::component_record> components;
|
|
std::vector<std::byte> component_data;
|
|
std::vector<eu07m::clip_record> clips;
|
|
std::optional<eu07m::model> whole;
|
|
tree_change change;
|
|
};
|
|
|
|
target wanted(scene::basic_node *Selected) const;
|
|
void open(target const &Target);
|
|
bool load(TModel3d &Model);
|
|
void render_unsaved_popup();
|
|
// the body or the cab of the vehicle, or the button which gets in its cab
|
|
void render_vehicle_part();
|
|
// the models of the folder of the models to put in the scenery
|
|
void render_insert();
|
|
void render_header();
|
|
void render_guide() const;
|
|
void render_lights_page();
|
|
void render_parts_page() const;
|
|
void render_elements_page();
|
|
void render_tree_node(std::uint32_t Index);
|
|
void render_animations_page();
|
|
void render_clips(TAnimModel &Instance);
|
|
void render_channels(TAnimModel &Instance);
|
|
void render_light_settings(std::uint32_t Component);
|
|
void render_place(std::uint32_t Index);
|
|
void render_advanced(std::uint32_t Index);
|
|
void render_component(std::uint32_t Index);
|
|
// over the 3d view: the frame of the part picked, the marks of the light sources and the gizmo
|
|
void render_view();
|
|
// the marks of the light sources; a click on one picks its node
|
|
void render_marks(glm::dmat4 const &Placement, bool Clicked);
|
|
void render_gizmo(glm::dmat4 const &Placement, glm::dvec3 const &Camera);
|
|
void select(std::uint32_t Node);
|
|
// the submodel of the node in the model the game has, or none when that model doesn't match the file
|
|
TSubModel *submodel(std::uint32_t Node) const;
|
|
// where the model is drawn: its space in the world
|
|
std::optional<glm::dmat4> placement() const;
|
|
// the part of the model at the point of the world: the smallest box of geometry holding it
|
|
std::optional<std::uint32_t> node_at(glm::dvec3 const &Point) const;
|
|
// the light source of the node, the first one when it has more
|
|
std::optional<std::uint32_t> light_of(std::uint32_t Node) const;
|
|
// the name of the part in words: the part of the vehicle it is, or the name of its node
|
|
std::string part_name(std::uint32_t Node) const;
|
|
// the change of a component shown on the model the game has
|
|
void show_change(std::uint32_t Index) const;
|
|
void moved(std::uint32_t Node);
|
|
// a change made: the model before it kept to be taken back, once a press of the mouse or a drag
|
|
void changed();
|
|
snapshot take(bool Whole) const;
|
|
void restore(snapshot const &Snapshot);
|
|
void apply_tree(tree_change const &Change, bool Forward);
|
|
void push_change(snapshot Snapshot);
|
|
// after a change taken back or made again: the lights shown as they are, the next change kept from here
|
|
void settled();
|
|
void add_light(std::uint32_t Parent, glm::vec3 const &Position, glm::quat const &Rotation, bool Spot);
|
|
void place_light(glm::dvec3 const &Point, std::optional<std::uint32_t> Part);
|
|
void fly_to(std::uint32_t Node) const;
|
|
void fly_to_vehicle(TDynamicObject const &Vehicle) const;
|
|
void save();
|
|
|
|
bool m_active{false};
|
|
target m_target; // shown
|
|
std::optional<target> m_pending; // asked for while the one shown has changes not saved
|
|
std::optional<target> m_kept; // the one shown kept although another was asked for: it isn't asked again until another one is
|
|
TDynamicObject *m_pickedvehicle{nullptr}; // in the window of the node bank
|
|
int m_part{0}; // of a vehicle, the one wanted: 0 the body, 1 the cab
|
|
scene::basic_node *m_lastselected{nullptr};
|
|
TModel3d *m_source{nullptr}; // the model shown, as the game has it
|
|
std::string m_path; // of the .eu07m file, empty when the model has none
|
|
std::string m_problem; // why the model shown can't be edited
|
|
eu07m::model m_model;
|
|
std::vector<TSubModel *> m_submodels; // of the nodes of the file, in the model the game has; empty when they don't match
|
|
std::vector<std::optional<box>> m_boxes; // of the geometry of the nodes, each in its space
|
|
bool m_dirty{false};
|
|
std::string m_message;
|
|
std::int64_t m_selected{-1}; // the node picked
|
|
bool m_scrolltoselected{false};
|
|
tool m_tool{tool::lights};
|
|
gizmo m_gizmo{gizmo::move};
|
|
bool m_marks{true}; // the light sources marked in the 3d view
|
|
bool m_gizmoshown{false};
|
|
bool m_tookpress{false};
|
|
std::optional<bool> m_placing; // a light to be put where the model is clicked: a spot or a point light
|
|
std::vector<snapshot> m_undo;
|
|
std::vector<snapshot> m_redo;
|
|
snapshot m_before; // the model when no press or drag was going on
|
|
bool m_changing{false}; // the press or the drag going on has changed the model, its change is kept
|
|
std::string m_filter; // of the parts in the list of all of them
|
|
bool m_importable{false}; // the model shown has no file of the format, one can be made of it
|
|
bool m_whole{false};
|
|
bool m_scanned{false}; // the folder of the models was looked through
|
|
std::vector<std::string> m_files; // of the models, relative to their folder
|
|
std::vector<std::size_t> m_found; // those of them the search takes
|
|
std::string m_filesearch;
|
|
std::vector<float> m_cliptimes; // the times the clips are held at, seconds
|
|
std::vector<float> m_channels; // the values the channels were set to
|
|
};
|