mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-29 01:07:28 +01:00
removed draw limit in track editor
This commit is contained in:
@@ -41,6 +41,7 @@ extern char **environ;
|
||||
#include "rendering/renderer.h"
|
||||
#include "model/AnimModel.h"
|
||||
#include "model/Model3d.h"
|
||||
#include "world/Track.h"
|
||||
#include "utilities/Float3d.h"
|
||||
#include "scene/scene.h"
|
||||
#include "scene/scenelayers.h"
|
||||
@@ -1192,6 +1193,7 @@ void editor_mode::redo_one()
|
||||
|
||||
bool editor_mode::update()
|
||||
{
|
||||
Global.editor_tracks = (current_work_area() == work_area::tracks);
|
||||
selftest_step();
|
||||
if (m_vehicle.leave)
|
||||
{
|
||||
@@ -4544,6 +4546,7 @@ void editor_mode::enter()
|
||||
|
||||
void editor_mode::exit()
|
||||
{
|
||||
Global.editor_tracks = false;
|
||||
EditorModeFlag = false;
|
||||
Global.ControlPicking = m_statebackup.picking;
|
||||
FreeFlyModeFlag = m_statebackup.freefly;
|
||||
@@ -5012,8 +5015,8 @@ void editor_mode::on_mouse_button(int const Button, int const Action, int const
|
||||
}
|
||||
}
|
||||
|
||||
// ignore picks that are beyond allowed placement distance
|
||||
if (node) {
|
||||
// models stay within placement distance; tracks in the track workspace have no range cap
|
||||
if (node && false == (Global.editor_tracks && dynamic_cast<TTrack *>(node) != nullptr)) {
|
||||
double const dist = glm::distance(node->location(), glm::dvec3{Global.pCamera.Pos});
|
||||
if (dist > static_cast<double>(kMaxPlacementDistance))
|
||||
{
|
||||
|
||||
@@ -222,10 +222,6 @@ void editor_mode::select_track(scene::basic_node *Node)
|
||||
m_track_point = {};
|
||||
return;
|
||||
}
|
||||
glm::dvec3 const camera{Global.pCamera.Pos};
|
||||
if (glm::distance(glm::dvec3(track->get_nearest_point(camera)), camera) > static_cast<double>(kMaxPlacementDistance))
|
||||
return;
|
||||
|
||||
if (track != m_node)
|
||||
{
|
||||
m_track_point = {};
|
||||
@@ -3795,14 +3791,21 @@ void editor_mode::update_build_tools()
|
||||
lay.preview_length = 0.0;
|
||||
if (false == lay.active)
|
||||
return;
|
||||
auto mouse{ground};
|
||||
// geometric ray, same as extend: Mouse_Position() is a delayed depth pick and lags the cursor
|
||||
screen_projection const lay_projection;
|
||||
double const height{false == lay.points.empty() ? lay.points.back().y : lay.start.track != nullptr ? lay.start.position.y : 0.0};
|
||||
glm::dvec3 mouse{ground};
|
||||
if (m_cursor_override.has_value())
|
||||
mouse = glm::dvec3{m_cursor_override->x, height, m_cursor_override->z};
|
||||
else if (false == lay_projection.on_level(io.MousePos, height, mouse))
|
||||
mouse = ground;
|
||||
glm::dvec2 heading;
|
||||
bool const straight{io.KeyShift && lay_heading(heading)};
|
||||
if (straight)
|
||||
{
|
||||
auto const &last{lay.points.back()};
|
||||
auto const along{std::max(0.0, glm::dot(glm::dvec2{ground.x - last.x, ground.z - last.z}, heading))};
|
||||
mouse = {last.x + heading.x * along, ground.y, last.z + heading.y * along};
|
||||
auto const along{std::max(0.0, glm::dot(glm::dvec2{mouse.x - last.x, mouse.z - last.z}, heading))};
|
||||
mouse = {last.x + heading.x * along, mouse.y, last.z + heading.y * along};
|
||||
}
|
||||
lay.mouse = typed_lay(mouse);
|
||||
lay.mouse_snap = straight ? editor_track::snap_target{} : m_typed.empty() ? snap_free_end(lay.mouse, cursor, nullptr, kRailCategory, {}) : editor_track::find_free_end(nullptr, kRailCategory, lay.mouse, kLaySnapRadius, {});
|
||||
@@ -3907,7 +3910,7 @@ glm::dvec3 editor_mode::cursor_level(double const Height) const
|
||||
glm::dvec3 const ground{cursor_ground()};
|
||||
screen_projection const projection;
|
||||
glm::dvec3 level;
|
||||
if (false == projection.on_level(ImGui::GetIO().MousePos, Height, level) || glm::distance(level, glm::dvec3{Global.pCamera.Pos}) > static_cast<double>(kMaxPlacementDistance))
|
||||
if (false == projection.on_level(ImGui::GetIO().MousePos, Height, level) || (false == Global.editor_tracks && glm::distance(level, glm::dvec3{Global.pCamera.Pos}) > static_cast<double>(kMaxPlacementDistance)))
|
||||
return ground;
|
||||
return level;
|
||||
}
|
||||
@@ -5049,15 +5052,11 @@ void editor_mode::draw_build_overlay() const
|
||||
previous = next;
|
||||
}
|
||||
};
|
||||
glm::dvec3 const camera{Global.pCamera.Pos};
|
||||
auto const &display{ImGui::GetIO().DisplaySize};
|
||||
for (auto const *track : simulation::Paths.sequence())
|
||||
{
|
||||
if (track == nullptr || track->m_editorremoved || track->m_paths.empty())
|
||||
continue;
|
||||
auto const &first{track->m_paths.front().points};
|
||||
if (glm::distance(first[segment_data::point::start], camera) > kJointRange && glm::distance(first[segment_data::point::end], camera) > kJointRange)
|
||||
continue;
|
||||
for (auto const &path : track->m_paths)
|
||||
for (auto const point : {segment_data::point::start, segment_data::point::end})
|
||||
{
|
||||
|
||||
@@ -40,8 +40,6 @@ namespace
|
||||
using geometry::bezier;
|
||||
|
||||
float const kHoverPixels{12.0f};
|
||||
double const kHoverReachMin{15.0};
|
||||
double const kHoverReachMax{250.0};
|
||||
double const kHoverLabelDelay{0.35}; // s the cursor rests on a path before its data shows up
|
||||
double const kFocusDistance{25.0};
|
||||
auto const kContextClick{std::chrono::milliseconds(350)};
|
||||
@@ -98,50 +96,40 @@ editor_mode::track_hover editor_mode::track_under_cursor() const
|
||||
{
|
||||
track_hover result;
|
||||
auto const &io{ImGui::GetIO()};
|
||||
glm::dvec3 const camera{Global.pCamera.Pos};
|
||||
glm::dvec3 const ground{cursor_ground()};
|
||||
auto const reach{std::clamp(glm::distance(camera, ground) * 0.1, kHoverReachMin, kHoverReachMax)};
|
||||
screen_projection const projection;
|
||||
glm::vec2 const mouse{io.MousePos.x, io.MousePos.y};
|
||||
double best{kHoverPixels * kHoverPixels};
|
||||
for (auto *section : simulation::Region->sections(ground, static_cast<float>(reach)))
|
||||
for (auto *track : simulation::Paths.sequence())
|
||||
{
|
||||
for (auto const &cell : section->m_cells)
|
||||
if (track == nullptr || false == rail(*track) || track->m_editorremoved)
|
||||
continue;
|
||||
for (int i = 0; i < static_cast<int>(track->m_paths.size()); ++i)
|
||||
{
|
||||
for (auto *track : cell.m_directories.paths)
|
||||
bezier const curve{track->m_paths[i]};
|
||||
auto const count{std::clamp(static_cast<int>(curve.plan_length() / 3.0), 6, 64)};
|
||||
auto previous{curve.point(0.0)};
|
||||
ImVec2 from;
|
||||
bool visible{projection.project(previous, from)};
|
||||
for (int k = 1; k <= count; ++k)
|
||||
{
|
||||
if (track == nullptr || false == rail(*track))
|
||||
continue;
|
||||
for (int i = 0; i < static_cast<int>(track->m_paths.size()); ++i)
|
||||
auto const next{curve.point(static_cast<double>(k) / count)};
|
||||
ImVec2 to;
|
||||
bool const shown{projection.project(next, to)};
|
||||
if (visible && shown)
|
||||
{
|
||||
bezier const curve{track->m_paths[i]};
|
||||
auto const count{std::clamp(static_cast<int>(curve.plan_length() / 3.0), 6, 64)};
|
||||
auto previous{curve.point(0.0)};
|
||||
ImVec2 from;
|
||||
bool visible{projection.project(previous, from)};
|
||||
for (int k = 1; k <= count; ++k)
|
||||
double t;
|
||||
auto const distance{segment_distance2(mouse, {from.x, from.y}, {to.x, to.y}, t)};
|
||||
if (distance < best)
|
||||
{
|
||||
auto const next{curve.point(static_cast<double>(k) / count)};
|
||||
ImVec2 to;
|
||||
bool const shown{projection.project(next, to)};
|
||||
if (visible && shown)
|
||||
{
|
||||
double t;
|
||||
auto const distance{segment_distance2(mouse, {from.x, from.y}, {to.x, to.y}, t)};
|
||||
auto const point{glm::mix(previous, next, t)};
|
||||
if (distance < best && glm::distance(point, camera) <= static_cast<double>(kMaxPlacementDistance))
|
||||
{
|
||||
best = distance;
|
||||
result.track = track;
|
||||
result.path = i;
|
||||
result.point = point;
|
||||
}
|
||||
}
|
||||
previous = next;
|
||||
from = to;
|
||||
visible = shown;
|
||||
best = distance;
|
||||
result.track = track;
|
||||
result.path = i;
|
||||
result.point = glm::mix(previous, next, t);
|
||||
}
|
||||
}
|
||||
previous = next;
|
||||
from = to;
|
||||
visible = shown;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -908,14 +896,13 @@ void editor_mode::finish_track_box()
|
||||
glm::vec2 const low{std::min(box.from.x, box.to.x), std::min(box.from.y, box.to.y)};
|
||||
glm::vec2 const high{std::max(box.from.x, box.to.x), std::max(box.from.y, box.to.y)};
|
||||
screen_projection const projection;
|
||||
glm::dvec3 const camera{Global.pCamera.Pos};
|
||||
track_set_prune();
|
||||
if (m_track_set.empty())
|
||||
if (auto *selected{selected_track()}; selected != nullptr)
|
||||
m_track_set.push_back(selected);
|
||||
for (auto *track : simulation::Paths.sequence())
|
||||
{
|
||||
if (track == nullptr || false == rail(*track) || in_track_set(track) || glm::distance(track->location(), camera) > static_cast<double>(Global.BaseDrawRange))
|
||||
if (track == nullptr || false == rail(*track) || in_track_set(track))
|
||||
continue;
|
||||
bool inside{false};
|
||||
for (auto const &path : track->m_paths)
|
||||
|
||||
Reference in New Issue
Block a user