Formatted EVERYTHING
This commit is contained in:
@@ -1,54 +1,46 @@
|
||||
#include "AssetImporter.h"
|
||||
#include "FontLoader.h"
|
||||
#include "TextureLoader.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "MaterialLoader.h"
|
||||
#include "MeshLoader.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "TextureLoader.h"
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
void AssetImporter::importMesh(MeshImportArgs args)
|
||||
{
|
||||
if (get().registry->getOrCreateFolder(args.importPath)->meshes.contains(args.filePath.stem().string()))
|
||||
{
|
||||
void AssetImporter::importMesh(MeshImportArgs args) {
|
||||
if (get().registry->getOrCreateFolder(args.importPath)->meshes.contains(args.filePath.stem().string())) {
|
||||
// skip importing duplicates
|
||||
return;
|
||||
}
|
||||
get().meshLoader->importAsset(args);
|
||||
}
|
||||
|
||||
void AssetImporter::importTexture(TextureImportArgs args)
|
||||
{
|
||||
if (get().registry->getOrCreateFolder(args.importPath)->textures.contains(args.filePath.stem().string()))
|
||||
{
|
||||
void AssetImporter::importTexture(TextureImportArgs args) {
|
||||
if (get().registry->getOrCreateFolder(args.importPath)->textures.contains(args.filePath.stem().string())) {
|
||||
// skip importing duplicates
|
||||
return;
|
||||
}
|
||||
get().textureLoader->importAsset(args);
|
||||
}
|
||||
|
||||
void AssetImporter::importFont(FontImportArgs args)
|
||||
{
|
||||
if (get().registry->getOrCreateFolder(args.importPath)->fonts.contains(args.filePath.stem().string()))
|
||||
{
|
||||
void AssetImporter::importFont(FontImportArgs args) {
|
||||
if (get().registry->getOrCreateFolder(args.importPath)->fonts.contains(args.filePath.stem().string())) {
|
||||
// skip importing duplicates
|
||||
return;
|
||||
}
|
||||
get().fontLoader->importAsset(args);
|
||||
}
|
||||
|
||||
void AssetImporter::importMaterial(MaterialImportArgs args)
|
||||
{
|
||||
if (get().registry->getOrCreateFolder(args.importPath)->materials.contains(args.filePath.stem().string()))
|
||||
{
|
||||
void AssetImporter::importMaterial(MaterialImportArgs args) {
|
||||
if (get().registry->getOrCreateFolder(args.importPath)->materials.contains(args.filePath.stem().string())) {
|
||||
// skip importing duplicates
|
||||
return;
|
||||
}
|
||||
get().materialLoader->importAsset(args);
|
||||
}
|
||||
|
||||
void AssetImporter::init(Gfx::PGraphics graphics)
|
||||
{
|
||||
void AssetImporter::init(Gfx::PGraphics graphics) {
|
||||
get().registry = AssetRegistry::getInstance();
|
||||
get().meshLoader = new MeshLoader(graphics);
|
||||
get().textureLoader = new TextureLoader(graphics);
|
||||
@@ -56,9 +48,7 @@ void AssetImporter::init(Gfx::PGraphics graphics)
|
||||
get().fontLoader = new FontLoader(graphics);
|
||||
}
|
||||
|
||||
AssetImporter& AssetImporter::get()
|
||||
{
|
||||
AssetImporter& AssetImporter::get() {
|
||||
static AssetImporter instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "MinimalEngine.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_REF(TextureLoader)
|
||||
DECLARE_REF(FontLoader)
|
||||
DECLARE_REF(MeshLoader)
|
||||
DECLARE_REF(MaterialLoader)
|
||||
class AssetImporter
|
||||
{
|
||||
public:
|
||||
class AssetImporter {
|
||||
public:
|
||||
static void importMesh(struct MeshImportArgs args);
|
||||
static void importTexture(struct TextureImportArgs args);
|
||||
static void importFont(struct FontImportArgs args);
|
||||
static void importMaterial(struct MaterialImportArgs args);
|
||||
static void init(Gfx::PGraphics graphics);
|
||||
private:
|
||||
|
||||
private:
|
||||
static AssetImporter& get();
|
||||
UPTextureLoader textureLoader;
|
||||
UPFontLoader fontLoader;
|
||||
|
||||
@@ -1,28 +1,23 @@
|
||||
#include "FontLoader.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Asset/FontAsset.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Asset/FontAsset.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Resources.h"
|
||||
#include "Graphics/Texture.h"
|
||||
#include <ft2build.h>
|
||||
|
||||
#include FT_FREETYPE_H
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
FontLoader::FontLoader(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
{
|
||||
|
||||
}
|
||||
FontLoader::FontLoader(Gfx::PGraphics graphics) : graphics(graphics) {}
|
||||
|
||||
FontLoader::~FontLoader()
|
||||
{
|
||||
}
|
||||
FontLoader::~FontLoader() {}
|
||||
|
||||
void FontLoader::importAsset(FontImportArgs args)
|
||||
{
|
||||
void FontLoader::importAsset(FontImportArgs args) {
|
||||
std::filesystem::path assetPath = args.filePath.filename();
|
||||
assetPath.replace_extension("asset");
|
||||
OFontAsset asset = new FontAsset(args.importPath, assetPath.stem().string());
|
||||
@@ -36,8 +31,7 @@ void FontLoader::importAsset(FontImportArgs args)
|
||||
// in case of the space character there is no bitmap
|
||||
// so we create a single pixel empty texture
|
||||
uint8 transparentPixel = 0;
|
||||
void FontLoader::import(FontImportArgs args, PFontAsset asset)
|
||||
{
|
||||
void FontLoader::import(FontImportArgs args, PFontAsset asset) {
|
||||
FT_Library ft;
|
||||
FT_Error error = FT_Init_FreeType(&ft);
|
||||
assert(!error);
|
||||
@@ -46,10 +40,8 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset)
|
||||
assert(!error);
|
||||
FT_Set_Pixel_Sizes(face, 0, 48);
|
||||
Array<Gfx::OTexture2D> usedTextures;
|
||||
for(uint32 c = 0; c < 256; ++c)
|
||||
{
|
||||
if(FT_Load_Char(face, c, FT_LOAD_RENDER))
|
||||
{
|
||||
for (uint32 c = 0; c < 256; ++c) {
|
||||
if (FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
||||
std::cout << "error loading " << (char)c << std::endl;
|
||||
continue;
|
||||
}
|
||||
@@ -63,8 +55,7 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset)
|
||||
imageData.height = face->glyph->bitmap.rows;
|
||||
imageData.sourceData.data = face->glyph->bitmap.buffer;
|
||||
imageData.sourceData.size = imageData.width * imageData.height;
|
||||
if(imageData.width == 0 || imageData.height == 0)
|
||||
{
|
||||
if (imageData.width == 0 || imageData.height == 0) {
|
||||
glyph.size.x = 1;
|
||||
glyph.size.y = 1;
|
||||
glyph.bearing.x = 0;
|
||||
@@ -81,7 +72,8 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset)
|
||||
FT_Done_FreeType(ft);
|
||||
asset->setUsedTextures(std::move(usedTextures));
|
||||
|
||||
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(asset->getFolderPath()) / asset->getName()).replace_extension("asset").string(), std::ios::binary);
|
||||
auto stream = AssetRegistry::createWriteStream(
|
||||
(std::filesystem::path(asset->getFolderPath()) / asset->getName()).replace_extension("asset").string(), std::ios::binary);
|
||||
|
||||
ArchiveBuffer archive;
|
||||
Serialization::save(archive, FontAsset::IDENTIFIER);
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Containers/List.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include <filesystem>
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_REF(FontAsset)
|
||||
DECLARE_NAME_REF(Gfx, Graphics)
|
||||
struct FontImportArgs
|
||||
{
|
||||
struct FontImportArgs {
|
||||
std::filesystem::path filePath;
|
||||
std::string importPath;
|
||||
};
|
||||
class FontLoader
|
||||
{
|
||||
public:
|
||||
class FontLoader {
|
||||
public:
|
||||
FontLoader(Gfx::PGraphics graphic);
|
||||
~FontLoader();
|
||||
void importAsset(FontImportArgs args);
|
||||
private:
|
||||
|
||||
private:
|
||||
void import(FontImportArgs args, PFontAsset asset);
|
||||
Gfx::PGraphics graphics;
|
||||
};
|
||||
|
||||
@@ -1,37 +1,35 @@
|
||||
#include "MaterialLoader.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Asset/MaterialAsset.h"
|
||||
#include "Asset/TextureAsset.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Asset/MaterialAsset.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Material/Material.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include "Material/ShaderExpression.h"
|
||||
#include "Asset/TextureAsset.h"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "Window/WindowManager.h"
|
||||
#include <fmt/core.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
using json = nlohmann::json;
|
||||
|
||||
MaterialLoader::MaterialLoader(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
{
|
||||
MaterialLoader::MaterialLoader(Gfx::PGraphics graphics) : graphics(graphics) {
|
||||
OMaterialAsset placeholderAsset = new MaterialAsset();
|
||||
import(MaterialImportArgs{
|
||||
.filePath = std::filesystem::absolute("./shaders/Placeholder.json"),
|
||||
.importPath = "",
|
||||
}, placeholderAsset);
|
||||
import(
|
||||
MaterialImportArgs{
|
||||
.filePath = std::filesystem::absolute("./shaders/Placeholder.json"),
|
||||
.importPath = "",
|
||||
},
|
||||
placeholderAsset);
|
||||
AssetRegistry::get().assetRoot->materials[""] = std::move(placeholderAsset);
|
||||
}
|
||||
|
||||
MaterialLoader::~MaterialLoader()
|
||||
{
|
||||
}
|
||||
MaterialLoader::~MaterialLoader() {}
|
||||
|
||||
void MaterialLoader::importAsset(MaterialImportArgs args)
|
||||
{
|
||||
void MaterialLoader::importAsset(MaterialImportArgs args) {
|
||||
std::filesystem::path assetPath = args.filePath.filename();
|
||||
assetPath.replace_extension("asset");
|
||||
OMaterialAsset asset = new MaterialAsset(args.importPath, assetPath.stem().string());
|
||||
@@ -41,14 +39,13 @@ void MaterialLoader::importAsset(MaterialImportArgs args)
|
||||
import(args, ref);
|
||||
}
|
||||
|
||||
void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
||||
{
|
||||
void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset) {
|
||||
auto jsonstream = std::ifstream(args.filePath.c_str());
|
||||
json j;
|
||||
jsonstream >> j;
|
||||
std::string materialName = j["name"].get<std::string>() + "Material";
|
||||
Gfx::ODescriptorLayout layout = graphics->createDescriptorLayout("pMaterial");
|
||||
//Shader file needs to conform to the slang standard, which prohibits _
|
||||
// Shader file needs to conform to the slang standard, which prohibits _
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '_'), materialName.end());
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '-'), materialName.end());
|
||||
|
||||
@@ -59,22 +56,21 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
||||
uint32 key = 0;
|
||||
uint32 auxKey = 0;
|
||||
Array<std::string> parameters;
|
||||
for(auto& param : j["params"].items())
|
||||
{
|
||||
for (auto& param : j["params"].items()) {
|
||||
std::string type = param.value()["type"].get<std::string>();
|
||||
auto defaultValue = param.value().find("default");
|
||||
// TODO: ALIGNMENT RULES
|
||||
if(type.compare("float") == 0)
|
||||
{
|
||||
if (type.compare("float") == 0) {
|
||||
float defaultData = 0.f;
|
||||
if (defaultValue != param.value().end())
|
||||
{
|
||||
if (defaultValue != param.value().end()) {
|
||||
defaultData = std::stof(defaultValue.value().get<std::string>());
|
||||
}
|
||||
OFloatParameter p = new FloatParameter(param.key(), defaultData, uniformBufferOffset, uniformBinding);
|
||||
if(uniformBinding == -1)
|
||||
{
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = bindingCounter, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,});
|
||||
if (uniformBinding == -1) {
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = bindingCounter,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
});
|
||||
uniformBinding = bindingCounter++;
|
||||
}
|
||||
uniformBufferOffset += 4;
|
||||
@@ -82,93 +78,85 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
||||
expressions.add(std::move(p));
|
||||
}
|
||||
// TODO: ALIGNMENT RULES
|
||||
else if(type.compare("float3") == 0)
|
||||
{
|
||||
else if (type.compare("float3") == 0) {
|
||||
Vector defaultData = Vector(0, 0, 0);
|
||||
if (defaultValue != param.value().end())
|
||||
{
|
||||
if (defaultValue != param.value().end()) {
|
||||
defaultData = parseVector(defaultValue.value().get<std::string>().c_str());
|
||||
}
|
||||
OVectorParameter p = new VectorParameter(param.key(), defaultData, uniformBufferOffset, uniformBinding);
|
||||
if(uniformBinding == -1)
|
||||
{
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = bindingCounter, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,});
|
||||
if (uniformBinding == -1) {
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = bindingCounter,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
});
|
||||
uniformBinding = bindingCounter++;
|
||||
}
|
||||
uniformBufferOffset += 16;
|
||||
parameters.add(p->key);
|
||||
parameters.add(p->key);
|
||||
expressions.add(std::move(p));
|
||||
}
|
||||
else if(type.compare("Texture2D") == 0)
|
||||
{
|
||||
} else if (type.compare("Texture2D") == 0) {
|
||||
PTextureAsset texture;
|
||||
if(defaultValue != param.value().end())
|
||||
{
|
||||
if (defaultValue != param.value().end()) {
|
||||
std::string defaultString = defaultValue.value().get<std::string>();
|
||||
auto slashPos = defaultString.rfind("/");
|
||||
std::string folder = "";
|
||||
if (slashPos != std::string::npos)
|
||||
{
|
||||
if (slashPos != std::string::npos) {
|
||||
folder = defaultString.substr(0, slashPos - 1);
|
||||
defaultString = defaultString.substr(slashPos, defaultString.length());
|
||||
}
|
||||
|
||||
texture = AssetRegistry::findTexture(folder, defaultString);
|
||||
}
|
||||
if(texture == nullptr)
|
||||
{
|
||||
if (texture == nullptr) {
|
||||
texture = AssetRegistry::findTexture("", ""); // this will return placeholder texture
|
||||
}
|
||||
OTextureParameter p = new TextureParameter(param.key(), texture, bindingCounter);
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = bindingCounter++, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, });
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = bindingCounter++,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
});
|
||||
parameters.add(p->key);
|
||||
expressions.add(std::move(p));
|
||||
}
|
||||
else if(type.compare("Sampler") == 0)
|
||||
{
|
||||
} else if (type.compare("Sampler") == 0) {
|
||||
OSamplerParameter p = new SamplerParameter(param.key(), graphics->createSampler({}), bindingCounter);
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = bindingCounter++, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,});
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = bindingCounter++,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
|
||||
});
|
||||
parameters.add(p->key);
|
||||
expressions.add(std::move(p));
|
||||
}
|
||||
else if (type.compare("Sampler2D") == 0)
|
||||
{
|
||||
} else if (type.compare("Sampler2D") == 0) {
|
||||
PTextureAsset texture;
|
||||
if (defaultValue != param.value().end())
|
||||
{
|
||||
if (defaultValue != param.value().end()) {
|
||||
std::string defaultString = defaultValue.value().get<std::string>();
|
||||
auto slashPos = defaultString.rfind("/");
|
||||
std::string folder = "";
|
||||
if (slashPos != std::string::npos)
|
||||
{
|
||||
if (slashPos != std::string::npos) {
|
||||
folder = defaultString.substr(0, slashPos - 1);
|
||||
defaultString = defaultString.substr(slashPos, defaultString.length());
|
||||
}
|
||||
|
||||
texture = AssetRegistry::findTexture(folder, defaultString);
|
||||
}
|
||||
if (texture == nullptr)
|
||||
{
|
||||
if (texture == nullptr) {
|
||||
texture = AssetRegistry::findTexture("", ""); // this will return placeholder texture
|
||||
}
|
||||
OCombinedTextureParameter p = new CombinedTextureParameter(param.key(), texture, graphics->createSampler({}), bindingCounter);
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = bindingCounter++, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER, });
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = bindingCounter++,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
|
||||
});
|
||||
parameters.add(p->key);
|
||||
expressions.add(std::move(p));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
std::cout << "Error unsupported parameter type" << std::endl;
|
||||
}
|
||||
}
|
||||
uint32 uniformDataSize = uniformBufferOffset;
|
||||
auto referenceExpression = [¶meters, &auxKey, &expressions](json obj) -> std::string
|
||||
{
|
||||
if(obj.is_string())
|
||||
{
|
||||
auto referenceExpression = [¶meters, &auxKey, &expressions](json obj) -> std::string {
|
||||
if (obj.is_string()) {
|
||||
std::string str = obj.get<std::string>();
|
||||
if (parameters.find(str) != parameters.end())
|
||||
{
|
||||
if (parameters.find(str) != parameters.end()) {
|
||||
return str;
|
||||
}
|
||||
OConstantExpression c = new ConstantExpression(str, ExpressionType::UNKNOWN);
|
||||
@@ -176,28 +164,23 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
||||
c->key = name;
|
||||
expressions.add(std::move(c));
|
||||
return name;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return fmt::format("{0}", obj.get<uint32>());
|
||||
}
|
||||
};
|
||||
MaterialNode mat;
|
||||
|
||||
for(auto& param : j["code"].items())
|
||||
{
|
||||
for (auto& param : j["code"].items()) {
|
||||
auto& obj = param.value();
|
||||
std::string exp = obj["exp"].get<std::string>();
|
||||
if (exp.compare("Const") == 0)
|
||||
{
|
||||
if (exp.compare("Const") == 0) {
|
||||
OConstantExpression p = new ConstantExpression();
|
||||
std::string name = fmt::format("{0}", key++);
|
||||
p->key = name;
|
||||
p->expr = obj["value"];
|
||||
expressions.add(std::move(p));
|
||||
}
|
||||
if(exp.compare("Add") == 0)
|
||||
{
|
||||
if (exp.compare("Add") == 0) {
|
||||
OAddExpression p = new AddExpression();
|
||||
std::string name = fmt::format("{0}", key++);
|
||||
p->key = name;
|
||||
@@ -205,8 +188,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
||||
p->inputs["rhs"].source = referenceExpression(obj["rhs"]);
|
||||
expressions.add(std::move(p));
|
||||
}
|
||||
if(exp.compare("Sub") == 0)
|
||||
{
|
||||
if (exp.compare("Sub") == 0) {
|
||||
OSubExpression p = new SubExpression();
|
||||
std::string name = fmt::format("{0}", key++);
|
||||
p->key = name;
|
||||
@@ -214,8 +196,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
||||
p->inputs["rhs"].source = referenceExpression(obj["rhs"]);
|
||||
expressions.add(std::move(p));
|
||||
}
|
||||
if(exp.compare("Mul") == 0)
|
||||
{
|
||||
if (exp.compare("Mul") == 0) {
|
||||
OMulExpression p = new MulExpression();
|
||||
std::string name = fmt::format("{0}", key++);
|
||||
p->key = name;
|
||||
@@ -223,63 +204,49 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
||||
p->inputs["rhs"].source = referenceExpression(obj["rhs"]);
|
||||
expressions.add(std::move(p));
|
||||
}
|
||||
if(exp.compare("Swizzle") == 0)
|
||||
{
|
||||
if (exp.compare("Swizzle") == 0) {
|
||||
OSwizzleExpression p = new SwizzleExpression();
|
||||
std::string name = fmt::format("{0}", key++);
|
||||
p->key = name;
|
||||
p->inputs["target"].source = referenceExpression(obj["target"]);
|
||||
int32 i = 0;
|
||||
for(auto& c : obj["comp"].items())
|
||||
{
|
||||
for (auto& c : obj["comp"].items()) {
|
||||
p->comp[i++] = c.value().get<uint32>();
|
||||
}
|
||||
expressions.add(std::move(p));
|
||||
}
|
||||
if(exp.compare("Sample") == 0)
|
||||
{
|
||||
if (exp.compare("Sample") == 0) {
|
||||
OSampleExpression p = new SampleExpression();
|
||||
std::string name = fmt::format("{0}", key++);
|
||||
p->key = name;
|
||||
if (obj.contains("texture"))
|
||||
{
|
||||
if (obj.contains("texture")) {
|
||||
p->inputs["texture"].source = referenceExpression(obj["texture"]);
|
||||
}
|
||||
p->inputs["sampler"].source = referenceExpression(obj["sampler"]);
|
||||
p->inputs["coords"].source = referenceExpression(obj["coords"]);
|
||||
expressions.add(std::move(p));
|
||||
}
|
||||
if(exp.compare("BRDF") == 0)
|
||||
{
|
||||
if (exp.compare("BRDF") == 0) {
|
||||
mat.profile = obj["profile"].get<std::string>();
|
||||
for(auto& val : obj["values"].items())
|
||||
{
|
||||
for (auto& val : obj["values"].items()) {
|
||||
mat.variables[val.key()] = referenceExpression(val.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
layout->create();
|
||||
asset->material = new Material(
|
||||
graphics,
|
||||
std::move(layout),
|
||||
uniformDataSize,
|
||||
uniformBinding,
|
||||
materialName,
|
||||
std::move(expressions),
|
||||
std::move(parameters),
|
||||
std::move(mat)
|
||||
);
|
||||
asset->material = new Material(graphics, std::move(layout), uniformDataSize, uniformBinding, materialName, std::move(expressions),
|
||||
std::move(parameters), std::move(mat));
|
||||
|
||||
asset->material->compile();
|
||||
graphics->getShaderCompiler()->registerMaterial(asset->material);
|
||||
asset->setStatus(Asset::Status::Ready);
|
||||
|
||||
if (asset->getName().empty())
|
||||
{
|
||||
if (asset->getName().empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(asset->folderPath) / asset->getName()).string().append(".asset"), std::ios::binary);
|
||||
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(asset->folderPath) / asset->getName()).string().append(".asset"),
|
||||
std::ios::binary);
|
||||
|
||||
ArchiveBuffer archive;
|
||||
Serialization::save(archive, MaterialAsset::IDENTIFIER);
|
||||
@@ -290,7 +257,4 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
||||
////co_return;
|
||||
}
|
||||
|
||||
PMaterialAsset MaterialLoader::getPlaceHolderMaterial()
|
||||
{
|
||||
return placeholderMaterial;
|
||||
}
|
||||
PMaterialAsset MaterialLoader::getPlaceHolderMaterial() { return placeholderMaterial; }
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Containers/List.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include <filesystem>
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_REF(MaterialAsset)
|
||||
DECLARE_NAME_REF(Gfx, Graphics)
|
||||
struct MaterialImportArgs
|
||||
{
|
||||
struct MaterialImportArgs {
|
||||
std::filesystem::path filePath;
|
||||
std::string importPath;
|
||||
};
|
||||
class MaterialLoader
|
||||
{
|
||||
public:
|
||||
class MaterialLoader {
|
||||
public:
|
||||
MaterialLoader(Gfx::PGraphics graphic);
|
||||
~MaterialLoader();
|
||||
void importAsset(MaterialImportArgs args);
|
||||
PMaterialAsset getPlaceHolderMaterial();
|
||||
private:
|
||||
|
||||
private:
|
||||
void import(MaterialImportArgs args, PMaterialAsset asset);
|
||||
Gfx::PGraphics graphics;
|
||||
PMaterialAsset placeholderMaterial;
|
||||
|
||||
+235
-314
@@ -1,37 +1,32 @@
|
||||
#include "MeshLoader.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Asset/MeshAsset.h"
|
||||
#include "Graphics/Mesh.h"
|
||||
#include "Graphics/StaticMeshVertexData.h"
|
||||
#include "Asset/AssetImporter.h"
|
||||
#include "Asset/MaterialAsset.h"
|
||||
#include "Asset/MeshAsset.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Mesh.h"
|
||||
#include "Graphics/Shader.h"
|
||||
#include <set>
|
||||
#include "Graphics/StaticMeshVertexData.h"
|
||||
#include <Asset/MaterialLoader.h>
|
||||
#include <Asset/TextureLoader.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/config.h>
|
||||
#include <assimp/material.h>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <fmt/core.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <stb_image_write.h>
|
||||
#include <assimp/config.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/material.h>
|
||||
#include <Asset/MaterialLoader.h>
|
||||
#include <Asset/TextureLoader.h>
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
MeshLoader::MeshLoader(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
{
|
||||
}
|
||||
MeshLoader::MeshLoader(Gfx::PGraphics graphics) : graphics(graphics) {}
|
||||
|
||||
MeshLoader::~MeshLoader()
|
||||
{
|
||||
}
|
||||
MeshLoader::~MeshLoader() {}
|
||||
|
||||
void MeshLoader::importAsset(MeshImportArgs args)
|
||||
{
|
||||
void MeshLoader::importAsset(MeshImportArgs args) {
|
||||
std::filesystem::path assetPath = args.filePath.filename();
|
||||
assetPath.replace_extension("asset");
|
||||
OMeshAsset asset = new MeshAsset(args.importPath, assetPath.stem().string());
|
||||
@@ -41,43 +36,31 @@ void MeshLoader::importAsset(MeshImportArgs args)
|
||||
import(args, ref);
|
||||
}
|
||||
|
||||
|
||||
void MeshLoader::convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels)
|
||||
{
|
||||
for (uint32 i = 0; i < numPixels; ++i)
|
||||
{
|
||||
void MeshLoader::convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels) {
|
||||
for (uint32 i = 0; i < numPixels; ++i) {
|
||||
dst[i * 4 + 0] = src[i].r;
|
||||
dst[i * 4 + 1] = src[i].g;
|
||||
dst[i * 4 + 2] = src[i].b;
|
||||
dst[i * 4 + 3] = src[i].a;
|
||||
}
|
||||
}
|
||||
void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PTextureAsset>& textures)
|
||||
{
|
||||
for (uint32 i = 0; i < scene->mNumTextures; ++i)
|
||||
{
|
||||
void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path& meshDirectory, const std::string& importPath,
|
||||
Array<PTextureAsset>& textures) {
|
||||
for (uint32 i = 0; i < scene->mNumTextures; ++i) {
|
||||
aiTexture* tex = scene->mTextures[i];
|
||||
auto texPath = std::filesystem::path(tex->mFilename.C_Str());
|
||||
if (std::filesystem::exists(texPath))
|
||||
{
|
||||
}
|
||||
else if (std::filesystem::exists(meshDirectory / texPath))
|
||||
{
|
||||
if (std::filesystem::exists(texPath)) {
|
||||
} else if (std::filesystem::exists(meshDirectory / texPath)) {
|
||||
texPath = meshDirectory / texPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
texPath = (meshDirectory / texPath).replace_extension("png");
|
||||
if (tex->mHeight == 0)
|
||||
{
|
||||
if (tex->mHeight == 0) {
|
||||
std::cout << "Dumping texture " << texPath << std::endl;
|
||||
// already compressed, just dump it to the disk
|
||||
std::ofstream file(texPath, std::ios::binary);
|
||||
file.write((const char*)tex->pcData, tex->mWidth);
|
||||
file.flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
std::cout << "Writing extracted png " << texPath << std::endl;
|
||||
// recompress data so that the TextureLoader can read it
|
||||
unsigned char* texData = new unsigned char[tex->mWidth * tex->mHeight * 4];
|
||||
@@ -90,7 +73,7 @@ void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path&
|
||||
AssetImporter::importTexture(TextureImportArgs{
|
||||
.filePath = texPath,
|
||||
.importPath = importPath,
|
||||
});
|
||||
});
|
||||
textures.add(AssetRegistry::findTexture(importPath, texPath.stem().string()));
|
||||
}
|
||||
}
|
||||
@@ -111,18 +94,23 @@ constexpr const char* KEY_ROUGHNESS_TEXTURE = "tex_r";
|
||||
constexpr const char* KEY_METALLIC_TEXTURE = "tex_m";
|
||||
constexpr const char* KEY_AMBIENT_OCCLUSION_TEXTURE = "tex_ao";
|
||||
|
||||
void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>& textures, const std::string& baseName, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PMaterialInstanceAsset>& globalMaterials)
|
||||
{
|
||||
for (uint32 m = 0; m < scene->mNumMaterials; ++m)
|
||||
{
|
||||
void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>& textures, const std::string& baseName,
|
||||
const std::filesystem::path& meshDirectory, const std::string& importPath,
|
||||
Array<PMaterialInstanceAsset>& globalMaterials) {
|
||||
for (uint32 m = 0; m < scene->mNumMaterials; ++m) {
|
||||
aiMaterial* material = scene->mMaterials[m];
|
||||
aiString texPath;
|
||||
std::string materialName = fmt::format("M{0}{1}{2}", baseName, material->GetName().C_Str(), m);
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end()); // dots break adding the .asset extension later
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '-'), materialName.end()); // dots break adding the .asset extension later
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), ' '), materialName.end()); // dots break adding the .asset extension later
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '('), materialName.end()); // dots break adding the .asset extension later
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), ')'), materialName.end()); // dots break adding the .asset extension later
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'),
|
||||
materialName.end()); // dots break adding the .asset extension later
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '-'),
|
||||
materialName.end()); // dots break adding the .asset extension later
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), ' '),
|
||||
materialName.end()); // dots break adding the .asset extension later
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '('),
|
||||
materialName.end()); // dots break adding the .asset extension later
|
||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), ')'),
|
||||
materialName.end()); // dots break adding the .asset extension later
|
||||
Gfx::ODescriptorLayout materialLayout = graphics->createDescriptorLayout("pMaterial");
|
||||
Array<OShaderExpression> expressions;
|
||||
Array<std::string> parameters;
|
||||
@@ -131,200 +119,183 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
|
||||
.binding = 0,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
|
||||
});
|
||||
});
|
||||
|
||||
size_t uniformSize = 0;
|
||||
uint32 bindingCounter = 1;
|
||||
auto addScalarParameter = [&](std::string paramKey, const char* matKey, int type, int index)
|
||||
{
|
||||
float scalar;
|
||||
material->Get(matKey, type, index, scalar);
|
||||
expressions.add(new FloatParameter(paramKey, scalar, uniformSize, 0));
|
||||
uniformSize += sizeof(float);
|
||||
parameters.add(paramKey);
|
||||
};
|
||||
auto addScalarParameter = [&](std::string paramKey, const char* matKey, int type, int index) {
|
||||
float scalar;
|
||||
material->Get(matKey, type, index, scalar);
|
||||
expressions.add(new FloatParameter(paramKey, scalar, uniformSize, 0));
|
||||
uniformSize += sizeof(float);
|
||||
parameters.add(paramKey);
|
||||
};
|
||||
|
||||
auto addVectorParameter = [&](std::string paramKey, const char* matKey, int type, int index)
|
||||
{
|
||||
aiColor3D color;
|
||||
material->Get(matKey, type, index, color);
|
||||
uniformSize = (uniformSize + sizeof(Vector4) - 1) / sizeof(Vector4) * sizeof(Vector4);
|
||||
expressions.add(new VectorParameter(paramKey, Vector(color.r, color.g, color.b), uniformSize, 0));
|
||||
uniformSize += sizeof(Vector);
|
||||
parameters.add(paramKey);
|
||||
};
|
||||
auto addVectorParameter = [&](std::string paramKey, const char* matKey, int type, int index) {
|
||||
aiColor3D color;
|
||||
material->Get(matKey, type, index, color);
|
||||
uniformSize = (uniformSize + sizeof(Vector4) - 1) / sizeof(Vector4) * sizeof(Vector4);
|
||||
expressions.add(new VectorParameter(paramKey, Vector(color.r, color.g, color.b), uniformSize, 0));
|
||||
uniformSize += sizeof(Vector);
|
||||
parameters.add(paramKey);
|
||||
};
|
||||
|
||||
auto addTextureParameter = [&](std::string paramKey, aiTextureType type, int index, std::string& result, StaticArray<int32, 4> extractMask = { 0, 1, 2, -1 })
|
||||
{
|
||||
aiString texPath;
|
||||
aiTextureMapping mapping;
|
||||
uint32 uvIndex = 0;
|
||||
aiTextureMapMode mapMode = aiTextureMapMode_Clamp;
|
||||
float blend = std::numeric_limits<float>::max();
|
||||
aiTextureOp op;
|
||||
if (material->GetTexture(type, index, &texPath, &mapping, &uvIndex, nullptr, nullptr, nullptr) != AI_SUCCESS)
|
||||
{
|
||||
std::cout << "fuck" << std::endl;
|
||||
}
|
||||
auto addTextureParameter = [&](std::string paramKey, aiTextureType type, int index, std::string& result,
|
||||
StaticArray<int32, 4> extractMask = {0, 1, 2, -1}) {
|
||||
aiString texPath;
|
||||
aiTextureMapping mapping;
|
||||
uint32 uvIndex = 0;
|
||||
aiTextureMapMode mapMode = aiTextureMapMode_Clamp;
|
||||
float blend = std::numeric_limits<float>::max();
|
||||
aiTextureOp op;
|
||||
if (material->GetTexture(type, index, &texPath, &mapping, &uvIndex, nullptr, nullptr, nullptr) != AI_SUCCESS) {
|
||||
std::cout << "fuck" << std::endl;
|
||||
}
|
||||
|
||||
std::string textureKey = fmt::format("{0}Texture{1}", paramKey, index);
|
||||
auto texFilename = std::filesystem::path(texPath.C_Str());
|
||||
PTextureAsset texture;
|
||||
std::string textureKey = fmt::format("{0}Texture{1}", paramKey, index);
|
||||
auto texFilename = std::filesystem::path(texPath.C_Str());
|
||||
PTextureAsset texture;
|
||||
|
||||
if (texFilename.string()[0] == '*')
|
||||
{
|
||||
texture = textures[atoi(texFilename.string().substr(1).c_str())];
|
||||
}
|
||||
else if (std::filesystem::exists(texFilename))
|
||||
{
|
||||
AssetImporter::importTexture(TextureImportArgs{
|
||||
if (texFilename.string()[0] == '*') {
|
||||
texture = textures[atoi(texFilename.string().substr(1).c_str())];
|
||||
} else if (std::filesystem::exists(texFilename)) {
|
||||
AssetImporter::importTexture(TextureImportArgs{
|
||||
.filePath = texFilename,
|
||||
.importPath = importPath,
|
||||
});
|
||||
texture = AssetRegistry::findTexture(importPath, texFilename.stem().string());
|
||||
}
|
||||
else if (std::filesystem::exists(meshDirectory / texFilename))
|
||||
{
|
||||
AssetImporter::importTexture(TextureImportArgs{
|
||||
});
|
||||
texture = AssetRegistry::findTexture(importPath, texFilename.stem().string());
|
||||
} else if (std::filesystem::exists(meshDirectory / texFilename)) {
|
||||
AssetImporter::importTexture(TextureImportArgs{
|
||||
.filePath = meshDirectory / texFilename,
|
||||
.importPath = importPath,
|
||||
.type = type == aiTextureType_NORMALS ? TextureImportType::TEXTURE_NORMAL : TextureImportType::TEXTURE_2D,
|
||||
});
|
||||
texture = AssetRegistry::findTexture(importPath, texFilename.stem().string());
|
||||
}
|
||||
else if (std::filesystem::exists(meshDirectory.parent_path() / "textures" / texFilename))
|
||||
{
|
||||
AssetImporter::importTexture(TextureImportArgs{
|
||||
});
|
||||
texture = AssetRegistry::findTexture(importPath, texFilename.stem().string());
|
||||
} else if (std::filesystem::exists(meshDirectory.parent_path() / "textures" / texFilename)) {
|
||||
AssetImporter::importTexture(TextureImportArgs{
|
||||
.filePath = meshDirectory.parent_path() / "textures" / texFilename,
|
||||
.importPath = importPath,
|
||||
.type = type == aiTextureType_NORMALS ? TextureImportType::TEXTURE_NORMAL : TextureImportType::TEXTURE_2D,
|
||||
});
|
||||
texture = AssetRegistry::findTexture(importPath, texFilename.stem().string());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "couldnt find " << texPath.C_Str() << std::endl;
|
||||
return;
|
||||
}
|
||||
expressions.add(new TextureParameter(textureKey, texture, bindingCounter));
|
||||
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = bindingCounter,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
.textureType = Gfx::SE_IMAGE_VIEW_TYPE_2D,
|
||||
.shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
|
||||
});
|
||||
parameters.add(textureKey);
|
||||
bindingCounter++;
|
||||
});
|
||||
texture = AssetRegistry::findTexture(importPath, texFilename.stem().string());
|
||||
} else {
|
||||
std::cout << "couldnt find " << texPath.C_Str() << std::endl;
|
||||
return;
|
||||
}
|
||||
expressions.add(new TextureParameter(textureKey, texture, bindingCounter));
|
||||
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = bindingCounter,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
.textureType = Gfx::SE_IMAGE_VIEW_TYPE_2D,
|
||||
.shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
|
||||
});
|
||||
parameters.add(textureKey);
|
||||
bindingCounter++;
|
||||
|
||||
std::string samplerKey = fmt::format("{0}Sampler{1}", paramKey, index);
|
||||
SamplerCreateInfo samplerInfo = {};
|
||||
switch (mapMode)
|
||||
{
|
||||
case aiTextureMapMode_Wrap:
|
||||
samplerInfo.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
samplerInfo.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
samplerInfo.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
break;
|
||||
case aiTextureMapMode_Clamp:
|
||||
samplerInfo.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
samplerInfo.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
samplerInfo.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case aiTextureMapMode_Decal:
|
||||
samplerInfo.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
|
||||
samplerInfo.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
|
||||
samplerInfo.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
|
||||
break;
|
||||
case aiTextureMapMode_Mirror:
|
||||
samplerInfo.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
|
||||
samplerInfo.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
|
||||
samplerInfo.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
|
||||
break;
|
||||
}
|
||||
expressions.add(new SamplerParameter(samplerKey, graphics->createSampler(samplerInfo), bindingCounter));
|
||||
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = bindingCounter,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
|
||||
.shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
|
||||
});
|
||||
parameters.add(samplerKey);
|
||||
bindingCounter++;
|
||||
std::string samplerKey = fmt::format("{0}Sampler{1}", paramKey, index);
|
||||
SamplerCreateInfo samplerInfo = {};
|
||||
switch (mapMode) {
|
||||
case aiTextureMapMode_Wrap:
|
||||
samplerInfo.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
samplerInfo.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
samplerInfo.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
break;
|
||||
case aiTextureMapMode_Clamp:
|
||||
samplerInfo.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
samplerInfo.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
samplerInfo.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case aiTextureMapMode_Decal:
|
||||
samplerInfo.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
|
||||
samplerInfo.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
|
||||
samplerInfo.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
|
||||
break;
|
||||
case aiTextureMapMode_Mirror:
|
||||
samplerInfo.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
|
||||
samplerInfo.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
|
||||
samplerInfo.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
|
||||
break;
|
||||
}
|
||||
expressions.add(new SamplerParameter(samplerKey, graphics->createSampler(samplerInfo), bindingCounter));
|
||||
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = bindingCounter,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
|
||||
.shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
|
||||
});
|
||||
parameters.add(samplerKey);
|
||||
bindingCounter++;
|
||||
|
||||
std::string sampleKey = fmt::format("{0}Sample{1}", paramKey, index);
|
||||
expressions.add(new SampleExpression());
|
||||
expressions.back()->key = sampleKey;
|
||||
expressions.back()->inputs["texture"].source = textureKey;
|
||||
expressions.back()->inputs["sampler"].source = samplerKey;
|
||||
expressions.back()->inputs["coords"].source = fmt::format("input.texCoords[{0}]", uvIndex);
|
||||
std::string sampleKey = fmt::format("{0}Sample{1}", paramKey, index);
|
||||
expressions.add(new SampleExpression());
|
||||
expressions.back()->key = sampleKey;
|
||||
expressions.back()->inputs["texture"].source = textureKey;
|
||||
expressions.back()->inputs["sampler"].source = samplerKey;
|
||||
expressions.back()->inputs["coords"].source = fmt::format("input.texCoords[{0}]", uvIndex);
|
||||
|
||||
std::string colorExtract = fmt::format("{0}Extract{1}", paramKey, index);
|
||||
expressions.add(new SwizzleExpression(extractMask));
|
||||
expressions.back()->key = colorExtract;
|
||||
expressions.back()->inputs["target"].source = sampleKey;
|
||||
//TODO: extract alpha, set opacity
|
||||
std::string colorExtract = fmt::format("{0}Extract{1}", paramKey, index);
|
||||
expressions.add(new SwizzleExpression(extractMask));
|
||||
expressions.back()->key = colorExtract;
|
||||
expressions.back()->inputs["target"].source = sampleKey;
|
||||
// TODO: extract alpha, set opacity
|
||||
|
||||
if (blend == std::numeric_limits<float>::max())
|
||||
{
|
||||
result = colorExtract;
|
||||
return;
|
||||
}
|
||||
std::string blendFactorKey = fmt::format("{0}BlendFactor{1}", paramKey, index);
|
||||
expressions.add(new FloatParameter(blendFactorKey, blend, uniformSize, 0));
|
||||
uniformSize += sizeof(float);
|
||||
parameters.add(blendFactorKey);
|
||||
if (blend == std::numeric_limits<float>::max()) {
|
||||
result = colorExtract;
|
||||
return;
|
||||
}
|
||||
std::string blendFactorKey = fmt::format("{0}BlendFactor{1}", paramKey, index);
|
||||
expressions.add(new FloatParameter(blendFactorKey, blend, uniformSize, 0));
|
||||
uniformSize += sizeof(float);
|
||||
parameters.add(blendFactorKey);
|
||||
|
||||
std::string strengthKey = fmt::format("{0}Strength{1}", paramKey, index);
|
||||
std::string strengthKey = fmt::format("{0}Strength{1}", paramKey, index);
|
||||
expressions.add(new MulExpression());
|
||||
expressions.back()->key = strengthKey;
|
||||
expressions.back()->inputs["lhs"].source = colorExtract;
|
||||
expressions.back()->inputs["rhs"].source = blendFactorKey;
|
||||
|
||||
std::string blendKey = fmt::format("{0}Blend{1}", paramKey, index);
|
||||
switch (op) {
|
||||
/** T = T1 * T2 */
|
||||
case aiTextureOp_Multiply:
|
||||
expressions.add(new MulExpression());
|
||||
expressions.back()->key = strengthKey;
|
||||
expressions.back()->inputs["lhs"].source = colorExtract;
|
||||
expressions.back()->inputs["rhs"].source = blendFactorKey;
|
||||
break;
|
||||
|
||||
std::string blendKey = fmt::format("{0}Blend{1}", paramKey, index);
|
||||
switch (op) {
|
||||
/** T = T1 * T2 */
|
||||
case aiTextureOp_Multiply:
|
||||
expressions.add(new MulExpression());
|
||||
break;
|
||||
/** T = T1 - T2 */
|
||||
case aiTextureOp_Subtract:
|
||||
expressions.add(new SubExpression());
|
||||
break;
|
||||
|
||||
/** T = T1 - T2 */
|
||||
case aiTextureOp_Subtract:
|
||||
expressions.add(new SubExpression());
|
||||
break;
|
||||
/** T = T1 / T2 */
|
||||
case aiTextureOp_Divide:
|
||||
// expressions[blendKey] = new DivExpression();
|
||||
throw std::logic_error("Not implemented");
|
||||
|
||||
/** T = T1 / T2 */
|
||||
case aiTextureOp_Divide:
|
||||
//expressions[blendKey] = new DivExpression();
|
||||
throw std::logic_error("Not implemented");
|
||||
/** T = (T1 + T2) - (T1 * T2) */
|
||||
case aiTextureOp_SmoothAdd:
|
||||
throw std::logic_error("Not implemented");
|
||||
|
||||
/** T = (T1 + T2) - (T1 * T2) */
|
||||
case aiTextureOp_SmoothAdd:
|
||||
throw std::logic_error("Not implemented");
|
||||
/** T = T1 + (T2-0.5) */
|
||||
case aiTextureOp_SignedAdd:
|
||||
throw std::logic_error("Not implemented");
|
||||
|
||||
/** T = T1 + T2 */
|
||||
case aiTextureOp_Add:
|
||||
default:
|
||||
expressions.add(new AddExpression());
|
||||
break;
|
||||
}
|
||||
expressions.back()->key = blendKey;
|
||||
expressions.back()->inputs["lhs"].source = result;
|
||||
expressions.back()->inputs["rhs"].source = strengthKey;
|
||||
|
||||
/** T = T1 + (T2-0.5) */
|
||||
case aiTextureOp_SignedAdd:
|
||||
throw std::logic_error("Not implemented");
|
||||
|
||||
/** T = T1 + T2 */
|
||||
case aiTextureOp_Add:
|
||||
default:
|
||||
expressions.add(new AddExpression());
|
||||
break;
|
||||
}
|
||||
expressions.back()->key = blendKey;
|
||||
expressions.back()->inputs["lhs"].source = result;
|
||||
expressions.back()->inputs["rhs"].source = strengthKey;
|
||||
|
||||
result = blendKey;
|
||||
|
||||
};
|
||||
result = blendKey;
|
||||
};
|
||||
|
||||
// Diffuse
|
||||
addVectorParameter(KEY_DIFFUSE_COLOR, AI_MATKEY_COLOR_DIFFUSE);
|
||||
std::string outputDiffuse = KEY_DIFFUSE_COLOR;
|
||||
uint32 numDiffuseTextures = material->GetTextureCount(aiTextureType_DIFFUSE);
|
||||
for (uint32 i = 0; i < numDiffuseTextures; ++i)
|
||||
{
|
||||
for (uint32 i = 0; i < numDiffuseTextures; ++i) {
|
||||
addTextureParameter(KEY_DIFFUSE_TEXTURE, aiTextureType_DIFFUSE, i, outputDiffuse);
|
||||
}
|
||||
|
||||
@@ -332,16 +303,14 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
|
||||
addVectorParameter(KEY_SPECULAR_COLOR, AI_MATKEY_COLOR_SPECULAR);
|
||||
std::string outputSpecular = KEY_SPECULAR_COLOR;
|
||||
uint32 numSpecular = material->GetTextureCount(aiTextureType_SPECULAR);
|
||||
for (uint32 i = 0; i < numSpecular; ++i)
|
||||
{
|
||||
for (uint32 i = 0; i < numSpecular; ++i) {
|
||||
addTextureParameter(KEY_SPECULAR_TEXTURE, aiTextureType_SPECULAR, i, outputSpecular);
|
||||
}
|
||||
|
||||
// Normal
|
||||
std::string outputNormal = "";
|
||||
uint32 numNormal = material->GetTextureCount(aiTextureType_NORMALS);
|
||||
for (uint32 i = 0; i < numNormal; ++i)
|
||||
{
|
||||
for (uint32 i = 0; i < numNormal; ++i) {
|
||||
addTextureParameter(KEY_NORMAL_TEXTURE, aiTextureType_NORMALS, i, outputNormal);
|
||||
}
|
||||
|
||||
@@ -349,8 +318,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
|
||||
addVectorParameter(KEY_AMBIENT_COLOR, AI_MATKEY_COLOR_AMBIENT);
|
||||
std::string outputAmbient = KEY_AMBIENT_COLOR;
|
||||
uint32 numAmbient = material->GetTextureCount(aiTextureType_AMBIENT);
|
||||
for (uint32 i = 0; i < numAmbient; ++i)
|
||||
{
|
||||
for (uint32 i = 0; i < numAmbient; ++i) {
|
||||
addTextureParameter(KEY_AMBIENT_TEXTURE, aiTextureType_AMBIENT, i, outputAmbient);
|
||||
}
|
||||
|
||||
@@ -358,42 +326,36 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
|
||||
addScalarParameter(KEY_SHININESS, AI_MATKEY_SHININESS);
|
||||
std::string outputShininess = KEY_SHININESS;
|
||||
uint32 numShiny = material->GetTextureCount(aiTextureType_SHININESS);
|
||||
for (uint32 i = 0; i < numShiny; ++i)
|
||||
{
|
||||
addTextureParameter(KEY_SHININESS_TEXTURE, aiTextureType_SHININESS, i, outputShininess, { 0, -1, -1, -1 });
|
||||
for (uint32 i = 0; i < numShiny; ++i) {
|
||||
addTextureParameter(KEY_SHININESS_TEXTURE, aiTextureType_SHININESS, i, outputShininess, {0, -1, -1, -1});
|
||||
}
|
||||
|
||||
// Roughness
|
||||
addScalarParameter(KEY_ROUGHNESS, AI_MATKEY_ROUGHNESS_FACTOR);
|
||||
std::string outputRoughness = KEY_ROUGHNESS;
|
||||
uint32 numRoughness = material->GetTextureCount(aiTextureType_DIFFUSE_ROUGHNESS);
|
||||
for (uint32 i = 0; i < numRoughness; ++i)
|
||||
{
|
||||
addTextureParameter(KEY_ROUGHNESS_TEXTURE, aiTextureType_DIFFUSE_ROUGHNESS, i, outputRoughness, { 0, -1, -1, -1 });
|
||||
for (uint32 i = 0; i < numRoughness; ++i) {
|
||||
addTextureParameter(KEY_ROUGHNESS_TEXTURE, aiTextureType_DIFFUSE_ROUGHNESS, i, outputRoughness, {0, -1, -1, -1});
|
||||
}
|
||||
|
||||
// Metallic
|
||||
addScalarParameter(KEY_METALLIC, AI_MATKEY_METALLIC_FACTOR);
|
||||
std::string outputMetallic = KEY_METALLIC;
|
||||
uint32 numMetallic = material->GetTextureCount(aiTextureType_METALNESS);
|
||||
for (uint32 i = 0; i < numMetallic; ++i)
|
||||
{
|
||||
addTextureParameter(KEY_METALLIC_TEXTURE, aiTextureType_METALNESS, i, outputMetallic, { 0, -1, -1, -1 });
|
||||
for (uint32 i = 0; i < numMetallic; ++i) {
|
||||
addTextureParameter(KEY_METALLIC_TEXTURE, aiTextureType_METALNESS, i, outputMetallic, {0, -1, -1, -1});
|
||||
}
|
||||
|
||||
// Ambient Occlusion
|
||||
std::string outputAO = "";
|
||||
uint32 numAO = material->GetTextureCount(aiTextureType_AMBIENT_OCCLUSION);
|
||||
for (uint32 i = 0; i < numAO; ++i)
|
||||
{
|
||||
addTextureParameter(KEY_AMBIENT_OCCLUSION_TEXTURE, aiTextureType_AMBIENT_OCCLUSION, i, outputAO, { 0, -1, -1, -1 });
|
||||
for (uint32 i = 0; i < numAO; ++i) {
|
||||
addTextureParameter(KEY_AMBIENT_OCCLUSION_TEXTURE, aiTextureType_AMBIENT_OCCLUSION, i, outputAO, {0, -1, -1, -1});
|
||||
}
|
||||
|
||||
|
||||
MaterialNode brdf;
|
||||
brdf.variables["baseColor"] = outputDiffuse;
|
||||
if (!outputNormal.empty())
|
||||
{
|
||||
if (!outputNormal.empty()) {
|
||||
expressions.add(new MulExpression());
|
||||
expressions.back()->key = "NormalMul";
|
||||
expressions.back()->inputs["lhs"].source = "2";
|
||||
@@ -429,8 +391,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
|
||||
brdf.profile = "CookTorrance";
|
||||
brdf.variables["roughness"] = outputRoughness;
|
||||
brdf.variables["metallic"] = outputMetallic;
|
||||
if (!outputAO.empty())
|
||||
{
|
||||
if (!outputAO.empty()) {
|
||||
brdf.variables["ambientOcclusion"] = outputAmbient;
|
||||
}
|
||||
break;
|
||||
@@ -439,41 +400,32 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
|
||||
materialLayout->create();
|
||||
|
||||
OMaterialAsset baseMat = new MaterialAsset(importPath, materialName);
|
||||
baseMat->material = new Material(graphics,
|
||||
std::move(materialLayout),
|
||||
uniformSize, 0, materialName,
|
||||
std::move(expressions),
|
||||
std::move(parameters),
|
||||
std::move(brdf)
|
||||
);
|
||||
baseMat->material = new Material(graphics, std::move(materialLayout), uniformSize, 0, materialName, std::move(expressions),
|
||||
std::move(parameters), std::move(brdf));
|
||||
baseMat->material->compile();
|
||||
graphics->getShaderCompiler()->registerMaterial(baseMat->material);
|
||||
globalMaterials[m] = baseMat->instantiate(InstantiationParameter{
|
||||
.name = fmt::format("{0}_Inst_0", baseMat->getName()),
|
||||
.folderPath = baseMat->getFolderPath(),
|
||||
});
|
||||
});
|
||||
AssetRegistry::get().saveAsset(PMaterialAsset(baseMat), MaterialAsset::IDENTIFIER, baseMat->getFolderPath(), baseMat->getName());
|
||||
AssetRegistry::get().registerMaterial(std::move(baseMat));
|
||||
}
|
||||
}
|
||||
|
||||
void findMeshRoots(aiNode* node, List<aiNode*>& meshNodes)
|
||||
{
|
||||
if (node->mNumMeshes > 0)
|
||||
{
|
||||
void findMeshRoots(aiNode* node, List<aiNode*>& meshNodes) {
|
||||
if (node->mNumMeshes > 0) {
|
||||
meshNodes.add(node);
|
||||
return;
|
||||
}
|
||||
for (uint32 i = 0; i < node->mNumChildren; ++i)
|
||||
{
|
||||
for (uint32 i = 0; i < node->mNumChildren; ++i) {
|
||||
findMeshRoots(node->mChildren[i], meshNodes);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes, Component::Collider& collider)
|
||||
{
|
||||
for (int32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex)
|
||||
{
|
||||
void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes,
|
||||
Component::Collider& collider) {
|
||||
for (int32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex) {
|
||||
aiMesh* mesh = scene->mMeshes[meshIndex];
|
||||
if (!(mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE))
|
||||
continue;
|
||||
@@ -483,8 +435,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
// assume static mesh for now
|
||||
Array<Vector> positions(mesh->mNumVertices);
|
||||
StaticArray<Array<Vector2>, MAX_TEXCOORDS> texCoords;
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
|
||||
{
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
texCoords[i].resize(mesh->mNumVertices);
|
||||
}
|
||||
Array<Vector> normals(mesh->mNumVertices);
|
||||
@@ -493,45 +444,33 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
Array<Vector> colors(mesh->mNumVertices);
|
||||
|
||||
StaticMeshVertexData* vertexData = StaticMeshVertexData::getInstance();
|
||||
for (int32 i = 0; i < mesh->mNumVertices; ++i)
|
||||
{
|
||||
for (int32 i = 0; i < mesh->mNumVertices; ++i) {
|
||||
positions[i] = Vector(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
|
||||
for (size_t j = 0; j < MAX_TEXCOORDS; ++j)
|
||||
{
|
||||
if (mesh->HasTextureCoords(j))
|
||||
{
|
||||
for (size_t j = 0; j < MAX_TEXCOORDS; ++j) {
|
||||
if (mesh->HasTextureCoords(j)) {
|
||||
texCoords[j][i] = Vector2(mesh->mTextureCoords[j][i].x, mesh->mTextureCoords[j][i].y);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
texCoords[j][i] = Vector2(0, 0);
|
||||
}
|
||||
}
|
||||
normals[i] = Vector(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z);
|
||||
if (mesh->HasTangentsAndBitangents())
|
||||
{
|
||||
if (mesh->HasTangentsAndBitangents()) {
|
||||
tangents[i] = Vector(mesh->mTangents[i].x, mesh->mTangents[i].y, mesh->mTangents[i].z);
|
||||
biTangents[i] = Vector(mesh->mBitangents[i].x, mesh->mBitangents[i].y, mesh->mBitangents[i].z);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
tangents[i] = Vector(0, 0, 1);
|
||||
biTangents[i] = Vector(1, 0, 0);
|
||||
}
|
||||
if (mesh->HasVertexColors(0))
|
||||
{
|
||||
if (mesh->HasVertexColors(0)) {
|
||||
colors[i] = Vector(mesh->mColors[0][i].r, mesh->mColors[0][i].g, mesh->mColors[0][i].b);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
colors[i] = Vector(1, 1, 1);
|
||||
}
|
||||
}
|
||||
MeshId id = vertexData->allocateVertexData(mesh->mNumVertices);
|
||||
vertexData->loadPositions(id, positions);
|
||||
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
|
||||
{
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
vertexData->loadTexCoords(id, i, texCoords[i]);
|
||||
}
|
||||
vertexData->loadNormals(id, normals);
|
||||
@@ -540,8 +479,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
vertexData->loadColors(id, colors);
|
||||
|
||||
Array<uint32> indices(mesh->mNumFaces * 3);
|
||||
for (int32 faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex)
|
||||
{
|
||||
for (int32 faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex) {
|
||||
indices[faceIndex * 3 + 0] = mesh->mFaces[faceIndex].mIndices[0];
|
||||
indices[faceIndex * 3 + 1] = mesh->mFaces[faceIndex].mIndices[1];
|
||||
indices[faceIndex * 3 + 2] = mesh->mFaces[faceIndex].mIndices[2];
|
||||
@@ -552,7 +490,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
Meshlet::build(positions, indices, meshlets);
|
||||
vertexData->loadMesh(id, indices, meshlets);
|
||||
|
||||
//collider.physicsMesh.addCollider(positions, indices, Matrix4(1.0f));
|
||||
// collider.physicsMesh.addCollider(positions, indices, Matrix4(1.0f));
|
||||
|
||||
globalMeshes[meshIndex] = new Mesh();
|
||||
globalMeshes[meshIndex]->vertexData = vertexData;
|
||||
@@ -564,42 +502,27 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Matrix4 convertMatrix(aiMatrix4x4 matrix)
|
||||
{
|
||||
return Matrix4(
|
||||
matrix.a1, matrix.b1, matrix.c1, matrix.d1,
|
||||
matrix.a2, matrix.b2, matrix.c2, matrix.d2,
|
||||
matrix.a3, matrix.b3, matrix.c3, matrix.d3,
|
||||
matrix.a4, matrix.b4, matrix.c4, matrix.d4
|
||||
);
|
||||
Matrix4 convertMatrix(aiMatrix4x4 matrix) {
|
||||
return Matrix4(matrix.a1, matrix.b1, matrix.c1, matrix.d1, matrix.a2, matrix.b2, matrix.c2, matrix.d2, matrix.a3, matrix.b3, matrix.c3,
|
||||
matrix.d3, matrix.a4, matrix.b4, matrix.c4, matrix.d4);
|
||||
}
|
||||
|
||||
aiMatrix4x4 loadNodeTransform(aiNode* node)
|
||||
{
|
||||
aiMatrix4x4 loadNodeTransform(aiNode* node) {
|
||||
aiMatrix4x4 parent = aiMatrix4x4();
|
||||
if (node->mParent != nullptr)
|
||||
{
|
||||
if (node->mParent != nullptr) {
|
||||
parent = loadNodeTransform(node->mParent);
|
||||
}
|
||||
return node->mTransformation * parent;
|
||||
}
|
||||
|
||||
void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset)
|
||||
{
|
||||
void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset) {
|
||||
std::cout << "Starting to import " << args.filePath << std::endl;
|
||||
meshAsset->setStatus(Asset::Status::Loading);
|
||||
Assimp::Importer importer;
|
||||
importer.ReadFile(args.filePath.string().c_str(), (uint32)(
|
||||
aiProcess_JoinIdenticalVertices |
|
||||
aiProcess_FlipUVs |
|
||||
aiProcess_Triangulate |
|
||||
aiProcess_SortByPType |
|
||||
aiProcess_GenBoundingBoxes |
|
||||
aiProcess_GenSmoothNormals |
|
||||
aiProcess_ImproveCacheLocality |
|
||||
aiProcess_GenUVCoords |
|
||||
aiProcess_FindDegenerates));
|
||||
importer.ReadFile(args.filePath.string().c_str(),
|
||||
(uint32)(aiProcess_JoinIdenticalVertices | aiProcess_FlipUVs | aiProcess_Triangulate | aiProcess_SortByPType |
|
||||
aiProcess_GenBoundingBoxes | aiProcess_GenSmoothNormals | aiProcess_ImproveCacheLocality |
|
||||
aiProcess_GenUVCoords | aiProcess_FindDegenerates));
|
||||
const aiScene* scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace);
|
||||
std::cout << importer.GetErrorString() << std::endl;
|
||||
|
||||
@@ -616,12 +539,9 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset)
|
||||
findMeshRoots(scene->mRootNode, meshNodes);
|
||||
|
||||
Array<OMesh> meshes;
|
||||
for (auto meshNode : meshNodes)
|
||||
{
|
||||
for (uint32 i = 0; i < meshNode->mNumMeshes; ++i)
|
||||
{
|
||||
if (globalMeshes[meshNode->mMeshes[i]] == nullptr)
|
||||
{
|
||||
for (auto meshNode : meshNodes) {
|
||||
for (uint32 i = 0; i < meshNode->mNumMeshes; ++i) {
|
||||
if (globalMeshes[meshNode->mMeshes[i]] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
meshes.add(std::move(globalMeshes[meshNode->mMeshes[i]]));
|
||||
@@ -631,7 +551,8 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset)
|
||||
meshAsset->meshes = std::move(meshes);
|
||||
meshAsset->physicsMesh = std::move(collider);
|
||||
|
||||
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(meshAsset->getFolderPath()) / meshAsset->getName()).replace_extension("asset").string(), std::ios::binary);
|
||||
auto stream = AssetRegistry::createWriteStream(
|
||||
(std::filesystem::path(meshAsset->getFolderPath()) / meshAsset->getName()).replace_extension("asset").string(), std::ios::binary);
|
||||
|
||||
ArchiveBuffer archive;
|
||||
Serialization::save(archive, MeshAsset::IDENTIFIER);
|
||||
|
||||
@@ -1,35 +1,38 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Component/Collider.h"
|
||||
#include "Containers/List.h"
|
||||
#include "Containers/Map.h"
|
||||
#include "Component/Collider.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include <filesystem>
|
||||
|
||||
|
||||
struct aiScene;
|
||||
struct aiTexel;
|
||||
struct aiNode;
|
||||
namespace Seele
|
||||
{
|
||||
namespace Seele {
|
||||
DECLARE_REF(Mesh)
|
||||
DECLARE_REF(MeshAsset)
|
||||
DECLARE_REF(MaterialInstanceAsset)
|
||||
DECLARE_REF(TextureAsset)
|
||||
DECLARE_NAME_REF(Gfx, Graphics)
|
||||
struct MeshImportArgs
|
||||
{
|
||||
struct MeshImportArgs {
|
||||
std::filesystem::path filePath;
|
||||
std::string importPath;
|
||||
};
|
||||
class MeshLoader
|
||||
{
|
||||
public:
|
||||
class MeshLoader {
|
||||
public:
|
||||
MeshLoader(Gfx::PGraphics graphic);
|
||||
~MeshLoader();
|
||||
void importAsset(MeshImportArgs args);
|
||||
private:
|
||||
void loadTextures(const aiScene* scene, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PTextureAsset>& textures);
|
||||
void loadMaterials(const aiScene* scene, const Array<PTextureAsset>& textures, const std::string& baseName, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PMaterialInstanceAsset>& globalMaterials);
|
||||
void loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes, Component::Collider& collider);
|
||||
|
||||
private:
|
||||
void loadTextures(const aiScene* scene, const std::filesystem::path& meshDirectory, const std::string& importPath,
|
||||
Array<PTextureAsset>& textures);
|
||||
void loadMaterials(const aiScene* scene, const Array<PTextureAsset>& textures, const std::string& baseName,
|
||||
const std::filesystem::path& meshDirectory, const std::string& importPath,
|
||||
Array<PMaterialInstanceAsset>& globalMaterials);
|
||||
void loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes,
|
||||
Component::Collider& collider);
|
||||
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels);
|
||||
|
||||
void import(MeshImportArgs args, PMeshAsset meshAsset);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "TextureLoader.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Asset/TextureAsset.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Graphics/Vulkan/Enums.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
|
||||
@@ -17,28 +18,25 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
TextureLoader::TextureLoader(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
{
|
||||
TextureLoader::TextureLoader(Gfx::PGraphics graphics) : graphics(graphics) {
|
||||
OTextureAsset placeholder = new TextureAsset();
|
||||
placeholderAsset = placeholder;
|
||||
import(TextureImportArgs{
|
||||
.filePath = std::filesystem::absolute("textures/placeholder.png"),
|
||||
.importPath = "",
|
||||
}, placeholderAsset);
|
||||
import(
|
||||
TextureImportArgs{
|
||||
.filePath = std::filesystem::absolute("textures/placeholder.png"),
|
||||
.importPath = "",
|
||||
},
|
||||
placeholderAsset);
|
||||
AssetRegistry::get().assetRoot->textures[""] = std::move(placeholder);
|
||||
}
|
||||
|
||||
TextureLoader::~TextureLoader()
|
||||
{
|
||||
}
|
||||
TextureLoader::~TextureLoader() {}
|
||||
|
||||
void TextureLoader::importAsset(TextureImportArgs args)
|
||||
{
|
||||
void TextureLoader::importAsset(TextureImportArgs args) {
|
||||
std::string str = args.filePath.filename().string();
|
||||
auto pos = str.rfind(".");
|
||||
str.replace(str.begin() + pos, str.end(), "");
|
||||
|
||||
|
||||
OTextureAsset asset = new TextureAsset(args.importPath, str);
|
||||
PTextureAsset ref = asset;
|
||||
asset->setStatus(Asset::Status::Loading);
|
||||
@@ -46,25 +44,26 @@ void TextureLoader::importAsset(TextureImportArgs args)
|
||||
import(args, ref);
|
||||
}
|
||||
|
||||
PTextureAsset TextureLoader::getPlaceholderTexture()
|
||||
{
|
||||
return placeholderAsset;
|
||||
}
|
||||
PTextureAsset TextureLoader::getPlaceholderTexture() { return placeholderAsset; }
|
||||
|
||||
#define KTX_ASSERT(x) { auto error = x; if(error != KTX_SUCCESS) { std::cout << ktxErrorString(error) << std::endl; abort(); } }
|
||||
#define KTX_ASSERT(x) \
|
||||
{ \
|
||||
auto error = x; \
|
||||
if (error != KTX_SUCCESS) { \
|
||||
std::cout << ktxErrorString(error) << std::endl; \
|
||||
abort(); \
|
||||
} \
|
||||
}
|
||||
|
||||
void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset)
|
||||
{
|
||||
void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
|
||||
// manually transcode ktx textures using toktx
|
||||
if (args.filePath.extension().compare("ktx") != 0)
|
||||
{
|
||||
if (args.filePath.extension().compare("ktx") != 0) {
|
||||
auto ktxFile = args.filePath;
|
||||
ktxFile.replace_extension("ktx");
|
||||
std::stringstream ss;
|
||||
ss << "toktx --encode etc1s ";
|
||||
if (args.type == TextureImportType::TEXTURE_NORMAL)
|
||||
{
|
||||
//ss << "--normal_mode ";
|
||||
if (args.type == TextureImportType::TEXTURE_NORMAL) {
|
||||
// ss << "--normal_mode ";
|
||||
}
|
||||
ss << ktxFile << " " << args.filePath;
|
||||
system(ss.str().c_str());
|
||||
@@ -72,31 +71,30 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset)
|
||||
}
|
||||
|
||||
ktxTexture2* ktxHandle;
|
||||
KTX_ASSERT(ktxTexture_CreateFromNamedFile(args.filePath.string().c_str(), 0, (ktxTexture**) & ktxHandle));
|
||||
KTX_ASSERT(ktxTexture_CreateFromNamedFile(args.filePath.string().c_str(), 0, (ktxTexture**)&ktxHandle));
|
||||
|
||||
|
||||
//int totalWidth = 0, totalHeight = 0, n = 0;
|
||||
//unsigned char* data = stbi_load(args.filePath.string().c_str(), &totalWidth, &totalHeight, &n, 4);
|
||||
//ktxTexture2* kTexture = nullptr;
|
||||
//VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||
//ktxTextureCreateInfo createInfo = {
|
||||
// .vkFormat = (uint32)format,
|
||||
// .baseDepth = 1,
|
||||
// .numLevels = 1,
|
||||
// .numLayers = 1,
|
||||
// .isArray = false,
|
||||
// .generateMipmaps = false,
|
||||
//};
|
||||
// int totalWidth = 0, totalHeight = 0, n = 0;
|
||||
// unsigned char* data = stbi_load(args.filePath.string().c_str(), &totalWidth, &totalHeight, &n, 4);
|
||||
// ktxTexture2* kTexture = nullptr;
|
||||
// VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||
// ktxTextureCreateInfo createInfo = {
|
||||
// .vkFormat = (uint32)format,
|
||||
// .baseDepth = 1,
|
||||
// .numLevels = 1,
|
||||
// .numLayers = 1,
|
||||
// .isArray = false,
|
||||
// .generateMipmaps = false,
|
||||
// };
|
||||
//
|
||||
//if (args.type == TextureImportType::TEXTURE_CUBEMAP)
|
||||
// if (args.type == TextureImportType::TEXTURE_CUBEMAP)
|
||||
//{
|
||||
// uint32 faceWidth = totalWidth / 4;
|
||||
// // uint32 faceHeight = totalHeight / 3;
|
||||
// // Cube map
|
||||
// createInfo.baseWidth = totalWidth / 4;
|
||||
// createInfo.baseHeight = totalHeight / 3;
|
||||
// createInfo.numFaces = 6;
|
||||
// createInfo.numDimensions = 2;
|
||||
// uint32 faceWidth = totalWidth / 4;
|
||||
// // uint32 faceHeight = totalHeight / 3;
|
||||
// // Cube map
|
||||
// createInfo.baseWidth = totalWidth / 4;
|
||||
// createInfo.baseHeight = totalHeight / 3;
|
||||
// createInfo.numFaces = 6;
|
||||
// createInfo.numDimensions = 2;
|
||||
|
||||
// KTX_ASSERT(ktxTexture2_Create(&createInfo,
|
||||
// KTX_TEXTURE_CREATE_ALLOC_STORAGE,
|
||||
@@ -124,7 +122,7 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset)
|
||||
// loadCubeFace(1, 1, 4); // +Z
|
||||
// loadCubeFace(3, 1, 5); // -Z
|
||||
//}
|
||||
//else
|
||||
// else
|
||||
//{
|
||||
// createInfo.baseWidth = totalWidth;
|
||||
// createInfo.baseHeight = totalHeight;
|
||||
@@ -138,34 +136,33 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset)
|
||||
// ktxTexture_SetImageFromMemory(ktxTexture(kTexture),
|
||||
// 0, 0, 0, data, totalWidth * totalHeight * n * sizeof(unsigned char));
|
||||
//}
|
||||
//ktxTexture_WriteToNamedFile(ktxTexture(kTexture), args.filePath.replace_extension(".ktx").string().c_str());
|
||||
// ktxTexture_WriteToNamedFile(ktxTexture(kTexture), args.filePath.replace_extension(".ktx").string().c_str());
|
||||
|
||||
//ktxBasisParams basisParams = {
|
||||
// .structSize = sizeof(ktxBasisParams),
|
||||
// .uastc = true,
|
||||
// .threadCount = std::thread::hardware_concurrency(),
|
||||
// .normalMap = normalMap,
|
||||
// .uastcFlags = KTX_PACK_UASTC_LEVEL_VERYSLOW,
|
||||
// .uastcRDO = true,
|
||||
// .uastcRDOQualityScalar = 1,
|
||||
//};
|
||||
//KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams));
|
||||
//KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 3));
|
||||
// ktxBasisParams basisParams = {
|
||||
// .structSize = sizeof(ktxBasisParams),
|
||||
// .uastc = true,
|
||||
// .threadCount = std::thread::hardware_concurrency(),
|
||||
// .normalMap = normalMap,
|
||||
// .uastcFlags = KTX_PACK_UASTC_LEVEL_VERYSLOW,
|
||||
// .uastcRDO = true,
|
||||
// .uastcRDOQualityScalar = 1,
|
||||
// };
|
||||
// KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams));
|
||||
// KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 3));
|
||||
|
||||
//char writer[100];
|
||||
//snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1");
|
||||
//ktxHashList_AddKVPair(&kTexture->kvDataHead, KTX_WRITER_KEY,
|
||||
// (ktx_uint32_t)strlen(writer) + 1,
|
||||
// writer);
|
||||
// char writer[100];
|
||||
// snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1");
|
||||
// ktxHashList_AddKVPair(&kTexture->kvDataHead, KTX_WRITER_KEY,
|
||||
// (ktx_uint32_t)strlen(writer) + 1,
|
||||
// writer);
|
||||
|
||||
//uint8* texData;
|
||||
//size_t texSize;
|
||||
//KTX_ASSERT(ktxTexture_WriteToMemory(ktxTexture(kTexture), &texData, &texSize));
|
||||
// uint8* texData;
|
||||
// size_t texSize;
|
||||
// KTX_ASSERT(ktxTexture_WriteToMemory(ktxTexture(kTexture), &texData, &texSize));
|
||||
//
|
||||
//stbi_image_free(data);
|
||||
// stbi_image_free(data);
|
||||
|
||||
if (textureAsset->getName().empty())
|
||||
{
|
||||
if (textureAsset->getName().empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,34 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Containers/List.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include <filesystem>
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_REF(TextureAsset)
|
||||
DECLARE_NAME_REF(Gfx, Graphics)
|
||||
DECLARE_NAME_REF(Gfx, Texture2D)
|
||||
enum class TextureImportType
|
||||
{
|
||||
enum class TextureImportType {
|
||||
TEXTURE_2D,
|
||||
TEXTURE_NORMAL,
|
||||
TEXTURE_CUBEMAP,
|
||||
};
|
||||
struct TextureImportArgs
|
||||
{
|
||||
struct TextureImportArgs {
|
||||
std::filesystem::path filePath;
|
||||
std::string importPath;
|
||||
TextureImportType type = TextureImportType::TEXTURE_2D;
|
||||
Gfx::SeImageUsageFlagBits usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT;
|
||||
uint32 numChannels = 4;
|
||||
};
|
||||
class TextureLoader
|
||||
{
|
||||
public:
|
||||
class TextureLoader {
|
||||
public:
|
||||
TextureLoader(Gfx::PGraphics graphic);
|
||||
~TextureLoader();
|
||||
void importAsset(TextureImportArgs args);
|
||||
PTextureAsset getPlaceholderTexture();
|
||||
private:
|
||||
|
||||
private:
|
||||
void import(TextureImportArgs args, PTextureAsset asset);
|
||||
Gfx::PGraphics graphics;
|
||||
PTextureAsset placeholderAsset;
|
||||
|
||||
@@ -1,74 +1,49 @@
|
||||
#include "InspectorView.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Actor/Actor.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Asset/FontLoader.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "UI/System.h"
|
||||
#include "Window/Window.h"
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Editor;
|
||||
|
||||
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo)
|
||||
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo)
|
||||
: View(graphics, std::move(window), std::move(createInfo), "InspectorView")
|
||||
//, renderGraph(RenderGraphBuilder::build(
|
||||
// UIPass(graphics),
|
||||
// TextPass(graphics)
|
||||
//))
|
||||
, uiSystem(new UI::System())
|
||||
{
|
||||
//renderGraph.updateViewport(viewport);
|
||||
//, renderGraph(RenderGraphBuilder::build(
|
||||
// UIPass(graphics),
|
||||
// TextPass(graphics)
|
||||
//))
|
||||
,
|
||||
uiSystem(new UI::System()) {
|
||||
// renderGraph.updateViewport(viewport);
|
||||
uiSystem->updateViewport(viewport);
|
||||
}
|
||||
|
||||
InspectorView::~InspectorView()
|
||||
{
|
||||
InspectorView::~InspectorView() {}
|
||||
|
||||
void InspectorView::beginUpdate() {
|
||||
// co_return;
|
||||
}
|
||||
|
||||
void InspectorView::beginUpdate()
|
||||
{
|
||||
//co_return;
|
||||
void InspectorView::update() {
|
||||
// co_return;
|
||||
}
|
||||
|
||||
void InspectorView::update()
|
||||
{
|
||||
//co_return;
|
||||
}
|
||||
void InspectorView::commitUpdate() {}
|
||||
|
||||
void InspectorView::commitUpdate()
|
||||
{
|
||||
}
|
||||
void InspectorView::prepareRender() {}
|
||||
|
||||
void InspectorView::prepareRender()
|
||||
{
|
||||
|
||||
}
|
||||
void InspectorView::render() {}
|
||||
|
||||
void InspectorView::render()
|
||||
{
|
||||
}
|
||||
void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier) {}
|
||||
|
||||
void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier)
|
||||
{
|
||||
|
||||
}
|
||||
void InspectorView::mouseMoveCallback(double, double) {}
|
||||
|
||||
void InspectorView::mouseMoveCallback(double, double)
|
||||
{
|
||||
|
||||
}
|
||||
void InspectorView::mouseButtonCallback(MouseButton, InputAction, KeyModifier) {}
|
||||
|
||||
void InspectorView::mouseButtonCallback(MouseButton, InputAction, KeyModifier)
|
||||
{
|
||||
|
||||
}
|
||||
void InspectorView::scrollCallback(double, double) {}
|
||||
|
||||
void InspectorView::scrollCallback(double, double)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InspectorView::fileCallback(int, const char**)
|
||||
{
|
||||
|
||||
}
|
||||
void InspectorView::fileCallback(int, const char**) {}
|
||||
|
||||
@@ -1,38 +1,36 @@
|
||||
#pragma once
|
||||
#include "Window/View.h"
|
||||
#include "Graphics/RenderPass/RenderGraph.h"
|
||||
#include "Graphics/RenderPass/UIPass.h"
|
||||
#include "Graphics/RenderPass/TextPass.h"
|
||||
#include "Graphics/RenderPass/UIPass.h"
|
||||
#include "UI/Elements/Panel.h"
|
||||
#include "Window/View.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_REF(Actor)
|
||||
namespace Editor
|
||||
{
|
||||
class InspectorView : public View
|
||||
{
|
||||
public:
|
||||
InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
|
||||
namespace Editor {
|
||||
class InspectorView : public View {
|
||||
public:
|
||||
InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo);
|
||||
virtual ~InspectorView();
|
||||
|
||||
virtual void beginUpdate() override;
|
||||
virtual void update() override;
|
||||
virtual void commitUpdate() override;
|
||||
|
||||
virtual void update() override;
|
||||
virtual void commitUpdate() override;
|
||||
|
||||
virtual void prepareRender() override;
|
||||
virtual void render() override;
|
||||
void selectActor();
|
||||
protected:
|
||||
|
||||
protected:
|
||||
UI::PSystem uiSystem;
|
||||
PActor selectedActor;
|
||||
|
||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) override;
|
||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
||||
virtual void fileCallback(int count, const char** paths) override;
|
||||
|
||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) override;
|
||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
||||
virtual void fileCallback(int count, const char** paths) override;
|
||||
};
|
||||
DEFINE_REF(InspectorView)
|
||||
} // namespace Editor
|
||||
|
||||
@@ -5,35 +5,16 @@ using namespace Seele;
|
||||
using namespace Seele::Editor;
|
||||
|
||||
PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath)
|
||||
: GameView(graphics, window, createInfo, dllPath)
|
||||
{
|
||||
}
|
||||
: GameView(graphics, window, createInfo, dllPath) {}
|
||||
|
||||
PlayView::~PlayView()
|
||||
{
|
||||
}
|
||||
PlayView::~PlayView() {}
|
||||
|
||||
void PlayView::beginUpdate()
|
||||
{
|
||||
GameView::beginUpdate();
|
||||
}
|
||||
void PlayView::beginUpdate() { GameView::beginUpdate(); }
|
||||
|
||||
void PlayView::update()
|
||||
{
|
||||
GameView::update();
|
||||
}
|
||||
void PlayView::update() { GameView::update(); }
|
||||
|
||||
void PlayView::commitUpdate()
|
||||
{
|
||||
GameView::commitUpdate();
|
||||
}
|
||||
void PlayView::commitUpdate() { GameView::commitUpdate(); }
|
||||
|
||||
void PlayView::prepareRender()
|
||||
{
|
||||
GameView::prepareRender();
|
||||
}
|
||||
void PlayView::prepareRender() { GameView::prepareRender(); }
|
||||
|
||||
void PlayView::render()
|
||||
{
|
||||
GameView::render();
|
||||
}
|
||||
void PlayView::render() { GameView::render(); }
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
#pragma once
|
||||
#include "Window/GameView.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Editor
|
||||
{
|
||||
class PlayView : public GameView
|
||||
{
|
||||
public:
|
||||
namespace Seele {
|
||||
namespace Editor {
|
||||
class PlayView : public GameView {
|
||||
public:
|
||||
PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath);
|
||||
virtual ~PlayView();
|
||||
virtual void beginUpdate() override;
|
||||
virtual void update() override;
|
||||
virtual void commitUpdate() override;
|
||||
virtual void beginUpdate() override;
|
||||
virtual void update() override;
|
||||
virtual void commitUpdate() override;
|
||||
|
||||
virtual void prepareRender() override;
|
||||
virtual void render() override;
|
||||
private:
|
||||
virtual void prepareRender() override;
|
||||
virtual void render() override;
|
||||
|
||||
private:
|
||||
};
|
||||
DECLARE_REF(PlayView)
|
||||
} // namespace Editor
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
#include "SceneView.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Window/Window.h"
|
||||
#include "Graphics/Mesh.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Asset/MeshAsset.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Actor/CameraActor.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Asset/MeshAsset.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Component/Mesh.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Mesh.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Window/Window.h"
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Editor;
|
||||
|
||||
SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo)
|
||||
: View(graphics, owner, createInfo, "SceneView")
|
||||
, scene(new Scene(graphics))
|
||||
, cameraSystem(createInfo.dimensions, Vector(0, 0, 10))
|
||||
{
|
||||
SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo& createInfo)
|
||||
: View(graphics, owner, createInfo, "SceneView"), scene(new Scene(graphics)), cameraSystem(createInfo.dimensions, Vector(0, 0, 10)) {
|
||||
cameraSystem.update(viewportCamera, static_cast<float>(Gfx::getCurrentFrameDelta()));
|
||||
renderGraph.addPass(new DepthPrepass(graphics, scene));
|
||||
renderGraph.addPass(new LightCullingPass(graphics, scene));
|
||||
@@ -25,54 +23,31 @@ SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreat
|
||||
renderGraph.createRenderPass();
|
||||
}
|
||||
|
||||
SceneView::~SceneView()
|
||||
{
|
||||
SceneView::~SceneView() {}
|
||||
|
||||
void SceneView::beginUpdate() {
|
||||
// co_return;
|
||||
}
|
||||
|
||||
void SceneView::beginUpdate()
|
||||
{
|
||||
//co_return;
|
||||
}
|
||||
|
||||
void SceneView::update()
|
||||
{
|
||||
void SceneView::update() {
|
||||
cameraSystem.update(viewportCamera, static_cast<float>(Gfx::getCurrentFrameDelta()));
|
||||
//co_return;
|
||||
// co_return;
|
||||
}
|
||||
|
||||
void SceneView::commitUpdate()
|
||||
{
|
||||
}
|
||||
void SceneView::commitUpdate() {}
|
||||
|
||||
void SceneView::prepareRender()
|
||||
{
|
||||
}
|
||||
void SceneView::prepareRender() {}
|
||||
|
||||
void SceneView::render()
|
||||
{
|
||||
renderGraph.render(viewportCamera);
|
||||
}
|
||||
void SceneView::render() { renderGraph.render(viewportCamera); }
|
||||
|
||||
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier)
|
||||
{
|
||||
cameraSystem.keyCallback(code, action);
|
||||
}
|
||||
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier) { cameraSystem.keyCallback(code, action); }
|
||||
|
||||
void SceneView::mouseMoveCallback(double xPos, double yPos)
|
||||
{
|
||||
cameraSystem.mouseMoveCallback(xPos, yPos);
|
||||
}
|
||||
void SceneView::mouseMoveCallback(double xPos, double yPos) { cameraSystem.mouseMoveCallback(xPos, yPos); }
|
||||
|
||||
void SceneView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier)
|
||||
{
|
||||
void SceneView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier) {
|
||||
cameraSystem.mouseButtonCallback(button, action);
|
||||
}
|
||||
|
||||
void SceneView::scrollCallback(double, double)
|
||||
{
|
||||
}
|
||||
void SceneView::scrollCallback(double, double) {}
|
||||
|
||||
void SceneView::fileCallback(int, const char**)
|
||||
{
|
||||
|
||||
}
|
||||
void SceneView::fileCallback(int, const char**) {}
|
||||
|
||||
@@ -1,43 +1,42 @@
|
||||
#pragma once
|
||||
#include "ThreadPool.h"
|
||||
#include "Window/View.h"
|
||||
#include "Graphics/RenderPass/BasePass.h"
|
||||
#include "Graphics/RenderPass/DepthPrepass.h"
|
||||
#include "Graphics/RenderPass/LightCullingPass.h"
|
||||
#include "Graphics/RenderPass/BasePass.h"
|
||||
#include "ThreadPool.h"
|
||||
#include "ViewportControl.h"
|
||||
#include "Window/View.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_REF(Scene)
|
||||
namespace Editor
|
||||
{
|
||||
class SceneView : public View
|
||||
{
|
||||
public:
|
||||
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo);
|
||||
~SceneView();
|
||||
namespace Editor {
|
||||
class SceneView : public View {
|
||||
public:
|
||||
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo& createInfo);
|
||||
~SceneView();
|
||||
|
||||
virtual void beginUpdate() override;
|
||||
virtual void update() override;
|
||||
virtual void commitUpdate() override;
|
||||
virtual void beginUpdate() override;
|
||||
virtual void update() override;
|
||||
virtual void commitUpdate() override;
|
||||
|
||||
virtual void prepareRender() override;
|
||||
virtual void render() override;
|
||||
virtual void prepareRender() override;
|
||||
virtual void render() override;
|
||||
|
||||
PScene getScene() const { return scene; }
|
||||
private:
|
||||
OScene scene;
|
||||
Component::Camera viewportCamera;
|
||||
|
||||
RenderGraph renderGraph;
|
||||
PScene getScene() const { return scene; }
|
||||
|
||||
ViewportControl cameraSystem;
|
||||
private:
|
||||
OScene scene;
|
||||
Component::Camera viewportCamera;
|
||||
|
||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) override;
|
||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
||||
virtual void fileCallback(int count, const char** paths) override;
|
||||
RenderGraph renderGraph;
|
||||
|
||||
ViewportControl cameraSystem;
|
||||
|
||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) override;
|
||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
||||
virtual void fileCallback(int count, const char** paths) override;
|
||||
};
|
||||
DEFINE_REF(SceneView)
|
||||
} // namespace Editor
|
||||
|
||||
@@ -6,81 +6,56 @@ using namespace Seele;
|
||||
using namespace Seele::Editor;
|
||||
|
||||
ViewportControl::ViewportControl(const URect& viewportDimensions, Vector initialPos)
|
||||
: position(initialPos)
|
||||
, fieldOfView(glm::radians(70.f))
|
||||
, aspectRatio(static_cast<float>(viewportDimensions.size.x) / viewportDimensions.size.y)
|
||||
, pitch(0)
|
||||
, yaw(glm::pi<float>()/-2.0f)
|
||||
{
|
||||
: position(initialPos), fieldOfView(glm::radians(70.f)),
|
||||
aspectRatio(static_cast<float>(viewportDimensions.size.x) / viewportDimensions.size.y), pitch(0), yaw(glm::pi<float>() / -2.0f) {
|
||||
std::cout << yaw << " " << pitch << std::endl;
|
||||
}
|
||||
|
||||
ViewportControl::~ViewportControl()
|
||||
{
|
||||
|
||||
}
|
||||
ViewportControl::~ViewportControl() {}
|
||||
|
||||
void ViewportControl::update(Component::Camera& camera, float deltaTime)
|
||||
{
|
||||
void ViewportControl::update(Component::Camera& camera, float deltaTime) {
|
||||
float cameraMove = deltaTime * 20;
|
||||
if(keys[KeyCode::KEY_LEFT_SHIFT])
|
||||
{
|
||||
if (keys[KeyCode::KEY_LEFT_SHIFT]) {
|
||||
cameraMove *= 4;
|
||||
}
|
||||
Vector moveVector = Vector();
|
||||
Vector forward = glm::normalize(springArm);
|
||||
Vector side = glm::cross(Vector(0, 1, 0), forward);
|
||||
if(keys[KeyCode::KEY_W])
|
||||
{
|
||||
if (keys[KeyCode::KEY_W]) {
|
||||
moveVector += forward * cameraMove;
|
||||
}
|
||||
if(keys[KeyCode::KEY_S])
|
||||
{
|
||||
if (keys[KeyCode::KEY_S]) {
|
||||
moveVector += forward * -cameraMove;
|
||||
}
|
||||
if(keys[KeyCode::KEY_A])
|
||||
{
|
||||
if (keys[KeyCode::KEY_A]) {
|
||||
moveVector += side * cameraMove;
|
||||
}
|
||||
if(keys[KeyCode::KEY_D])
|
||||
{
|
||||
if (keys[KeyCode::KEY_D]) {
|
||||
moveVector += side * -cameraMove;
|
||||
}
|
||||
if(keys[KeyCode::KEY_E])
|
||||
{
|
||||
if (keys[KeyCode::KEY_E]) {
|
||||
moveVector += glm::vec3(0, cameraMove, 0);
|
||||
}
|
||||
if(keys[KeyCode::KEY_Q])
|
||||
{
|
||||
}
|
||||
if (keys[KeyCode::KEY_Q]) {
|
||||
moveVector += glm::vec3(0, -cameraMove, 0);
|
||||
}
|
||||
throw std::logic_error("Not implemented");
|
||||
}
|
||||
|
||||
void ViewportControl::keyCallback(KeyCode key, InputAction action)
|
||||
{
|
||||
keys[static_cast<size_t>(key)] = action != InputAction::RELEASE;
|
||||
}
|
||||
void ViewportControl::keyCallback(KeyCode key, InputAction action) { keys[static_cast<size_t>(key)] = action != InputAction::RELEASE; }
|
||||
|
||||
void ViewportControl::mouseMoveCallback(double xPos, double yPos)
|
||||
{
|
||||
void ViewportControl::mouseMoveCallback(double xPos, double yPos) {
|
||||
mouseX = static_cast<float>(xPos);
|
||||
mouseY = static_cast<float>(yPos);
|
||||
}
|
||||
|
||||
void ViewportControl::mouseButtonCallback(MouseButton button, InputAction action)
|
||||
{
|
||||
if(button == MouseButton::MOUSE_BUTTON_1)
|
||||
{
|
||||
void ViewportControl::mouseButtonCallback(MouseButton button, InputAction action) {
|
||||
if (button == MouseButton::MOUSE_BUTTON_1) {
|
||||
mouse1 = action != InputAction::RELEASE;
|
||||
}
|
||||
if(button == MouseButton::MOUSE_BUTTON_2)
|
||||
{
|
||||
if (button == MouseButton::MOUSE_BUTTON_2) {
|
||||
mouse2 = action != InputAction::RELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportControl::viewportResize(URect dimensions)
|
||||
{
|
||||
aspectRatio = static_cast<float>(dimensions.size.x) / dimensions.size.y;
|
||||
}
|
||||
void ViewportControl::viewportResize(URect dimensions) { aspectRatio = static_cast<float>(dimensions.size.x) / dimensions.size.y; }
|
||||
|
||||
@@ -1,37 +1,36 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Math/Math.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Containers/Array.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Math/Math.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "MinimalEngine.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Editor
|
||||
{
|
||||
class ViewportControl
|
||||
{
|
||||
public:
|
||||
ViewportControl(const URect& viewportDimensions, Vector initialPos /*TODO: configurable initial rotations*/);
|
||||
~ViewportControl();
|
||||
void update(Component::Camera& camera, float deltaTime);
|
||||
void keyCallback(KeyCode key, InputAction action);
|
||||
void mouseMoveCallback(double xPos, double yPos);
|
||||
void mouseButtonCallback(MouseButton button, InputAction action);
|
||||
void viewportResize(URect dimensions);
|
||||
private:
|
||||
Vector position;
|
||||
Vector springArm;
|
||||
float fieldOfView;
|
||||
float aspectRatio;
|
||||
StaticArray<bool, static_cast<size_t>(KeyCode::KEY_LAST)> keys;
|
||||
bool mouse1 = false;
|
||||
bool mouse2 = false;
|
||||
float mouseX;
|
||||
float mouseY;
|
||||
float pitch;
|
||||
float yaw;
|
||||
};
|
||||
|
||||
namespace Seele {
|
||||
namespace Editor {
|
||||
class ViewportControl {
|
||||
public:
|
||||
ViewportControl(const URect& viewportDimensions, Vector initialPos /*TODO: configurable initial rotations*/);
|
||||
~ViewportControl();
|
||||
void update(Component::Camera& camera, float deltaTime);
|
||||
void keyCallback(KeyCode key, InputAction action);
|
||||
void mouseMoveCallback(double xPos, double yPos);
|
||||
void mouseButtonCallback(MouseButton button, InputAction action);
|
||||
void viewportResize(URect dimensions);
|
||||
|
||||
private:
|
||||
Vector position;
|
||||
Vector springArm;
|
||||
float fieldOfView;
|
||||
float aspectRatio;
|
||||
StaticArray<bool, static_cast<size_t>(KeyCode::KEY_LAST)> keys;
|
||||
bool mouse1 = false;
|
||||
bool mouse2 = false;
|
||||
float mouseX;
|
||||
float mouseY;
|
||||
float pitch;
|
||||
float yaw;
|
||||
};
|
||||
} // namespace Editor
|
||||
} // namespace Seele
|
||||
|
||||
+71
-73
@@ -25,88 +25,86 @@ static Gfx::OGraphics graphics;
|
||||
int main() {
|
||||
std::string gameName = "MeshShadingDemo";
|
||||
#ifdef WIN32
|
||||
std::filesystem::path outputPath = "C:/Users/Dynamitos/MeshShadingDemoGame";
|
||||
std::filesystem::path sourcePath = "C:/Users/Dynamitos/MeshShadingDemo";
|
||||
std::filesystem::path binaryPath = sourcePath / "bin" / "MeshShadingDemo.dll";
|
||||
std::filesystem::path outputPath = "C:/Users/Dynamitos/MeshShadingDemoGame";
|
||||
std::filesystem::path sourcePath = "C:/Users/Dynamitos/MeshShadingDemo";
|
||||
std::filesystem::path binaryPath = sourcePath / "bin" / "MeshShadingDemo.dll";
|
||||
#elif __APPLE__
|
||||
std::filesystem::path outputPath = "/Users/dynamitos/MeshShadingDemoGame";
|
||||
std::filesystem::path sourcePath = "/Users/dynamitos/MeshShadingDemo";
|
||||
std::filesystem::path binaryPath = sourcePath / "cmake" / "libMeshShadingDemo.dylib";
|
||||
std::filesystem::path outputPath = "/Users/dynamitos/MeshShadingDemoGame";
|
||||
std::filesystem::path sourcePath = "/Users/dynamitos/MeshShadingDemo";
|
||||
std::filesystem::path binaryPath = sourcePath / "cmake" / "libMeshShadingDemo.dylib";
|
||||
#else
|
||||
std::filesystem::path outputPath = "/home/dynamitos/MeshShadingDemoGame";
|
||||
std::filesystem::path sourcePath = "/home/dynamitos/MeshShadingDemo";
|
||||
std::filesystem::path binaryPath = sourcePath / "cmake" / "libMeshShadingDemo.so";
|
||||
std::filesystem::path outputPath = "/home/dynamitos/MeshShadingDemoGame";
|
||||
std::filesystem::path sourcePath = "/home/dynamitos/MeshShadingDemo";
|
||||
std::filesystem::path binaryPath = sourcePath / "cmake" / "libMeshShadingDemo.so";
|
||||
#endif
|
||||
std::filesystem::path cmakePath = outputPath / "cmake";
|
||||
std::filesystem::path cmakePath = outputPath / "cmake";
|
||||
|
||||
#ifdef __APPLE__
|
||||
graphics = new Metal::Graphics();
|
||||
graphics = new Metal::Graphics();
|
||||
#else
|
||||
graphics = new Vulkan::Graphics();
|
||||
graphics = new Vulkan::Graphics();
|
||||
#endif
|
||||
GraphicsInitializer initializer;
|
||||
graphics->init(initializer);
|
||||
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
|
||||
vd->init(graphics);
|
||||
GraphicsInitializer initializer;
|
||||
graphics->init(initializer);
|
||||
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
|
||||
vd->init(graphics);
|
||||
|
||||
OWindowManager windowManager = new WindowManager();
|
||||
AssetRegistry::init(sourcePath / "Assets", graphics);
|
||||
AssetImporter::init(graphics);
|
||||
AssetImporter::importFont(FontImportArgs{
|
||||
.filePath = "./fonts/Calibri.ttf",
|
||||
});
|
||||
AssetImporter::importMesh(MeshImportArgs{
|
||||
.filePath = sourcePath / "import/models/cube.fbx",
|
||||
});
|
||||
//AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/greek-temple/source/greek-temple.fbx",
|
||||
// .importPath = "temple"
|
||||
// });
|
||||
AssetImporter::importMesh(MeshImportArgs{
|
||||
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.fbx",
|
||||
.importPath = "Whitechapel"
|
||||
});
|
||||
//AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/nitra-castle-rawscan/source/Nitriansky.obj",
|
||||
// .importPath = "Nitriansky"
|
||||
// });
|
||||
WindowCreateInfo mainWindowInfo;
|
||||
mainWindowInfo.title = "SeeleEngine";
|
||||
mainWindowInfo.width = 1920;
|
||||
mainWindowInfo.height = 1080;
|
||||
mainWindowInfo.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB;
|
||||
auto window = windowManager->addWindow(graphics, mainWindowInfo);
|
||||
ViewportCreateInfo sceneViewInfo;
|
||||
sceneViewInfo.dimensions.size.x = 1920;
|
||||
sceneViewInfo.dimensions.size.y = 1080;
|
||||
sceneViewInfo.dimensions.offset.x = 0;
|
||||
sceneViewInfo.dimensions.offset.y = 0;
|
||||
sceneViewInfo.numSamples = Gfx::SE_SAMPLE_COUNT_1_BIT;
|
||||
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
|
||||
sceneView->setFocused();
|
||||
OWindowManager windowManager = new WindowManager();
|
||||
AssetRegistry::init(sourcePath / "Assets", graphics);
|
||||
AssetImporter::init(graphics);
|
||||
AssetImporter::importFont(FontImportArgs{
|
||||
.filePath = "./fonts/Calibri.ttf",
|
||||
});
|
||||
AssetImporter::importMesh(MeshImportArgs{
|
||||
.filePath = sourcePath / "import/models/cube.fbx",
|
||||
});
|
||||
// AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/greek-temple/source/greek-temple.fbx",
|
||||
// .importPath = "temple"
|
||||
// });
|
||||
AssetImporter::importMesh(MeshImportArgs{.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.fbx",
|
||||
.importPath = "Whitechapel"});
|
||||
// AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/nitra-castle-rawscan/source/Nitriansky.obj",
|
||||
// .importPath = "Nitriansky"
|
||||
// });
|
||||
WindowCreateInfo mainWindowInfo;
|
||||
mainWindowInfo.title = "SeeleEngine";
|
||||
mainWindowInfo.width = 1920;
|
||||
mainWindowInfo.height = 1080;
|
||||
mainWindowInfo.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB;
|
||||
auto window = windowManager->addWindow(graphics, mainWindowInfo);
|
||||
ViewportCreateInfo sceneViewInfo;
|
||||
sceneViewInfo.dimensions.size.x = 1920;
|
||||
sceneViewInfo.dimensions.size.y = 1080;
|
||||
sceneViewInfo.dimensions.offset.x = 0;
|
||||
sceneViewInfo.dimensions.offset.y = 0;
|
||||
sceneViewInfo.numSamples = Gfx::SE_SAMPLE_COUNT_1_BIT;
|
||||
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
|
||||
sceneView->setFocused();
|
||||
|
||||
while (windowManager->isActive()) {
|
||||
windowManager->render();
|
||||
}
|
||||
vd->destroy();
|
||||
// export game
|
||||
if (false) {
|
||||
std::filesystem::create_directories(outputPath);
|
||||
std::system(fmt::format("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" "
|
||||
"-DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake",
|
||||
gameName, outputPath.generic_string(), binaryPath.generic_string())
|
||||
.c_str());
|
||||
std::system(fmt::format("cmake -S {} -B {}", cmakePath.generic_string(), cmakePath.generic_string()).c_str());
|
||||
std::system(fmt::format("cmake --build {}", cmakePath.generic_string()).c_str());
|
||||
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);
|
||||
while (windowManager->isActive()) {
|
||||
windowManager->render();
|
||||
}
|
||||
vd->destroy();
|
||||
// export game
|
||||
if (false) {
|
||||
std::filesystem::create_directories(outputPath);
|
||||
std::system(fmt::format("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" "
|
||||
"-DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake",
|
||||
gameName, outputPath.generic_string(), binaryPath.generic_string())
|
||||
.c_str());
|
||||
std::system(fmt::format("cmake -S {} -B {}", cmakePath.generic_string(), cmakePath.generic_string()).c_str());
|
||||
std::system(fmt::format("cmake --build {}", cmakePath.generic_string()).c_str());
|
||||
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);
|
||||
#ifdef WIN32
|
||||
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");
|
||||
std::filesystem::copy_file("slang-llvm.dll", outputPath / "slang-llvm.dll");
|
||||
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");
|
||||
std::filesystem::copy_file("slang-llvm.dll", outputPath / "slang-llvm.dll");
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user