Archived
1
Fork 0

Reformat editor code

This commit is contained in:
Joshua Goins 2022-08-15 11:10:06 -04:00
parent c0928ea80c
commit 68d4512763
27 changed files with 1364 additions and 1323 deletions

View file

@ -1,5 +1,5 @@
#include <fmt/format.h>
#include <filesystem>
#include <fmt/format.h>
#include <vector>
int main(int argc, char* argv[]) {

View file

@ -4,24 +4,24 @@
#include <vector>
#include "app.hpp"
#include "assertions.hpp"
#include "asset.hpp"
#include "components.hpp"
#include "debugpass.hpp"
#include "engine.hpp"
#include "file.hpp"
#include "imgui_backend.hpp"
#include "log.hpp"
#include "math.hpp"
#include "object.hpp"
#include "platform.hpp"
#include "renderer.hpp"
#include "scene.hpp"
#include "undostack.hpp"
#include "utility.hpp"
#include <imgui.h>
#include "math.hpp"
#include <imgui_stdlib.h>
#include <imgui_internal.h>
#include "platform.hpp"
#include "file.hpp"
#include "object.hpp"
#include "undostack.hpp"
#include "components.hpp"
#include "engine.hpp"
#include "debugpass.hpp"
#include "assertions.hpp"
#include "log.hpp"
#include "asset.hpp"
#include "scene.hpp"
#include "renderer.hpp"
#include "imgui_backend.hpp"
#include <imgui_stdlib.h>
class TransformCommand : public Command {
public:
@ -69,7 +69,8 @@ public:
prism::Object new_parent;
std::string fetch_name() override {
return "Change parent of " + engine->get_scene()->get(object).name + " to " + engine->get_scene()->get(new_parent).name;
return "Change parent of " + engine->get_scene()->get(object).name + " to " +
engine->get_scene()->get(new_parent).name;
}
void undo() override {
@ -89,8 +90,7 @@ enum class AssetType {
Scene
};
template<typename T>
AssetType get_asset_type() {
template<typename T> AssetType get_asset_type() {
if constexpr (std::is_same<T, Mesh>::value) {
return AssetType::Mesh;
} else if constexpr (std::is_same<T, Material>::value) {
@ -130,10 +130,16 @@ public:
virtual void updateEditor([[maybe_unused]] float deltaTime) {}
virtual void object_selected([[maybe_unused]] prism::Object object) {}
virtual void asset_selected([[maybe_unused]] const std::filesystem::path& path, [[maybe_unused]] AssetType type) {}
bool wants_no_scene_rendering() override { return true; }
bool is_multimodal() override { return true; }
bool wants_no_scene_rendering() override {
return true;
}
bool is_multimodal() override {
return true;
}
void createDockArea();
void drawViewport(Scene* scene);
@ -162,8 +168,7 @@ public:
GFXTexture* get_texture_preview(Texture& texture);
GFXTexture* generate_common_preview(Scene& scene, prism::float3 camera_position);
template<typename T>
GFXTexture* get_asset_thumbnail(AssetPtr<T>& asset) {
template<typename T> GFXTexture* get_asset_thumbnail(AssetPtr<T>& asset) {
Expects(asset.handle != nullptr);
if (asset_thumbnails.count(asset->path)) {
@ -226,8 +231,7 @@ public:
bool has_asset_edit_changed = false;
template<typename T>
bool edit_asset(const char* name, AssetPtr<T>& asset) {
template<typename T> bool edit_asset(const char* name, AssetPtr<T>& asset) {
ImGui::PushID(&asset);
auto draw_list = ImGui::GetWindowDrawList();
@ -242,18 +246,33 @@ public:
const auto frame_color = ImGui::GetStyle().Colors[ImGuiCol_FrameBg];
const auto text_color = ImGui::GetStyle().Colors[ImGuiCol_Text];
const ImRect edit_rect = ImRect(window_pos, ImVec2(window_pos.x + thumbnail_size, window_pos.y + thumbnail_size));
const ImRect edit_rect =
ImRect(window_pos, ImVec2(window_pos.x + thumbnail_size, window_pos.y + thumbnail_size));
if (asset)
draw_list->AddImageRounded(get_asset_thumbnail(asset), edit_rect.Min, edit_rect.Max, ImVec2(0, 0), ImVec2(1, 1), IM_COL32_WHITE, 3.0f);
draw_list->AddImageRounded(
get_asset_thumbnail(asset),
edit_rect.Min,
edit_rect.Max,
ImVec2(0, 0),
ImVec2(1, 1),
IM_COL32_WHITE,
3.0f);
ImRect path_rect = ImRect(ImVec2(window_pos.x + thumbnail_size + 10.0f, window_pos.y), ImVec2(window_pos.x + item_width - inner_spacing, window_pos.y + 20.0f));
ImRect path_rect = ImRect(
ImVec2(window_pos.x + thumbnail_size + 10.0f, window_pos.y),
ImVec2(window_pos.x + item_width - inner_spacing, window_pos.y + 20.0f));
draw_list->AddText(ImVec2(window_pos.x + item_width, window_pos.y + (thumbnail_size / 2.0f) - (line_height / 2.0f)), ImColor(text_color), name);
draw_list->AddText(
ImVec2(window_pos.x + item_width, window_pos.y + (thumbnail_size / 2.0f) - (line_height / 2.0f)),
ImColor(text_color),
name);
draw_list->AddRectFilled(path_rect.Min, path_rect.Max, ImColor(frame_color), 3.0f);
ImRect clear_rect = ImRect(ImVec2(window_pos.x + thumbnail_size + 10.0f, window_pos.y + 20.0f), ImVec2(window_pos.x + thumbnail_size + 30.0f, window_pos.y + 40.0f));
ImRect clear_rect = ImRect(
ImVec2(window_pos.x + thumbnail_size + 10.0f, window_pos.y + 20.0f),
ImVec2(window_pos.x + thumbnail_size + 30.0f, window_pos.y + 40.0f));
draw_list->AddRectFilled(clear_rect.Min, clear_rect.Max, ImColor(255, 0, 0, 255), 3.0f);
@ -265,7 +284,8 @@ public:
ImGui::PushClipRect(path_rect.Min, path_rect.Max, false);
draw_list->AddText(ImVec2(window_pos.x + thumbnail_size + 10.0f, window_pos.y), ImColor(text_color), path.c_str());
draw_list->AddText(
ImVec2(window_pos.x + thumbnail_size + 10.0f, window_pos.y), ImColor(text_color), path.c_str());
ImGui::Dummy(ImVec2(thumbnail_size, thumbnail_size + 10.0f));
@ -302,8 +322,7 @@ public:
}
}
template<class T>
void open_asset(const AssetType type, const std::function<void(prism::path)>& func_ptr) {
template<class T> void open_asset(const AssetType type, const std::function<void(prism::path)>& func_ptr) {
current_asset_type = type;
open_asset_popup = true;
on_asset_select = func_ptr;
@ -355,7 +374,11 @@ private:
void editRenderable(Renderable& mesh);
};
inline void editPath(const char* label, std::string& path, bool editable = true, const std::function<void()> on_selected = nullptr) {
inline void editPath(
const char* label,
std::string& path,
bool editable = true,
const std::function<void()> on_selected = nullptr) {
ImGui::PushID(label);
if (!editable) {

View file

@ -4,15 +4,15 @@
#include <functional>
#include <vector>
#include "pass.hpp"
#include "gfx_renderpass.hpp"
#include "gfx_pipeline.hpp"
#include "gfx_texture.hpp"
#include "assetptr.hpp"
#include "gfx_buffer.hpp"
#include "gfx_framebuffer.hpp"
#include "gfx_pipeline.hpp"
#include "gfx_renderpass.hpp"
#include "gfx_texture.hpp"
#include "matrix.hpp"
#include "object.hpp"
#include "assetptr.hpp"
#include "pass.hpp"
class Texture;
class Mesh;

View file

@ -1,8 +1,8 @@
#pragma once
#include <memory>
#include <string>
#include <vector>
#include <memory>
class Command {
public:
@ -23,8 +23,7 @@ public:
class UndoStack {
public:
template<class T>
T& new_command() {
template<class T> T& new_command() {
// if we are in the middle of the stack currently, wipe out everything and start fresh
// TODO: only do it up to the point we're modifing
if (stack_position != (command_stack.size() - 1)) {

View file

@ -1,22 +1,22 @@
#include "commoneditor.hpp"
#include <imgui.h>
#include <imgui_stdlib.h>
#include <imgui_internal.h>
#include <nlohmann/json.hpp>
#include <debug.hpp>
#include <imgui.h>
#include <imgui_internal.h>
#include <imgui_stdlib.h>
#include <nlohmann/json.hpp>
#include "engine.hpp"
#include "file.hpp"
#include "platform.hpp"
#include "transform.hpp"
#include "log.hpp"
#include "shadowpass.hpp"
#include "gfx.hpp"
#include "gfx_commandbuffer.hpp"
#include "imgui_utility.hpp"
#include "input.hpp"
#include "log.hpp"
#include "platform.hpp"
#include "scenecapture.hpp"
#include "shadowpass.hpp"
#include "transform.hpp"
const std::map<ImGuiKey, InputButton> imToPl = {
{ImGuiKey_Tab, InputButton::Tab},
@ -39,8 +39,7 @@ const std::map<ImGuiKey, InputButton> imToPl = {
{ImGuiKey_V, InputButton::V},
{ImGuiKey_X, InputButton::X},
{ImGuiKey_Y, InputButton::Y},
{ImGuiKey_Z, InputButton::Z}
};
{ImGuiKey_Z, InputButton::Z}};
CommonEditor::CommonEditor(const std::string_view id) : id(id) {
ImGuiIO& io = ImGui::GetIO();
@ -103,7 +102,9 @@ void CommonEditor::update(float deltaTime) {
const float speed = 7.00f;
prism::float3 forward, right;
forward = normalize(angle_axis(yaw, prism::float3(0, 1, 0)) * angle_axis(pitch, prism::float3(1, 0, 0)) * prism::float3(0, 0, 1));
forward = normalize(
angle_axis(yaw, prism::float3(0, 1, 0)) * angle_axis(pitch, prism::float3(1, 0, 0)) *
prism::float3(0, 0, 1));
right = normalize(angle_axis(yaw, prism::float3(0, 1, 0)) * prism::float3(1, 0, 0));
float movX = engine->get_input()->get_value("movementX");
@ -114,7 +115,8 @@ void CommonEditor::update(float deltaTime) {
engine->get_scene()->get<Transform>(obj).position += right * movX * speed * deltaTime;
engine->get_scene()->get<Transform>(obj).position += forward * -movY * speed * deltaTime;
engine->get_scene()->get<Transform>(obj).rotation = angle_axis(yaw, prism::float3(0, 1, 0)) * angle_axis(pitch, prism::float3(1, 0, 0));
engine->get_scene()->get<Transform>(obj).rotation =
angle_axis(yaw, prism::float3(0, 1, 0)) * angle_axis(pitch, prism::float3(1, 0, 0));
}
}
@ -148,7 +150,8 @@ void CommonEditor::update(float deltaTime) {
const auto width = viewport_width;
const auto height = viewport_height;
prism::float2 n = prism::float2(((viewport_x / (float)width) * 2) - 1,
prism::float2 n = prism::float2(
((viewport_x / (float)width) * 2) - 1,
((viewport_y / (float)height) * 2) - 1); // [-1, 1] mouse coordinates
n.y = -n.y;
@ -309,7 +312,8 @@ std::vector<std::string> CommonEditor::getOpenedFiles() const {
}
void CommonEditor::walkObject(prism::Object object, prism::Object) {
static ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth;
static ImGuiTreeNodeFlags base_flags =
ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth;
auto& data = engine->get_scene()->get<Data>(object);
if (data.editor_object)
@ -492,7 +496,10 @@ bool componentHeader(Scene& scene, prism::Object& object, const char* name, cons
const auto line_height = ImGui::GetTextLineHeight();
draw_list->AddRectFilled(header_start, header_end, ImColor(widget_color), 5.0f);
draw_list->AddText(ImVec2(header_start.x + frame_padding.x, header_start.y + (25.0f / 2.0f) - (line_height / 2.0f)), ImColor(text_color), name);
draw_list->AddText(
ImVec2(header_start.x + frame_padding.x, header_start.y + (25.0f / 2.0f) - (line_height / 2.0f)),
ImColor(text_color),
name);
ImGui::Dummy(ImVec2(window_size.x - window_pos.x, 25));
@ -503,7 +510,10 @@ bool componentHeader(Scene& scene, prism::Object& object, const char* name, cons
}
if (removable) {
draw_list->AddText(ImVec2(header_end.x - (button_size / 2.0f), header_start.y + (25.0f / 2.0f) - (line_height / 2.0f)), ImColor(text_color), "X");
draw_list->AddText(
ImVec2(header_end.x - (button_size / 2.0f), header_start.y + (25.0f / 2.0f) - (line_height / 2.0f)),
ImColor(text_color),
"X");
ImGui::ItemAdd(ImRect(ImVec2(header_end.x - button_size, header_start.y), header_end), ImGui::GetID(name));
@ -638,12 +648,9 @@ void CommonEditor::createDockArea() {
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoNavFocus;
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin("dockspace", nullptr, window_flags);
@ -656,7 +663,8 @@ void CommonEditor::createDockArea() {
void CommonEditor::drawViewport(Scene* scene) {
const auto size = ImGui::GetContentRegionAvail();
const auto real_size = ImVec2(static_cast<int>(size.x * platform::get_monitor_dpi()), static_cast<int>(size.y * platform::get_monitor_dpi()));
const auto real_size = ImVec2(
static_cast<int>(size.x * platform::get_monitor_dpi()), static_cast<int>(size.y * platform::get_monitor_dpi()));
if (real_size.x <= 0 || real_size.y <= 0)
return;
@ -796,7 +804,8 @@ GFXTexture* CommonEditor::get_material_preview(Material& material) {
auto sphere = scene.add_object();
scene.add<Renderable>(sphere).mesh = assetm->get<Mesh>(prism::base_domain / "models" / "sphere.model");
scene.get<Renderable>(sphere).materials.push_back(assetm->get<Material>(prism::game_domain / material.path)); // we throw away our material handle here :-(
scene.get<Renderable>(sphere).materials.push_back(
assetm->get<Material>(prism::game_domain / material.path)); // we throw away our material handle here :-(
scene.get<Transform>(sphere).rotation = euler_to_quat(prism::float3(radians(90.0f), 0, 0));
@ -821,7 +830,8 @@ GFXTexture* CommonEditor::get_mesh_preview(Mesh& mesh) {
find_biggest_component(part.bounding_box.min);
find_biggest_component(part.bounding_box.max);
scene.get<Renderable>(mesh_obj).materials.push_back(assetm->get<Material>(prism::game_domain / "materials" / "Material.material"));
scene.get<Renderable>(mesh_obj).materials.push_back(
assetm->get<Material>(prism::game_domain / "materials" / "Material.material"));
}
return generate_common_preview(scene, prism::float3(biggest_component * 2.0f));
@ -873,8 +883,13 @@ GFXTexture* CommonEditor::get_texture_preview(Texture& texture) {
prism::float4 viewport;
prism::float4 options;
} pc;
pc.options.w = 1.0;
pc.viewport = prism::float4(1.0 / (float)thumbnail_resolution, 1.0 / (float)thumbnail_resolution, thumbnail_resolution, thumbnail_resolution);
pc.viewport = prism::float4(
1.0 / (float)thumbnail_resolution,
1.0 / (float)thumbnail_resolution,
thumbnail_resolution,
thumbnail_resolution);
command_buffer->set_push_constant(&pc, sizeof(PostPushConstants));
@ -969,7 +984,8 @@ GFXTexture* CommonEditor::generate_common_preview(Scene& scene, const prism::flo
command_buffer->set_render_pass(begin_info);
prism::renderer::controller_continuity continuity;
renderer->render_camera(command_buffer, scene, camera, scene.get<Camera>(camera), begin_info.render_area.extent, *target, continuity);
renderer->render_camera(
command_buffer, scene, camera, scene.get<Camera>(camera), begin_info.render_area.extent, *target, continuity);
// render post
begin_info.framebuffer = final_framebuffer;
@ -994,8 +1010,13 @@ GFXTexture* CommonEditor::generate_common_preview(Scene& scene, const prism::flo
prism::float4 viewport;
prism::float4 options;
} pc;
pc.options.w = 1.0;
pc.viewport = prism::float4(1.0 / (float)thumbnail_resolution, 1.0 / (float)thumbnail_resolution, thumbnail_resolution, thumbnail_resolution);
pc.viewport = prism::float4(
1.0 / (float)thumbnail_resolution,
1.0 / (float)thumbnail_resolution,
thumbnail_resolution,
thumbnail_resolution);
command_buffer->set_push_constant(&pc, sizeof(PostPushConstants));
@ -1023,8 +1044,7 @@ void CommonEditor::load_options() {
for (auto& file : j["files"])
lastOpenedFiles.push_back(file.get<std::string>());
}
else {
} else {
defaultX = -1;
defaultY = -1;
defaultWidth = 1280;
@ -1077,7 +1097,8 @@ void CommonEditor::load_thumbnail_cache() {
}
void CommonEditor::save_thumbnail_cache() {
GFXBuffer* thumbnailBuffer = engine->get_gfx()->create_buffer(nullptr, thumbnail_resolution * thumbnail_resolution * 4, false, GFXBufferUsage::Storage);
GFXBuffer* thumbnailBuffer = engine->get_gfx()->create_buffer(
nullptr, thumbnail_resolution * thumbnail_resolution * 4, false, GFXBufferUsage::Storage);
FILE* file = fopen("thumbnail-cache", "wb");
if (file == nullptr) {

View file

@ -1,13 +1,13 @@
#include "debugpass.hpp"
#include "gfx_commandbuffer.hpp"
#include "asset.hpp"
#include "engine.hpp"
#include "scene.hpp"
#include "transform.hpp"
#include "file.hpp"
#include "gfx.hpp"
#include "asset.hpp"
#include "gfx_commandbuffer.hpp"
#include "renderer.hpp"
#include "scene.hpp"
#include "transform.hpp"
struct BillPushConstant {
Matrix4x4 mvp;
@ -32,13 +32,9 @@ void DebugPass::initialize() {
createInfo.vertex_input.attributes.push_back(positionAttribute);
createInfo.shader_input.push_constants = {
{sizeof(Matrix4x4) + sizeof(prism::float4), 0}
};
createInfo.shader_input.push_constants = {{sizeof(Matrix4x4) + sizeof(prism::float4), 0}};
createInfo.shader_input.bindings = {
{1, GFXBindingType::PushConstant}
};
createInfo.shader_input.bindings = {{1, GFXBindingType::PushConstant}};
createInfo.render_pass = engine->get_renderer()->offscreen_render_pass;
createInfo.rasterization.polygon_type = GFXPolygonType::Line;
@ -80,13 +76,9 @@ void DebugPass::initialize() {
pipelineInfo.vertex_input.attributes.push_back(attribute);
pipelineInfo.shader_input.bindings = {
{1, GFXBindingType::PushConstant}
};
pipelineInfo.shader_input.bindings = {{1, GFXBindingType::PushConstant}};
pipelineInfo.shader_input.push_constants = {
{sizeof(Matrix4x4) + sizeof(prism::float4), 0}
};
pipelineInfo.shader_input.push_constants = {{sizeof(Matrix4x4) + sizeof(prism::float4), 0}};
pipelineInfo.render_pass = selectRenderPass;
pipelineInfo.depth.depth_mode = GFXDepthMode::Less;
@ -121,13 +113,9 @@ void DebugPass::initialize() {
pipelineInfo.vertex_input.attributes.push_back(attribute);
pipelineInfo.shader_input.bindings = {
{1, GFXBindingType::PushConstant}
};
pipelineInfo.shader_input.bindings = {{1, GFXBindingType::PushConstant}};
pipelineInfo.shader_input.push_constants = {
{sizeof(Matrix4x4) + sizeof(prism::float4), 0}
};
pipelineInfo.shader_input.push_constants = {{sizeof(Matrix4x4) + sizeof(prism::float4), 0}};
pipelineInfo.render_pass = sobelRenderPass;
@ -144,14 +132,9 @@ void DebugPass::initialize() {
pipelineInfo.shaders.fragment_src = ShaderSource(prism::path("billboard.frag"));
pipelineInfo.shader_input.bindings = {
{1, GFXBindingType::PushConstant},
{2, GFXBindingType::Texture},
{3, GFXBindingType::StorageBuffer}
};
{1, GFXBindingType::PushConstant}, {2, GFXBindingType::Texture}, {3, GFXBindingType::StorageBuffer}};
pipelineInfo.shader_input.push_constants = {
{sizeof(BillPushConstant), 0}
};
pipelineInfo.shader_input.push_constants = {{sizeof(BillPushConstant), 0}};
pipelineInfo.depth.depth_mode = GFXDepthMode::Less;
@ -198,7 +181,8 @@ void DebugPass::createOffscreenResources() {
selectFramebuffer = engine->get_gfx()->create_framebuffer(info);
selectBuffer = engine->get_gfx()->create_buffer(nullptr, extent.width * extent.height * 4 * sizeof(uint8_t), false, GFXBufferUsage::Storage);
selectBuffer = engine->get_gfx()->create_buffer(
nullptr, extent.width * extent.height * 4 * sizeof(uint8_t), false, GFXBufferUsage::Storage);
}
// sobel
@ -226,6 +210,7 @@ void DebugPass::draw_arrow(GFXCommandBuffer* commandBuffer, prism::float3 color,
Matrix4x4 mvp;
prism::float4 color;
} pc;
pc.mvp = model;
pc.color = color;
@ -381,10 +366,16 @@ void DebugPass::render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) {
draw_arrow(commandBuffer, prism::float3(0, 1, 0), vp * base_model);
// draw x axis
draw_arrow(commandBuffer, prism::float3(1, 0, 0), vp * base_model * matrix_from_quat(angle_axis(radians(-90.0f), prism::float3(0, 0, 1))));
draw_arrow(
commandBuffer,
prism::float3(1, 0, 0),
vp * base_model * matrix_from_quat(angle_axis(radians(-90.0f), prism::float3(0, 0, 1))));
// draw z axis
draw_arrow(commandBuffer, prism::float3(0, 0, 1), vp * base_model * matrix_from_quat(angle_axis(radians(90.0f), prism::float3(1, 0, 0))));
draw_arrow(
commandBuffer,
prism::float3(0, 0, 1),
vp * base_model * matrix_from_quat(angle_axis(radians(90.0f), prism::float3(1, 0, 0))));
}
// draw sobel
@ -485,9 +476,13 @@ void DebugPass::get_selected_object(int x, int y, const std::function<void(Selec
add_arrow(SelectableObject::Axis::Y, translate_model * scale_model);
add_arrow(SelectableObject::Axis::X, translate_model * matrix_from_quat(angle_axis(radians(-90.0f), prism::float3(0, 0, 1))) * scale_model);
add_arrow(
SelectableObject::Axis::X,
translate_model * matrix_from_quat(angle_axis(radians(-90.0f), prism::float3(0, 0, 1))) * scale_model);
add_arrow(SelectableObject::Axis::Z, translate_model * matrix_from_quat(angle_axis(radians(90.0f), prism::float3(1, 0, 0))) * scale_model);
add_arrow(
SelectableObject::Axis::Z,
translate_model * matrix_from_quat(angle_axis(radians(90.0f), prism::float3(1, 0, 0))) * scale_model);
}
GFXCommandBuffer* commandBuffer = engine->get_gfx()->acquire_command_buffer(false);
@ -565,8 +560,7 @@ void DebugPass::get_selected_object(int x, int y, const std::function<void(Selec
uint8_t a = mapped_texture[buffer_position + 3];
const int id = mapped_texture[buffer_position] +
mapped_texture[buffer_position + 1] * 256 +
const int id = mapped_texture[buffer_position] + mapped_texture[buffer_position + 1] * 256 +
mapped_texture[buffer_position + 2] * 256 * 256;
engine->get_gfx()->release_buffer_contents(selectBuffer, mapped_texture);

View file

@ -3,11 +3,11 @@
#include <imgui.h>
#include <imgui_stdlib.h>
#include "cutscene.hpp"
#include "engine.hpp"
#include "file.hpp"
#include "json_conversions.hpp"
#include "platform.hpp"
#include "cutscene.hpp"
Shot* currentShot = nullptr;
AnimationChannel* currentChannel = nullptr;
@ -18,11 +18,13 @@ std::string currentPath;
void app_main(prism::engine* engine) {
auto editor = (CommonEditor*)engine->get_app();
platform::open_window("Cutscene Editor",
platform::open_window(
"Cutscene Editor",
{editor->getDefaultX(),
editor->getDefaultY(),
static_cast<uint32_t>(editor->getDefaultWidth()),
static_cast<uint32_t>(editor->getDefaultHeight())}, WindowFlags::Resizable);
static_cast<uint32_t>(editor->getDefaultHeight())},
WindowFlags::Resizable);
}
CutsceneEditor::CutsceneEditor() : CommonEditor("CutsceneEditor") {}
@ -76,10 +78,8 @@ void CutsceneEditor::drawUI() {
has_been_docked = true;
}
if (ImGui::BeginMainMenuBar())
{
if (ImGui::BeginMenu("File"))
{
if (ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("New", "CTRL+N")) {
engine->cutscene = std::make_unique<Cutscene>();
@ -128,8 +128,7 @@ void CutsceneEditor::drawUI() {
platform::set_window_title(0, ("Cutscene Editor - " + path).c_str());
});
}
else {
} else {
engine->save_cutscene(currentPath);
}
}
@ -151,14 +150,18 @@ void CutsceneEditor::drawUI() {
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edit"))
{
if (ImGui::MenuItem("Undo", "CTRL+Z")) {}
if (ImGui::MenuItem("Redo", "CTRL+Y", false, false)) {} // Disabled item
if (ImGui::BeginMenu("Edit")) {
if (ImGui::MenuItem("Undo", "CTRL+Z")) {
}
if (ImGui::MenuItem("Redo", "CTRL+Y", false, false)) {
} // Disabled item
ImGui::Separator();
if (ImGui::MenuItem("Cut", "CTRL+X")) {}
if (ImGui::MenuItem("Copy", "CTRL+C")) {}
if (ImGui::MenuItem("Paste", "CTRL+V")) {}
if (ImGui::MenuItem("Cut", "CTRL+X")) {
}
if (ImGui::MenuItem("Copy", "CTRL+C")) {
}
if (ImGui::MenuItem("Paste", "CTRL+V")) {
}
ImGui::EndMenu();
}
@ -179,7 +182,6 @@ void CutsceneEditor::drawUI() {
if (ImGui::BeginMenu("Help")) {
if (ImGui::MenuItem("About")) {
}
ImGui::EndMenu();
@ -269,7 +271,10 @@ void CutsceneEditor::drawUI() {
i++;
}
draw_list->AddLine(ImVec2(p.x + (engine->current_cutscene_time * 5), p.y), ImVec2(p.x + (engine->current_cutscene_time * 5), p.y + 75), IM_COL32_WHITE);
draw_list->AddLine(
ImVec2(p.x + (engine->current_cutscene_time * 5), p.y),
ImVec2(p.x + (engine->current_cutscene_time * 5), p.y + 75),
IM_COL32_WHITE);
} else {
ImGui::Text("No cutscene loaded.");
}
@ -315,7 +320,8 @@ void CutsceneEditor::drawUI() {
ImGui::SetNextItemWidth(50.0f);
const char* preview_value = "None";
if(currentChannel->target != prism::NullObject && currentShot->scene->has<Data>(currentChannel->target))
if (currentChannel->target != prism::NullObject &&
currentShot->scene->has<Data>(currentChannel->target))
preview_value = currentShot->scene->get(currentChannel->target).name.c_str();
if (ImGui::BeginCombo("Target", preview_value)) {
@ -325,7 +331,8 @@ void CutsceneEditor::drawUI() {
currentChannel->bone = nullptr;
}
if(currentShot->scene->has<Renderable>(object) && !currentShot->scene->get<Renderable>(object).mesh->bones.empty()) {
if (currentShot->scene->has<Renderable>(object) &&
!currentShot->scene->get<Renderable>(object).mesh->bones.empty()) {
ImGui::Indent();
for (auto& bone : currentShot->scene->get<Renderable>(object).mesh->bones) {
@ -403,7 +410,10 @@ void CutsceneEditor::drawUI() {
draw_list->AddCircleFilled(shot_start, 2.5f, IM_COL32(255, 0, 0, 255));
draw_list->AddCircleFilled(shot_end, 2.5f, IM_COL32(255, 0, 0, 255));
draw_list->AddLine(ImVec2(p.x + ((engine->current_cutscene_time - currentShot->begin) * 5), p.y), ImVec2(p.x + ((engine->current_cutscene_time - currentShot->begin) * 5), p.y + 75), IM_COL32_WHITE);
draw_list->AddLine(
ImVec2(p.x + ((engine->current_cutscene_time - currentShot->begin) * 5), p.y),
ImVec2(p.x + ((engine->current_cutscene_time - currentShot->begin) * 5), p.y + 75),
IM_COL32_WHITE);
}
} else {
ImGui::TextDisabled("No animation selected.");

View file

@ -1,7 +1,7 @@
#pragma once
#include "prismeditor.hpp"
#include "asset.hpp"
#include "prismeditor.hpp"
#include "scene.hpp"
class MaterialEditor : public Editor {

View file

@ -24,10 +24,16 @@ public:
return nullptr;
}
virtual bool has_menubar() const { return false; }
virtual bool has_menubar() const {
return false;
}
virtual std::string get_title() const {
return "";
}
virtual std::string get_title() const { return ""; }
virtual void draw([[maybe_unused]] CommonEditor* editor) {}
virtual void setup_windows([[maybe_unused]] ImGuiID dockspace) {}
ImGuiWindowClass get_window_class() const {

View file

@ -1,7 +1,7 @@
#pragma once
#include "prismeditor.hpp"
#include "engine.hpp"
#include "prismeditor.hpp"
class AddObjectCommand : public Command {
public:

View file

@ -1,8 +1,8 @@
#include "materialeditor.hpp"
#include <imgui.h>
#include <imgui_stdlib.h>
#include <imgui_internal.h>
#include <imgui_stdlib.h>
#include "engine.hpp"
@ -130,9 +130,7 @@ void MaterialEditor::draw(CommonEditor* editor) {
if (changed)
recompile(*material);
}
ImGui::End();
}

View file

@ -1,8 +1,8 @@
#include "prefabeditor.hpp"
#include <imgui.h>
#include <imgui_stdlib.h>
#include <imgui_internal.h>
#include <imgui_stdlib.h>
#include "engine.hpp"

View file

@ -1,17 +1,17 @@
#include "prismeditor.hpp"
#include <imgui.h>
#include <imgui_stdlib.h>
#include <imgui_internal.h>
#include <imgui_stdlib.h>
#include "engine.hpp"
#include "file.hpp"
#include "json_conversions.hpp"
#include "platform.hpp"
#include "string_utils.hpp"
#include "sceneeditor.hpp"
#include "materialeditor.hpp"
#include "platform.hpp"
#include "prefabeditor.hpp"
#include "sceneeditor.hpp"
#include "string_utils.hpp"
std::string get_filename(const std::string path) {
return path.substr(path.find_last_of("/") + 1, path.length());
@ -22,7 +22,8 @@ std::vector<Editor*> editors;
void app_main(prism::engine* engine) {
CommonEditor* editor = (CommonEditor*)engine->get_app();
platform::open_window("Prism Editor",
platform::open_window(
"Prism Editor",
{editor->getDefaultX(),
editor->getDefaultY(),
static_cast<uint32_t>(editor->getDefaultWidth()),
@ -32,9 +33,7 @@ void app_main(prism::engine* engine) {
engine->update_physics = false;
}
PrismEditor::PrismEditor() : CommonEditor("PrismEditor") {
}
PrismEditor::PrismEditor() : CommonEditor("PrismEditor") {}
void prepScene() {
auto scene = engine->get_scene();
@ -93,7 +92,8 @@ Renderable* prepMaterialScene() {
scene->get<Transform>(plane).scale = prism::float3(50);
scene->add<Renderable>(plane).mesh = assetm->get<Mesh>(prism::base_domain / "models/plane.model");
scene->get<Renderable>(plane).materials.push_back(assetm->get<Material>(prism::base_domain / "materials/Material.material"));
scene->get<Renderable>(plane).materials.push_back(
assetm->get<Material>(prism::base_domain / "materials/Material.material"));
auto sphere = scene->add_object();
scene->get(sphere).name = "sphere";

View file

@ -1,8 +1,8 @@
#include "sceneeditor.hpp"
#include <imgui.h>
#include <imgui_stdlib.h>
#include <imgui_internal.h>
#include <imgui_stdlib.h>
#include "engine.hpp"
@ -133,7 +133,6 @@ void SceneEditor::draw(CommonEditor* editor) {
if (viewport_scene != nullptr) {
if (showSceneSettings) {
if (begin("Scene Settings", &showSceneSettings)) {
}
ImGui::End();

View file

@ -1,15 +1,12 @@
#include <cstdio>
#include <string_view>
#include <array>
#include <iostream>
#include <string_view>
#include <stb_truetype.h>
constexpr std::array sizes_to_pack = {
36.0f,
24.0f
};
constexpr std::array sizes_to_pack = {36.0f, 24.0f};
constexpr int num_glyphs = 95;
constexpr int texture_width = 2048, texture_height = 1150;

View file

@ -1,15 +1,15 @@
#include "modeleditor.hpp"
#include <imgui.h>
#include <imgui_stdlib.h>
#include <nlohmann/json.hpp>
#include <magic_enum.hpp>
#include <cstdio>
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <unordered_map>
#include <cstdio>
#include <functional>
#include <imgui.h>
#include <imgui_stdlib.h>
#include <magic_enum.hpp>
#include <nlohmann/json.hpp>
#include <unordered_map>
#include "engine.hpp"
#include "file.hpp"
@ -27,9 +27,8 @@ void app_main(prism::engine* engine) {
editor->flags.hide_ui = true;
if (!editor->flags.hide_ui) {
platform::open_window("Model Compiler",
{editor->getDefaultX(), editor->getDefaultY(), 300, 300},
WindowFlags::None);
platform::open_window(
"Model Compiler", {editor->getDefaultX(), editor->getDefaultY(), 300, 300}, WindowFlags::None);
} else {
std::string compiled_model_path;
@ -189,13 +188,9 @@ void ModelEditor::compile_model(std::string compiled_model_path) {
Assimp::Importer importer;
unsigned int importer_flags =
aiProcess_Triangulate |
aiProcess_ImproveCacheLocality |
aiProcess_JoinIdenticalVertices |
aiProcess_OptimizeMeshes |
aiProcess_CalcTangentSpace |
aiProcess_GenNormals;
unsigned int importer_flags = aiProcess_Triangulate | aiProcess_ImproveCacheLocality |
aiProcess_JoinIdenticalVertices | aiProcess_OptimizeMeshes |
aiProcess_CalcTangentSpace | aiProcess_GenNormals;
if (flags.compile_static) {
importer.SetPropertyFloat(AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY, 1.0);
@ -487,7 +482,10 @@ void ModelEditor::compile_model(std::string compiled_model_path) {
for (auto k = 0; k < channel->mNumPositionKeys; k++) {
PositionKeyFrame key;
key.value = prism::float3(channel->mPositionKeys[k].mValue.x, channel->mPositionKeys[k].mValue.y, channel->mPositionKeys[k].mValue.z);
key.value = prism::float3(
channel->mPositionKeys[k].mValue.x,
channel->mPositionKeys[k].mValue.y,
channel->mPositionKeys[k].mValue.z);
key.time = channel->mPositionKeys[k].mTime;
fwrite(&key, sizeof(PositionKeyFrame), 1, file);
@ -497,7 +495,11 @@ void ModelEditor::compile_model(std::string compiled_model_path) {
for (auto k = 0; k < channel->mNumRotationKeys; k++) {
RotationKeyFrame key;
key.value = Quaternion(channel->mRotationKeys[k].mValue.x, channel->mRotationKeys[k].mValue.y, channel->mRotationKeys[k].mValue.z, channel->mRotationKeys[k].mValue.w);
key.value = Quaternion(
channel->mRotationKeys[k].mValue.x,
channel->mRotationKeys[k].mValue.y,
channel->mRotationKeys[k].mValue.z,
channel->mRotationKeys[k].mValue.w);
key.time = channel->mRotationKeys[k].mTime;
fwrite(&key, sizeof(RotationKeyFrame), 1, file);
@ -507,7 +509,10 @@ void ModelEditor::compile_model(std::string compiled_model_path) {
for (auto k = 0; k < channel->mNumScalingKeys; k++) {
ScaleKeyFrame key;
key.value = prism::float3(channel->mScalingKeys[k].mValue.x, channel->mScalingKeys[k].mValue.y, channel->mScalingKeys[k].mValue.z);
key.value = prism::float3(
channel->mScalingKeys[k].mValue.x,
channel->mScalingKeys[k].mValue.y,
channel->mScalingKeys[k].mValue.z);
key.time = channel->mScalingKeys[k].mTime;
fwrite(&key, sizeof(ScaleKeyFrame), 1, file);
@ -523,7 +528,8 @@ void ModelEditor::drawUI() {
auto viewport = ImGui::GetMainViewport();
ImGui::Begin("mcompile", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration);
ImGui::Begin(
"mcompile", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration);
ImGui::SetWindowPos(viewport->Pos, ImGuiCond_Always);
ImGui::SetWindowSize(viewport->Size, ImGuiCond_Always);
@ -535,9 +541,12 @@ void ModelEditor::drawUI() {
}
if (ImGui::Button("Open data path...")) {
engine->get_imgui().open_dialog(true, [this](std::string path) {
engine->get_imgui().open_dialog(
true,
[this](std::string path) {
data_path = path;
}, true);
},
true);
}
ImGui::Checkbox("Compile as static (remove transforms)", &flags.compile_static);

View file

@ -36,10 +36,10 @@
#pragma once
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <fstream>
#include <string>
#include <vector>
#include <glslang/Public/ShaderLang.h>
@ -50,17 +50,13 @@ class DirStackFileIncluder : public glslang::TShader::Includer {
public:
DirStackFileIncluder() : externalLocalDirectoryCount(0) {}
virtual IncludeResult* includeLocal(const char* headerName,
const char* includerName,
size_t inclusionDepth) override
{
virtual IncludeResult*
includeLocal(const char* headerName, const char* includerName, size_t inclusionDepth) override {
return readLocalPath(headerName, includerName, (int)inclusionDepth);
}
virtual IncludeResult* includeSystem(const char* headerName,
const char* /*includerName*/,
size_t /*inclusionDepth*/) override
{
virtual IncludeResult*
includeSystem(const char* headerName, const char* /*includerName*/, size_t /*inclusionDepth*/) override {
return readSystemPath(headerName);
}
@ -70,14 +66,12 @@ public:
// is checked.
// - This only applies to the "local" form of #include.
// - Makes its own copy of the path.
virtual void pushExternalLocalDirectory(const std::string& dir)
{
virtual void pushExternalLocalDirectory(const std::string& dir) {
directoryStack.push_back(dir);
externalLocalDirectoryCount = (int)directoryStack.size();
}
virtual void releaseInclude(IncludeResult* result) override
{
virtual void releaseInclude(IncludeResult* result) override {
if (result != nullptr) {
delete[] static_cast<tUserDataElement*>(result->userData);
delete result;
@ -93,8 +87,7 @@ protected:
// Search for a valid "local" path based on combining the stack of include
// directories and the nominal name of the header.
virtual IncludeResult* readLocalPath(const char* headerName, const char* includerName, int depth)
{
virtual IncludeResult* readLocalPath(const char* headerName, const char* includerName, int depth) {
// Discard popped include directories, and
// initialize when at parse-time first level.
directoryStack.resize(depth + externalLocalDirectoryCount);
@ -117,14 +110,12 @@ protected:
// Search for a valid <system> path.
// Not implemented yet; returning nullptr signals failure to find.
virtual IncludeResult* readSystemPath(const char* /*headerName*/) const
{
virtual IncludeResult* readSystemPath(const char* /*headerName*/) const {
return nullptr;
}
// Do actual reading of the file, filling in a new include result.
virtual IncludeResult* newIncludeResult(const std::string& path, std::ifstream& file, int length) const
{
virtual IncludeResult* newIncludeResult(const std::string& path, std::ifstream& file, int length) const {
char* content = new tUserDataElement[length];
file.seekg(0, file.beg);
file.read(content, length);
@ -133,8 +124,7 @@ protected:
// If no path markers, return current working directory.
// Otherwise, strip file name and return path leading up to it.
virtual std::string getDirectory(const std::string path) const
{
virtual std::string getDirectory(const std::string path) const {
size_t last = path.find_last_of("/\\");
return last == std::string::npos ? "." : path.substr(0, last);
}

View file

@ -1,8 +1,8 @@
#include <sstream>
#include <filesystem>
#include <sstream>
#include "shadercompiler.hpp"
#include "log.hpp"
#include "shadercompiler.hpp"
#include "string_utils.hpp"
bool has_extension(const std::filesystem::path& path, const std::string_view extension) {
@ -56,7 +56,8 @@ int main(int argc, char* argv[]) {
else if (has_extension(source_path, ".comp"))
stage = ShaderStage::Compute;
const auto compiled_source = shader_compiler.compile(ShaderLanguage::GLSL, stage, ShaderSource(buffer.str()), language, options);
const auto compiled_source =
shader_compiler.compile(ShaderLanguage::GLSL, stage, ShaderSource(buffer.str()), language, options);
if (!compiled_source.has_value()) {
prism::log("Error when compiling {}!", source_path.string());
return -1;
@ -64,26 +65,20 @@ int main(int argc, char* argv[]) {
switch (language) {
// right now, WGSL is outputted as SPIR-V with some WGSL compatibility stuff included
case ShaderLanguage::SPIRV:
{
case ShaderLanguage::SPIRV: {
const auto spirv = compiled_source->as_bytecode();
std::ofstream out(destination_path, std::ios::binary); // remove .glsl
out.write((char*)spirv.data(), spirv.size() * sizeof(uint32_t));
}
break;
case ShaderLanguage::MSL:
{
} break;
case ShaderLanguage::MSL: {
std::ofstream out(destination_path); // remove .glsl
out << compiled_source->as_string();
}
break;
case ShaderLanguage::HLSL:
{
} break;
case ShaderLanguage::HLSL: {
std::ofstream out(destination_path); // remove .glsl
out << compiled_source->as_string();
}
break;
} break;
default:
break;
}