Skip to content

Commit

Permalink
3d mode WIP
Browse files Browse the repository at this point in the history
- Currently only basic flats are rendered
- Trying out a different control scheme with the cursor unlocked to select flats/walls, and can hold right click to mouselook around. An 'always mouselook' style like before will probably also be an option, but the new scheme will probably be required in certain cases like wayland where we can't warp the mouse pointer (yet)
- Also includes other various fixes/updates and refactoring
  • Loading branch information
sirjuddington committed Jan 24, 2025
1 parent 1f050e5 commit 2195f5e
Show file tree
Hide file tree
Showing 42 changed files with 805 additions and 3,855 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if(BUILD_WX)
FetchContent_Declare(
wxWidgets
GIT_REPOSITORY https://github.com/wxWidgets/wxWidgets.git
GIT_TAG 181f7a1d5533a3b135de1fd8f0467ba15a8a9f69 # master (3.3.0) as of 2024-11-26
GIT_TAG 01e7c6bc919369601533c84d10d6664aaa4220c3 # master (3.3.0) as of 2025-01-14
)
FetchContent_GetProperties(wxwidgets)
if(NOT wxwidgets_POPULATED)
Expand Down
19 changes: 19 additions & 0 deletions dist/res/shaders/default3d.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
in VertexData
{
vec2 tex_coord;
vec3 normal;
} vertex_in;

out vec4 f_colour;

uniform vec4 colour = vec4(1.0);
//uniform vec2 viewport_size;

uniform sampler2D tex_unit;

void main()
{
vec4 col = colour * texture(tex_unit, vertex_in.tex_coord);

f_colour = col;
}
19 changes: 19 additions & 0 deletions dist/res/shaders/default3d.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
layout (location = 0) in vec3 in_position;
layout (location = 1) in vec2 in_tex_coord;
layout (location = 2) in vec3 in_normal;

out VertexData
{
vec2 tex_coord;
vec3 normal;
} vertex_out;

uniform mat4 mvp;

