update materials loader
							parent
							
								
									077d91916f
								
							
						
					
					
						commit
						7733ba49ee
					
				| 
						 | 
				
			
			@ -86,6 +86,26 @@
 | 
			
		|||
			if (glTFMaterial.values.find("baseColorTexture") != glTFMaterial.values.end()) {
 | 
			
		||||
				materials[i].baseColorTextureIndex = glTFMaterial.values["baseColorTexture"].TextureIndex();
 | 
			
		||||
			}
 | 
			
		||||
			if (glTFMaterial.values.find("metallicRoughnessTexture") != glTFMaterial.values.end()) {
 | 
			
		||||
				materials[i].matalicRoughTextureIndex = glTFMaterial.values["metallicRoughnessTexture"].TextureIndex();
 | 
			
		||||
			}
 | 
			
		||||
			if (glTFMaterial.additionalValues.find("normalTexture") != glTFMaterial.additionalValues.end())
 | 
			
		||||
			{
 | 
			
		||||
				materials[i].normalMapTextureIndex = glTFMaterial.additionalValues["normalTexture"].TextureIndex();
 | 
			
		||||
			}
 | 
			
		||||
			if (glTFMaterial.emissiveTexture.index != -1)
 | 
			
		||||
			{
 | 
			
		||||
				materials[i].emissiveTextureIndex = glTFMaterial.emissiveTexture.index;
 | 
			
		||||
			}
 | 
			
		||||
			if (glTFMaterial.emissiveFactor.size() == 3)
 | 
			
		||||
			{
 | 
			
		||||
				materials[i].materialData.values.emissiveFactor = glm::make_vec3(glTFMaterial.emissiveFactor.data());
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (glTFMaterial.values.find("baseColorFactor") != glTFMaterial.values.end())
 | 
			
		||||
			{
 | 
			
		||||
				materials[i].materialData.values.baseColorFactor = glm::make_vec4(glTFMaterial.values["baseColorFactor"].ColorFactor().data());
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
| 
						 | 
				
			
			@ -280,15 +300,18 @@
 | 
			
		|||
		{
 | 
			
		||||
			node->matrix =glm::translate(node->matrix,glm::vec3(glm::make_vec3(inputNode.translation.data())));
 | 
			
		||||
		}
 | 
			
		||||
		if (inputNode.scale.size() == 3)
 | 
			
		||||
		{
 | 
			
		||||
			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->matrix = glm::mat4(q);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (inputNode.scale.size() == 3)
 | 
			
		||||
		{
 | 
			
		||||
			node->matrix =glm::scale(node->matrix,glm::vec3(glm::make_vec3(inputNode.scale.data())));
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (inputNode.matrix.size() == 16)
 | 
			
		||||
		{
 | 
			
		||||
			node->matrix = glm::make_mat4x4(inputNode.matrix.data());
 | 
			
		||||
| 
						 | 
				
			
			@ -318,10 +341,11 @@
 | 
			
		|||
				const float* normalsBuffer = nullptr;
 | 
			
		||||
				const float* texcoordsBuffer = nullptr;
 | 
			
		||||
				const float* tangentsBuffer = nullptr;
 | 
			
		||||
				size_t vertexCount = 0;
 | 
			
		||||
				//skin joints
 | 
			
		||||
				const float* jointWeightsBuffer = nullptr;
 | 
			
		||||
				const uint16_t * jointIndicesBuffer = nullptr;
 | 
			
		||||
				size_t vertexCount = 0;
 | 
			
		||||
				
 | 
			
		||||
				bool hasSkin = false;
 | 
			
		||||
				//get buffer by index in primmitive.attributes
 | 
			
		||||
				{
 | 
			
		||||
| 
						 | 
				
			
			@ -556,7 +580,7 @@
 | 
			
		|||
		std::vector<glm::mat4> nodeMatrics(nodeCount);
 | 
			
		||||
		for (auto& node : nodes)
 | 
			
		||||
		{
 | 
			
		||||
			updateJoints(node);
 | 
			
		||||
			//updateJoints(node);
 | 
			
		||||
			updateNodeMatrix(node, nodeMatrics);
 | 
			
		||||
		}
 | 
			
		||||
		buffer.copyTo(nodeMatrics.data(), nodeCount * sizeof(glm::mat4));
 | 
			
		||||
| 
						 | 
				
			
			@ -578,21 +602,28 @@
 | 
			
		|||
				nodeMatrix = currentParent->matrix * nodeMatrix;
 | 
			
		||||
				currentParent = currentParent->parent;
 | 
			
		||||
			}
 | 
			
		||||
			// Pass the final matrix to the vertex shader using push constants
 | 
			
		||||
			vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::mat4), &nodeMatrix);
 | 
			
		||||
			if (skins.size() > 0)
 | 
			
		||||
			{
 | 
			
		||||
				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) 
 | 
			
		||||
				{
 | 
			
		||||
					
 | 
			
		||||
				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
 | 
			
		||||
					vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 2, 1, &images[texture.imageIndex].descriptorSet, 0, nullptr);
 | 
			
		||||
					if (textures.size() > 0)
 | 
			
		||||
					{
 | 
			
		||||
						VulkanglTFModel::Texture texture = textures[materials[primitive.materialIndex].baseColorTextureIndex];
 | 
			
		||||
						auto normalMap = textures[materials[primitive.materialIndex].normalMapTextureIndex];
 | 
			
		||||
						auto roughMetalMap = textures[materials[primitive.materialIndex].matalicRoughTextureIndex];
 | 
			
		||||
 | 
			
		||||
						if (materials[primitive.materialIndex].emissiveTextureIndex >= 0)
 | 
			
		||||
						{
 | 
			
		||||
							auto emissiveMap = textures[materials[primitive.materialIndex].emissiveTextureIndex];
 | 
			
		||||
							vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 4, 1, &images[emissiveMap.imageIndex].descriptorSet, 0, nullptr);
 | 
			
		||||
						}
 | 
			
		||||
 | 
			
		||||
						// Bind the descriptor for the current primitive's texture
 | 
			
		||||
						vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 1, 1, &images[texture.imageIndex].descriptorSet, 0, nullptr);
 | 
			
		||||
						vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 2, 1, &images[normalMap.imageIndex].descriptorSet, 0, nullptr);
 | 
			
		||||
						vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 3, 1, &images[roughMetalMap.imageIndex].descriptorSet, 0, nullptr);
 | 
			
		||||
						vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 5, 1, &materials[primitive.materialIndex].materialData.descriptorSet, 0, nullptr);
 | 
			
		||||
					}
 | 
			
		||||
					vkCmdDrawIndexed(commandBuffer, primitive.indexCount, 1, primitive.firstIndex, 0, 0);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue