Skip to content

Commit

Permalink
Merge pull request #23 from Tokeiburu/lub-effect
Browse files Browse the repository at this point in the history
Small fixes for lub effects and basic support for 0x207
  • Loading branch information
Borf authored Jun 17, 2024
2 parents c4cd61c + cb13df6 commit d7f4e8c
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 19 deletions.
2 changes: 2 additions & 0 deletions BrowEdit3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ClCompile Include="browedit\actions\GndVersionChangeAction.cpp" />
<ClCompile Include="browedit\actions\GroupAction.cpp" />
<ClCompile Include="browedit\actions\LightmapNewAction.cpp" />
<ClCompile Include="browedit\actions\LubChangeTextureAction.cpp" />
<ClCompile Include="browedit\actions\ModelChangeAction.cpp" />
<ClCompile Include="browedit\actions\NewObjectAction.cpp" />
<ClCompile Include="browedit\actions\ObjectChangeAction.cpp" />
Expand Down Expand Up @@ -144,6 +145,7 @@
<ClInclude Include="browedit\actions\GndVersionChangeAction.h" />
<ClInclude Include="browedit\actions\GroupAction.h" />
<ClInclude Include="browedit\actions\LightmapNewAction.h" />
<ClInclude Include="browedit\actions\LubChangeTextureAction.h" />
<ClInclude Include="browedit\actions\ModelChangeAction.h" />
<ClInclude Include="browedit\actions\NewObjectAction.h" />
<ClInclude Include="browedit\actions\ObjectChangeAction.h" />
Expand Down
6 changes: 6 additions & 0 deletions BrowEdit3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@
<ClCompile Include="browedit\actions\LightmapNewAction.cpp">
<Filter>browedit\actions</Filter>
</ClCompile>
<ClCompile Include="browedit\actions\LubChangeTextureAction.cpp">
<Filter>browedit\actions</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="lib\imgui\imgui.h">
Expand Down Expand Up @@ -735,6 +738,9 @@
<ClInclude Include="browedit\actions\LightmapNewAction.h">
<Filter>browedit\actions</Filter>
</ClInclude>
<ClInclude Include="browedit\actions\LubChangeTextureAction.h">
<Filter>browedit\actions</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="BrowEdit3.rc">
Expand Down
1 change: 1 addition & 0 deletions browedit/actions/LubChangeTextureAction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "LubChangeTextureAction.h"
36 changes: 36 additions & 0 deletions browedit/actions/LubChangeTextureAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include "Action.h"
#include <browedit/components/Rsw.h>
#include <browedit/components/RsmRenderer.h>
#include <browedit/components/GndRenderer.h>
#include <browedit/components/WaterRenderer.h>

class LubChangeTextureAction : public Action
{
std::string oldValue;
std::string newValue;
LubEffect* lubEffect;
public:
LubChangeTextureAction(LubEffect *lubEffect, std::string oldValue, std::string newValue)
{
this->lubEffect = lubEffect;
this->oldValue = oldValue;
this->newValue = newValue;
}

virtual void perform(Map* map, BrowEdit* browEdit)
{
this->lubEffect->texture = newValue;
this->lubEffect->dirty = true;
}
virtual void undo(Map* map, BrowEdit* browEdit)
{
this->lubEffect->texture = oldValue;
this->lubEffect->dirty = true;
}
virtual std::string str()
{
return "Texture changed to " + newValue;
};
};
28 changes: 26 additions & 2 deletions browedit/components/LubRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <browedit/Node.h>
#include <browedit/components/Rsw.h>
#include <browedit/components/Gnd.h>
#include <browedit/components/BillboardRenderer.h>
#include <browedit/gl/Texture.h>
#include <browedit/gl/Vertex.h>

Expand Down Expand Up @@ -44,7 +45,9 @@ void LubRenderer::render()
rswObject = node->getComponent<RswObject>();
if (!gnd)
gnd = node->root->getComponent<Gnd>();
if (!lubEffect || dirty)
if (!billboardRenderer)
billboardRenderer = node->getComponent<BillboardRenderer>();
if (!lubEffect || dirty || lubEffect->dirty)
{
lubEffect = node->getComponent<LubEffect>();
dirty = false;
Expand All @@ -60,6 +63,9 @@ void LubRenderer::render()
}
else
texture = nullptr;

