jkuhlmann / cgltf

:diamond_shape_with_a_dot_inside: Single-file glTF 2.0 loader and writer written in C99

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature] add new KHR_mesh_quantization extension

maxxnino opened this issue · comments

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

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().

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

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.

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

  • position is cgltf_component_type_r_16u and normalized is false, int16_t[3] each. Vulkan type VK_FORMAT_R16G16B16_SNORM
  • texcoords is cgltf_component_type_r_16u and normalized is false, uint16_t[2] each. Vulkan type VK_FORMAT_R16G16_UNORM
  • normal is cgltf_component_type_r_8 and normalized is true, char[3] each. Vulkan type VK_FORMAT_R8G8B8_SNORM
  • tangent is cgltf_component_type_r_8 and normalized is true, char[4] each. Vulkan type VK_FORMAT_R8G8B8A8_SNORM

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

  • gltfpack
- Vertices
Vector3(u16){ .x = 0, .y = 0, .z = 16383 }
Vector3(u16){ .x = 0, .y = 16383, .z = 0 }
Vector3(u16){ .x = 16383, .y = 0, .z = 16383 }
Vector3(u16){ .x = 0, .y = 0, .z = 0 }
- Indices: 0, 1, 2, 0, 2, 3
  • blender
- Vertices
Vector3(f32){ .x = -1.0, .y = 0.0, .z = 1.0 }
Vector3(f32){ .x = 1.0, .y = 0.0, .z = 1.0 }
Vector3(f32){ .x = -1.0, .y = 0.0, .z = -1.0 }
Vector3(f32){ .x = 1.0, .y = 0.0, .z = -1.0 }
-Indices: 0, 1, 3, 0, 3, 2
  • gltfpack results I reproduce in blender
    Untitled

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