Skip to content

Commit

Permalink
gltfpack: Remove point normal streams when they are constant
Browse files Browse the repository at this point in the history
A fair amount of point cloud exports to glTF seem to have a redundant
normal stream (filled with the same value). This is relatively common
(about one in 6-7 files from Sketchfab has this issue), and it results
in incorrect rendering for renderers that respect normals *and* extra
data (4 out of 16 bytes in point clouds with normals & colors).

While it may sometimes be incorrect to remove this data, for now let's
err on the side of aggressive optimization and detect & remove it.
  • Loading branch information
zeux committed Oct 8, 2023
1 parent 7e0bc75 commit ac94493
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gltf/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ void filterStreams(Mesh& mesh, const MaterialInfo& mi)
if (stream.target && stream.type == cgltf_attribute_type_tangent && !morph_tangent)
continue;

if (mesh.type == cgltf_primitive_type_points && stream.type == cgltf_attribute_type_normal && !stream.data.empty() && isConstant(stream.data, stream.data[0]))
continue;

// the following code is roughly equivalent to streams[write] = std::move(stream)
std::vector<Attr> data;
data.swap(stream.data);
Expand Down

0 comments on commit ac94493

Please sign in to comment.