Skip to content

Commit

Permalink
Added light/effect/sound billboards
Browse files Browse the repository at this point in the history
  • Loading branch information
Borf committed Feb 4, 2022
1 parent 6ebcdc1 commit f24b8ab
Show file tree
Hide file tree
Showing 65 changed files with 823 additions and 167 deletions.
6 changes: 6 additions & 0 deletions BrowEdit3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
<ItemGroup>
<ClCompile Include="browedit\actions\DeleteObjectAction.cpp" />
<ClCompile Include="browedit\actions\GroupAction.cpp" />
<ClCompile Include="browedit\actions\ModelChangeAction.cpp" />
<ClCompile Include="browedit\actions\NewObjectAction.cpp" />
<ClCompile Include="browedit\actions\ObjectChangeAction.cpp" />
<ClCompile Include="browedit\actions\SelectAction.cpp" />
<ClCompile Include="browedit\BrowEdit.cpp" />
<ClCompile Include="browedit\BrowEdit.glfw.cpp" />
<ClCompile Include="browedit\BrowEdit.imgui.cpp" />
<ClCompile Include="browedit\components\BillboardRenderer.cpp" />
<ClCompile Include="browedit\components\Component.cpp" />
<ClCompile Include="browedit\components\Gnd.cpp" />
<ClCompile Include="browedit\components\GndRenderer.cpp" />
Expand Down Expand Up @@ -83,10 +85,12 @@
<ClInclude Include="browedit\actions\Action.h" />
<ClInclude Include="browedit\actions\DeleteObjectAction.h" />
<ClInclude Include="browedit\actions\GroupAction.h" />
<ClInclude Include="browedit\actions\ModelChangeAction.h" />
<ClInclude Include="browedit\actions\NewObjectAction.h" />
<ClInclude Include="browedit\actions\ObjectChangeAction.h" />
<ClInclude Include="browedit\actions\SelectAction.h" />
<ClInclude Include="browedit\BrowEdit.h" />
<ClInclude Include="browedit\components\BillboardRenderer.h" />
<ClInclude Include="browedit\components\Collider.h" />
<ClInclude Include="browedit\components\Component.h" />
<ClInclude Include="browedit\components\Gnd.h" />
Expand Down Expand Up @@ -150,6 +154,8 @@
<Image Include="icon.ico" />
</ItemGroup>
<ItemGroup>
<None Include="data\shaders\billboard.fs" />
<None Include="data\shaders\billboard.vs" />
<None Include="data\shaders\gnd.fs" />
<None Include="data\shaders\gnd.vs" />
<None Include="data\shaders\rsm.fs" />
Expand Down
18 changes: 18 additions & 0 deletions BrowEdit3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@
<ClCompile Include="browedit\windows\HelpWindow.cpp">
<Filter>browedit\windows</Filter>
</ClCompile>
<ClCompile Include="browedit\actions\ModelChangeAction.cpp">
<Filter>browedit\actions</Filter>
</ClCompile>
<ClCompile Include="browedit\components\BillboardRenderer.cpp">
<Filter>browedit\components</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="lib\imgui\imgui.h">
Expand Down Expand Up @@ -433,6 +439,12 @@
<ClInclude Include="lib\imgui\imgui_markdown.h">
<Filter>lib\imgui</Filter>
</ClInclude>
<ClInclude Include="browedit\actions\ModelChangeAction.h">
<Filter>browedit\actions</Filter>
</ClInclude>
<ClInclude Include="browedit\components\BillboardRenderer.h">
<Filter>browedit\components</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="BrowEdit3.rc">
Expand Down Expand Up @@ -463,5 +475,11 @@
<None Include="data\shaders\rsm.vs">
<Filter>data\shaders</Filter>
</None>
<None Include="data\shaders\billboard.fs">
<Filter>data\shaders</Filter>
</None>
<None Include="data\shaders\billboard.vs">
<Filter>data\shaders</Filter>
</None>
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions Doc Edit.url
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,11
[InternetShortcut]
IDList=
URL=https://stackedit.io/app#providerId=googleDriveWorkspace&folderId=1Fx2lndtJ9DBJ2F0ZI_aIb0fk-ppD27Si
39 changes: 25 additions & 14 deletions browedit/BrowEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void BrowEdit::run()
openWindow();
if (windowData.undoVisible)
showUndoWindow();
if (windowData.objectWindowVisible)
if (windowData.objectWindowVisible && editMode == EditMode::Object)
showObjectWindow();
if (windowData.demoWindowVisible)
ImGui::ShowDemoWindow(&windowData.demoWindowVisible);
Expand Down Expand Up @@ -252,7 +252,9 @@ void BrowEdit::configBegin()
try {
config = configJson.get<Config>();
}
catch (...) {}
catch (...) {
std::cerr << "Config file invalid, resetting config" << std::endl;
}
if (config.isValid() != "")
{
windowData.configVisible = true;
Expand All @@ -272,14 +274,20 @@ void BrowEdit::configBegin()
}
}

