petrbroz / svf-utils

Utilities for working with the SVF file format used by Autodesk Platform Services.
https://petrbroz.github.io/svf-utils/
MIT License
123 stars 53 forks source link

Fixed handling of TypedArrays #69

Closed henrikbuchholz closed 1 year ago

henrikbuchholz commented 1 year ago

Problem: When using gltf writer, some meshes appeared "imploded" like this - and were fully rejected by some standard gltf viewers: image

Reason: The code to write BufferViews ignored the byteOffset/byteLength values of the index array. Therefore, if a TypedArray had a byteOffset>0 or byteLength!=buffer.byteLength, the typed array was incorrectly replaced by the whole ArrayBuffer containing it. This could mess up geometry, e.g. by introducing random indices.

Solution: Add byteOffset and byteLength to various code sections to avoid this problem.

After the fix, the exported mesh looks correct again:

image

petrbroz commented 1 year ago

You're the best, thank you @henrikbuchholz!

Btw I noticed that you fixed the byteOffset/byteLength in the createMeshGeometry method and in the createLineGeometry but not in the createPointGeometry. Any specific reason for that?

petrbroz commented 1 year ago

Alright, no reason, just in a hurry :) Let me merge this PR and fix the createPointGeometry method in the same way.