minidraco 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # 🐲 minidraco
2
2
 
3
3
  A fast, pure-TypeScript [Draco](https://google.github.io/draco/) mesh decoder with a drop-in
4
- `DRACOLoader` for [Three.js](https://threejs.org/) — no wasm to host or fetch, and a worker pool
5
- so decoding never blocks the main thread.
4
+ `DRACOLoader` for [Three.js](https://threejs.org/) — no wasm to host or fetch, and an optional
5
+ worker pool so decoding never blocks the main thread.
6
6
 
7
7
  ## Usage
8
8
 
@@ -15,12 +15,11 @@ gltfLoader.setDRACOLoader(new MinidracoLoader())
15
15
  gltfLoader.load('model.glb', gltf => scene.add(gltf.scene))
16
16
  ```
17
17
 
18
- A drop-in for `THREE.DRACOLoader`, no cast needed. Decoding runs in a worker pool by default, with
19
- a main-thread fallback. Options:
18
+ A drop-in for `THREE.DRACOLoader`. Decoding runs on the main thread by default. Opt into a worker pool if you prefer to keep it free:
20
19
 
21
20
  ```ts
22
- new MinidracoLoader({ workers: false }) // decode on the main thread
23
- new MinidracoLoader({ workerLimit: 8 }) // pool size (default 4)
21
+ new MinidracoLoader({ workers: true }) // decode in a pool of 4 workers
22
+ new MinidracoLoader({ workerLimit: 8 }) // pool of 8
24
23
  ```
25
24
 
26
25
  Or decode a raw bitstream without Three.js:
@@ -39,28 +38,23 @@ const mesh = decodeDracoMesh(new Uint8Array(bytes))
39
38
 
40
39
  ## Performance
41
40
 
42
- Median across an 18-model corpus vs [draco.js](https://github.com/mrdoob/draco.js) and the official
41
+ Median across 18 models vs [draco.js](https://github.com/mrdoob/draco.js) and the official
43
42
  [draco3d](https://www.npmjs.com/package/draco3d) wasm decoder (full results in
44
43
  [BENCH.md](https://github.com/verekia/minidraco/blob/main/BENCH.md)):
45
44
 
46
45
  | benchmark | vs draco.js | vs draco3d wasm |
47
46
  | -------------------------------------------------- | --------------- | --------------- |
48
- | single-threaded decode — bun (JSC) | 🟢 1.27× faster | 🟢 1.38× faster |
49
- | single-threaded decode — Chrome (V8) | 🟢 1.29× faster | 🟢 1.11× faster |
50
- | `GLTFLoader.parse`, warm worker pool — Chrome (V8) | 🟢 1.62× faster | ⚪ even |
51
- | `GLTFLoader.parse`, cold first load — Chrome (V8) | 🟢 1.31× faster | ⚪ even |
52
-
53
- Faster than draco.js across the corpus, ahead of the wasm decoder single-threaded, and even with
54
- it in a real `GLTFLoader.parse` with the main thread left free — both warm and on the first load
55
- of a session, where minidraco's worker pool is still JIT-warming while the wasm decoder is
56
- fetching and compiling its module (no `draco_decoder.wasm` to host or download here).
47
+ | single-threaded decode — bun (JSC) | 🟢 1.53× faster | 🟢 1.53× faster |
48
+ | single-threaded decode — Chrome (V8) | 🟢 1.44× faster | 🟢 1.27× faster |
49
+ | `GLTFLoader.parse`, warm worker pool — Chrome (V8) | 🟢 1.47× faster | 🟢 1.03× faster |
50
+ | `GLTFLoader.parse`, cold first load — Chrome (V8) | 🟢 1.42× faster | 🟢 1.26× faster |
57
51
 
58
52
  ## Download size
59
53
 
60
- Over the wire (brotli): **~23 KB** ships in your app bundle. With the worker pool on (default) the
61
- browser also fetches a **~22 KB** worker chunk on the first decode — **~45 KB** total; `workers: false`
62
- skips that fetch. **draco.js ~22 KB**, **draco3d wasm ~76 KB** — the wasm is a separate file you
63
- must host, while the JS decoders ship inside your bundle.
54
+ | download (brotli) | minidraco | vs draco.js | vs draco3d wasm |
55
+ | ----------------------------- | --------- | ------------------------ | ------------------------ |
56
+ | single-threaded (default) | 21 KB | 🟢 1.04× smaller (22 KB) | 🟢 3.82× smaller (81 KB) |
57
+ | worker pool (`workers: true`) | 44 KB | 🟢 not supported | 🟢 1.84× smaller (81 KB) |
64
58
 
65
59
  ## Monorepo
66
60
 
@@ -76,5 +70,5 @@ bun run bench # cross-decoder benchmark
76
70
 
77
71
  ## License
78
72
 
79
- MIT — derived from [mrdoob/draco.js](https://github.com/mrdoob/draco.js) (MIT), implementing
73
+ MIT — initially derived from [mrdoob/draco.js](https://github.com/mrdoob/draco.js) (MIT), implementing
80
74
  Google's [Draco](https://github.com/google/draco) bitstream (Apache-2.0).
package/dist/index.d.ts CHANGED
@@ -1,12 +1,8 @@
1
1
  declare class DataBuffer {
2
2
  _data: Uint8Array;
3
- constructor();
4
- update(data: Uint8Array | ArrayBufferView | ArrayBuffer | null | undefined, size: number, offset?: number): boolean;
5
- resize(newSize: number): void;
6
- adoptScratch(size: number): void;
7
- write(bytePos: number, inArray: Uint8Array | ArrayBufferView | ArrayBuffer, dataSize: number): void;
3
+ update(data: Uint8Array | null, size: number): void;
4
+ write(bytePos: number, inArray: Uint8Array, dataSize: number): void;
8
5
  get data(): Uint8Array;
9
- get dataSize(): number;
10
6
  _resize(newSize: number): void;
11
7
  }
12
8
 
@@ -28,10 +24,7 @@ declare class GeometryAttribute {
28
24
  _byteOffset: number;
29
25
  _attributeType: number;
30
26
  _uniqueId: number;
31
- constructor();
32
27
  init(attributeType: number, buffer: DataBuffer | null, numComponents: number, dataType: number, normalized: boolean, byteStride: number, byteOffset: number): void;
33
- getAddress(attIndex: number): Uint8Array;
34
- copyFrom(srcAtt: GeometryAttribute): boolean;
35
28
  resetBuffer(buffer: DataBuffer, byteStride: number, byteOffset: number): void;
36
29
  get attributeType(): number;
37
30
  get dataType(): number;
@@ -43,72 +36,52 @@ declare class GeometryAttribute {
43
36
  set uniqueId(id: number);
44
37
  }
45
38
 
46
- declare class AttributeTransformData {
47
- _transformType: number;
48
- _bytes: Uint8Array;
49
- _view: DataView;
50
- _size: number;
51
- constructor();
52
- get transformType(): number;
53
- set transformType(type: number);
54
- get dataSize(): number;
55
- get data(): Uint8Array;
56
- _reserve(sizeNeeded: number): void;
57
- setParameterValue(byteOffset: number, value: number, type: string): void;
58
- appendParameterValue(value: number, type: string): void;
59
- _typeSize(type: string): number;
60
- }
61
-
62
39
  type ExtractTypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
40
+ type ViewCtor = (new (buffer: ArrayBufferLike) => ExtractTypedArray) & {
41
+ BYTES_PER_ELEMENT: number;
42
+ };
63
43
  declare class PointAttribute extends GeometryAttribute {
64
44
  _identityMapping: boolean;
65
45
  _numUniqueEntries: number;
66
46
  _indicesMap: number[] | Uint32Array;
67
47
  _attributeBuffer: DataBuffer | null;
68
- _attributeTransformData: AttributeTransformData | null;
69
- _cachedFloat32View?: Float32Array;
70
- _cachedFloat32Buffer?: ArrayBufferLike;
71
- _cachedInt32View?: Int32Array;
72
- _cachedInt32Buffer?: ArrayBufferLike;
73
- _cachedUint32View?: Uint32Array;
74
- _cachedUint32Buffer?: ArrayBufferLike;
75
- _cachedUint16View?: Uint16Array;
76
- _cachedUint16Buffer?: ArrayBufferLike;
77
- _cachedInt16View?: Int16Array;
78
- _cachedInt16Buffer?: ArrayBufferLike;
79
- _cachedUint8View?: Uint8Array;
80
- _cachedUint8Buffer?: ArrayBufferLike;
81
- _cachedInt8View?: Int8Array;
82
- _cachedInt8Buffer?: ArrayBufferLike;
83
- _cachedFloat64View?: Float64Array;
84
- _cachedFloat64Buffer?: ArrayBufferLike;
85
- _cachedDataView?: DataView;
86
- _cachedDVBuffer?: ArrayBufferLike;
48
+ _cachedViewCtor: ViewCtor | null;
49
+ _cachedViewBuffer: ArrayBufferLike | null;
50
+ _cachedView: ExtractTypedArray | null;
51
+ _lazyKind: number;
52
+ _lazyValues: Int32Array | null;
53
+ _lazyMin: number[];
54
+ _lazyScale: number;
87
55
  constructor(geometryAttribute?: GeometryAttribute);
88
56
  init(attributeType: number, numComponents: number, dataType: number, normalized: boolean, numAttributeValues: number): void;
89
57
  reset(numAttributeValues: number): boolean;
90
- resetScratch(numAttributeValues: number): boolean;
58
+ resetLazy(numAttributeValues: number): void;
59
+ setLazyInteger(values: Int32Array | null): void;
60
+ setLazyQuantized(values: Int32Array | null, minValues: number[], delta: number): void;
61
+ setLazyOctahedron(values: Int32Array | null, scale: number): void;
91
62
  get size(): number;
92
63
  mappedIndex(pointIndex: number): number;
93
64
  get isMappingIdentity(): boolean;
94
65
  get indicesMapSize(): number;
95
66
  get indicesMap(): number[] | Uint32Array;
96
67
  setIdentityMapping(): void;
97
- setExplicitMapping(numPoints: number): void;
98
68
  setExplicitMappingUnfilled(numPoints: number): void;
99
69
  setExplicitMappingShared(map: Uint32Array): void;
100
70
  setExplicitMappingScratch(numPoints: number): void;
101
- setAttributeTransformData(transformData: AttributeTransformData): void;
71
+ _view(Ctor: ViewCtor, bufData: Uint8Array): ExtractTypedArray;
102
72
  convertValue(attIndex: number, outVal: number[] | Int32Array | Uint32Array | Float32Array | Float64Array): void;
103
73
  extractTo<C extends new (length: number) => ExtractTypedArray>(OutputTypedArray: C, numPoints: number): InstanceType<C>;
104
- copyFrom(srcAtt: PointAttribute): void;
74
+ _lazyMap(numPoints: number): Uint32Array;
75
+ _lazyFloatValues(): Int32Array;
76
+ _extractQuantized(out: ExtractTypedArray, numPoints: number): void;
77
+ _extractOctahedron(out: ExtractTypedArray, numPoints: number): void;
78
+ _extractInteger(out: ExtractTypedArray, numPoints: number): void;
105
79
  }
106
80
 
107
81
  declare class PointCloud {
108
82
  num_points_: number;
109
83
  attributes_: (PointAttribute | null)[];
110
84
  named_attribute_index_: number[][];
111
- constructor();
112
85
  numNamedAttributes(type: number): number;
113
86
  getNamedAttributeId(type: number, i?: number): number;
114
87
  getNamedAttribute(type: number, i?: number): PointAttribute | null;
@@ -123,16 +96,10 @@ declare class PointCloud {
123
96
  }
124
97
 
125
98
  declare class Mesh extends PointCloud {
126
- faces_: Int32Array;
99
+ faces_: Int32Array<ArrayBuffer>;
127
100
  numFaces_: number;
128
- attribute_data_: {
129
- elementType: number;
130
- }[];
131
- constructor();
132
101
  setNumFaces(numFaces: number): void;
133
102
  numFaces(): number;
134
- face(faceId: number): number[];
135
- setAttribute(attId: number, pa: PointAttribute): void;
136
103
  }
137
104
 
138
105
  declare const decodeDracoMesh: (data: Uint8Array) => Mesh;