Skip to content

Some fastgltf updates I needed to implement from their gl_viewer example: #161

Description

@wark77

in the load_image function https://vkguide.dev/docs/new_chapter_5/gltf_textures/:


[&](fastgltf::sources::BufferView& view) {
					auto& bufferView = asset.bufferViews[view.bufferViewIndex];
					auto& buffer = asset.buffers[bufferView.bufferIndex];

					std::visit(fastgltf::visitor { 
								   [](auto& arg) {},
								   [&](fastgltf::sources::Array& vector) {  //fastgltf::sources::**Array**& vector replaces fastgltf::sources::**Vector**& vector

									   unsigned char* data = stbi_load_from_memory(reinterpret_cast<const stbi_uc*>(vector.bytes.data() + bufferView.byteOffset),
					                                            static_cast<int>(bufferView.byteLength), &width, &height, &nrChannels, 4);



and in the gltf loading loop through meshes and primitives https://vkguide.dev/docs/new_chapter_5/gltf_nodes/:

// load vertex positions  vkguide.dev version

        {
            fastgltf::Accessor& posAccessor = gltf.accessors[p.findAttribute("POSITION")->second];  
            vertices.resize(vertices.size() + posAccessor.count);

            fastgltf::iterateAccessorWithIndex<glm::vec3>(gltf, posAccessor,
                [&](glm::vec3 v, size_t index) {
                    Vertex newvtx;
                    newvtx.position = v;
                    newvtx.normal = { 1, 0, 0 };
                    newvtx.color = glm::vec4 { 1.f };
                    newvtx.uv_x = 0;
                    newvtx.uv_y = 0;
                    vertices[initial_vtx + index] = newvtx;
                });
        }
//all accessors using ->second had to be replaced not just position, but all in the same way

auto* positionIt = p.findAttribute("POSITION");
auto& posAccessor = asset.accessors[positionIt->accessorIndex];  //can't use ->second anymore, changed to accessorIndex
vertices.resize(vertices.size() + posAccessor.count);                              

fastgltf::iterateAccessorWithIndex<fastgltf::math::fvec3>(asset, posAccessor,
[&](fastgltf::math::fvec3 v, std::size_t index) {          // had to change the glm::vec3 to fastgltf::math::fvec3 here

	Vertex newvtx;
	newvtx.pos = glm::vec3{v.x(),v.y(),v.z()};
	newvtx.normal = { 1, 0, 0 };
	newvtx.color = glm::vec3 { 1.f };//temp
	newvtx.uv_x = 0;
	newvtx.uv_y = 0;
	vertices[initial_vtx + index] = newvtx;
});

thanks for making this great guide! it really helps with breaking into understanding vulkan.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions