Repository navigation
Description
Describe the bug 📝
packages/core/src/realityCapture/e57.ts (3.6.0, unchanged in main) has two problems.
1. e57Packets computes the points per packet as xStreamBytes / 4 (line 190). That is only right when cartesianX is a 32-bit value (Float with precision="single", or a 32-bit ScaledInteger). In E57 (ASTM E2807):
- a
Floatis double precision unless it saysprecision="single", so 8 bytes per value; IntegerandScaledIntegervalues are bit-packed, least significant bit first, with ceil(log2(maximum − minimum + 1)) bits each (19, 24 and 30 bits are common), so a value can be split across two packets;- each field has its own bytestream, and the writer does not cut them at the same record, so the fields of one packet carry different numbers of values.
So n is wrong, and the loop that stops at recordCount stops too early (doubles) or never reaches it and walks past the section (bit-packed). With the libE57.org sample files and the published 3.6.0 code:
| File (X field) | recordCount |
Σ n from e57Packets |
Points actually in the X bytes it read |
|---|---|---|---|
| bunnyFloat.e57 (Float, 32 bits) | 30 571 | 30 571 | 30 571 ✔ |
| bunnyInt32.e57 (ScaledInteger, 32 bits) | 30 571 | 30 571 | 30 571 ✔ |
| bunnyDouble.e57 (Float, 64 bits) | 30 571 | 32 800 | 16 400 (stops at 54 %) |
| bunnyInt19.e57 (ScaledInteger, 19 bits) | 30 571 | 18 152 | 30 571 |
| pumpACartesian.e57 (ScaledInteger, 24 bits) | 370 530 | 277 898 | 370 530 |
| Station018.e57 (ScaledInteger, 30 bits) | 4 067 815 | 3 813 577 | — |
Values per field in the first packet of pumpACartesian.e57 (bytes × 8 / bits): X, Y, Z 3521.33 · intensity 3521.07 · colorRed/Green/Blue 3522 · cartesianInvalidState 3520, while n = 2641. There is no single point count per packet.
2. openE57 reads only the first <points> of the XML (lines 111–112) and ignores the rest of /data3D and every scan's pose (rotation quaternion and translation). Multi-station scans are the usual case:
- Trimble_StSulpice-Cloud-50mm.e57: 5 scans, 8 484 455 points; only the first, 1 274 653 (15 %);
- manitouNoInvalidPoints.e57: 5 scans with rotations, 1 095 702 points; only 346 444;
- Station018.e57: one scan, rotated; the pose is not applied.
Suggested fix.
- Do not derive a point count per packet. Yield each field's bytes as they come, and decode with one bit queue per field that carries over to the next packet; a record is complete when every needed field has a value.
- Read the
Floatsize fromprecision, and the integer width fromminimum/maximum(64 bits when they are absent). - Let
openE57return every/data3Dchild with itspointssection, its prototype and its pose, so the caller can apply rotation × point + translation per scan.sphericalRange/Azimuth/Elevationand the*InvalidStatefields come for free from the same decoder.
We wrote and tested such a reader (pure TypeScript, no dependencies). Against the independent references that libE57.org publishes with the samples (pumpA.ptx and bunnyData.pts), the points match to 2–4 µm, the quantization of a 1e-6 scale. It handles cartesian and spherical, invalid points, colour limits and poses. We can share it as a PR.
Reproduction ▶️
No response
Steps to reproduce 🔢
- Download the sample files from https://sourceforge.net/projects/e57-3d-imgfmt/files/E57Example-data/ (bunnyDouble.e57, bunnyInt19.e57, pumpACartesian.e57, Trimble_StSulpice-Cloud-50mm.e57).
- Run this with Node 22 next to them:
import { openSync, readSync, fstatSync } from "node:fs";
import { openE57, e57Packets } from "@thatopen/components/dist/realityCapture/index.js";
const fd = openSync("bunnyDouble.e57", "r");
const size = fstatSync(fd).size;
const source = {
readBytes: async (offset, length) => {
const b = Buffer.alloc(Math.max(0, Math.min(length, size - offset)));
if (b.length) readSync(fd, b, 0, b.length, offset);
return new Uint8Array(b.buffer, b.byteOffset, b.length);
},
};
const file = await openE57(source);
let n = 0, xBytes = 0;
for await (const p of e57Packets(file)) {
n += p.n;
xBytes += p.off[file.iY] - p.off[file.iX]; // X is followed by Y in these files
}
console.log(file.recordCount, n, xBytes / 8); // 30571 32800 16400- With bunnyInt19.e57 the sum of
nis 18152 (of 30571) although all the X bytes are read; with Trimble_StSulpice-Cloud-50mm.e57,recordCountis 1274653: the first of its 5 scans.
System Info 💻
OS: Windows 11 Pro 10.0.26200
Node: 22.17.0 · npm 10.9.2
Browser: Chrome 155
@thatopen/components 3.6.0 · @thatopen/components-front 3.6.0 · @thatopen/fragments 3.6.0 · three 0.185.0Used Package Manager 📦
npm
Error Trace/Logs 📃
No response
Validations ✅
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a repository issue and not a framework-specific issue. For example, if it's a THREE.js related bug, it should likely be reported to mrdoob/threejs instead.
- Check that this is a concrete bug. For Q&A join our Community.
- The provided reproduction is a minimal reproducible example of the bug.
Activity