@bendyline/molen-client 0.0.8 → 0.0.10
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 +1 -0
- package/dist/aircraft.d.mts +11 -4
- package/dist/aircraft.mjs +56 -10
- package/dist/audio.d.mts +9 -0
- package/dist/audio.mjs +68 -10
- package/dist/camera-track.d.mts +1 -1
- package/dist/index.d.mts +6 -2
- package/dist/index.mjs +260 -28
- package/dist/{input-CfbIm1MS.mjs → input-BVZjf4T-.mjs} +6 -2
- package/dist/instruments.d.mts +63 -0
- package/dist/instruments.mjs +137 -0
- package/dist/model-signals-BpeXhsim.d.mts +25 -0
- package/dist/model-signals-DLgvjBeZ.mjs +172 -0
- package/dist/navigation.d.mts +25 -2
- package/dist/navigation.mjs +231 -43
- package/dist/{renderer-DPT7XAYh.d.mts → renderer-CtEtmwJG.d.mts} +75 -2
- package/dist/text.d.mts +24 -0
- package/dist/text.mjs +62 -0
- package/dist/{vehicle-interior-0o-8QV_-.d.mts → vehicle-interior-BgcC750p.d.mts} +2 -2
- package/dist/{vehicle-interior-DZT0HmWC.mjs → vehicle-interior-DfpZwWEh.mjs} +4 -1
- package/dist/vehicles.d.mts +20 -4
- package/dist/vehicles.mjs +43 -10
- package/dist/webgpu-ambient-occlusion-9gnp3qOY.mjs +126 -0
- package/dist/{webgpu-driver-Bt2mvZk9.mjs → webgpu-driver-BQnmPRqs.mjs} +41 -1
- package/dist/{webgpu-scene-optimizer-DKRyHBRC.mjs → webgpu-scene-optimizer-Cup4Yvzs.mjs} +9 -2
- package/package.json +12 -4
- package/dist/model-signals-DVlLyP-w.d.mts +0 -17
- package/dist/model-signals-Gw1COJfo.mjs +0 -53
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { t as createModelSignalVisual } from "./model-signals-
|
|
1
|
+
import { t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
|
|
2
2
|
//#region src/vehicle-interior.ts
|
|
3
3
|
/** Vehicle convenience wrapper around the platform's model-signal binding system. */
|
|
4
4
|
function createVehicleInteriorVisual(model, spec) {
|
|
5
5
|
const visual = createModelSignalVisual(model, spec);
|
|
6
6
|
return {
|
|
7
7
|
...visual,
|
|
8
|
+
get missingSignals() {
|
|
9
|
+
return visual.missingSignals;
|
|
10
|
+
},
|
|
8
11
|
missingNodes: [...new Set([...spec.nodes.filter((name) => !model.getObjectByName(name)), ...visual.missingNodes])]
|
|
9
12
|
};
|
|
10
13
|
}
|
package/dist/vehicles.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as ModelSignalVisual } from "./model-signals-BpeXhsim.mjs";
|
|
2
|
+
import { a as VehicleCameraPose, i as VehicleCameraOptions, n as VehicleInteriorVisual, o as vehicleCameraPose, r as createVehicleInteriorVisual, t as VehicleInteriorSignals } from "./vehicle-interior-BgcC750p.mjs";
|
|
2
3
|
import { VehicleData, VehiclePlacement } from "@bendyline/molen-schema";
|
|
3
4
|
import * as THREE from "three";
|
|
4
5
|
|
|
@@ -6,11 +7,26 @@ import * as THREE from "three";
|
|
|
6
7
|
interface VehicleVisual {
|
|
7
8
|
object: THREE.Object3D;
|
|
8
9
|
interior?: VehicleInteriorVisual;
|
|
9
|
-
|
|
10
|
+
/** The visual's exterior `animation` bindings, posed from the same signals as the interior. */
|
|
11
|
+
animation?: ModelSignalVisual;
|
|
12
|
+
update(steer: number, wheelAngle: number, signals?: VehicleInteriorSignals, timeSeconds?: number): void;
|
|
10
13
|
dispose(): void;
|
|
11
14
|
}
|
|
12
|
-
/**
|
|
13
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Bind a loaded entity GLB to generic wheel/steering animation using external node names.
|
|
17
|
+
*
|
|
18
|
+
* The simulation leans the whole model with its sprung body (`vehicleState.bodyRoll` and
|
|
19
|
+
* `bodyPitch`). Given those as signals, the wheels take up the lean as suspension travel instead:
|
|
20
|
+
* each moves along the body's up axis to keep its centre at its resting height, so the outside
|
|
21
|
+
* wheels stay on the road in a turn rather than sinking into it.
|
|
22
|
+
*/
|
|
23
|
+
declare function createVehicleVisual(model: THREE.Object3D, vehicle: Pick<VehicleData, "visual"> & {
|
|
24
|
+
color?: string;
|
|
25
|
+
spec?: {
|
|
26
|
+
length: number;
|
|
27
|
+
cycle?: unknown;
|
|
28
|
+
};
|
|
29
|
+
}): VehicleVisual;
|
|
14
30
|
/** The dimensions a vehicle proxy is built from (a `VehicleSpec` satisfies it). */
|
|
15
31
|
interface VehicleProxyDimensions {
|
|
16
32
|
width: number;
|
package/dist/vehicles.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
|
|
2
|
+
import { t as createVehicleInteriorVisual } from "./vehicle-interior-DfpZwWEh.mjs";
|
|
2
3
|
import * as THREE from "three";
|
|
3
4
|
import { mergeGeometries } from "three/addons/utils/BufferGeometryUtils.js";
|
|
4
5
|
//#region src/vehicle-camera.ts
|
|
@@ -29,9 +30,21 @@ function vehicleCameraPose(transform, spec, options) {
|
|
|
29
30
|
}
|
|
30
31
|
//#endregion
|
|
31
32
|
//#region src/vehicles.ts
|
|
32
|
-
|
|
33
|
+
const bodyLean = new THREE.Quaternion();
|
|
34
|
+
const leanEuler = new THREE.Euler(0, 0, 0, "YXZ");
|
|
35
|
+
const leaned = new THREE.Vector3();
|
|
36
|
+
const travel = new THREE.Vector3();
|
|
37
|
+
/**
|
|
38
|
+
* Bind a loaded entity GLB to generic wheel/steering animation using external node names.
|
|
39
|
+
*
|
|
40
|
+
* The simulation leans the whole model with its sprung body (`vehicleState.bodyRoll` and
|
|
41
|
+
* `bodyPitch`). Given those as signals, the wheels take up the lean as suspension travel instead:
|
|
42
|
+
* each moves along the body's up axis to keep its centre at its resting height, so the outside
|
|
43
|
+
* wheels stay on the road in a turn rather than sinking into it.
|
|
44
|
+
*/
|
|
33
45
|
function createVehicleVisual(model, vehicle) {
|
|
34
46
|
const interior = vehicle.visual.interior === void 0 ? void 0 : createVehicleInteriorVisual(model, vehicle.visual.interior);
|
|
47
|
+
const animation = vehicle.visual.animation === void 0 ? void 0 : createModelSignalVisual(model, vehicle.visual.animation);
|
|
35
48
|
const nodes = /* @__PURE__ */ new Map();
|
|
36
49
|
const frontWheels = new Set(vehicle.visual.frontWheelNodes);
|
|
37
50
|
const wheels = [];
|
|
@@ -53,27 +66,47 @@ function createVehicleVisual(model, vehicle) {
|
|
|
53
66
|
object.material = Array.isArray(object.material) ? cloned : cloned[0];
|
|
54
67
|
}
|
|
55
68
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
model.updateMatrixWorld(true);
|
|
70
|
+
const toModel = new THREE.Matrix4().copy(model.matrixWorld).invert();
|
|
71
|
+
for (const name of vehicle.visual.wheelNodes) for (const node of nodes.get(name) ?? []) {
|
|
72
|
+
const parent = new THREE.Matrix4().multiplyMatrices(toModel, node.parent?.matrixWorld ?? model.matrixWorld);
|
|
73
|
+
wheels.push({
|
|
74
|
+
node,
|
|
75
|
+
front: frontWheels.has(name),
|
|
76
|
+
baseY: node.rotation.y,
|
|
77
|
+
rest: node.position.clone(),
|
|
78
|
+
center: node.getWorldPosition(new THREE.Vector3()).applyMatrix4(toModel),
|
|
79
|
+
toParent: new THREE.Quaternion().setFromRotationMatrix(parent).invert()
|
|
80
|
+
});
|
|
81
|
+
}
|
|
61
82
|
if (vehicle.visual.steeringWheelNode !== void 0) steeringWheel = nodes.get(vehicle.visual.steeringWheelNode)?.[0];
|
|
62
83
|
return {
|
|
63
84
|
object: model,
|
|
64
85
|
interior,
|
|
65
|
-
|
|
86
|
+
animation,
|
|
87
|
+
update(steer, angle, signals, timeSeconds) {
|
|
88
|
+
const roll = signals?.bodyRoll ?? 0;
|
|
89
|
+
const pitch = signals?.bodyPitch ?? 0;
|
|
90
|
+
const lean = Number.isFinite(roll) && Number.isFinite(pitch) && (roll !== 0 || pitch !== 0);
|
|
91
|
+
if (lean) bodyLean.setFromEuler(leanEuler.set(pitch, 0, roll));
|
|
66
92
|
for (const wheel of wheels) {
|
|
67
93
|
wheel.node.rotation.y = wheel.baseY + (wheel.front ? -steer : 0);
|
|
68
94
|
const spinner = wheel.node.children[0] ?? wheel.node;
|
|
69
95
|
spinner.rotation.x = angle;
|
|
96
|
+
wheel.node.position.copy(wheel.rest);
|
|
97
|
+
if (!lean || vehicle.spec?.cycle !== void 0) continue;
|
|
98
|
+
const up = travel.set(0, 1, 0).applyQuaternion(bodyLean).y;
|
|
99
|
+
const lift = (wheel.center.y - leaned.copy(wheel.center).applyQuaternion(bodyLean).y) / up;
|
|
100
|
+
wheel.node.position.add(travel.set(0, lift, 0).applyQuaternion(wheel.toParent));
|
|
70
101
|
}
|
|
71
102
|
if (interior === void 0 && steeringWheel !== void 0) steeringWheel.rotation.z = steer * 2.5;
|
|
72
|
-
|
|
103
|
+
const telemetry = {
|
|
73
104
|
steering: steer,
|
|
74
105
|
wheelAngle: angle,
|
|
75
106
|
...signals
|
|
76
|
-
}
|
|
107
|
+
};
|
|
108
|
+
interior?.update(telemetry, timeSeconds);
|
|
109
|
+
animation?.update(telemetry, timeSeconds);
|
|
77
110
|
},
|
|
78
111
|
dispose() {
|
|
79
112
|
const geometries = /* @__PURE__ */ new Set();
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
//#region src/three/webgpu-ambient-occlusion.ts
|
|
3
|
+
async function createWebGpuAmbientOcclusion(renderer, scene, camera, options = {}) {
|
|
4
|
+
const [webgpu, tsl, gtao] = await Promise.all([
|
|
5
|
+
import("three/webgpu"),
|
|
6
|
+
import("three/tsl"),
|
|
7
|
+
import("three/addons/tsl/display/GTAONode.js")
|
|
8
|
+
]);
|
|
9
|
+
const { abs, clamp, colorToDirection, directionToColor, float, Fn, max, mix, mrt, normalView, output, perspectiveDepthToViewZ, rtt, sample, screenUV, select, texture, uniform, uv, vec2, vec4 } = tsl;
|
|
10
|
+
const depthTexture = new THREE.DepthTexture(1, 1);
|
|
11
|
+
if (renderer.reversedDepthBuffer) depthTexture.type = THREE.FloatType;
|
|
12
|
+
const target = new webgpu.RenderTarget(1, 1, {
|
|
13
|
+
count: 2,
|
|
14
|
+
samples: renderer.samples,
|
|
15
|
+
type: THREE.HalfFloatType,
|
|
16
|
+
depthTexture
|
|
17
|
+
});
|
|
18
|
+
target.textures[0].name = "output";
|
|
19
|
+
const normalTexture = target.textures[1];
|
|
20
|
+
normalTexture.name = "normal";
|
|
21
|
+
normalTexture.type = THREE.UnsignedByteType;
|
|
22
|
+
const normals = mrt({
|
|
23
|
+
output,
|
|
24
|
+
normal: directionToColor(normalView)
|
|
25
|
+
});
|
|
26
|
+
const image = texture(target.textures[0]);
|
|
27
|
+
const depth = texture(depthTexture);
|
|
28
|
+
const packed = texture(normalTexture);
|
|
29
|
+
const normal = sample((uv) => colorToDirection(packed.sample(uv)));
|
|
30
|
+
const lens = camera;
|
|
31
|
+
const nearPlane = uniform(lens.near);
|
|
32
|
+
const farPlane = uniform(lens.far);
|
|
33
|
+
const reach = uniform(options.reach ?? 250);
|
|
34
|
+
const meters = (stored) => perspectiveDepthToViewZ(stored, nearPlane, farPlane).negate();
|
|
35
|
+
const viewDepth = (at) => meters(depth.sample(at).r);
|
|
36
|
+
const sceneDepth = sample((uv) => {
|
|
37
|
+
const d = depth.sample(uv).r;
|
|
38
|
+
return vec4(select(meters(d).greaterThan(reach), float(1), d));
|
|
39
|
+
});
|
|
40
|
+
const occlusion = gtao.ao(sceneDepth, normal, camera);
|
|
41
|
+
occlusion.resolutionScale = .5;
|
|
42
|
+
occlusion.radius.value = options.radius ?? 3;
|
|
43
|
+
occlusion.scale.value = 2.5;
|
|
44
|
+
occlusion.distanceFallOff.value = .6;
|
|
45
|
+
occlusion.samples.value = 8;
|
|
46
|
+
const raw = occlusion.getTextureNode();
|
|
47
|
+
const texel = uniform(new THREE.Vector2(1, 1));
|
|
48
|
+
const cleaned = rtt(Fn(() => {
|
|
49
|
+
const at = uv();
|
|
50
|
+
const middle = viewDepth(at).toVar();
|
|
51
|
+
const sum = float(0).toVar();
|
|
52
|
+
const total = float(0).toVar();
|
|
53
|
+
for (const y of [
|
|
54
|
+
-1.5,
|
|
55
|
+
0,
|
|
56
|
+
1.5
|
|
57
|
+
]) for (const x of [
|
|
58
|
+
-1.5,
|
|
59
|
+
0,
|
|
60
|
+
1.5
|
|
61
|
+
]) {
|
|
62
|
+
const tap = at.add(texel.mul(vec2(x, y)));
|
|
63
|
+
const there = viewDepth(tap).toVar();
|
|
64
|
+
const weight = float((x === 0 ? 1 : 2) * (y === 0 ? 1 : 2)).mul(clamp(float(1).sub(abs(there.sub(middle)).div(middle.mul(.08))), 0, 1)).mul(there.lessThanEqual(reach).select(float(1), float(0)));
|
|
65
|
+
sum.addAssign(raw.sample(tap).r.mul(weight));
|
|
66
|
+
total.addAssign(weight);
|
|
67
|
+
}
|
|
68
|
+
return vec4(select(total.greaterThan(0), sum.div(max(total, 1e-4)), float(1)), 0, 0, 1);
|
|
69
|
+
})(), 1, 1);
|
|
70
|
+
const fade = float(1).sub(meters(depth.r).smoothstep(reach.mul(.67), reach));
|
|
71
|
+
const shade = mix(float(1), cleaned.sample(screenUV).r, fade.mul(options.strength ?? .85));
|
|
72
|
+
const pipeline = new webgpu.RenderPipeline(renderer);
|
|
73
|
+
pipeline.outputNode = vec4(image.rgb.mul(shade), image.a);
|
|
74
|
+
const copy = new webgpu.RenderPipeline(renderer);
|
|
75
|
+
copy.outputNode = image;
|
|
76
|
+
const size = new THREE.Vector2();
|
|
77
|
+
const intoTarget = (use) => {
|
|
78
|
+
const previousTarget = renderer.getRenderTarget();
|
|
79
|
+
const previousMrt = renderer.getMRT();
|
|
80
|
+
try {
|
|
81
|
+
renderer.setRenderTarget(target);
|
|
82
|
+
renderer.setMRT(normals);
|
|
83
|
+
return use();
|
|
84
|
+
} finally {
|
|
85
|
+
renderer.setRenderTarget(previousTarget);
|
|
86
|
+
renderer.setMRT(previousMrt);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
compile: (object) => intoTarget(() => renderer.compileAsync(object, camera, scene)),
|
|
91
|
+
render(sky, occlude = true) {
|
|
92
|
+
renderer.getDrawingBufferSize(size);
|
|
93
|
+
nearPlane.value = lens.near;
|
|
94
|
+
farPlane.value = lens.far;
|
|
95
|
+
if (target.width !== size.x || target.height !== size.y) {
|
|
96
|
+
target.setSize(size.x, size.y);
|
|
97
|
+
cleaned.setSize(Math.ceil(size.x / 2), Math.ceil(size.y / 2));
|
|
98
|
+
texel.value.set(1 / Math.max(1, Math.round(size.x / 2)), 1 / Math.max(1, Math.round(size.y / 2)));
|
|
99
|
+
}
|
|
100
|
+
const autoClear = renderer.autoClear;
|
|
101
|
+
try {
|
|
102
|
+
intoTarget(() => {
|
|
103
|
+
renderer.autoClear = true;
|
|
104
|
+
if (sky) {
|
|
105
|
+
renderer.render(sky.scene, sky.camera);
|
|
106
|
+
renderer.autoClear = false;
|
|
107
|
+
renderer.clearDepth();
|
|
108
|
+
}
|
|
109
|
+
renderer.render(scene, camera);
|
|
110
|
+
});
|
|
111
|
+
} finally {
|
|
112
|
+
renderer.autoClear = autoClear;
|
|
113
|
+
}
|
|
114
|
+
(occlude ? pipeline : copy).render();
|
|
115
|
+
},
|
|
116
|
+
dispose() {
|
|
117
|
+
pipeline.dispose();
|
|
118
|
+
copy.dispose();
|
|
119
|
+
occlusion.dispose();
|
|
120
|
+
cleaned.dispose();
|
|
121
|
+
target.dispose();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { createWebGpuAmbientOcclusion };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { n as installWebGpuTimestampGuard } from "./webgpu-frame-timer-Xnuq1Hld.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { instanceIndex, objectGroup } from "three/tsl";
|
|
3
|
+
import * as WebGPU from "three/webgpu";
|
|
4
|
+
import { CanvasTarget, StorageBufferNode, WebGPUBackend, WebGPURenderer } from "three/webgpu";
|
|
3
5
|
//#region src/three/webgpu-depth-bias.ts
|
|
4
6
|
const guardedBackends = /* @__PURE__ */ new WeakSet();
|
|
5
7
|
/**
|
|
@@ -122,6 +124,38 @@ function listenWeakly(ref, material, geometry) {
|
|
|
122
124
|
};
|
|
123
125
|
}
|
|
124
126
|
//#endregion
|
|
127
|
+
//#region src/three/webgpu-shared-instancing.ts
|
|
128
|
+
const patched = /* @__PURE__ */ new WeakSet();
|
|
129
|
+
/**
|
|
130
|
+
* Give every InstancedMesh drawn with one material the same shader. Three reads an InstancedMesh's
|
|
131
|
+
* matrices from a uniform array declared with the batch's instance count and named after its node,
|
|
132
|
+
* so each batch compiled a WGSL module and a GPU pipeline of its own. Streaming worldgen's plant
|
|
133
|
+
* batches in flight made hundreds a minute, and those created mid-frame, synchronously, stalled the
|
|
134
|
+
* browser's GPU process for seconds. A runtime-sized storage buffer under one name makes the shader
|
|
135
|
+
* text identical, and three's pipeline cache serves every batch after the first; matrices upload
|
|
136
|
+
* when the attribute's version changes, as vertex buffers do. Each batch still builds its node
|
|
137
|
+
* state on the CPU, since three keys that by mesh. (Sharing that state across meshes, each render
|
|
138
|
+
* object binding its own mesh's buffers, broke the WebGPU scene optimizer's render bundles: whole
|
|
139
|
+
* buildings stopped drawing.) Applies to WebGPU backends only; the matrices of the previous frame
|
|
140
|
+
* (velocity) keep three's own path.
|
|
141
|
+
*/
|
|
142
|
+
function installWebGpuSharedInstancing(three) {
|
|
143
|
+
const prototype = three.InstanceNode?.prototype;
|
|
144
|
+
const Storage = three.StorageBufferNode;
|
|
145
|
+
const { instanceIndex, objectGroup } = three;
|
|
146
|
+
if (!prototype || patched.has(prototype) || typeof prototype._createInstanceMatrixNode !== "function") return;
|
|
147
|
+
patched.add(prototype);
|
|
148
|
+
const create = prototype._createInstanceMatrixNode;
|
|
149
|
+
prototype._createInstanceMatrixNode = function(assignBuffer, builder) {
|
|
150
|
+
if (!assignBuffer || builder.renderer?.backend?.isWebGPUBackend !== true) return create.call(this, assignBuffer, builder);
|
|
151
|
+
const matrices = this.instanceMatrix;
|
|
152
|
+
const node = new Storage(matrices, "mat4", Math.max(matrices.count, 1));
|
|
153
|
+
node.name = "instanceMatrices";
|
|
154
|
+
node.groupNode = objectGroup;
|
|
155
|
+
return node.element(instanceIndex);
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
125
159
|
//#region src/three/webgpu-driver.ts
|
|
126
160
|
/** Loaded only by the asynchronous backend factory, never by a legacy WebGL-only viewer. */
|
|
127
161
|
async function createWebGpuDriver(options) {
|
|
@@ -144,6 +178,12 @@ async function createWebGpuDriver(options) {
|
|
|
144
178
|
installWebGpuTimestampGuard(renderer);
|
|
145
179
|
installWebGpuDepthBiasGuard(renderer);
|
|
146
180
|
installWebGpuRenderObjectRelease(renderer);
|
|
181
|
+
installWebGpuSharedInstancing({
|
|
182
|
+
InstanceNode: Reflect.get(WebGPU, "InstanceNode"),
|
|
183
|
+
StorageBufferNode,
|
|
184
|
+
instanceIndex,
|
|
185
|
+
objectGroup
|
|
186
|
+
});
|
|
147
187
|
renderer.getContext();
|
|
148
188
|
if (options.canvas !== void 0) {
|
|
149
189
|
const previousTarget = renderer.getCanvasTarget();
|
|
@@ -85,6 +85,8 @@ var WebGpuSceneOptimizer = class {
|
|
|
85
85
|
matrixSamples = /* @__PURE__ */ new WeakMap();
|
|
86
86
|
restoreRefresh;
|
|
87
87
|
materialSamples = /* @__PURE__ */ new Map();
|
|
88
|
+
/** The render each material last refreshed a replayed object in; see the constructor. */
|
|
89
|
+
refreshed = /* @__PURE__ */ new WeakMap();
|
|
88
90
|
videoMaterials = /* @__PURE__ */ new WeakSet();
|
|
89
91
|
materialStates = /* @__PURE__ */ new WeakMap();
|
|
90
92
|
constructor(renderer) {
|
|
@@ -94,9 +96,14 @@ var WebGpuSceneOptimizer = class {
|
|
|
94
96
|
const refresh = nodes.needsRefresh;
|
|
95
97
|
nodes.needsRefresh = (object) => {
|
|
96
98
|
const group = object.bundle;
|
|
97
|
-
if (group !== null && this.groups.has(group) && group.eligible && group.version === group.recordedVersion && !renderer.
|
|
99
|
+
if (group !== null && this.groups.has(group) && group.eligible && group.version === group.recordedVersion && !renderer.getMRT()?.has("velocity")) {
|
|
98
100
|
const monitor = object.getMonitor();
|
|
99
|
-
|
|
101
|
+
const material = object.material;
|
|
102
|
+
if (!monitor.hasAnimation && (monitor.hasNode ? material.userData.bundleStatic === true : monitor.renderObjects.has(object))) {
|
|
103
|
+
const renderId = nodes.nodeFrame.renderId;
|
|
104
|
+
if (this.refreshed.get(material) === renderId) return false;
|
|
105
|
+
this.refreshed.set(material, renderId);
|
|
106
|
+
}
|
|
100
107
|
}
|
|
101
108
|
return refresh.call(nodes, object);
|
|
102
109
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/molen-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"audio"
|
|
30
30
|
],
|
|
31
31
|
"exports": {
|
|
32
|
+
"./text": {
|
|
33
|
+
"types": "./dist/text.d.mts",
|
|
34
|
+
"default": "./dist/text.mjs"
|
|
35
|
+
},
|
|
32
36
|
".": {
|
|
33
37
|
"types": "./dist/index.d.mts",
|
|
34
38
|
"default": "./dist/index.mjs"
|
|
@@ -57,6 +61,10 @@
|
|
|
57
61
|
"types": "./dist/markers.d.mts",
|
|
58
62
|
"default": "./dist/markers.mjs"
|
|
59
63
|
},
|
|
64
|
+
"./instruments": {
|
|
65
|
+
"types": "./dist/instruments.d.mts",
|
|
66
|
+
"default": "./dist/instruments.mjs"
|
|
67
|
+
},
|
|
60
68
|
"./audio": {
|
|
61
69
|
"types": "./dist/audio.d.mts",
|
|
62
70
|
"default": "./dist/audio.mjs"
|
|
@@ -67,9 +75,9 @@
|
|
|
67
75
|
"NOTICE.md"
|
|
68
76
|
],
|
|
69
77
|
"dependencies": {
|
|
70
|
-
"
|
|
71
|
-
"@bendyline/molen-
|
|
72
|
-
"
|
|
78
|
+
"@bendyline/molen-materials": "0.0.9",
|
|
79
|
+
"@bendyline/molen-schema": "0.0.8",
|
|
80
|
+
"zod": "^4.6.5"
|
|
73
81
|
},
|
|
74
82
|
"peerDependencies": {
|
|
75
83
|
"@types/three": ">=0.184.0 <0.187.0",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ModelSignalSource, ModelSignalSpec } from "@bendyline/molen-schema";
|
|
2
|
-
import { Object3D } from "three";
|
|
3
|
-
|
|
4
|
-
//#region src/model-signals.d.ts
|
|
5
|
-
type ModelSignals = Readonly<Record<string, number | undefined>>;
|
|
6
|
-
interface ModelSignalVisual {
|
|
7
|
-
readonly missingNodes: readonly string[];
|
|
8
|
-
update(signals: ModelSignals): void;
|
|
9
|
-
/** Restore authored transforms before removing or replacing bindings. */
|
|
10
|
-
reset(): void;
|
|
11
|
-
}
|
|
12
|
-
/** Read data only: no expressions, evaluation, prototype traversal, or simulation writes. */
|
|
13
|
-
declare function readModelSignals(sources: Readonly<Record<string, ModelSignalSource>> | undefined, readComponent: (name: string) => unknown): ModelSignals;
|
|
14
|
-
/** Model-agnostic; moves existing geometry without creating a cockpit or changing physics. */
|
|
15
|
-
declare function createModelSignalVisual(model: Object3D, spec: ModelSignalSpec): ModelSignalVisual;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { readModelSignals as i, ModelSignals as n, createModelSignalVisual as r, ModelSignalVisual as t };
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
//#region src/model-signals.ts
|
|
2
|
-
/** Read data only: no expressions, evaluation, prototype traversal, or simulation writes. */
|
|
3
|
-
function readModelSignals(sources, readComponent) {
|
|
4
|
-
const signals = Object.create(null);
|
|
5
|
-
for (const [name, source] of Object.entries(sources ?? {})) {
|
|
6
|
-
let value = readComponent(source.component);
|
|
7
|
-
for (const part of source.path) {
|
|
8
|
-
if (value === null || typeof value !== "object" || !Object.hasOwn(value, part)) {
|
|
9
|
-
value = void 0;
|
|
10
|
-
break;
|
|
11
|
-
}
|
|
12
|
-
value = value[part];
|
|
13
|
-
}
|
|
14
|
-
if (typeof value === "boolean") signals[name] = Number(value);
|
|
15
|
-
else if (typeof value === "number" && Number.isFinite(value)) signals[name] = value;
|
|
16
|
-
}
|
|
17
|
-
return signals;
|
|
18
|
-
}
|
|
19
|
-
/** Model-agnostic; moves existing geometry without creating a cockpit or changing physics. */
|
|
20
|
-
function createModelSignalVisual(model, spec) {
|
|
21
|
-
const nodes = /* @__PURE__ */ new Map();
|
|
22
|
-
model.traverse((node) => {
|
|
23
|
-
const matches = nodes.get(node.name) ?? [];
|
|
24
|
-
matches.push(node);
|
|
25
|
-
nodes.set(node.name, matches);
|
|
26
|
-
});
|
|
27
|
-
const missingNodes = [...new Set(spec.bindings.map((b) => b.node))].filter((name) => !nodes.has(name));
|
|
28
|
-
const bindings = spec.bindings.flatMap((binding) => (nodes.get(binding.node) ?? []).map((node) => {
|
|
29
|
-
node.matrixAutoUpdate = true;
|
|
30
|
-
return {
|
|
31
|
-
binding,
|
|
32
|
-
node,
|
|
33
|
-
rest: node[binding.property][binding.axis]
|
|
34
|
-
};
|
|
35
|
-
}));
|
|
36
|
-
return {
|
|
37
|
-
missingNodes,
|
|
38
|
-
update(signals) {
|
|
39
|
-
for (const { binding, node, rest } of bindings) {
|
|
40
|
-
const signal = signals[binding.source];
|
|
41
|
-
if (signal === void 0 || !Number.isFinite(signal)) continue;
|
|
42
|
-
const value = signal * binding.scale + (binding.offset ?? 0);
|
|
43
|
-
if (!Number.isFinite(value)) continue;
|
|
44
|
-
node[binding.property][binding.axis] = rest + Math.max(binding.min ?? -Infinity, Math.min(binding.max ?? Infinity, value));
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
reset() {
|
|
48
|
-
for (const { binding, node, rest } of bindings) node[binding.property][binding.axis] = rest;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
|
-
export { readModelSignals as n, createModelSignalVisual as t };
|