google / draco

Draco is a library for compressing and decompressing 3D geometric meshes and point clouds. It is intended to improve the storage and transmission of 3D graphics.
https://google.github.io/draco/
Apache License 2.0
6.48k stars 963 forks source link

Vertex attributes added using emscripten path hard codes normalized flag to false #1023

Open bghgary opened 1 year ago

bghgary commented 1 year ago

See https://github.com/KhronosGroup/glTF-Blender-IO/issues/2013 for some context.

It appears from the code here that there is no way to add a vertex attribute that has the normalized flag set to true through the emscripten code path. This causes issues when trying to decode normalized vertex attributes since the decode APIs will return an attribute with normalized as false when it should be true.

int PointCloudBuilder::AddAttribute(GeometryAttribute::Type attribute_type,
                                    int8_t num_components, DataType data_type) {
  GeometryAttribute ga;
  ga.Init(attribute_type, nullptr, num_components, data_type, false /* !!THIS IS HARDCODED!! */,
          DataTypeLength(data_type) * num_components, 0);
  return point_cloud_->AddAttribute(ga, true, point_cloud_->num_points());
}

To repro:

  1. Download the test.zip from this issue and extract no_draco_ushort_uvs.glb.
  2. Use Don's glTF-Transform tool to encode Draco with the following command line:
    gltf-transform draco no_draco_ushort_uvs.glb test.glb
  3. Open test.glb with the Babylon.js sandbox

Result: The console will output:

Normalized flag from Draco data (false) does not match normalized flag from glTF accessor (true). Using flag from glTF accessor.

Expected: The console does not show this warning.

ondys commented 11 months ago

Support for normalized attributes in encoder emscripten will be added in the next release.