if (lubEffect)
lubEffect->dirty = false;
}
if (!rswObject || !lubEffect || !gnd)
return;
Expand Down Expand Up @@ -164,10 +170,28 @@ void LubRenderer::render()
shader->setUniform(LubShader::Uniforms::modelMatrix, modelMatrixSub);
glDrawArrays(GL_QUADS, 4 * i, 4);
}

glDepthMask(1);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);

if (ImGui::GetIO().KeyShift && billboardRenderer != nullptr && billboardRenderer->selected) {
glLineWidth(2.0f);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
shader->setUniform(LubShader::Uniforms::selection, true);

for (int i = 0; i < particles.size(); i++)
{
Particle p = particles[i];
glm::mat4 modelMatrixSub = modelMatrix;
modelMatrixSub[3] += glm::vec4(p.position.x, p.position.y, -p.position.z, 0.0f);
shader->setUniform(LubShader::Uniforms::modelMatrix, modelMatrixSub);
glDrawArrays(GL_QUADS, 4 * i, 4);
}

shader->setUniform(LubShader::Uniforms::selection, false);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
}


Expand Down
4 changes: 4 additions & 0 deletions browedit/components/LubRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace gl { class Texture; }
class RswObject;
class Gnd;
class LubEffect;
class BillboardRenderer;

class LubRenderer : public Renderer
{
Expand All @@ -26,6 +27,7 @@ class LubRenderer : public Renderer
s_texture,
color,
billboard_off,
selection,
End
};
};
Expand All @@ -37,12 +39,14 @@ class LubRenderer : public Renderer
bindUniform(Uniforms::modelMatrix, "modelMatrix");
bindUniform(Uniforms::color, "color");
bindUniform(Uniforms::billboard_off, "billboard_off");
bindUniform(Uniforms::selection, "selection");
}
};
private:
bool dirty = true;
RswObject* rswObject = nullptr;
LubEffect* lubEffect = nullptr;
BillboardRenderer* billboardRenderer = nullptr;

gl::Texture* texture = nullptr;

Expand Down
8 changes: 4 additions & 4 deletions browedit/components/Rsw.Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <browedit/components/BillboardRenderer.h>
#include <browedit/actions/AddComponentAction.h>
#include <browedit/actions/RemoveComponentAction.h>
#include <browedit/actions/LubChangeTextureAction.h>

#include <iostream>
#include <fstream>
Expand Down Expand Up @@ -180,10 +181,9 @@ void LubEffect::buildImGuiMulti(BrowEdit* browEdit, const std::vector<Node*>& no
util::DragFloat2Multi<LubEffect>(browEdit, browEdit->activeMapView->map, lubEffects, "rate", [](LubEffect* e) {return &e->rate; }, 0.1f, 0, 0);
util::DragFloat2Multi<LubEffect>(browEdit, browEdit->activeMapView->map, lubEffects, "size", [](LubEffect* e) {return &e->size; }, 0.1f, 0, 0);
util::DragFloat2Multi<LubEffect>(browEdit, browEdit->activeMapView->map, lubEffects, "life", [](LubEffect* e) {return &e->life; }, 0.1f, 0, 0);
if (util::InputTextMulti<LubEffect>(browEdit, browEdit->activeMapView->map, lubEffects, "texture", [](LubEffect* e) {return &e->texture; }))
{

}
util::InputTextMulti<LubEffect>(browEdit, browEdit->activeMapView->map, lubEffects, "texture", [](LubEffect* e) {return &e->texture;}, [&](Node* node, std::string* ptr, std::string* startValue, const std::string& action) {
browEdit->activeMapView->map->doAction(new LubChangeTextureAction(node->getComponent<LubEffect>(), *startValue, *ptr), browEdit);
});
util::DragFloatMulti<LubEffect>(browEdit, browEdit->activeMapView->map, lubEffects, "speed", [](LubEffect* e) {return &e->speed; }, 0.1f, 0, 0);
util::DragIntMulti<LubEffect>(browEdit, browEdit->activeMapView->map, lubEffects, "srcmode", [](LubEffect* e) {return &e->srcmode; }, 1, 0, 0);
util::DragIntMulti<LubEffect>(browEdit, browEdit->activeMapView->map, lubEffects, "destmode", [](LubEffect* e) {return &e->destmode; }, 1, 0, 20);
Expand Down
16 changes: 15 additions & 1 deletion browedit/components/Rsw.Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ void RswModel::load(std::istream* is, int version, unsigned char buildNumber, bo
is->read(reinterpret_cast<char*>(&animSpeed), sizeof(float));
is->read(reinterpret_cast<char*>(&blockType), sizeof(int));
}
if (version >= 0x0206 && buildNumber >= 186)
if (version >= 0x206 && buildNumber >= 186)
{
unsigned char c = is->get(); // unknown, 0?
}

if (version >= 0x207)
{
// Tokei: No idea what this is for
int unknown;
is->read(reinterpret_cast<char*>(&unknown), sizeof(int));
}

std::string fileNameRaw = util::FileIO::readString(is, 80);
//std::cout << "Model: " << node->name << "\t" << fileNameRaw << std::endl;
fileName = util::iso_8859_1_to_utf8(fileNameRaw);
Expand Down Expand Up @@ -77,6 +84,13 @@ void RswModel::save(std::ofstream& file, int version, int buildNumber)
if (version >= 0x206 && buildNumber >= 186) {
file.put(0); // ??
}

if (version >= 0x207)
{
// Tokei: No idea what this is for
int unknown = -1;
file.write(reinterpret_cast<char*>(&unknown), sizeof(int));
}
}
util::FileIO::writeString(file, util::utf8_to_iso_8859_1(fileName), 80);
util::FileIO::writeString(file, util::utf8_to_iso_8859_1(objectName), 80); //unknown
Expand Down
25 changes: 25 additions & 0 deletions browedit/components/Rsw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@ void Rsw::load(const std::string& fileName, Map* map, BrowEdit* browEdit, bool l
unknown[1] = unknown[3] = 500;
}

