ugly-game 0.15.64 → 0.15.65

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.
@@ -1,2 +1,15 @@
1
- export declare function encodeGpuGeometry(raw: Uint8Array, precisionBits?: number): Promise<Uint8Array>;
1
+ /**
2
+ * Bits kept per vertex stream when precision is reduced. One number applies to every stream; an
3
+ * object sets them apart, because they need very different precision: a world position spans
4
+ * kilometres, a unit normal or a 0..1 colour does not, and at a shared 18 bits the normals and
5
+ * colours were most of a cooked mesh's bytes. The decoder reverses the same exponential filter
6
+ * whatever the bit count, so files cooked either way read with no format change.
7
+ */
8
+ export type GpuGeometryPrecision = number | {
9
+ position: number;
10
+ normal: number;
11
+ color: number;
12
+ uv: number;
13
+ };
14
+ export declare function encodeGpuGeometry(raw: Uint8Array, precisionBits?: GpuGeometryPrecision): Promise<Uint8Array>;
2
15
  export declare function decodeGpuGeometry(packed: Uint8Array): Promise<Uint8Array>;
@@ -3,10 +3,16 @@
3
3
  * without topology, color, normal or layout rebuilding. */
4
4
  import { MeshoptEncoder, MeshoptDecoder } from 'meshoptimizer';
5
5
  export async function encodeGpuGeometry(raw, precisionBits = 0) {
6
- if (precisionBits &&
7
- (!Number.isInteger(precisionBits) ||
8
- precisionBits < 12 ||
9
- precisionBits > 24))
6
+ const bits = typeof precisionBits === 'number'
7
+ ? [precisionBits, precisionBits, precisionBits, precisionBits]
8
+ : [
9
+ precisionBits.position,
10
+ precisionBits.normal,
11
+ precisionBits.color,
12
+ precisionBits.uv,
13
+ ];
14
+ const reduced = bits.some((b) => b !== 0);
15
+ if (reduced && bits.some((b) => !Number.isInteger(b) || b < 8 || b > 24))
10
16
  throw new Error('Unsupported cook precision');
11
17
  await MeshoptEncoder.ready;
12
18
  const h = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);
@@ -22,8 +28,9 @@ export async function encodeGpuGeometry(raw, precisionBits = 0) {
22
28
  ]) {
23
29
  const bytes = raw.subarray(offset, offset + count * stride);
24
30
  const indexStream = streamIndex++ === 4;
25
- const filtered = precisionBits && !indexStream && count
26
- ? MeshoptEncoder.encodeFilterExp(new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), count, stride, precisionBits, 'SharedComponent')
31
+ const streamBits = indexStream ? 0 : bits[streamIndex - 1];
32
+ const filtered = reduced && !indexStream && count
33
+ ? MeshoptEncoder.encodeFilterExp(new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), count, stride, streamBits, 'SharedComponent')
27
34
  : bytes;
28
35
  streams.push(count
29
36
  ? indexStream
@@ -36,7 +43,7 @@ export async function encodeGpuGeometry(raw, precisionBits = 0) {
36
43
  result.set(raw.subarray(0, 32));
37
44
  const header = new DataView(result.buffer);
38
45
  header.setUint32(0, 0x32595047, true);
39
- header.setUint32(20, precisionBits ? 1 : 0, true);
46
+ header.setUint32(20, reduced ? 1 : 0, true);
40
47
  header.setUint32(24, 1, true);
41
48
  offset = 64;
42
49
  streams.forEach((stream, i) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.64",
3
+ "version": "0.15.65",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {