jkuhlmann / cgltf

:diamond_shape_with_a_dot_inside: Single-file glTF 2.0 loader and writer written in C99
MIT License
1.46k stars 135 forks source link

[Feature] add new KHR_mesh_quantization extension #172

Closed maxxnino closed 2 years ago

maxxnino commented 2 years ago

We can use gltfpack to generate quantization mesh, but this required KHR_mesh_quantization extension. I wish you can add support for this extension

pezcode commented 2 years ago

This is already supported. That extension only extends some allowed attribute/accessor types, but cgltf doesn't actually check the type to begin with.

If you want the data converted to float, use cgltf_accessor_unpack_floats().

maxxnino commented 2 years ago

Thank you. I have one more question, maybe outside the scope of this library. Do you have experience with meshoptimizer library. After optimized mesh with quantization. How can I use it. I load mesh data position with format [3]uint16 on the cpu side and in vulkan is VK_FORMAT_R16G16B16_UNORM. But it messed up the mesh so much. Do I need to use cgltf_accessor_unpack_floats() to convert to float. Or I can use it directly

pezcode commented 2 years ago

If you used gltfpack without -c you should be able to pass the data directly to Vulkan. Make sure the Vulkan type matches cgltf_accessor::component_type and cgltf_accessor::normalized. Specifically for positions, I would expect the component type to be signed, meaning you probably need VK_FORMAT_R16G16B16_SNORM.

maxxnino commented 2 years ago

I tried as you suggest but It didn't work. Here the result

I try a simple plane. And gltfpack seem to mess up the mesh

maxxnino commented 2 years ago

I found the problem. Type is vec3 but stride is 8 bytes for position.