bool BrowEdit::toolBarToggleButton(const std::string_view &name, int icon, bool* status, const char* tooltip)

ImVec4 enabledColor(144 / 255.0f, 193 / 255.0f, 249 / 255.0f, 0.5f);
ImVec4 disabledColor(72 / 255.0f, 96 / 255.0f, 125 / 255.0f, 0.5f);

bool BrowEdit::toolBarToggleButton(const std::string_view &name, int icon, bool* status, const char* tooltip, ImVec4 tint)
{
ImVec2 v1((1.0f / iconsTexture->width) * (36 * (icon%4) + 1.5f), //TODO: remove these hardcoded numbers
(1.0f / iconsTexture->height) * (36 * (icon/4) + 1.5f));
ImVec2 v2(v1.x + (1.0f / iconsTexture->width) * 34, v1.y + (1.0f / iconsTexture->height) * 34);
if (tint.w < 0)
tint = config.toolbarButtonTint;
ImVec2 v1((1.0f / iconsTexture->width) * (100 * (icon % 8)), //TODO: remove these hardcoded numbers
(1.0f / iconsTexture->height) * (100 * (icon / 8)));
ImVec2 v2(v1.x + (1.0f / iconsTexture->width) * 100, v1.y + (1.0f / iconsTexture->height) * 100);
ImGui::PushID(name.data());

bool clicked = ImGui::ImageButton((ImTextureID)(long long)iconsTexture->id, ImVec2(32, 32), v1, v2, 0, ImVec4(144 / 255.0f, 193 / 255.0f, 249 / 255.0f, *status ? 1.0f : 0.0f));
bool clicked = ImGui::ImageButton((ImTextureID)(long long)iconsTexture->id, ImVec2(config.toolbarButtonSize, config.toolbarButtonSize), v1, v2, 0, *status ? enabledColor : disabledColor, tint);
if (ImGui::IsItemHovered())
ImGui::SetTooltip(tooltip);
if(clicked)
Expand All @@ -288,14 +296,16 @@ bool BrowEdit::toolBarToggleButton(const std::string_view &name, int icon, bool*
return clicked;
}

bool BrowEdit::toolBarToggleButton(const std::string_view& name, int icon, bool status, const char* tooltip)
bool BrowEdit::toolBarToggleButton(const std::string_view& name, int icon, bool status, const char* tooltip, ImVec4 tint)
{
ImVec2 v1((1.0f / iconsTexture->width) * (36 * (icon % 4) + 1.5f), //TODO: remove these hardcoded numbers
(1.0f / iconsTexture->height) * (36 * (icon / 4) + 1.5f));
ImVec2 v2(v1.x + (1.0f / iconsTexture->width) * 34, v1.y + (1.0f / iconsTexture->height) * 34);
if (tint.w < 0)
tint = config.toolbarButtonTint;
ImVec2 v1((1.0f / iconsTexture->width) * (100 * (icon % 8)), //TODO: remove these hardcoded numbers
(1.0f / iconsTexture->height) * (100 * (icon / 8)));
ImVec2 v2(v1.x + (1.0f / iconsTexture->width) * 100, v1.y + (1.0f / iconsTexture->height) * 100);
ImGui::PushID(name.data());

bool clicked = ImGui::ImageButton((ImTextureID)(long long)iconsTexture->id, ImVec2(32, 32), v1, v2, 0, ImVec4(144 / 255.0f, 193 / 255.0f, 249 / 255.0f, status ? 1.0f : 0.0f));
bool clicked = ImGui::ImageButton((ImTextureID)(long long)iconsTexture->id, ImVec2(config.toolbarButtonSize, config.toolbarButtonSize), v1, v2, 0, status ? enabledColor : disabledColor, tint);
if (ImGui::IsItemHovered())
ImGui::SetTooltip(tooltip);
ImGui::PopID();
Expand All @@ -320,8 +330,9 @@ void BrowEdit::showMapWindow(MapView& mapView)
}

ImTextureID id = (ImTextureID)((long long)mapView.fbo->texid[0]); //TODO: remove cast for 32bit
ImGui::Image(id, size, ImVec2(0,1), ImVec2(1,0));
mapView.hovered = ImGui::IsItemHovered();
ImGui::ImageButton(id, size, ImVec2(0,1), ImVec2(1,0), 0, ImVec4(0,0,0,1), ImVec4(1,1,1,1));
//ImGui::Image(id, size, ImVec2(0, 1), ImVec2(1, 0));
mapView.hovered = ImGui::IsItemHovered() || ImGui::IsItemClicked();
}
if (ImGui::IsWindowFocused())
{
Expand Down
12 changes: 6 additions & 6 deletions browedit/BrowEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ namespace gl
class Texture;
}

