Skip to content

PLYExporter: Fix export of quantized attributes. - #35192

Merged
Mugen87 merged 4 commits into
mrdoob:devfrom
nk-batman21:plyexporter-quantized-attributes
Oct 24, 2026
Merged

Mugen87 merged 4 commits into
mrdoob:devfrom
nk-batman21:plyexporter-quantized-attributes

Conversation

@nk-batman21

Copy link
Copy Markdown

Related issue: -

Description

Since #33625, PLYExporter picks each PLY property type from the attribute's typed array. That breaks quantized geometry: positions and normals are transformed to world space before they are written, and normalized attributes are dequantized by getX(), so the values are fractional. With an integer property type they get rounded (ASCII) or truncated (binary).

Quantized glTF assets (KHR_mesh_quantization, e.g. gltfpack or glTF-Transform output) hit this. Loading examples/models/gltf/facecap.glb with GLTFLoader and exporting the scene with { binary: true }, which is what File > Export > PLY (BINARY) does in the editor, writes ushort x/y/z and char nx/ny/nz. Read back with PLYLoader, every coordinate of the 4368 vertices is 0, 1 or 65535, and every normal is 0. The ASCII export rounds coordinates to integers and normals to -1, 0 or 1. Before r185 these attributes were always written as float.

This PR writes positions and normals as float again (double for a Float64Array, as now), and normalized uv and custom attributes as float. Colors keep their current handling. Geometries with float attributes export the same bytes as before. There was no unit test file for PLYExporter, so I added one that exports a small quantized mesh in both formats and reads it back.

Ran: npm run lint, npm run test-unit, npm run test-unit-addons (the new test fails without the fix) and npx eslint on the changed files.
Checked: the exported facecap bounding box now matches the dequantized one in three.js, and float meshes, colors, points, Float64Array positions and custom attributes export byte-identical output before and after.

@Mugen87

Mugen87 commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

Sorry, but the suggested code was incredible confusing. I think it's better if we adapt the policy in PLYExporter that quantized attributes must set normalized===true which covers most use cases.

@Mugen87
Mugen87 merged commit 5e6eee6 into mrdoob:dev Oct 24, 2026
7 of 8 checks passed
@Mugen87 Mugen87 added this to the r187 milestone Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants