pull/2/head
ink-soul 2023-05-20 15:09:51 +08:00
parent 104ebaa0a7
commit 39ba805802
2 changed files with 19 additions and 7 deletions

View File

@ -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<const float*> (&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset]));
vertexCount = accessor.count;
}
@ -356,6 +356,7 @@ VulkanglTFModel::~VulkanglTFModel()
normalsBuffer = reinterpret_cast<const float*> (&(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<const float*> (&(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<const float*> (&(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<const float*> (&(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);
@ -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

View File

@ -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 {