#define MISSING 63

class BrowEdit
{
const float toolbarHeight = 40.0f;


gl::Texture* backgroundTexture;
gl::Texture* iconsTexture;
std::vector<Map*> maps;
Expand Down Expand Up @@ -55,9 +53,11 @@ class BrowEdit
ImFont* font;
enum class EditMode
{
Height,
Texture,
Object,
Wall
Wall,
Gat,
} editMode = EditMode::Object;

std::map<std::string, std::vector<std::string>> tagList; // tag -> [ file ], utf8
Expand Down Expand Up @@ -103,6 +103,6 @@ class BrowEdit
void showHelpWindow();


bool toolBarToggleButton(const std::string_view &name, int icon, bool* status, const char* tooltip);
bool toolBarToggleButton(const std::string_view &name, int icon, bool status, const char* tooltip);
bool toolBarToggleButton(const std::string_view &name, int icon, bool* status, const char* tooltip, ImVec4 tint = ImVec4(1,1,1,-1));
bool toolBarToggleButton(const std::string_view &name, int icon, bool status, const char* tooltip, ImVec4 tint = ImVec4(1, 1, 1, -1));
};
4 changes: 2 additions & 2 deletions browedit/BrowEdit.imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void BrowEdit::imguiLoopBegin()
ImGui::NewFrame();

auto viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(ImVec2(viewport->WorkPos.x, viewport->WorkPos.y + toolbarHeight));
ImGui::SetNextWindowSize(ImVec2(viewport->WorkSize.x, viewport->WorkSize.y - 2*toolbarHeight));
ImGui::SetNextWindowPos(ImVec2(viewport->WorkPos.x, viewport->WorkPos.y + config.toolbarHeight()));
ImGui::SetNextWindowSize(ImVec2(viewport->WorkSize.x, viewport->WorkSize.y - 2*config.toolbarHeight()));
ImGui::SetNextWindowViewport(viewport->ID);
ImGuiWindowFlags host_window_flags = 0;
host_window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDocking;
Expand Down
2 changes: 2 additions & 0 deletions browedit/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ bool Config::showWindow(BrowEdit* browEdit)
ImGui::ColorEdit3("Background Color", glm::value_ptr(backgroundColor));
ImGui::DragFloat2 ("Object Window thumbnail size", &thumbnailSize.x, 1, 32, 512);
ImGui::Checkbox("Close object window when adding a model", &closeObjectWindowOnAdd);
ImGui::DragFloat("Toolbar Button Size", &toolbarButtonSize, 1, 1, 100);
ImGui::ColorEdit4("Toolbar Button Tint", &toolbarButtonTint.x);


if (ImGui::Button("Save"))
Expand Down
13 changes: 10 additions & 3 deletions browedit/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <json.hpp>
#include <vector>
#include <imgui.h>
#include <browedit/util/Util.h>
class BrowEdit;

