Files
Seele/src/Editor/main.cpp
T

191 lines
8.6 KiB
C++
Raw Normal View History

2023-02-24 22:09:07 +01:00
#include "Asset/AssetImporter.h"
2024-04-18 13:33:35 +02:00
#include "Asset/AssetRegistry.h"
#include "Asset/FontLoader.h"
#include "Asset/MaterialLoader.h"
2023-02-24 22:09:07 +01:00
#include "Asset/MeshLoader.h"
#include "Asset/TextureLoader.h"
2024-04-18 13:33:35 +02:00
#include "Graphics/Initializer.h"
2024-04-23 08:11:44 +02:00
#ifdef __APPLE__
2024-04-18 13:33:35 +02:00
#include "Graphics/Metal/Graphics.h"
2024-04-23 08:11:44 +02:00
#else
#include "Graphics/Vulkan/Graphics.h"
#endif
2023-11-05 11:47:22 +01:00
#include "Graphics/StaticMeshVertexData.h"
2025-01-08 19:15:12 +01:00
#include "Window/InspectorView.h"
2024-04-18 13:33:35 +02:00
#include "Window/PlayView.h"
#include "Window/WindowManager.h"
2024-01-16 19:24:49 +01:00
#include <fmt/core.h>
2024-06-11 14:15:29 +02:00
#include <random>
2021-03-31 12:18:16 +02:00
2020-03-05 11:43:38 +01:00
using namespace Seele;
2022-11-17 16:47:42 +01:00
using namespace Seele::Editor;
2021-03-31 12:18:16 +02:00
2023-12-12 11:37:00 +01:00
// make it global so it gets deleted last and automatically
static Gfx::OGraphics graphics;
2024-10-07 20:14:00 +02:00
struct Halfedge {
uint32 vertexID;
uint32 nextID;
uint32 prevID;
uint32 twinID;
};
Array<Halfedge> generateEdges() {
Array<UVector> indices = {UVector(0, 1, 4), UVector(4, 1, 5), UVector(1, 2, 5), UVector(5, 2, 6), UVector(2, 3, 6),
UVector(6, 3, 7), UVector(4, 5, 8), UVector(8, 5, 9), UVector(5, 6, 9), UVector(9, 6, 10),
UVector(6, 7, 10), UVector(10, 7, 11), UVector(8, 9, 12), UVector(12, 9, 13), UVector(9, 10, 13),
UVector(13, 10, 14), UVector(10, 11, 14), UVector(14, 11, 15)};
Array<Halfedge> edges;
for (auto ind : indices) {
uint32 baseIndex = edges.size();
2025-01-08 19:15:12 +01:00
edges.add(Halfedge{ind.x, baseIndex + 1, baseIndex + 2, UINT32_MAX});
edges.add(Halfedge{ind.y, baseIndex + 2, baseIndex, UINT32_MAX});
edges.add(Halfedge{ind.z, baseIndex, baseIndex + 1, UINT32_MAX});
2024-10-07 20:14:00 +02:00
}
for (uint32 i = 0; i < edges.size(); ++i) {
if (edges[i].twinID == UINT32_MAX) {
for (uint32 j = 0; j < edges.size(); ++j) {
if (edges[i].vertexID == edges[edges[j].nextID].vertexID && edges[edges[i].nextID].vertexID == edges[j].vertexID) {
edges[i].twinID = j;
edges[j].twinID = i;
}
}
}
}
return edges;
}
2024-04-18 13:33:35 +02:00
int main() {
2024-04-23 08:11:44 +02:00
std::string gameName = "MeshShadingDemo";
2023-11-06 14:47:21 +01:00
#ifdef WIN32
2024-06-09 12:20:04 +02:00
std::filesystem::path outputPath = "C:/Users/Dynamitos/MeshShadingDemoGame";
std::filesystem::path sourcePath = "C:/Users/Dynamitos/MeshShadingDemo";
std::filesystem::path binaryPath = sourcePath / "bin" / "MeshShadingDemo.dll";
2024-01-17 17:57:59 +01:00
#elif __APPLE__
2024-06-09 12:20:04 +02:00
std::filesystem::path outputPath = "/Users/dynamitos/MeshShadingDemoGame";
std::filesystem::path sourcePath = "/Users/dynamitos/MeshShadingDemo";
std::filesystem::path binaryPath = sourcePath / "cmake" / "libMeshShadingDemo.dylib";
2023-11-06 14:47:21 +01:00
#else
2024-06-09 12:20:04 +02:00
std::filesystem::path outputPath = "/home/dynamitos/MeshShadingDemoGame";
std::filesystem::path sourcePath = "/home/dynamitos/MeshShadingDemo";
std::filesystem::path binaryPath = sourcePath / "cmake" / "libMeshShadingDemo.so";
2023-11-06 14:47:21 +01:00
#endif
2024-06-09 12:20:04 +02:00
std::filesystem::path cmakePath = outputPath / "cmake";
2024-07-05 12:02:46 +02:00
if (true) {
2024-04-09 18:24:21 +02:00
#ifdef __APPLE__
2024-07-05 12:02:46 +02:00
graphics = new Metal::Graphics();
2024-04-09 18:24:21 +02:00
#else
2024-07-05 12:02:46 +02:00
graphics = new Vulkan::Graphics();
2024-04-09 18:24:21 +02:00
#endif
2024-07-05 12:02:46 +02:00
GraphicsInitializer initializer;
graphics->init(initializer);
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
vd->init(graphics);
2024-04-26 19:32:38 +02:00
2024-07-05 12:02:46 +02:00
OWindowManager windowManager = new WindowManager();
AssetRegistry::init(sourcePath / "Assets", graphics);
AssetImporter::init(graphics);
2025-01-08 19:15:12 +01:00
AssetImporter::importFont(FontImportArgs{
.filePath = "./fonts/arial.ttf",
});
2024-09-26 17:09:53 +02:00
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/cube.fbx",
});
// AssetImporter::importMesh(MeshImportArgs{
2024-09-16 13:00:53 +02:00
// .filePath = sourcePath / "import/models/culling.fbx",
//});
2024-07-05 12:02:46 +02:00
AssetImporter::importTexture(TextureImportArgs{
2024-12-25 14:59:08 +01:00
.filePath = sourcePath / "import/textures/skybox.jpg",
2024-07-05 12:02:46 +02:00
.type = TextureImportType::TEXTURE_CUBEMAP,
});
2024-09-26 17:09:53 +02:00
// AssetImporter::importMesh(MeshImportArgs{
2024-10-07 20:14:00 +02:00
// .filePath = sourcePath / "import/models/ship.fbx",
// .importPath = "ship",
// });
2025-01-08 19:15:12 +01:00
// AssetImporter::importTexture(TextureImportArgs{
2024-10-07 20:14:00 +02:00
// .filePath = sourcePath / "import/textures/azeroth.png",
//});
2025-01-08 19:15:12 +01:00
// AssetImporter::importTexture(TextureImportArgs{
2024-10-07 20:14:00 +02:00
// .filePath = sourcePath / "import/textures/azeroth_height.png",
//});
2025-01-08 19:15:12 +01:00
// AssetImporter::importTexture(TextureImportArgs{
2024-11-01 21:04:06 +01:00
// .filePath = sourcePath / "import/textures/wgen.png",
//});
2024-10-07 20:14:00 +02:00
// AssetImporter::importMesh(MeshImportArgs{
2025-01-08 19:15:12 +01:00
// .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
// .importPath = "Whitechapel",
//});
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/plane.obj",
// .importPath = "",
2024-09-26 17:09:53 +02:00
// });
2025-01-08 19:15:12 +01:00
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
// .importPath = "suburbs",
// });
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/minecraft-medieval-city.fbx",
// .importPath = "minecraft",
// });
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/Volvo/Volvo.fbx",
// .importPath = "Volvo",
// });
2024-08-30 09:29:41 +02:00
getThreadPool().waitIdle();
2024-07-05 12:02:46 +02:00
vd->commitMeshes();
WindowCreateInfo mainWindowInfo = {
.width = 1920,
.height = 1080,
.title = "SeeleEngine",
.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB,
};
auto window = windowManager->addWindow(graphics, mainWindowInfo);
2025-01-08 19:15:12 +01:00
// ViewportCreateInfo sceneViewInfo = {
// .dimensions =
// {
// .size = {1920, 1080},
// .offset = {0, 0},
// },
// .numSamples = Gfx::SE_SAMPLE_COUNT_4_BIT,
// };
// OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
// sceneView->setFocused();
OInspectorView inspectorView = new Editor::InspectorView(graphics, window,
ViewportCreateInfo{
.dimensions =
{
.size = {1920, 1080},
.offset = {0, 0},
},
.fieldOfView = 0,
.numSamples = Gfx::SE_SAMPLE_COUNT_1_BIT,
});
2023-02-24 22:09:07 +01:00
2024-07-05 12:02:46 +02:00
while (windowManager->isActive() && getGlobals().running) {
windowManager->render();
}
2024-07-18 11:45:56 +02:00
graphics->waitDeviceIdle();
Material::destroy();
2024-07-05 12:02:46 +02:00
vd->destroy();
// export game
} else {
2024-06-09 12:20:04 +02:00
std::filesystem::create_directories(outputPath);
2024-07-05 12:02:46 +02:00
std::system(fmt::format("cmake -DCMAKE_BUILD_TYPE=Release -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" "
2024-06-09 12:20:04 +02:00
"-DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake",
gameName, outputPath.generic_string(), binaryPath.generic_string())
.c_str());
2024-07-05 12:02:46 +02:00
std::system(fmt::format("cmake -S {} -B {}", cmakePath.generic_string(), outputPath.generic_string()).c_str());
2024-06-09 12:20:04 +02:00
std::system(fmt::format("cmake --build {}", cmakePath.generic_string()).c_str());
2024-07-05 12:02:46 +02:00
std::filesystem::copy(binaryPath, outputPath, std::filesystem::copy_options::recursive);
2024-06-09 12:20:04 +02:00
std::filesystem::copy(sourcePath / "Assets", outputPath / "Assets", std::filesystem::copy_options::recursive);
std::filesystem::copy("shaders", outputPath / "shaders", std::filesystem::copy_options::recursive);
std::filesystem::copy("textures", outputPath / "textures", std::filesystem::copy_options::recursive);
2023-11-06 14:47:21 +01:00
#ifdef WIN32
2024-06-09 12:20:04 +02:00
std::filesystem::copy_file("assimp-vc143-mt.dll", outputPath / "assimp-vc143-mt.dll");
std::filesystem::copy_file("slang.dll", outputPath / "slang.dll");
std::filesystem::copy_file("slang-glslang.dll", outputPath / "slang-glslang.dll");
2023-11-06 14:47:21 +01:00
#endif
2024-06-09 12:20:04 +02:00
}
return 0;
2024-04-19 18:23:36 +02:00
}