// Tokei: Not sure what this is meant for
if (version >= 0x207)
{
int unknownCount;
file->read(reinterpret_cast<char*>(&unknownCount), sizeof(int));

for (int i = 0; i < unknownCount; i++) {
int unknownValue;
file->read(reinterpret_cast<char*>(&unknownValue), sizeof(int));
}
}

int objectCount;
file->read(reinterpret_cast<char*>(&objectCount), sizeof(int));
std::cout << "RSW: Loading " << objectCount << " objects" << std::endl;
Expand Down Expand Up @@ -549,6 +561,13 @@ void Rsw::save(const std::string& fileName, BrowEdit* browEdit)
file.write(reinterpret_cast<char*>(&unknown[3]), sizeof(int));
}

// Tokei: Not sure what this is meant for; fill it with 0 for now
if (version >= 0x207)
{
int unknownCount = 0;
file.write(reinterpret_cast<char*>(&unknownCount), sizeof(int));
}

std::vector<Node*> objects;
node->traverse([&objects](Node* n)
{
Expand Down Expand Up @@ -756,6 +775,12 @@ void Rsw::buildImGui(BrowEdit* browEdit)
version = 0x0203;
if (ImGui::Selectable("0204", version == 0x0204))
version = 0x0204;
if (ImGui::Selectable("0205", version == 0x0205))
version = 0x0205;
if (ImGui::Selectable("0206", version == 0x0206))
version = 0x0206;
if (ImGui::Selectable("0207", version == 0x0207))
version = 0x0207;
ImGui::EndCombo();
}

Expand Down
1 change: 1 addition & 0 deletions browedit/components/Rsw.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class LubEffect : public Component
int zenable;
int billboard_off;
glm::vec3 rotate_angle; // v3
bool dirty;

void load(const nlohmann::json& data);
static void buildImGuiMulti(BrowEdit* browEdit, const std::vector<Node*>&);
Expand Down
79 changes: 73 additions & 6 deletions browedit/util/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,73 @@ namespace util
}


