Fixing mesh import
This commit is contained in:
@@ -50,6 +50,7 @@ find_package(Ktx CONFIG REQUIRED)
|
||||
find_package(nlohmann_json CONFIG REQUIRED)
|
||||
find_package(fmt CONFIG REQUIRED)
|
||||
find_package(VulkanMemoryAllocator CONFIG REQUIRED)
|
||||
find_package(OpenMP REQUIRED)
|
||||
|
||||
if(UNIX)
|
||||
find_package(Threads REQUIRED)
|
||||
@@ -75,6 +76,7 @@ target_link_libraries(Engine PUBLIC crcpp)
|
||||
target_link_libraries(Engine PUBLIC fmt::fmt)
|
||||
target_link_libraries(Engine PUBLIC GPUOpen::VulkanMemoryAllocator)
|
||||
target_link_libraries(Engine PUBLIC slang)
|
||||
target_link_libraries(Engine PUBLIC OpenMP::OpenMP_CXX)
|
||||
if(APPLE)
|
||||
target_link_libraries(Engine PUBLIC metal)
|
||||
SET(CMAKE_OSX_DEPLOYMENT_TARGET 14.3)
|
||||
|
||||
@@ -41,5 +41,6 @@ struct Scene
|
||||
StructuredBuffer<uint8_t> primitiveIndices;
|
||||
StructuredBuffer<uint32_t> vertexIndices;
|
||||
};
|
||||
layout(set=1)
|
||||
ParameterBlock<Scene> pScene;
|
||||
|
||||
|
||||
@@ -11,4 +11,5 @@ interface IVertexData
|
||||
VertexAttributes getAttributes(uint index);
|
||||
};
|
||||
|
||||
uniform ParameterBlock<IVertexData> pVertexData;
|
||||
layout(set=2)
|
||||
ParameterBlock<IVertexData> pVertexData;
|
||||
@@ -243,8 +243,8 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
Array<Vector> colors(mesh->mNumVertices);
|
||||
|
||||
StaticMeshVertexData* vertexData = StaticMeshVertexData::getInstance();
|
||||
|
||||
for (uint32 i = 0; i < mesh->mNumVertices; ++i)
|
||||
#pragma omp parallel for
|
||||
for (int32 i = 0; i < mesh->mNumVertices; ++i)
|
||||
{
|
||||
positions[i] = Vector(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
|
||||
if (mesh->HasTextureCoords(0))
|
||||
@@ -275,7 +275,6 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
colors[i] = Vector(1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
MeshId id = vertexData->allocateVertexData(mesh->mNumVertices);
|
||||
vertexData->loadPositions(id, positions);
|
||||
vertexData->loadTexCoords(id, texCoords);
|
||||
@@ -285,7 +284,8 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
vertexData->loadColors(id, colors);
|
||||
|
||||
Array<uint32> indices(mesh->mNumFaces * 3);
|
||||
for (size_t faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex)
|
||||
#pragma omp parallel for
|
||||
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];
|
||||
@@ -349,6 +349,27 @@ void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path&
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Matrix4 convertMatrix(aiMatrix4x4 matrix)
|
||||
{
|
||||
return Matrix4(
|
||||
matrix.a1, matrix.a2, matrix.a3, matrix.a4,
|
||||
matrix.b1, matrix.b2, matrix.b3, matrix.b4,
|
||||
matrix.c1, matrix.c2, matrix.c3, matrix.c4,
|
||||
matrix.d1, matrix.d2, matrix.d3, matrix.d4
|
||||
);
|
||||
}
|
||||
|
||||
Matrix4 MeshLoader::loadNodeTransform(aiNode* node)
|
||||
{
|
||||
Matrix4 parent = Matrix4(1);
|
||||
if (node->mParent != nullptr)
|
||||
{
|
||||
parent = loadNodeTransform(node->mParent);
|
||||
}
|
||||
return parent * convertMatrix(node->mTransformation);
|
||||
}
|
||||
|
||||
void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset)
|
||||
{
|
||||
std::cout << "Starting to import "<<args.filePath<< std::endl;
|
||||
@@ -382,13 +403,17 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset)
|
||||
{
|
||||
for(uint32 i = 0; i < meshNode->mNumMeshes; ++i)
|
||||
{
|
||||
if (globalMeshes[meshNode->mMeshes[i]] == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
meshes.add(std::move(globalMeshes[meshNode->mMeshes[i]]));
|
||||
meshes.back()->transform = loadNodeTransform(meshNode);
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
ArchiveBuffer archive;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
struct aiScene;
|
||||
struct aiTexel;
|
||||
struct aiNode;
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(Mesh)
|
||||
@@ -29,6 +30,7 @@ private:
|
||||
void loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes, Component::Collider& collider);
|
||||
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels);
|
||||
|
||||
Matrix4 loadNodeTransform(aiNode* node);
|
||||
void import(MeshImportArgs args, PMeshAsset meshAsset);
|
||||
Gfx::PGraphics graphics;
|
||||
};
|
||||
|
||||
+4
-4
@@ -57,10 +57,10 @@ int main() {
|
||||
AssetImporter::importMesh(MeshImportArgs{
|
||||
.filePath = sourcePath / "import/models/cube.fbx",
|
||||
});
|
||||
//AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.blend",
|
||||
// .importPath = "Whitechapel"
|
||||
// });
|
||||
AssetImporter::importMesh(MeshImportArgs{
|
||||
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.blend",
|
||||
.importPath = "Whitechapel"
|
||||
});
|
||||
WindowCreateInfo mainWindowInfo;
|
||||
mainWindowInfo.title = "SeeleEngine";
|
||||
mainWindowInfo.width = 1920;
|
||||
|
||||
@@ -14,6 +14,7 @@ Mesh::~Mesh()
|
||||
|
||||
void Mesh::save(ArchiveBuffer& buffer) const
|
||||
{
|
||||
Serialization::save(buffer, transform);
|
||||
Serialization::save(buffer, vertexData->getTypeName());
|
||||
Serialization::save(buffer, vertexCount);
|
||||
Serialization::save(buffer, indices);
|
||||
@@ -25,6 +26,7 @@ void Mesh::save(ArchiveBuffer& buffer) const
|
||||
void Mesh::load(ArchiveBuffer& buffer)
|
||||
{
|
||||
std::string typeName;
|
||||
Serialization::load(buffer, transform);
|
||||
Serialization::load(buffer, typeName);
|
||||
Serialization::load(buffer, vertexCount);
|
||||
vertexData = VertexData::findByTypeName(typeName);
|
||||
|
||||
@@ -11,6 +11,8 @@ public:
|
||||
Mesh();
|
||||
~Mesh();
|
||||
|
||||
// transform from importing
|
||||
Matrix4 transform = Matrix4(1);
|
||||
VertexData* vertexData;
|
||||
MeshId id;
|
||||
uint64 vertexCount;
|
||||
|
||||
@@ -150,5 +150,6 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
|
||||
createInfo.entryPoint = "fragmentMain";
|
||||
collection.fragmentShader = graphics->createFragmentShader(createInfo);
|
||||
}
|
||||
collection.pipelineLayout->create();
|
||||
shaders[perm] = std::move(collection);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
|
||||
{
|
||||
matInstanceData.meshes.add(MeshInstanceData{
|
||||
.instance = InstanceData {
|
||||
.transformMatrix = transform.toMatrix(),
|
||||
.transformMatrix = mesh->transform * transform.toMatrix(),
|
||||
},
|
||||
.data = data,
|
||||
});
|
||||
|
||||
@@ -324,11 +324,15 @@ PipelineLayout::~PipelineLayout() {}
|
||||
Map<uint32, VkPipelineLayout> cachedLayouts;
|
||||
|
||||
void PipelineLayout::create() {
|
||||
vulkanDescriptorLayouts.resize(descriptorSetLayouts.size());
|
||||
for (auto [name, desc] : descriptorSetLayouts) {
|
||||
PDescriptorLayout layout = desc.cast<DescriptorLayout>();
|
||||
layout->create();
|
||||
vulkanDescriptorLayouts[parameterMapping[layout->getName()]] = layout->getHandle();
|
||||
uint32 parameterIndex = parameterMapping[layout->getName()];
|
||||
if (parameterIndex > vulkanDescriptorLayouts.size())
|
||||
{
|
||||
vulkanDescriptorLayouts.resize(parameterIndex + 1);
|
||||
}
|
||||
vulkanDescriptorLayouts[parameterIndex] = layout->getHandle();
|
||||
}
|
||||
|
||||
Array<VkPushConstantRange> vkPushConstants(pushConstants.size());
|
||||
|
||||
@@ -16,7 +16,7 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
||||
}
|
||||
slang::SessionDesc sessionDesc;
|
||||
sessionDesc.flags = 0;
|
||||
slang::CompilerOptionEntry option[2];
|
||||
StaticArray<slang::CompilerOptionEntry, 4> option;
|
||||
option[0].name = slang::CompilerOptionName::DumpIntermediates;
|
||||
option[0].value = slang::CompilerOptionValue();
|
||||
option[0].value.kind = slang::CompilerOptionValueKind::Int;
|
||||
@@ -25,8 +25,16 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
||||
option[1].value = slang::CompilerOptionValue();
|
||||
option[1].value.kind = slang::CompilerOptionValueKind::Int;
|
||||
option[1].value.intValue0 = 1;
|
||||
sessionDesc.compilerOptionEntries = option;
|
||||
sessionDesc.compilerOptionEntryCount = 2;
|
||||
option[2].name = slang::CompilerOptionName::DebugInformation;
|
||||
option[2].value = slang::CompilerOptionValue();
|
||||
option[2].value.kind = slang::CompilerOptionValueKind::Int;
|
||||
option[2].value.intValue0 = 3;
|
||||
option[3].name = slang::CompilerOptionName::DebugInformationFormat;
|
||||
option[3].value = slang::CompilerOptionValue();
|
||||
option[3].value.kind = slang::CompilerOptionValueKind::Int;
|
||||
option[3].value.stringValue0 = "c7";
|
||||
sessionDesc.compilerOptionEntries = option.data();
|
||||
sessionDesc.compilerOptionEntryCount = option.size();
|
||||
sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR;
|
||||
Array<slang::PreprocessorMacroDesc> macros;
|
||||
for(const auto& [key, val] : createInfo.defines)
|
||||
@@ -41,8 +49,6 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
||||
slang::TargetDesc targetDesc;
|
||||
targetDesc.profile = globalSession->findProfile("sm_6_6");
|
||||
targetDesc.format = target;
|
||||
targetDesc.compilerOptionEntryCount = 2;
|
||||
targetDesc.compilerOptionEntries = option;
|
||||
sessionDesc.targetCount = 1;
|
||||
sessionDesc.targets = &targetDesc;
|
||||
StaticArray<const char*, 3> searchPaths = {"shaders/", "shaders/lib/", "shaders/generated/"};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "ArchiveBuffer.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "Math/Matrix.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -52,6 +53,44 @@ namespace Serialization
|
||||
save(buffer, vec.y);
|
||||
save(buffer, vec.z);
|
||||
}
|
||||
static void load(ArchiveBuffer& buffer, Matrix4& mat)
|
||||
{
|
||||
load(buffer, mat[0][0]);
|
||||
load(buffer, mat[0][1]);
|
||||
load(buffer, mat[0][2]);
|
||||
load(buffer, mat[0][3]);
|
||||
load(buffer, mat[1][0]);
|
||||
load(buffer, mat[1][1]);
|
||||
load(buffer, mat[1][2]);
|
||||
load(buffer, mat[1][3]);
|
||||
load(buffer, mat[2][0]);
|
||||
load(buffer, mat[2][1]);
|
||||
load(buffer, mat[2][2]);
|
||||
load(buffer, mat[2][3]);
|
||||
load(buffer, mat[3][0]);
|
||||
load(buffer, mat[3][1]);
|
||||
load(buffer, mat[3][2]);
|
||||
load(buffer, mat[3][3]);
|
||||
}
|
||||
static void save(ArchiveBuffer& buffer, const Matrix4& mat)
|
||||
{
|
||||
save(buffer, mat[0][0]);
|
||||
save(buffer, mat[0][1]);
|
||||
save(buffer, mat[0][2]);
|
||||
save(buffer, mat[0][3]);
|
||||
save(buffer, mat[1][0]);
|
||||
save(buffer, mat[1][1]);
|
||||
save(buffer, mat[1][2]);
|
||||
save(buffer, mat[1][3]);
|
||||
save(buffer, mat[2][0]);
|
||||
save(buffer, mat[2][1]);
|
||||
save(buffer, mat[2][2]);
|
||||
save(buffer, mat[2][3]);
|
||||
save(buffer, mat[3][0]);
|
||||
save(buffer, mat[3][1]);
|
||||
save(buffer, mat[3][2]);
|
||||
save(buffer, mat[3][3]);
|
||||
}
|
||||
static void load(ArchiveBuffer& buffer, Vector& vec)
|
||||
{
|
||||
load(buffer, vec.x);
|
||||
|
||||
Reference in New Issue
Block a user