-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce38b44
commit 71c7fef
Showing
9 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "CommonMaterial.h" | ||
|
||
cdc::MaterialData* cdc::CommonMaterial::GetMaterialData() const noexcept | ||
{ | ||
return m_pData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "MaterialData.h" | ||
|
||
namespace cdc | ||
{ | ||
class IMaterial | ||
{ | ||
public: | ||
virtual ~IMaterial() = 0; | ||
}; | ||
|
||
class CommonMaterial : public IMaterial | ||
{ | ||
private: | ||
MaterialData* m_pData; | ||
|
||
public: | ||
MaterialData* GetMaterialData() const noexcept; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
namespace cdc | ||
{ | ||
struct MaterialData | ||
{ | ||
char pad[88]; | ||
|
||
__int16 numParameters; | ||
float* parameters; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
namespace cdc | ||
{ | ||
template <typename T> | ||
class Array | ||
{ | ||
public: | ||
unsigned int m_size; | ||
unsigned int m_cap; | ||
|
||
T* m_data; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <utility> | ||
|
||
#include "Array.h" | ||
|
||
namespace cdc | ||
{ | ||
template <typename K, typename V> | ||
class HashTable | ||
{ | ||
public: | ||
class Node | ||
{ | ||
public: | ||
Node* m_next; | ||
std::pair<K, V> m_data; | ||
}; | ||
|
||
cdc::Array<Node*> m_buckets; | ||
unsigned int m_size; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include <imgui.h> | ||
#include <string> | ||
|
||
#include "Materials.h" | ||
#include "render/Material.h" | ||
|
||
#include "cdc/sys/HashMap.h" | ||
|
||
void Materials::OnMenu() | ||
{ | ||
if (ImGui::BeginMenu("Materials")) | ||
{ | ||
ImGui::MenuItem("Material editor", nullptr, &m_show); | ||
|
||
ImGui::EndMenu(); | ||
} | ||
} | ||
|
||
void Materials::OnDraw() | ||
{ | ||
if (m_show) | ||
{ | ||
DrawMaterialEditor(); | ||
} | ||
} | ||
|
||
void Materials::DrawMaterialEditor() | ||
{ | ||
ImGui::Begin("Materials", &m_show); | ||
ImGui::Columns(2); | ||
|
||
// Filter | ||
ImGui::InputText("Material", m_filter, sizeof(m_filter)); | ||
|
||
// Material list | ||
ImGui::BeginChild("MaterialsTree"); | ||
|
||
auto materials = (cdc::HashTable<unsigned int, MaterialEntry>*)0x8A6EBC; | ||
|
||
for (int i = 0; i < materials->m_buckets.m_size; i++) | ||
{ | ||
auto node = materials->m_buckets.m_data[i]; | ||
|
||
if (node) | ||
{ | ||
auto id = node->m_data.first; | ||
auto entry = &node->m_data.second; | ||
|
||
// Check the filter | ||
if (strlen(m_filter) > 0 && std::to_string(id).find(m_filter) == std::string::npos) | ||
{ | ||
continue; | ||
} | ||
|
||
if (ImGui::TreeNodeEx((void*)entry, ImGuiTreeNodeFlags_Leaf, "%d", id)) | ||
{ | ||
if (ImGui::IsItemClicked()) | ||
{ | ||
m_selected = entry->pMaterial; | ||
} | ||
|
||
ImGui::TreePop(); | ||
} | ||
} | ||
} | ||
|
||
ImGui::EndChild(); | ||
|
||
// Material editor | ||
ImGui::NextColumn(); | ||
|
||
if (m_selected) | ||
{ | ||
ImGui::BeginChild("MaterialEditor"); | ||
|
||
DrawMaterialEditor(m_selected); | ||
|
||
ImGui::EndChild(); | ||
} | ||
|
||
ImGui::End(); | ||
} | ||
|
||
void Materials::DrawMaterialEditor(cdc::CommonMaterial* material) | ||
{ | ||
auto data = material->GetMaterialData(); | ||
|
||
for (int i = 0; i < data->numParameters; i++) | ||
{ | ||
ImGui::PushID(i); | ||
ImGui::InputFloat4("##Parameters", &data->parameters[i * 4]); | ||
ImGui::PopID(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include "Module.h" | ||
#include "render/Material.h" | ||
|
||
class Materials : public Module | ||
{ | ||
private: | ||
bool m_show = false; | ||
cdc::CommonMaterial* m_selected = nullptr; | ||
char m_filter[12] = ""; | ||
|
||
void DrawMaterialEditor(); | ||
void DrawMaterialEditor(cdc::CommonMaterial* material); | ||
|
||
public: | ||
void OnDraw(); | ||
void OnMenu(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include "cdc/render/CommonMaterial.h" | ||
|
||
struct MaterialEntry | ||
{ | ||
cdc::CommonMaterial* pMaterial; | ||
int field_4; | ||
unsigned int refCount; | ||
unsigned int size; | ||
unsigned int versionID; | ||
}; |