template<class T>
bool InputTextMulti(BrowEdit* browEdit, Map* map, const std::vector<T*>& data, const char* label, const std::function<std::string* (T*)>& getProp, const std::function<void(Node* node, std::string* ptr, std::string* startValue, const std::string& action)>& editAction)
{
static std::vector<std::string> startValues;
bool differentValues = !std::all_of(data.begin(), data.end(), [&](T* o) { return *getProp(o) == *getProp(data.front()); });
std::string f = *getProp(data.front());
if (differentValues)
f = "multiple";
bool ret = ImGui::InputText(label, &f);
if (ret)
for (auto o : data)
*getProp(o) = f;
if (ImGui::IsItemActivated())
{
startValues.clear();
for (auto o : data)
startValues.push_back(*getProp(o));
}
if (ImGui::IsItemDeactivatedAfterEdit())
{
auto ga = new GroupAction();
for (auto i = 0; i < data.size(); i++)
editAction(data[i]->node, getProp(data[i]), &startValues[i], label);
map->doAction(ga, browEdit);
}
if (!differentValues)
{
ImGui::PushID(label);
if (ImGui::BeginPopupContextItem("CopyPaste"))
{
try {
if (ImGui::MenuItem("Copy"))
{
ImGui::SetClipboardText(getProp(data[0])->c_str());
}
if (ImGui::MenuItem("Paste"))
{
auto cb = ImGui::GetClipboardText();
if (cb)
{
startValues.clear();
for (auto o : data)
{
startValues.push_back(*getProp(o));
*getProp(o) = cb;
}
auto ga = new GroupAction();
for (auto i = 0; i < data.size(); i++)
editAction(data[i]->node, getProp(data[i]), &startValues[i], label);
ret = true;
}
}
}
catch (...) {}
ImGui::EndPopup();
}
ImGui::PopID();
}
return ret;
}
template bool InputTextMulti<RswObject>(BrowEdit* browEdit, Map* map, const std::vector<RswObject*>& data, const char* label, const std::function<std::string* (RswObject*)>& getProp, const std::function<void(Node* node, std::string* ptr, std::string* startValue, const std::string& action)>& editAction);
template bool InputTextMulti<RswLight>(BrowEdit* browEdit, Map* map, const std::vector<RswLight*>& data, const char* label, const std::function<std::string* (RswLight*)>& getProp, const std::function<void(Node* node, std::string* ptr, std::string* startValue, const std::string& action)>& editAction);
template bool InputTextMulti<RswEffect>(BrowEdit* browEdit, Map* map, const std::vector<RswEffect*>& data, const char* label, const std::function<std::string* (RswEffect*)>& getProp, const std::function<void(Node* node, std::string* ptr, std::string* startValue, const std::string& action)>& editAction);
template bool InputTextMulti<LubEffect>(BrowEdit* browEdit, Map* map, const std::vector<LubEffect*>& data, const char* label, const std::function<std::string* (LubEffect*)>& getProp, const std::function<void(Node* node, std::string* ptr, std::string* startValue, const std::string& action)>& editAction);
template bool InputTextMulti<RswSound>(BrowEdit* browEdit, Map* map, const std::vector<RswSound*>& data, const char* label, const std::function<std::string* (RswSound*)>& getProp, const std::function<void(Node* node, std::string* ptr, std::string* startValue, const std::string& action)>& editAction);
template bool InputTextMulti<RswModel>(BrowEdit* browEdit, Map* map, const std::vector<RswModel*>& data, const char* label, const std::function<std::string* (RswModel*)>& getProp, const std::function<void(Node* node, std::string* ptr, std::string* startValue, const std::string& action)>& editAction);

template<class T>
bool InputTextMulti(BrowEdit* browEdit, Map* map, const std::vector<T*>& data, const char* label, const std::function<std::string* (T*)>& getProp)
{
Expand Down Expand Up @@ -774,12 +841,6 @@ namespace util
else if ((*f)[0] == (*f)[2])
(*f)[2] = (*f)[0] = (*f)[1];
}
if (ImGui::IsItemActivated())
{
startValues.clear();
for (auto o : data)
startValues.push_back(*getProp(o));
}
if (ret)
{
for (auto o : data)
Expand All @@ -799,6 +860,12 @@ namespace util
ga->addAction(new ObjectChangeAction(data[i]->node, getProp(data[i]), startValues[i], label));
map->doAction(ga, browEdit);
}
if (ImGui::IsItemActivated())
{
startValues.clear();
for (auto o : data)
startValues.push_back(*getProp(o));
}
if (!differentValues)
{
ImGui::PushID(label);
Expand Down
3 changes: 3 additions & 0 deletions browedit/util/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ namespace util
bool InputText(BrowEdit* browEdit, Map* map, Node* node, const char* label, std::string* ptr, ImGuiInputTextFlags flags = 0, const std::string& action = "");
bool Checkbox(BrowEdit* browEdit, Map* map, Node* node, const char* label, bool* ptr, const std::string& action = "");

template<class T>
bool InputTextMulti(BrowEdit* browEdit, Map* map, const std::vector<T*>& data, const char* label, const std::function<std::string* (T*)>& getProp, const std::function<void(Node* node, std::string* ptr, std::string* startValue, const std::string& action)>& editAction);

template<class T>
bool InputTextMulti(BrowEdit* browEdit, Map* map, const std::vector<T*>& data, const char* label, const std::function<std::string* (T*)>& getProp);

Expand Down
Loading

0 comments on commit d7f4e8c

Please sign in to comment.