void main()
{
vertex_out.tex_coord = in_tex_coord;
vertex_out.normal = in_normal;

gl_Position = mvp * vec4(in_position, 1.0);
}
2 changes: 1 addition & 1 deletion src/Audio/AudioTags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ wxString parseID3v1Tag(const MemChunk& mc, size_t start)
album = wxString::FromAscii(tag.album, 30);
comment = wxString::FromAscii(tag.comment, 30);
year = wxString::FromAscii(tag.year, 4);
genre = (tag.genre < 192) ? wxString::FromAscii(ID3_V1_GENRES[tag.genre]) : "";
genre = (tag.genre < 192) ? wxString::FromAscii(ID3_V1_GENRES[tag.genre]) : wxString{};
if (tag.comment[28] == 0 && tag.comment[29] != 0)
{
version = "ID3v1.1";
Expand Down
2 changes: 1 addition & 1 deletion src/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ void game::init()
if (!zscript_entry)
{
// Bail out if no entry is found.
log::warning(1, "Could not find \'zscript.txt\' in " + zdoom_pk3_path);
log::warning(1, "Could not find \'zscript.txt\' in " + zdoom_pk3_path.value);
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions src/MainEditor/EntryOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ bool entryoperations::compileACS(ArchiveEntry* entry, bool hexen, ArchiveEntry*
entry->exportFile(srcfile);

// Execute acc
wxString command = "\"" + path_acc + "\"" + " " + opt + " \"" + srcfile + "\" \"" + ofile + "\"";
wxString command = "\"" + path_acc.value + "\"" + " " + opt + " \"" + srcfile + "\" \"" + ofile + "\"";
wxArrayString output;
wxArrayString errout;
wxGetApp().SetTopWindow(parent);
Expand Down Expand Up @@ -1590,7 +1590,7 @@ bool entryoperations::compileDECOHack(ArchiveEntry* entry, ArchiveEntry* target,
entry->exportFile(srcfile);

// Execute DECOHack
wxString command = "\"" + path_java + "\" -cp \"" + path_decohack + "\""
wxString command = "\"" + path_java.value + "\" -cp \"" + path_decohack.value + "\""
+ " -Xms64M -Xmx4G net.mtrop.doom.tools.DecoHackMain \"" + srcfile + "\" -o \"" + dehfile + "\"";
wxArrayString output;
wxArrayString errout;
Expand Down Expand Up @@ -1757,7 +1757,7 @@ bool entryoperations::optimizePNG(ArchiveEntry* entry)
wxString optfile = fn.GetFullPath();
entry->exportFile(pngfile.ToStdString());

wxString command = path_pngcrush + " -brute \"" + pngfile + "\" \"" + optfile + "\"";
wxString command = path_pngcrush.value + " -brute \"" + pngfile + "\" \"" + optfile + "\"";
output.Empty();
errors.Empty();
wxExecute(command, output, errors, wxEXEC_SYNC);
Expand Down Expand Up @@ -1809,7 +1809,7 @@ bool entryoperations::optimizePNG(ArchiveEntry* entry)
wxString optfile = fn.GetFullPath();
entry->exportFile(pngfile.ToStdString());

wxString command = path_pngout + " /y \"" + pngfile + "\" \"" + optfile + "\"";
wxString command = path_pngout.value + " /y \"" + pngfile + "\" \"" + optfile + "\"";
output.Empty();
errors.Empty();
wxExecute(command, output, errors, wxEXEC_SYNC);
Expand Down Expand Up @@ -1860,7 +1860,7 @@ bool entryoperations::optimizePNG(ArchiveEntry* entry)
wxString pngfile = fn.GetFullPath();
entry->exportFile(pngfile.ToStdString());

wxString command = path_deflopt + " /sf \"" + pngfile + "\"";
wxString command = path_deflopt.value + " /sf \"" + pngfile + "\"";
output.Empty();
errors.Empty();
wxExecute(command, output, errors, wxEXEC_SYNC);
Expand Down
16 changes: 8 additions & 8 deletions src/MapEditor/Edit/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "MapEditor/ItemSelection.h"
#include "MapEditor/MapEditContext.h"
#include "MapEditor/MapEditor.h"
#include "MapEditor/Renderer/Camera.h"
#include "MapEditor/Renderer/MCAnimations.h"
#include "MapEditor/Renderer/MapRenderer3D.h"
#include "MapEditor/Renderer/Overlays/MCOverlay.h"
Expand All @@ -50,6 +49,7 @@
#include "MapEditor/UI/ObjectEditPanel.h"
#include "MoveObjects.h"
#include "ObjectEdit.h"
#include "OpenGL/Camera.h"
#include "OpenGL/View.h"
#include "SLADEMap/MapObject/MapThing.h"
#include "UI/UI.h"
Expand Down Expand Up @@ -244,9 +244,9 @@ bool Input::mouseDown(MouseButton button, bool double_click)
if (context_->editMode() == Mode::Visual)
{
// If the mouse is unlocked, lock the mouse
if (!context_->mouseLocked())
context_->lockMouse(true);
else
// if (!context_->mouseLocked())
// context_->lockMouse(true);
// else
{
// Shift down, select all matching adjacent structures
if (shift_down_)
Expand Down Expand Up @@ -1146,8 +1146,7 @@ bool Input::updateCamera3d(double mult) const
// --- Check for held-down keys ---
bool moving = false;
double speed = shift_down_ ? mult * 8 : mult * 4;
auto& r3d = context_->renderer().renderer3D();
auto& camera = r3d.camera();
auto& camera = context_->renderer().camera();

// Camera forward
if (KeyBind::isPressed("me3d_camera_forward"))
Expand Down Expand Up @@ -1206,8 +1205,9 @@ bool Input::updateCamera3d(double mult) const
}

// Apply gravity to camera if needed
if (camera_3d_gravity)
r3d.cameraApplyGravity(mult);
// TODO: 3dmode
// if (camera_3d_gravity)
// r3d.cameraApplyGravity(mult);

return moving;
}
Expand Down
23 changes: 13 additions & 10 deletions src/MapEditor/MapEditContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
#include "MapEditor/UI/Dialogs/SectorSpecialDialog.h"
#include "MapEditor/UI/Dialogs/ShowItemDialog.h"
#include "MapTextureManager.h"
#include "OpenGL/Camera.h"
#include "OpenGL/Draw2D.h"
#include "Renderer/Camera.h"
#include "Renderer/MapRenderer3D.h"
#include "Renderer/Overlays/LineInfoOverlay.h"
#include "Renderer/Overlays/SectorInfoOverlay.h"
Expand Down Expand Up @@ -166,7 +166,7 @@ void MapEditContext::setEditMode(Mode mode)
// Clear 3d mode undo manager etc on exiting 3d mode
if (edit_mode_ == Mode::Visual && mode != Mode::Visual)
{
info_3d_.reset();
info_3d_->reset();
undo_manager_->createMergedLevel(edit_3d_->undoManager(), "3D Mode Editing");
edit_3d_->undoManager()->clear();
}
Expand Down Expand Up @@ -248,8 +248,9 @@ void MapEditContext::setEditMode(Mode mode)
{
SAction::fromId("mapw_mode_3d")->setChecked();
KeyBind::releaseAll();
lockMouse(true);
renderer_->renderer3D().refresh();
// lockMouse(true);
// TODO: 3dmode
// renderer_->renderer3D().refresh();
}
mapeditor::window()->refreshToolBar();
}
Expand Down Expand Up @@ -321,7 +322,7 @@ bool MapEditContext::update(double frametime)
next_frame_length_ = 2;

// Update status bar
auto pos = camera3d().position();
auto pos = renderer_->camera().position();
mapeditor::setStatusText(
fmt::format(
"Position: ({}, {}, {})", static_cast<int>(pos.x), static_cast<int>(pos.y), static_cast<int>(pos.z)),
Expand All @@ -332,7 +333,8 @@ bool MapEditContext::update(double frametime)
if (!selection_->hilightLocked())
{
auto old_hl = selection_->hilight();
hl = renderer_->renderer3D().determineHilight();
// TODO: 3dmode
// hl = renderer_->renderer3D().determineHilight();
if (selection_->setHilight(hl))
{
// Update 3d info overlay
Expand Down Expand Up @@ -547,8 +549,9 @@ void MapEditContext::forceRefreshRenderer() const
// Update 3d mode info overlay if needed
if (edit_mode_ == Mode::Visual)
{
auto hl = renderer_->renderer3D().determineHilight();
info_3d_->update({ hl.index, hl.type }, map_.get());
// TODO: 3dmode
// auto hl = renderer_->renderer3D().determineHilight();
// info_3d_->update({ hl.index, hl.type }, map_.get());
}

if (!canvas_->activateContext())
Expand Down Expand Up @@ -1596,9 +1599,9 @@ void MapEditContext::resetPlayerStart() const
// -----------------------------------------------------------------------------
// Returns the 3d renderer's camera
// -----------------------------------------------------------------------------
Camera& MapEditContext::camera3d() const
gl::Camera& MapEditContext::camera3d() const
{
return renderer_->renderer3D().camera();
return renderer_->camera();
}

// -----------------------------------------------------------------------------
Expand Down
13 changes: 8 additions & 5 deletions src/MapEditor/MapEditContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Forward declarations
namespace slade
{
class Camera;
class InfoOverlay3D;
class ItemSelection;
class LineInfoOverlay;
Expand All @@ -17,10 +16,14 @@ class ThingInfoOverlay;
class UndoManager;
class UndoStep;
class VertexInfoOverlay;
namespace gl::draw2d
namespace gl
{
struct Context;
}
class Camera;
namespace draw2d
{
struct Context;
}
} // namespace gl
namespace ui
{
enum class MouseCursor;
Expand Down Expand Up @@ -150,7 +153,7 @@ class MapEditContext : public SActionHandler
void resetPlayerStart() const;

// Renderer
Camera& camera3d() const;
gl::Camera& camera3d() const;

// Misc
string modeString(bool plural = true) const;
Expand Down
43 changes: 0 additions & 43 deletions src/MapEditor/Renderer/Camera.h

This file was deleted.

23 changes: 23 additions & 0 deletions src/MapEditor/Renderer/Flat3D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

namespace slade::mapeditor
{
struct Flat3D
{
// Origin
const MapSector* sector = nullptr;
// const MapSector* control_sector = nullptr; // Maybe for 3d floors?
bool ceiling = false;

// Vertex buffer info
unsigned vertex_offset = 0;
unsigned vertex_count = 0;

// Render info
glm::vec4 colour = glm::vec4{ 1.0f };
glm::vec3 normal = glm::vec3{ 0.0f, 0.0f, 1.0f };
unsigned texture = 0;

long updated_time = 0;
};
} // namespace slade::mapeditor
4 changes: 2 additions & 2 deletions src/MapEditor/Renderer/MCAnimations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "General/ColourConfiguration.h"
#include "MapEditor/Item.h"
#include "MapRenderer2D.h"
#include "MapRenderer3D.h"
#include "OpenGL/Draw2D.h"
#include "OpenGL/GLTexture.h"
#include "OpenGL/OpenGL.h"
Expand Down Expand Up @@ -611,5 +610,6 @@ bool MCAHilightFade3D::update(long time)
// -----------------------------------------------------------------------------
void MCAHilightFade3D::draw()
{
renderer_->renderHilight({ item_index_, item_type_ }, fade_);
// TODO: 3dmode
// renderer_->renderHilight({ item_index_, item_type_ }, fade_);
}
Loading

0 comments on commit 2195f5e

Please sign in to comment.