class Config
Expand All @@ -17,6 +18,10 @@ class Config
glm::vec3 backgroundColor = glm::vec3(0.1f, 0.1f, 0.15f);
ImVec2 thumbnailSize = ImVec2(200, 200);
bool closeObjectWindowOnAdd = false;
float toolbarButtonSize = 32;
ImVec4 toolbarButtonTint = ImVec4(1, 1, 1, 1);

float toolbarHeight() { return toolbarButtonSize + 8; }

std::string isValid() const;
bool showWindow(BrowEdit* browEdit);
Expand All @@ -28,7 +33,9 @@ class Config
fov,
cameraMouseSpeed,
style,
backgroundColor.r, backgroundColor.g, backgroundColor.b,
thumbnailSize.x, thumbnailSize.y,
closeObjectWindowOnAdd);
backgroundColor,
thumbnailSize,
closeObjectWindowOnAdd,
toolbarButtonSize,
toolbarButtonTint);
};
32 changes: 16 additions & 16 deletions browedit/MapView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ MapView::MapView(Map* map, const std::string &viewName) : map(map), viewName(vie

void MapView::toolbar(BrowEdit* browEdit)
{
browEdit->toolBarToggleButton("ortho", 11, &ortho, "Toggle between ortho and perspective camera");
browEdit->toolBarToggleButton("ortho", ortho ? 24 : 25, &ortho, "Toggle between ortho and perspective camera");
ImGui::SameLine();

browEdit->toolBarToggleButton("viewLightMapShadow", 0, &viewLightmapShadow, "Toggle shadowmap");
browEdit->toolBarToggleButton("viewLightMapShadow", 8, &viewLightmapShadow, "Toggle shadowmap");
ImGui::SameLine();
browEdit->toolBarToggleButton("viewLightmapColor", 1, &viewLightmapColor, "Toggle colormap");
browEdit->toolBarToggleButton("viewLightmapColor", 9, &viewLightmapColor, "Toggle colormap");
ImGui::SameLine();
browEdit->toolBarToggleButton("viewColors", 2, &viewColors, "Toggle tile colors");
browEdit->toolBarToggleButton("viewColors", 11, &viewColors, "Toggle tile colors");
ImGui::SameLine();
browEdit->toolBarToggleButton("viewLighting", 3, &viewLighting, "Toggle lighting");
browEdit->toolBarToggleButton("viewLighting", 12, &viewLighting, "Toggle lighting");
ImGui::SameLine();
browEdit->toolBarToggleButton("smoothColors", 2, &smoothColors, "Smooth colormap");
browEdit->toolBarToggleButton("smoothColors", 63, &smoothColors, "Smooth colormap");
ImGui::SameLine();
ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal);
ImGui::SameLine();

bool snapping = snapToGrid;
if (ImGui::GetIO().KeyShift)
snapping = !snapping;
bool ret = browEdit->toolBarToggleButton("snapToGrid", 7, snapping, "Snap to grid");
bool ret = browEdit->toolBarToggleButton("snapToGrid", 14, snapping, "Snap to grid");
if (!ImGui::GetIO().KeyShift && ret)
snapToGrid = !snapToGrid;
if (snapping || snapToGrid)
Expand All @@ -76,26 +76,26 @@ void MapView::toolbar(BrowEdit* browEdit)
ImGui::SetTooltip("Local or Global grid. Either makes the movement rounded off, or the final position");
}

ImGui::SameLine();
ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal);
ImGui::SameLine();

if (browEdit->editMode == BrowEdit::EditMode::Object)
{
if (browEdit->toolBarToggleButton("translate", 8, gadget.mode == Gadget::Mode::Translate, "Move"))
ImGui::SameLine();
ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal);
ImGui::SameLine();
if (browEdit->toolBarToggleButton("translate", 20, gadget.mode == Gadget::Mode::Translate, "Move"))
gadget.mode = Gadget::Mode::Translate;
ImGui::SameLine();
if (browEdit->toolBarToggleButton("rotate", 9, gadget.mode == Gadget::Mode::Rotate, "Rotate"))
if (browEdit->toolBarToggleButton("rotate", 21, gadget.mode == Gadget::Mode::Rotate, "Rotate"))
gadget.mode = Gadget::Mode::Rotate;
ImGui::SameLine();
if (browEdit->toolBarToggleButton("scale", 10, gadget.mode == Gadget::Mode::Scale, "Scale"))
if (browEdit->toolBarToggleButton("scale", 22, gadget.mode == Gadget::Mode::Scale, "Scale"))
gadget.mode = Gadget::Mode::Scale;


