diff --git a/homework/homework1/homework1.cpp b/homework/homework1/homework1.cpp index 4705722..4012170 100644 --- a/homework/homework1/homework1.cpp +++ b/homework/homework1/homework1.cpp @@ -295,16 +295,16 @@ VulkanglTFModel::~VulkanglTFModel() //get distributions of node if (inputNode.translation.size() == 3) { - node->translation = glm::make_vec3(inputNode.translation.data()); + node->matrix =glm::translate(node->matrix,glm::vec3(glm::make_vec3(inputNode.translation.data()))); } if (inputNode.scale.size() == 3) { - node->scale = glm::make_vec3(inputNode.scale.data()); + node->matrix =glm::scale(node->matrix,glm::vec3(glm::make_vec3(inputNode.scale.data()))); } if (inputNode.rotation.size() == 4) { //rotation is given by quaternion glm::quat q = glm::make_quat(inputNode.rotation.data()); - node->rotation = glm::mat4(q); + node->matrix = glm::mat4(q); } if (inputNode.matrix.size() == 16) { @@ -345,7 +345,7 @@ VulkanglTFModel::~VulkanglTFModel() if (glTFPrimmitive.attributes.find("POSITION") != glTFPrimmitive.attributes.end()) { const tinygltf::Accessor& accessor = input.accessors[glTFPrimmitive.attributes.find("POSITION")->second]; - const tinygltf::BufferView view = input.bufferViews[accessor.bufferView]; + const tinygltf::BufferView &view = input.bufferViews[accessor.bufferView]; positionBuffer = reinterpret_cast (&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); vertexCount = accessor.count; } @@ -356,6 +356,7 @@ VulkanglTFModel::~VulkanglTFModel() normalsBuffer = reinterpret_cast (&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); } + //texture and tangent data if (glTFPrimmitive.attributes.find("TEXCOORD_0") != glTFPrimmitive.attributes.end()) { const tinygltf::Accessor& accessor = input.accessors[glTFPrimmitive.attributes.find("TEXCOORD_0")->second]; @@ -363,6 +364,14 @@ VulkanglTFModel::~VulkanglTFModel() texcoordsBuffer = reinterpret_cast (&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); } + if (glTFPrimmitive.attributes.find("TANGENT") != glTFPrimmitive.attributes.end()) + { + const tinygltf::Accessor& accessor = input.accessors[glTFPrimmitive.attributes.find("TANGENT")->second]; + const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView]; + tangentsBuffer = reinterpret_cast (&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); + + } + //skin joints and weights data if (glTFPrimmitive.attributes.find("JOINTS_0") != glTFPrimmitive.attributes.end()) { const tinygltf::Accessor& accessor = input.accessors[glTFPrimmitive.attributes.find("JOINTS_0")->second]; @@ -377,6 +386,7 @@ VulkanglTFModel::~VulkanglTFModel() jointWeightsBuffer = reinterpret_cast (&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); } + hasSkin = (jointIndicesBuffer && jointWeightsBuffer); for (size_t v = 0; v < vertexCount; v++) @@ -386,6 +396,7 @@ VulkanglTFModel::~VulkanglTFModel() vert.uv = texcoordsBuffer ? glm::make_vec2(&texcoordsBuffer[v*2]) : glm::vec3(0.0f); vert.normal = glm::normalize(glm::vec3(normalsBuffer ? glm::make_vec3(&normalsBuffer[v * 3]) : glm::vec3(0.0f))); vert.color = glm::vec3(1.0f,1.0f,nodeIndex); + vert.tangent = tangentsBuffer ? glm::normalize(glm::make_vec3(&tangentsBuffer[v * 4])) : glm::vec3(0.0f); vert.jointIndices = hasSkin ? glm::vec4(glm::make_vec4(&jointIndicesBuffer[v * 4])) : glm::vec4(0.0f); vert.jointWeights = hasSkin ? glm::make_vec4(&jointWeightsBuffer[v * 4]) : glm::vec4(0.0f); vertexBuffer.push_back(vert); @@ -472,7 +483,7 @@ VulkanglTFModel::~VulkanglTFModel() nodeMatrics[node->index] = getNodeMatrix(node); for (auto& child : node->children) { - updateNodeMatrix(child, nodeMatrics); + updateNodeMatrix(child, nodeMatrics); } } @@ -590,11 +601,10 @@ VulkanglTFModel::~VulkanglTFModel() vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 1, 1, &skins[node.skin].descriptorSet, 0, nullptr); } - - for (VulkanglTFModel::Primitive& primitive : node.mesh.primitives) { if (primitive.indexCount > 0) { + // Get the texture index for this primitive VulkanglTFModel::Texture texture = textures[materials[primitive.materialIndex].baseColorTextureIndex]; // Bind the descriptor for the current primitive's texture diff --git a/homework/homework1/homework1.h b/homework/homework1/homework1.h index a4b30be..5198a25 100644 --- a/homework/homework1/homework1.h +++ b/homework/homework1/homework1.h @@ -41,6 +41,7 @@ public: glm::vec3 normal; glm::vec2 uv; glm::vec3 color; + glm::vec3 tangent; glm::vec3 jointIndices; glm::vec3 jointWeights; }; @@ -208,6 +209,7 @@ public: glm::vec4 lightPos = glm::vec4(5.0f, 5.0f, 5.0f, 1.0f); glm::vec4 viewPos; } values; + vks::Buffer animationBuffer; } shaderData; struct Pipelines {