Skip to content
Snippets Groups Projects
Commit 02d89358 authored by Mara Vogt's avatar Mara Vogt
Browse files

[#63] scene test wip

parent ca767691
No related branches found
No related tags found
1 merge request!51Resolve "Laden mehrer Meshes mit Materials und Textures"
Pipeline #25739 failed
......@@ -137,6 +137,7 @@ typedef struct {
* such as Materials. */
typedef struct {
std::string name;
std::array<float, 16> modelMatrix;
std::vector<int> vertexGroups;
} Mesh;
......
......@@ -71,6 +71,41 @@ enum IndexType getIndexType(const enum fx::gltf::Accessor::ComponentType &t)
}
}
std::array<float, 16> computeModelMatrix(std::array<float, 3> translation, std::array<float, 3> scale, std::array<float, 4> rotation){
std::array<float, 16> modelMatrix;
// row 4
modelMatrix[12] = 0;
modelMatrix[13] = 0;
modelMatrix[14] = 0;
modelMatrix[15] = 1;
// translation
modelMatrix[3] = translation[0];
modelMatrix[7] = translation[1];
modelMatrix[11] = translation[2];
// scale
//modelMatrix[0] = scale[0];
//modelMatrix[5] = scale[1];
//modelMatrix[10] = scale[2];
// rotation and scale
auto a = rotation[0];
auto q1 = rotation[1];
auto q2 = rotation[2];
auto q3 = rotation[3];
modelMatrix[0] = (2 * (a * a + q1 * q1) + 1) * scale[0];
modelMatrix[1] = (2 * (q1 * q2 - a * q3)) * scale[1];
modelMatrix[2] = (2 * (q1 * q3 + a * q2)) * scale[2];
modelMatrix[4] = (2 * (q1 * q2 + a * q3)) * scale[0];
modelMatrix[5] = (2 * (a * a + q2 * q2) + 1) * scale[1];
modelMatrix[6] = (2 * (q2 * q3 - a * q1)) * scale[2];
modelMatrix[8] = (2 * (q1 * q3 - a * q2)) * scale[0];
modelMatrix[9] = (2 * (q2 * q3 + a * q1)) * scale[1];
modelMatrix[10] = (2 * (a * a + q3 * q3) - 1) * scale[2];
return modelMatrix;
}
int loadMesh(const std::string &path, Mesh &mesh) {
fx::gltf::Document object;
......@@ -200,6 +235,7 @@ int loadMesh(const std::string &path, Mesh &mesh) {
std::vector<int> vertexGroupsIndex;
//glm::mat4 modelMatrix = object.nodes[0].matrix;
for(int i = 0; i < numVertexGroups; i++){
vertexGroupsIndex.push_back(i);
}
......@@ -207,6 +243,7 @@ int loadMesh(const std::string &path, Mesh &mesh) {
mesh = {
object.meshes[0].name,
object.nodes[0].matrix,
vertexGroupsIndex,
};
......@@ -391,14 +428,23 @@ int loadScene(const std::string &path, Scene &scene){
vertexGroupsIndex.push_back(groupCount);
}
std::array<float, 16> modelMatrix = computeModelMatrix(sceneObjects.nodes[i].translation, sceneObjects.nodes[i].scale, sceneObjects.nodes[i].rotation);
mesh = {
sceneObjects.meshes[i].name,
modelMatrix,
vertexGroupsIndex,
};
/*mesh.name = sceneObjects.meshes[i].name;
mesh.vertexGroups = vertexGroupsIndex;*/
meshes.push_back(mesh);
}
/*for(int m = 0; m < sceneObjects.nodes.size(); m++){
meshes[sceneObjects.nodes[m].mesh].modelMatrix = sceneObjects.nodes[m].matrix;
}*/
if (sceneObjects.textures.size() > 0){
textures.reserve(sceneObjects.textures.size());
......
......@@ -5,6 +5,19 @@
#include <chrono>
#include <vkcv/asset/asset_loader.hpp>
glm::mat4 arrayTo4x4Matrix(std::array<float,16> array){
glm::mat4 matrix;
int r = 0;
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
matrix[i][j] = array[r];
r++;
std::cout << matrix[i][j] << std::endl;
}
}
return matrix;
}
int main(int argc, const char** argv) {
const char* applicationName = "First Scene";
......@@ -178,6 +191,13 @@ int main(int argc, const char** argv) {
drawcalls.push_back(vkcv::DrawcallInfo(renderMesh, {descriptorUsage}));
}
std::vector<glm::mat4> modelMatrices;
modelMatrices.clear();
for(int m = 0; m < scene.meshes.size(); m++){
modelMatrices.push_back(arrayTo4x4Matrix(scene.meshes[m].modelMatrix));
}
std::vector<glm::mat4> mvp;
auto start = std::chrono::system_clock::now();
while (window.isWindowOpen()) {
vkcv::Window::pollEvents();
......@@ -201,11 +221,18 @@ int main(int argc, const char** argv) {
auto deltatime = end - start;
start = end;
cameraManager.getCamera().updateView(std::chrono::duration<double>(deltatime).count());
const glm::mat4 mvp = cameraManager.getCamera().getProjection() * cameraManager.getCamera().getView();
const glm::mat4 vp = cameraManager.getCamera().getProjection() * cameraManager.getCamera().getView();
mvp.clear();
for (const auto& m : modelMatrices) {
mvp.push_back(vp * m);
}
//vkcv::PushConstantData pushConstantData((void*)mainPassMatrices.data(), 2 * sizeof(glm::mat4));
std::vector<glm::mat4> pushConstantDataVector(drawcalls.size(), mvp);
//std::vector<glm::mat4> pushConstantDataVector(drawcalls.size(), mvp);
vkcv::PushConstantData pushConstantData((void*)pushConstantDataVector.data(), sizeof(glm::mat4));
vkcv::PushConstantData pushConstantData((void*)mvp.data(), sizeof(glm::mat4));
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment