minidraco 0.5.0 → 0.6.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,12 @@ 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`, no cast needed. Decoding runs on the main thread by default;
19
+ opt into a worker pool (with a main-thread fallback) to keep it free:
20
20
 
21
21
  ```ts
22
- new MinidracoLoader({ workers: false }) // decode on the main thread
23
- new MinidracoLoader({ workerLimit: 8 }) // pool size (default 4)
22
+ new MinidracoLoader({ workers: true }) // decode in a pool of 4 workers
23
+ new MinidracoLoader({ workerLimit: 8 }) // pool of 8
24
24
  ```
25
25
 
26
26
  Or decode a raw bitstream without Three.js:
@@ -45,22 +45,30 @@ Median across an 18-model corpus vs [draco.js](https://github.com/mrdoob/draco.j
45
45
 
46
46
  | benchmark | vs draco.js | vs draco3d wasm |
47
47
  | -------------------------------------------------- | --------------- | --------------- |
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 |
48
+ | single-threaded decode — bun (JSC) | 🟢 1.37× faster | 🟢 1.49× faster |
49
+ | single-threaded decode — Chrome (V8) | 🟢 1.41× faster | 🟢 1.26× faster |
50
+ | `GLTFLoader.parse`, warm worker pool — Chrome (V8) | 🟢 1.45× faster | 🟢 1.03× faster |
51
+ | `GLTFLoader.parse`, cold first load — Chrome (V8) | 🟢 1.37× faster | 🟢 1.23× faster |
52
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).
53
+ Faster than draco.js across the corpus, ahead of the wasm decoder single-threaded, and level with
54
+ it in a real `GLTFLoader.parse` with `workers: true` and the main thread left free — warm, and
55
+ level to ahead on the first load of a session (cold numbers swing run to run), where minidraco's
56
+ worker pool is still JIT-warming while the wasm decoder is fetching and compiling its module (no
57
+ `draco_decoder.wasm` to host or download here).
57
58
 
58
59
  ## Download size
59
60
 
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.
61
+ Minified + brotli, vs the same two decoders (regenerate with `bun run sizes`):
62
+
63
+ | download (brotli) | minidraco | vs draco.js | vs draco3d wasm |
64
+ | ----------------------------- | --------- | ---------------- | ----------------------- |
65
+ | single-threaded (default) | 22 KB | ⚪ even (22 KB) | 🟢 3.7× smaller (81 KB) |
66
+ | worker pool (`workers: true`) | 45 KB | 🟢 not supported | 🟢 1.8× smaller (81 KB) |
67
+
68
+ With `workers: true` the browser also fetches the pool module and a worker chunk holding a second
69
+ copy of the decoder on the first decode. draco.js has no worker pool. The wasm path ships three's
70
+ `DRACOLoader` in your bundle and fetches the wrapper and `draco_decoder.wasm`, which you must
71
+ host, before the first decode.
64
72
 
65
73
  ## Monorepo
66
74
 
package/dist/index.d.ts CHANGED
@@ -1,12 +1,9 @@
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;
3
+ update(data: Uint8Array | null, size: number): void;
6
4
  adoptScratch(size: number): void;
7
- write(bytePos: number, inArray: Uint8Array | ArrayBufferView | ArrayBuffer, dataSize: number): void;
5
+ write(bytePos: number, inArray: Uint8Array, dataSize: number): void;
8
6
  get data(): Uint8Array;
9
- get dataSize(): number;
10
7
  _resize(newSize: number): void;
11
8
  }
12
9
 
@@ -28,10 +25,7 @@ declare class GeometryAttribute {
28
25
  _byteOffset: number;
29
26
  _attributeType: number;
30
27
  _uniqueId: number;
31
- constructor();
32
28
  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
29
  resetBuffer(buffer: DataBuffer, byteStride: number, byteOffset: number): void;
36
30
  get attributeType(): number;
37
31
  get dataType(): number;
@@ -44,46 +38,25 @@ declare class GeometryAttribute {
44
38
  }
45
39
 
46
40
  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;
41
+ transformType: number;
42
+ _values: number[];
43
+ _types: string[];
58
44
  appendParameterValue(value: number, type: string): void;
59
- _typeSize(type: string): number;
60
45
  }
61
46
 
62
47
  type ExtractTypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
48
+ type ViewCtor = (new (buffer: ArrayBufferLike) => ExtractTypedArray) & {
49
+ BYTES_PER_ELEMENT: number;
50
+ };
63
51
  declare class PointAttribute extends GeometryAttribute {
64
52
  _identityMapping: boolean;
65
53
  _numUniqueEntries: number;
66
54
  _indicesMap: number[] | Uint32Array;
67
55
  _attributeBuffer: DataBuffer | null;
68
56
  _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;
57
+ _cachedViewCtor: ViewCtor | null;
58
+ _cachedViewBuffer: ArrayBufferLike | null;
59
+ _cachedView: ExtractTypedArray | null;
87
60
  constructor(geometryAttribute?: GeometryAttribute);
88
61
  init(attributeType: number, numComponents: number, dataType: number, normalized: boolean, numAttributeValues: number): void;
89
62
  reset(numAttributeValues: number): boolean;
@@ -94,21 +67,19 @@ declare class PointAttribute extends GeometryAttribute {
94
67
  get indicesMapSize(): number;
95
68
  get indicesMap(): number[] | Uint32Array;
96
69
  setIdentityMapping(): void;
97
- setExplicitMapping(numPoints: number): void;
98
70
  setExplicitMappingUnfilled(numPoints: number): void;
99
71
  setExplicitMappingShared(map: Uint32Array): void;
100
72
  setExplicitMappingScratch(numPoints: number): void;
101
73
  setAttributeTransformData(transformData: AttributeTransformData): void;
74
+ _view(Ctor: ViewCtor, bufData: Uint8Array): ExtractTypedArray;
102
75
  convertValue(attIndex: number, outVal: number[] | Int32Array | Uint32Array | Float32Array | Float64Array): void;
103
76
  extractTo<C extends new (length: number) => ExtractTypedArray>(OutputTypedArray: C, numPoints: number): InstanceType<C>;
104
- copyFrom(srcAtt: PointAttribute): void;
105
77
  }
106
78
 
107
79
  declare class PointCloud {
108
80
  num_points_: number;
109
81
  attributes_: (PointAttribute | null)[];
110
82
  named_attribute_index_: number[][];
111
- constructor();
112
83
  numNamedAttributes(type: number): number;
113
84
  getNamedAttributeId(type: number, i?: number): number;
114
85
  getNamedAttribute(type: number, i?: number): PointAttribute | null;
@@ -123,16 +94,10 @@ declare class PointCloud {
123
94
  }
124
95
 
125
96
  declare class Mesh extends PointCloud {
126
- faces_: Int32Array;
97
+ faces_: Int32Array<ArrayBuffer>;
127
98
  numFaces_: number;
128
- attribute_data_: {
129
- elementType: number;
130
- }[];
131
- constructor();
132
99
  setNumFaces(numFaces: number): void;
133
100
  numFaces(): number;
134
- face(faceId: number): number[];
135
- setAttribute(attId: number, pa: PointAttribute): void;
136
101
  }
137
102
 
138
103
  declare const decodeDracoMesh: (data: Uint8Array) => Mesh;