UV adjustment feature

This commit is contained in:
KP 2024-07-31 00:58:55 -05:00
parent cc42b4ea87
commit 35ccb134b5
4 changed files with 856 additions and 354 deletions

File diff suppressed because it is too large Load diff

View file

@ -304,9 +304,9 @@ void Map::BuildQuad(Sector& sector, Wall& wall, Flat& flat_topr, Flat& flat_bott
// Fix up the UVs so they keep the right scale // Fix up the UVs so they keep the right scale
float tw = texture_scale / wall.materials[mat_type]->textures[MAT_TEX_DIFFUSE].GetWidth(); float tw = texture_scale / wall.materials[mat_type]->textures[MAT_TEX_DIFFUSE].GetWidth();
float th = texture_scale / wall.materials[mat_type]->textures[MAT_TEX_DIFFUSE].GetHeight(); float th = texture_scale / wall.materials[mat_type]->textures[MAT_TEX_DIFFUSE].GetHeight();
Vertex3D vtxa = Vertex3D(fva, Vec2(au * tw, av * th)); Vertex3D vtxa = Vertex3D(fva, Vec2(au * tw + uv_offset.x/128.0f, av * th + uv_offset.y/128.0f));
Vertex3D vtxb = Vertex3D(fvb, Vec2(bu * tw, bv * th)); Vertex3D vtxb = Vertex3D(fvb, Vec2(bu * tw + uv_offset.x/128.0f, bv * th + uv_offset.y/128.0f));
Vertex3D vtxc = Vertex3D(fvc, Vec2(cu * tw, cv * th)); Vertex3D vtxc = Vertex3D(fvc, Vec2(cu * tw + uv_offset.x/128.0f, cv * th + uv_offset.y/128.0f));
BatchSectorInfo info = {BatchSectorInfo::BATCH_WALL, (MaterialType)(mat_type + 2), &sector, nullptr, &wall}; BatchSectorInfo info = {BatchSectorInfo::BATCH_WALL, (MaterialType)(mat_type + 2), &sector, nullptr, &wall};
m_mesh.AddBatch(&wall.materials[mat_type]->textures[MAT_TEX_DIFFUSE], {vtxa, vtxb, vtxc}, flip, std::make_any<BatchSectorInfo>(info), &wall.materials[mat_type]->textures[MAT_TEX_NORMAL]); m_mesh.AddBatch(&wall.materials[mat_type]->textures[MAT_TEX_DIFFUSE], {vtxa, vtxb, vtxc}, flip, std::make_any<BatchSectorInfo>(info), &wall.materials[mat_type]->textures[MAT_TEX_NORMAL]);
} }

View file

@ -230,14 +230,6 @@ void Editor::UpdateModeNormal()
{ {
using namespace kp3d; using namespace kp3d;
// Wall/flat selection
if (sandbox->IsMouseButtonDown(kp3d::MOUSE_BUTTON_LEFT) && !editing_gizmo)
{
// editor_hovered_batch = nullptr;
if (!sandbox->IsKeyDown(kp3d::KEY_LSHIFT))
{
editor_hovered_batch.clear();
}
struct Target struct Target
{ {
Vec3 position; Vec3 position;
@ -268,6 +260,23 @@ void Editor::UpdateModeNormal()
{ {
std::sort(targets.begin(), targets.end(), [&](const Target& a, const Target& b) { return a.distance > b.distance; }); std::sort(targets.begin(), targets.end(), [&](const Target& a, const Target& b) { return a.distance > b.distance; });
const Target& target = targets.back(); const Target& target = targets.back();
ray_pos = target.position;
}
// Wall/flat selection
if (sandbox->IsMouseButtonDown(kp3d::MOUSE_BUTTON_LEFT) && !editing_gizmo)
{
// editor_hovered_batch = nullptr;
if (!sandbox->IsKeyDown(kp3d::KEY_LSHIFT))
{
editor_hovered_batch.clear();
}
if (!targets.empty())
{
const Target& target = targets.back();
//std::sort(targets.begin(), targets.end(), [&](const Target& a, const Target& b) { return a.distance > b.distance; });
//const Target& target = targets.back();
//ray_pos = target.position;
if (editor_hovered_batch.empty()) if (editor_hovered_batch.empty())
{ {
if (std::find(editor_hovered_batch.begin(), editor_hovered_batch.end(), target.b) == editor_hovered_batch.end()) if (std::find(editor_hovered_batch.begin(), editor_hovered_batch.end(), target.b) == editor_hovered_batch.end())
@ -414,11 +423,42 @@ void Editor::UpdateModeNormal()
// UV adjust // UV adjust
if (sandbox->IsMouseButtonDown(kp3d::MOUSE_BUTTON_MIDDLE)) if (sandbox->IsMouseButtonDown(kp3d::MOUSE_BUTTON_MIDDLE))
{ {
if (!uv_adjusting)
{
old_ray_pos = ray_pos;
uv_adjusting = true;
}
try
{
const auto& info = std::any_cast<kp3d::BatchSectorInfo>(kp3d::editor_hovered_batch[0]->userdata);
if (info.wall)
{
Vec3 delta = ray_pos - old_ray_pos;
Vec2 delta_proj = {
(delta.x - delta.z),
-delta.y
};
info.wall->uv_offset[info.mat_type - 2].x += delta_proj.x * 128.0f;
info.wall->uv_offset[info.mat_type - 2].y += delta_proj.y * 128.0f;
if (Distance(ray_pos, old_ray_pos) > 1.0f/128.0f)
RebuildMap();
old_ray_pos = ray_pos;
}
}
catch (std::bad_any_cast& e)
{
KP3D_LOG_ERROR("Bad any cast: {}", e.what());
kp3d::editor_hovered_batch.clear();
}
} }
else else
{ {
uv_adjusting = false;
} }
if (editing_gizmo) if (editing_gizmo)

View file

@ -75,4 +75,8 @@ private:
WallUpdate wall_update; WallUpdate wall_update;
bool can_wall_update = false; bool can_wall_update = false;
kp3d::Vec3 old_ray_pos;
kp3d::Vec3 ray_pos;
bool uv_adjusting = false;
}; };