ugly-game 0.15.63 → 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.
- package/dist/assets/gpuGeometry.d.ts +14 -1
- package/dist/assets/gpuGeometry.js +14 -7
- package/dist/assets/gpuProps.d.ts +8 -2
- package/dist/assets/gpuProps.js +15 -1
- package/package.json +18 -17
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
precisionBits
|
|
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
|
|
26
|
-
|
|
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,
|
|
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) => {
|
|
@@ -350,8 +350,14 @@ export declare class GpuPropsRenderer {
|
|
|
350
350
|
* getting this wrong is the classic washed-out-albedo bug.
|
|
351
351
|
*/
|
|
352
352
|
private uploadAlbedo;
|
|
353
|
-
/**
|
|
354
|
-
|
|
353
|
+
/**
|
|
354
|
+
* Change scalar PBR properties without rebuilding geometry or texture bindings.
|
|
355
|
+
*
|
|
356
|
+
* `alpha` fades a model in place (a body fading away to show what is inside it). Below 1 the
|
|
357
|
+
* model moves to the blended pipeline and out of shadowPass from the next frame, exactly as if
|
|
358
|
+
* `setModels` had been given that alpha; back at 1 it is opaque and casts again.
|
|
359
|
+
*/
|
|
360
|
+
setMaterial(model: number, surface: Pick<PropMesh, 'alpha' | 'roughness' | 'metalness' | 'clearcoat' | 'clearcoatRoughness' | 'reflectionStrength' | 'specularIntensity' | 'metalFlakes' | 'flakeScale' | 'pearlStrength'>): void;
|
|
355
361
|
setModels(meshes: PropMesh[]): void;
|
|
356
362
|
/**
|
|
357
363
|
* Group instances by model and upload the per-model instance buffers.
|
package/dist/assets/gpuProps.js
CHANGED
|
@@ -981,7 +981,13 @@ export class GpuPropsRenderer {
|
|
|
981
981
|
}
|
|
982
982
|
return tex;
|
|
983
983
|
}
|
|
984
|
-
/**
|
|
984
|
+
/**
|
|
985
|
+
* Change scalar PBR properties without rebuilding geometry or texture bindings.
|
|
986
|
+
*
|
|
987
|
+
* `alpha` fades a model in place (a body fading away to show what is inside it). Below 1 the
|
|
988
|
+
* model moves to the blended pipeline and out of shadowPass from the next frame, exactly as if
|
|
989
|
+
* `setModels` had been given that alpha; back at 1 it is opaque and casts again.
|
|
990
|
+
*/
|
|
985
991
|
setMaterial(model, surface) {
|
|
986
992
|
const packed = this.models.at(model);
|
|
987
993
|
if (model < 0 || !packed)
|
|
@@ -1010,6 +1016,14 @@ export class GpuPropsRenderer {
|
|
|
1010
1016
|
packed.materialValues[index] = bounded;
|
|
1011
1017
|
changed = true;
|
|
1012
1018
|
}
|
|
1019
|
+
if (surface.alpha !== undefined && Number.isFinite(surface.alpha)) {
|
|
1020
|
+
const alpha = Math.max(0, Math.min(1, surface.alpha));
|
|
1021
|
+
if (Math.abs(packed.alpha - alpha) >= 1e-7) {
|
|
1022
|
+
packed.alpha = alpha;
|
|
1023
|
+
packed.materialValues[0] = alpha;
|
|
1024
|
+
changed = true;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1013
1027
|
if (changed)
|
|
1014
1028
|
this.device.queue.writeBuffer(packed.matBuf, 0, packed.materialValues);
|
|
1015
1029
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ugly-game",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.65",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -15,6 +15,22 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"preinstall": "npx only-allow pnpm",
|
|
20
|
+
"build": "tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/",
|
|
21
|
+
"lint": "ugly-app lint",
|
|
22
|
+
"lint:fix": "ugly-app lint --fix",
|
|
23
|
+
"test": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/*.test.mts && pnpm run test:gpu-skin",
|
|
24
|
+
"test:flight": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/flight*.test.mts",
|
|
25
|
+
"test:flight-browser": "playwright test -c playwright.flight.config.ts",
|
|
26
|
+
"test:props-browser": "playwright test -c playwright.props.config.ts",
|
|
27
|
+
"test:flight-perf": "playwright test -c playwright.flight.config.ts --grep 'CPU and retained-memory'",
|
|
28
|
+
"test:types": "tsc -p tsconfig.test.json",
|
|
29
|
+
"test:package-types": "node tools/packageTypesSmoke.mjs",
|
|
30
|
+
"pretty": "prettier --write .",
|
|
31
|
+
"prepublishOnly": "pnpm run pretty && ugly-app lint && tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/",
|
|
32
|
+
"test:gpu-skin": "node --experimental-transform-types --import ./tools/tsResolve.mjs --test src/assets/gpuSkin.test.mts"
|
|
33
|
+
},
|
|
18
34
|
"dependencies": {
|
|
19
35
|
"@webgpu/types": "^0.1.40",
|
|
20
36
|
"meshoptimizer": "^1.2.0"
|
|
@@ -30,20 +46,5 @@
|
|
|
30
46
|
"typescript": "^5.6.0",
|
|
31
47
|
"ugly-app": "^0.1.841",
|
|
32
48
|
"wesl": "0.7.28"
|
|
33
|
-
},
|
|
34
|
-
"scripts": {
|
|
35
|
-
"preinstall": "npx only-allow pnpm",
|
|
36
|
-
"build": "tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/",
|
|
37
|
-
"lint": "ugly-app lint",
|
|
38
|
-
"lint:fix": "ugly-app lint --fix",
|
|
39
|
-
"test": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/*.test.mts && pnpm run test:gpu-skin",
|
|
40
|
-
"test:flight": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/flight*.test.mts",
|
|
41
|
-
"test:flight-browser": "playwright test -c playwright.flight.config.ts",
|
|
42
|
-
"test:props-browser": "playwright test -c playwright.props.config.ts",
|
|
43
|
-
"test:flight-perf": "playwright test -c playwright.flight.config.ts --grep 'CPU and retained-memory'",
|
|
44
|
-
"test:types": "tsc -p tsconfig.test.json",
|
|
45
|
-
"test:package-types": "node tools/packageTypesSmoke.mjs",
|
|
46
|
-
"pretty": "prettier --write .",
|
|
47
|
-
"test:gpu-skin": "node --experimental-transform-types --import ./tools/tsResolve.mjs --test src/assets/gpuSkin.test.mts"
|
|
48
49
|
}
|
|
49
|
-
}
|
|
50
|
+
}
|