if (gadget.mode == Gadget::Mode::Rotate || gadget.mode == Gadget::Mode::Scale)
{
ImGui::SameLine();
if (browEdit->toolBarToggleButton("localglobal", pivotPoint == MapView::PivotPoint::Local ? 12 : 13, false, "Changes the pivot point for rotations"))
if (browEdit->toolBarToggleButton("localglobal", pivotPoint == MapView::PivotPoint::Local ? MISSING : MISSING, false, "Changes the pivot point for rotations"))
{
if (pivotPoint == MapView::PivotPoint::Local)
pivotPoint = MapView::PivotPoint::GroupCenter;
Expand Down Expand Up @@ -178,7 +178,7 @@ void MapView::update(BrowEdit* browEdit, const ImVec2 &size)
(ImGui::IsMouseDown(1) ? 0x02 : 0x00) |
(ImGui::IsMouseDown(2) ? 0x04 : 0x00);

if (ImGui::IsWindowHovered())
if (hovered)
{
if (browEdit->editMode == BrowEdit::EditMode::Object)
updateObjectMode(browEdit);
Expand Down Expand Up @@ -223,7 +223,7 @@ void MapView::updateObjectMode(BrowEdit* browEdit)

void MapView::postRenderObjectMode(BrowEdit* browEdit)
{
if (!ImGui::IsWindowHovered())
if (!hovered)
return;
glUseProgram(0);
glMatrixMode(GL_PROJECTION);
Expand Down
43 changes: 43 additions & 0 deletions browedit/actions/ModelChangeAction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "ModelChangeAction.h"
#include <browedit/util/Util.h>
#include <browedit/util/ResourceManager.h>
#include <browedit/components/Rsw.h>
#include <browedit/components/Rsm.h>
#include <browedit/components/RsmRenderer.h>
#include <browedit/Node.h>

ModelChangeAction::ModelChangeAction(Node* node, const std::string& newFileName) : node(node), newFileName(newFileName)
{
auto rswModel = node->getComponent<RswModel>();
oldFileName = "data\\model\\" + util::utf8_to_iso_8859_1(rswModel->fileName);

}

void ModelChangeAction::perform(Map* map, BrowEdit* browEdit)
{
auto rswModel = node->getComponent<RswModel>();
rswModel->fileName = util::iso_8859_1_to_utf8(newFileName);
auto removed = node->removeComponent<Rsm>();
for (auto r : removed)
util::ResourceManager<Rsm>::unload(r);
node->addComponent(util::ResourceManager<Rsm>::load(newFileName));
node->getComponent<RsmRenderer>()->begin();
node->getComponent<RswModelCollider>()->begin();
}

void ModelChangeAction::undo(Map* map, BrowEdit* browEdit)
{
auto rswModel = node->getComponent<RswModel>();
rswModel->fileName = util::iso_8859_1_to_utf8(oldFileName);
auto removed = node->removeComponent<Rsm>();
for (auto r : removed)
util::ResourceManager<Rsm>::unload(r);
node->addComponent(util::ResourceManager<Rsm>::load(oldFileName));
node->getComponent<RsmRenderer>()->begin();
node->getComponent<RswModelCollider>()->begin();
}

std::string ModelChangeAction::str()
{
return "Changing model for " + node->name;
}
16 changes: 16 additions & 0 deletions browedit/actions/ModelChangeAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "Action.h"
class Node;

class ModelChangeAction : public Action
{
Node* node;
std::string newFileName;
std::string oldFileName;
public:
ModelChangeAction(Node* node, const std::string& newFileName); // ISO format
virtual void perform(Map* map, BrowEdit* browEdit) override;
virtual void undo(Map* map, BrowEdit* browEdit) override;
virtual std::string str() override;
};
Loading

0 comments on commit f24b8ab

Please sign in to comment.