kitchen-simulator 3.16.5 → 3.16.7
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/es/index.js +47 -51
- package/lib/index.js +47 -51
- package/package.json +1 -1
package/es/index.js
CHANGED
|
@@ -23,11 +23,14 @@ function nextFrame() {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* Track
|
|
26
|
+
* Track 3D asset network activity (gltf/glb/bin/textures/hdr/etc)
|
|
27
27
|
* Ref-counted global install so multiple instances don't clobber each other.
|
|
28
28
|
*/
|
|
29
29
|
function installGltfTracker() {
|
|
30
30
|
if (typeof window === 'undefined') {
|
|
31
|
+
var _subscribe = function _subscribe() {
|
|
32
|
+
return function () {};
|
|
33
|
+
};
|
|
31
34
|
return {
|
|
32
35
|
getInFlight: function getInFlight() {
|
|
33
36
|
return 0;
|
|
@@ -49,7 +52,8 @@ function installGltfTracker() {
|
|
|
49
52
|
}
|
|
50
53
|
return waitForIdle;
|
|
51
54
|
}(),
|
|
52
|
-
uninstall: function uninstall() {}
|
|
55
|
+
uninstall: function uninstall() {},
|
|
56
|
+
subscribe: _subscribe
|
|
53
57
|
};
|
|
54
58
|
}
|
|
55
59
|
var GLOBAL_KEY = '__kitchenSimulatorGltfTracker__';
|
|
@@ -65,12 +69,12 @@ function installGltfTracker() {
|
|
|
65
69
|
};
|
|
66
70
|
}
|
|
67
71
|
var g = window[GLOBAL_KEY];
|
|
68
|
-
var
|
|
72
|
+
var is3dAssetUrl = function is3dAssetUrl(url) {
|
|
69
73
|
try {
|
|
70
74
|
var _url$toString, _url$toString2;
|
|
71
75
|
var s = typeof url === 'string' ? url : (_url$toString = url === null || url === void 0 || (_url$toString2 = url.toString) === null || _url$toString2 === void 0 ? void 0 : _url$toString2.call(url)) !== null && _url$toString !== void 0 ? _url$toString : '';
|
|
72
|
-
var u = s.toLowerCase();
|
|
73
|
-
return u.
|
|
76
|
+
var u = s.toLowerCase().split('?')[0]; // ignore cache params
|
|
77
|
+
return u.endsWith('.gltf') || u.endsWith('.glb') || u.endsWith('.bin') || u.endsWith('.ktx2') || u.endsWith('.hdr') || u.endsWith('.exr') || u.endsWith('.png') || u.endsWith('.jpg') || u.endsWith('.jpeg') || u.endsWith('.webp');
|
|
74
78
|
} catch (_unused) {
|
|
75
79
|
return false;
|
|
76
80
|
}
|
|
@@ -91,7 +95,7 @@ function installGltfTracker() {
|
|
|
91
95
|
};
|
|
92
96
|
var subscribe = function subscribe(fn) {
|
|
93
97
|
g.listeners.add(fn);
|
|
94
|
-
fn(g.inFlight); // sync emit
|
|
98
|
+
fn(g.inFlight); // sync emit on subscribe
|
|
95
99
|
return function () {
|
|
96
100
|
return g.listeners["delete"](fn);
|
|
97
101
|
};
|
|
@@ -107,7 +111,7 @@ function installGltfTracker() {
|
|
|
107
111
|
g.originalSend = XHR.prototype.send;
|
|
108
112
|
XHR.prototype.open = function (method, url) {
|
|
109
113
|
var _g$originalOpen;
|
|
110
|
-
this.
|
|
114
|
+
this.__is3dAssetRequest = is3dAssetUrl(url);
|
|
111
115
|
for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
112
116
|
rest[_key - 2] = arguments[_key];
|
|
113
117
|
}
|
|
@@ -115,7 +119,7 @@ function installGltfTracker() {
|
|
|
115
119
|
};
|
|
116
120
|
XHR.prototype.send = function () {
|
|
117
121
|
var _this = this;
|
|
118
|
-
if (this.
|
|
122
|
+
if (this.__is3dAssetRequest) {
|
|
119
123
|
g.inFlight += 1;
|
|
120
124
|
notify();
|
|
121
125
|
var _done = function done() {
|
|
@@ -150,7 +154,7 @@ function installGltfTracker() {
|
|
|
150
154
|
args[_key3] = _args2[_key3];
|
|
151
155
|
}
|
|
152
156
|
url = args === null || args === void 0 ? void 0 : args[0];
|
|
153
|
-
track =
|
|
157
|
+
track = is3dAssetUrl(url);
|
|
154
158
|
if (track) {
|
|
155
159
|
_context2.next = 1;
|
|
156
160
|
break;
|
|
@@ -180,7 +184,7 @@ function installGltfTracker() {
|
|
|
180
184
|
g.installed = true;
|
|
181
185
|
};
|
|
182
186
|
|
|
183
|
-
//
|
|
187
|
+
// “No grace” but stable: idle must remain idle for 2 RAF frames
|
|
184
188
|
function waitStableIdle2Frames() {
|
|
185
189
|
return _waitStableIdle2Frames.apply(this, arguments);
|
|
186
190
|
}
|
|
@@ -221,7 +225,7 @@ function installGltfTracker() {
|
|
|
221
225
|
while (1) switch (_context4.prev = _context4.next) {
|
|
222
226
|
case 0:
|
|
223
227
|
_ref3 = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {}, _ref3$timeoutMs = _ref3.timeoutMs, timeoutMs = _ref3$timeoutMs === void 0 ? 30000 : _ref3$timeoutMs;
|
|
224
|
-
start = Date.now();
|
|
228
|
+
start = Date.now();
|
|
225
229
|
_context4.next = 1;
|
|
226
230
|
return waitStableIdle2Frames();
|
|
227
231
|
case 1:
|
|
@@ -245,7 +249,7 @@ function installGltfTracker() {
|
|
|
245
249
|
}
|
|
246
250
|
if (Date.now() - start > timeoutMs) {
|
|
247
251
|
if (unsub) unsub();
|
|
248
|
-
reject(new Error('
|
|
252
|
+
reject(new Error('3D assets did not become idle within timeout'));
|
|
249
253
|
}
|
|
250
254
|
return _context3.abrupt("return");
|
|
251
255
|
case 1:
|
|
@@ -263,7 +267,7 @@ function installGltfTracker() {
|
|
|
263
267
|
case 3:
|
|
264
268
|
if (Date.now() - start > timeoutMs) {
|
|
265
269
|
if (unsub) unsub();
|
|
266
|
-
reject(new Error('
|
|
270
|
+
reject(new Error('3D assets did not become idle within timeout'));
|
|
267
271
|
}
|
|
268
272
|
case 4:
|
|
269
273
|
case "end":
|
|
@@ -309,11 +313,12 @@ function installGltfTracker() {
|
|
|
309
313
|
return g.inFlight;
|
|
310
314
|
},
|
|
311
315
|
waitForIdle: waitForIdle,
|
|
312
|
-
uninstall: uninstall
|
|
316
|
+
uninstall: uninstall,
|
|
317
|
+
subscribe: subscribe // ✅ IMPORTANT: return subscribe (this fixes your error)
|
|
313
318
|
};
|
|
314
319
|
}
|
|
315
320
|
export function renderKitchenSimulator(container) {
|
|
316
|
-
var _props$framesPerEvent, _props$waitForGltfIdl, _props$gltfTimeoutMs
|
|
321
|
+
var _props$framesPerEvent, _props$waitForGltfIdl, _props$gltfTimeoutMs;
|
|
317
322
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
318
323
|
if (!container) throw new Error('renderKitchenSimulator: container is required');
|
|
319
324
|
|
|
@@ -337,11 +342,13 @@ export function renderKitchenSimulator(container) {
|
|
|
337
342
|
var MARKER = Symbol('marker');
|
|
338
343
|
var gltfTracker = installGltfTracker();
|
|
339
344
|
|
|
340
|
-
//
|
|
341
|
-
var defaultFramesPerEvent = (_props$framesPerEvent = props.framesPerEvent) !== null && _props$framesPerEvent !== void 0 ? _props$framesPerEvent : 1;
|
|
342
|
-
var
|
|
345
|
+
// FAST defaults (safe)
|
|
346
|
+
var defaultFramesPerEvent = (_props$framesPerEvent = props.framesPerEvent) !== null && _props$framesPerEvent !== void 0 ? _props$framesPerEvent : 1;
|
|
347
|
+
var waitForAssets = (_props$waitForGltfIdl = props.waitForGltfIdleAfterEachEvent) !== null && _props$waitForGltfIdl !== void 0 ? _props$waitForGltfIdl : true;
|
|
343
348
|
var defaultTimeout = (_props$gltfTimeoutMs = props.gltfTimeoutMs) !== null && _props$gltfTimeoutMs !== void 0 ? _props$gltfTimeoutMs : 30000;
|
|
344
|
-
|
|
349
|
+
|
|
350
|
+
// If you want ultra-fast UI responsiveness, you can disable waiting per-event
|
|
351
|
+
// and only wait on “important” events, see comment in settle() below.
|
|
345
352
|
|
|
346
353
|
var draining = false;
|
|
347
354
|
function isSyncScene(ev) {
|
|
@@ -353,12 +360,12 @@ export function renderKitchenSimulator(container) {
|
|
|
353
360
|
}
|
|
354
361
|
function _settle() {
|
|
355
362
|
_settle = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(ev) {
|
|
356
|
-
var _ev$framesPerEvent, _ev$
|
|
357
|
-
var frames, i,
|
|
363
|
+
var _ev$framesPerEvent, _ev$waitForGltfIdleAf;
|
|
364
|
+
var frames, i, shouldWait, _ev$gltfTimeoutMs, timeoutMs;
|
|
358
365
|
return _regeneratorRuntime.wrap(function (_context7) {
|
|
359
366
|
while (1) switch (_context7.prev = _context7.next) {
|
|
360
367
|
case 0:
|
|
361
|
-
frames = (_ev$framesPerEvent = ev === null || ev === void 0 ? void 0 : ev.framesPerEvent) !== null && _ev$framesPerEvent !== void 0 ? _ev$framesPerEvent : defaultFramesPerEvent; // 1) allow reducers
|
|
368
|
+
frames = (_ev$framesPerEvent = ev === null || ev === void 0 ? void 0 : ev.framesPerEvent) !== null && _ev$framesPerEvent !== void 0 ? _ev$framesPerEvent : defaultFramesPerEvent; // (1) allow react/reducers to run (fixes “must zoom to see updates”)
|
|
362
369
|
i = 0;
|
|
363
370
|
case 1:
|
|
364
371
|
if (!(i < frames)) {
|
|
@@ -372,39 +379,30 @@ export function renderKitchenSimulator(container) {
|
|
|
372
379
|
_context7.next = 1;
|
|
373
380
|
break;
|
|
374
381
|
case 3:
|
|
375
|
-
|
|
382
|
+
// (2) optionally wait for assets
|
|
383
|
+
// fastest safe approach: keep ON for events that add/replace/load models
|
|
384
|
+
// You can override per-event via ev.waitForGltfIdleAfterEachEvent = false
|
|
385
|
+
shouldWait = (_ev$waitForGltfIdleAf = ev === null || ev === void 0 ? void 0 : ev.waitForGltfIdleAfterEachEvent) !== null && _ev$waitForGltfIdleAf !== void 0 ? _ev$waitForGltfIdleAf : waitForAssets;
|
|
386
|
+
if (!shouldWait) {
|
|
376
387
|
_context7.next = 4;
|
|
377
388
|
break;
|
|
378
389
|
}
|
|
379
|
-
return _context7.abrupt("return");
|
|
380
|
-
case 4:
|
|
381
|
-
// 2) wait for gltf idle (stable-idle 2 frames, no time grace)
|
|
382
390
|
timeoutMs = (_ev$gltfTimeoutMs = ev === null || ev === void 0 ? void 0 : ev.gltfTimeoutMs) !== null && _ev$gltfTimeoutMs !== void 0 ? _ev$gltfTimeoutMs : defaultTimeout;
|
|
383
|
-
_context7.next =
|
|
391
|
+
_context7.next = 4;
|
|
384
392
|
return gltfTracker.waitForIdle({
|
|
385
393
|
timeoutMs: timeoutMs
|
|
386
394
|
});
|
|
387
|
-
case
|
|
388
|
-
_context7.next =
|
|
395
|
+
case 4:
|
|
396
|
+
_context7.next = 5;
|
|
389
397
|
return nextFrame();
|
|
390
|
-
case
|
|
398
|
+
case 5:
|
|
391
399
|
if (!isSyncScene(ev)) {
|
|
392
|
-
_context7.next =
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
_i = 0;
|
|
396
|
-
case 7:
|
|
397
|
-
if (!(_i < syncExtraFrames)) {
|
|
398
|
-
_context7.next = 9;
|
|
400
|
+
_context7.next = 6;
|
|
399
401
|
break;
|
|
400
402
|
}
|
|
401
|
-
_context7.next =
|
|
403
|
+
_context7.next = 6;
|
|
402
404
|
return nextFrame();
|
|
403
|
-
case
|
|
404
|
-
_i += 1;
|
|
405
|
-
_context7.next = 7;
|
|
406
|
-
break;
|
|
407
|
-
case 9:
|
|
405
|
+
case 6:
|
|
408
406
|
case "end":
|
|
409
407
|
return _context7.stop();
|
|
410
408
|
}
|
|
@@ -441,10 +439,6 @@ export function renderKitchenSimulator(container) {
|
|
|
441
439
|
_context8.next = 4;
|
|
442
440
|
return nextFrame();
|
|
443
441
|
case 4:
|
|
444
|
-
if (setExternalEventFn) {
|
|
445
|
-
_context8.next = 5;
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
442
|
return _context8.abrupt("continue", 3);
|
|
449
443
|
case 5:
|
|
450
444
|
item = queue.shift();
|
|
@@ -516,11 +510,13 @@ export function renderKitchenSimulator(container) {
|
|
|
516
510
|
__render: function __render(nextProps) {
|
|
517
511
|
root.render(/*#__PURE__*/React.createElement(Wrapper, nextProps));
|
|
518
512
|
},
|
|
519
|
-
|
|
513
|
+
// ✅ host can query current inFlight
|
|
514
|
+
getGltfInFlight: function getGltfInFlight() {
|
|
520
515
|
return gltfTracker.getInFlight();
|
|
521
516
|
},
|
|
522
|
-
|
|
523
|
-
|
|
517
|
+
// ✅ host can subscribe to inFlight changes (loader)
|
|
518
|
+
subscribeGltfInFlight: function subscribeGltfInFlight(cb) {
|
|
519
|
+
return gltfTracker.subscribe(cb);
|
|
524
520
|
},
|
|
525
521
|
sendExternalEvents: function sendExternalEvents(eventOrEvents) {
|
|
526
522
|
var events = Array.isArray(eventOrEvents) ? eventOrEvents : [eventOrEvents];
|
|
@@ -544,7 +540,7 @@ export function renderKitchenSimulator(container) {
|
|
|
544
540
|
});
|
|
545
541
|
drain();
|
|
546
542
|
|
|
547
|
-
//
|
|
543
|
+
// resolve when marker cleared
|
|
548
544
|
return new Promise(function (resolve) {
|
|
549
545
|
var check = /*#__PURE__*/function () {
|
|
550
546
|
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
package/lib/index.js
CHANGED
|
@@ -31,11 +31,14 @@ function nextFrame() {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* Track
|
|
34
|
+
* Track 3D asset network activity (gltf/glb/bin/textures/hdr/etc)
|
|
35
35
|
* Ref-counted global install so multiple instances don't clobber each other.
|
|
36
36
|
*/
|
|
37
37
|
function installGltfTracker() {
|
|
38
38
|
if (typeof window === 'undefined') {
|
|
39
|
+
var _subscribe = function _subscribe() {
|
|
40
|
+
return function () {};
|
|
41
|
+
};
|
|
39
42
|
return {
|
|
40
43
|
getInFlight: function getInFlight() {
|
|
41
44
|
return 0;
|
|
@@ -57,7 +60,8 @@ function installGltfTracker() {
|
|
|
57
60
|
}
|
|
58
61
|
return waitForIdle;
|
|
59
62
|
}(),
|
|
60
|
-
uninstall: function uninstall() {}
|
|
63
|
+
uninstall: function uninstall() {},
|
|
64
|
+
subscribe: _subscribe
|
|
61
65
|
};
|
|
62
66
|
}
|
|
63
67
|
var GLOBAL_KEY = '__kitchenSimulatorGltfTracker__';
|
|
@@ -73,12 +77,12 @@ function installGltfTracker() {
|
|
|
73
77
|
};
|
|
74
78
|
}
|
|
75
79
|
var g = window[GLOBAL_KEY];
|
|
76
|
-
var
|
|
80
|
+
var is3dAssetUrl = function is3dAssetUrl(url) {
|
|
77
81
|
try {
|
|
78
82
|
var _url$toString, _url$toString2;
|
|
79
83
|
var s = typeof url === 'string' ? url : (_url$toString = url === null || url === void 0 || (_url$toString2 = url.toString) === null || _url$toString2 === void 0 ? void 0 : _url$toString2.call(url)) !== null && _url$toString !== void 0 ? _url$toString : '';
|
|
80
|
-
var u = s.toLowerCase();
|
|
81
|
-
return u.
|
|
84
|
+
var u = s.toLowerCase().split('?')[0]; // ignore cache params
|
|
85
|
+
return u.endsWith('.gltf') || u.endsWith('.glb') || u.endsWith('.bin') || u.endsWith('.ktx2') || u.endsWith('.hdr') || u.endsWith('.exr') || u.endsWith('.png') || u.endsWith('.jpg') || u.endsWith('.jpeg') || u.endsWith('.webp');
|
|
82
86
|
} catch (_unused) {
|
|
83
87
|
return false;
|
|
84
88
|
}
|
|
@@ -99,7 +103,7 @@ function installGltfTracker() {
|
|
|
99
103
|
};
|
|
100
104
|
var subscribe = function subscribe(fn) {
|
|
101
105
|
g.listeners.add(fn);
|
|
102
|
-
fn(g.inFlight); // sync emit
|
|
106
|
+
fn(g.inFlight); // sync emit on subscribe
|
|
103
107
|
return function () {
|
|
104
108
|
return g.listeners["delete"](fn);
|
|
105
109
|
};
|
|
@@ -115,7 +119,7 @@ function installGltfTracker() {
|
|
|
115
119
|
g.originalSend = XHR.prototype.send;
|
|
116
120
|
XHR.prototype.open = function (method, url) {
|
|
117
121
|
var _g$originalOpen;
|
|
118
|
-
this.
|
|
122
|
+
this.__is3dAssetRequest = is3dAssetUrl(url);
|
|
119
123
|
for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
120
124
|
rest[_key - 2] = arguments[_key];
|
|
121
125
|
}
|
|
@@ -123,7 +127,7 @@ function installGltfTracker() {
|
|
|
123
127
|
};
|
|
124
128
|
XHR.prototype.send = function () {
|
|
125
129
|
var _this = this;
|
|
126
|
-
if (this.
|
|
130
|
+
if (this.__is3dAssetRequest) {
|
|
127
131
|
g.inFlight += 1;
|
|
128
132
|
notify();
|
|
129
133
|
var _done = function done() {
|
|
@@ -158,7 +162,7 @@ function installGltfTracker() {
|
|
|
158
162
|
args[_key3] = _args2[_key3];
|
|
159
163
|
}
|
|
160
164
|
url = args === null || args === void 0 ? void 0 : args[0];
|
|
161
|
-
track =
|
|
165
|
+
track = is3dAssetUrl(url);
|
|
162
166
|
if (track) {
|
|
163
167
|
_context2.next = 1;
|
|
164
168
|
break;
|
|
@@ -188,7 +192,7 @@ function installGltfTracker() {
|
|
|
188
192
|
g.installed = true;
|
|
189
193
|
};
|
|
190
194
|
|
|
191
|
-
//
|
|
195
|
+
// “No grace” but stable: idle must remain idle for 2 RAF frames
|
|
192
196
|
function waitStableIdle2Frames() {
|
|
193
197
|
return _waitStableIdle2Frames.apply(this, arguments);
|
|
194
198
|
}
|
|
@@ -229,7 +233,7 @@ function installGltfTracker() {
|
|
|
229
233
|
while (1) switch (_context4.prev = _context4.next) {
|
|
230
234
|
case 0:
|
|
231
235
|
_ref3 = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {}, _ref3$timeoutMs = _ref3.timeoutMs, timeoutMs = _ref3$timeoutMs === void 0 ? 30000 : _ref3$timeoutMs;
|
|
232
|
-
start = Date.now();
|
|
236
|
+
start = Date.now();
|
|
233
237
|
_context4.next = 1;
|
|
234
238
|
return waitStableIdle2Frames();
|
|
235
239
|
case 1:
|
|
@@ -253,7 +257,7 @@ function installGltfTracker() {
|
|
|
253
257
|
}
|
|
254
258
|
if (Date.now() - start > timeoutMs) {
|
|
255
259
|
if (unsub) unsub();
|
|
256
|
-
reject(new Error('
|
|
260
|
+
reject(new Error('3D assets did not become idle within timeout'));
|
|
257
261
|
}
|
|
258
262
|
return _context3.abrupt("return");
|
|
259
263
|
case 1:
|
|
@@ -271,7 +275,7 @@ function installGltfTracker() {
|
|
|
271
275
|
case 3:
|
|
272
276
|
if (Date.now() - start > timeoutMs) {
|
|
273
277
|
if (unsub) unsub();
|
|
274
|
-
reject(new Error('
|
|
278
|
+
reject(new Error('3D assets did not become idle within timeout'));
|
|
275
279
|
}
|
|
276
280
|
case 4:
|
|
277
281
|
case "end":
|
|
@@ -317,11 +321,12 @@ function installGltfTracker() {
|
|
|
317
321
|
return g.inFlight;
|
|
318
322
|
},
|
|
319
323
|
waitForIdle: waitForIdle,
|
|
320
|
-
uninstall: uninstall
|
|
324
|
+
uninstall: uninstall,
|
|
325
|
+
subscribe: subscribe // ✅ IMPORTANT: return subscribe (this fixes your error)
|
|
321
326
|
};
|
|
322
327
|
}
|
|
323
328
|
function renderKitchenSimulator(container) {
|
|
324
|
-
var _props$framesPerEvent, _props$waitForGltfIdl, _props$gltfTimeoutMs
|
|
329
|
+
var _props$framesPerEvent, _props$waitForGltfIdl, _props$gltfTimeoutMs;
|
|
325
330
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
326
331
|
if (!container) throw new Error('renderKitchenSimulator: container is required');
|
|
327
332
|
|
|
@@ -345,11 +350,13 @@ function renderKitchenSimulator(container) {
|
|
|
345
350
|
var MARKER = Symbol('marker');
|
|
346
351
|
var gltfTracker = installGltfTracker();
|
|
347
352
|
|
|
348
|
-
//
|
|
349
|
-
var defaultFramesPerEvent = (_props$framesPerEvent = props.framesPerEvent) !== null && _props$framesPerEvent !== void 0 ? _props$framesPerEvent : 1;
|
|
350
|
-
var
|
|
353
|
+
// FAST defaults (safe)
|
|
354
|
+
var defaultFramesPerEvent = (_props$framesPerEvent = props.framesPerEvent) !== null && _props$framesPerEvent !== void 0 ? _props$framesPerEvent : 1;
|
|
355
|
+
var waitForAssets = (_props$waitForGltfIdl = props.waitForGltfIdleAfterEachEvent) !== null && _props$waitForGltfIdl !== void 0 ? _props$waitForGltfIdl : true;
|
|
351
356
|
var defaultTimeout = (_props$gltfTimeoutMs = props.gltfTimeoutMs) !== null && _props$gltfTimeoutMs !== void 0 ? _props$gltfTimeoutMs : 30000;
|
|
352
|
-
|
|
357
|
+
|
|
358
|
+
// If you want ultra-fast UI responsiveness, you can disable waiting per-event
|
|
359
|
+
// and only wait on “important” events, see comment in settle() below.
|
|
353
360
|
|
|
354
361
|
var draining = false;
|
|
355
362
|
function isSyncScene(ev) {
|
|
@@ -361,12 +368,12 @@ function renderKitchenSimulator(container) {
|
|
|
361
368
|
}
|
|
362
369
|
function _settle() {
|
|
363
370
|
_settle = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7(ev) {
|
|
364
|
-
var _ev$framesPerEvent, _ev$
|
|
365
|
-
var frames, i,
|
|
371
|
+
var _ev$framesPerEvent, _ev$waitForGltfIdleAf;
|
|
372
|
+
var frames, i, shouldWait, _ev$gltfTimeoutMs, timeoutMs;
|
|
366
373
|
return _regenerator["default"].wrap(function (_context7) {
|
|
367
374
|
while (1) switch (_context7.prev = _context7.next) {
|
|
368
375
|
case 0:
|
|
369
|
-
frames = (_ev$framesPerEvent = ev === null || ev === void 0 ? void 0 : ev.framesPerEvent) !== null && _ev$framesPerEvent !== void 0 ? _ev$framesPerEvent : defaultFramesPerEvent; // 1) allow reducers
|
|
376
|
+
frames = (_ev$framesPerEvent = ev === null || ev === void 0 ? void 0 : ev.framesPerEvent) !== null && _ev$framesPerEvent !== void 0 ? _ev$framesPerEvent : defaultFramesPerEvent; // (1) allow react/reducers to run (fixes “must zoom to see updates”)
|
|
370
377
|
i = 0;
|
|
371
378
|
case 1:
|
|
372
379
|
if (!(i < frames)) {
|
|
@@ -380,39 +387,30 @@ function renderKitchenSimulator(container) {
|
|
|
380
387
|
_context7.next = 1;
|
|
381
388
|
break;
|
|
382
389
|
case 3:
|
|
383
|
-
|
|
390
|
+
// (2) optionally wait for assets
|
|
391
|
+
// fastest safe approach: keep ON for events that add/replace/load models
|
|
392
|
+
// You can override per-event via ev.waitForGltfIdleAfterEachEvent = false
|
|
393
|
+
shouldWait = (_ev$waitForGltfIdleAf = ev === null || ev === void 0 ? void 0 : ev.waitForGltfIdleAfterEachEvent) !== null && _ev$waitForGltfIdleAf !== void 0 ? _ev$waitForGltfIdleAf : waitForAssets;
|
|
394
|
+
if (!shouldWait) {
|
|
384
395
|
_context7.next = 4;
|
|
385
396
|
break;
|
|
386
397
|
}
|
|
387
|
-
return _context7.abrupt("return");
|
|
388
|
-
case 4:
|
|
389
|
-
// 2) wait for gltf idle (stable-idle 2 frames, no time grace)
|
|
390
398
|
timeoutMs = (_ev$gltfTimeoutMs = ev === null || ev === void 0 ? void 0 : ev.gltfTimeoutMs) !== null && _ev$gltfTimeoutMs !== void 0 ? _ev$gltfTimeoutMs : defaultTimeout;
|
|
391
|
-
_context7.next =
|
|
399
|
+
_context7.next = 4;
|
|
392
400
|
return gltfTracker.waitForIdle({
|
|
393
401
|
timeoutMs: timeoutMs
|
|
394
402
|
});
|
|
395
|
-
case
|
|
396
|
-
_context7.next =
|
|
403
|
+
case 4:
|
|
404
|
+
_context7.next = 5;
|
|
397
405
|
return nextFrame();
|
|
398
|
-
case
|
|
406
|
+
case 5:
|
|
399
407
|
if (!isSyncScene(ev)) {
|
|
400
|
-
_context7.next =
|
|
401
|
-
break;
|
|
402
|
-
}
|
|
403
|
-
_i = 0;
|
|
404
|
-
case 7:
|
|
405
|
-
if (!(_i < syncExtraFrames)) {
|
|
406
|
-
_context7.next = 9;
|
|
408
|
+
_context7.next = 6;
|
|
407
409
|
break;
|
|
408
410
|
}
|
|
409
|
-
_context7.next =
|
|
411
|
+
_context7.next = 6;
|
|
410
412
|
return nextFrame();
|
|
411
|
-
case
|
|
412
|
-
_i += 1;
|
|
413
|
-
_context7.next = 7;
|
|
414
|
-
break;
|
|
415
|
-
case 9:
|
|
413
|
+
case 6:
|
|
416
414
|
case "end":
|
|
417
415
|
return _context7.stop();
|
|
418
416
|
}
|
|
@@ -449,10 +447,6 @@ function renderKitchenSimulator(container) {
|
|
|
449
447
|
_context8.next = 4;
|
|
450
448
|
return nextFrame();
|
|
451
449
|
case 4:
|
|
452
|
-
if (setExternalEventFn) {
|
|
453
|
-
_context8.next = 5;
|
|
454
|
-
break;
|
|
455
|
-
}
|
|
456
450
|
return _context8.abrupt("continue", 3);
|
|
457
451
|
case 5:
|
|
458
452
|
item = queue.shift();
|
|
@@ -524,11 +518,13 @@ function renderKitchenSimulator(container) {
|
|
|
524
518
|
__render: function __render(nextProps) {
|
|
525
519
|
root.render(/*#__PURE__*/_react["default"].createElement(Wrapper, nextProps));
|
|
526
520
|
},
|
|
527
|
-
|
|
521
|
+
// ✅ host can query current inFlight
|
|
522
|
+
getGltfInFlight: function getGltfInFlight() {
|
|
528
523
|
return gltfTracker.getInFlight();
|
|
529
524
|
},
|
|
530
|
-
|
|
531
|
-
|
|
525
|
+
// ✅ host can subscribe to inFlight changes (loader)
|
|
526
|
+
subscribeGltfInFlight: function subscribeGltfInFlight(cb) {
|
|
527
|
+
return gltfTracker.subscribe(cb);
|
|
532
528
|
},
|
|
533
529
|
sendExternalEvents: function sendExternalEvents(eventOrEvents) {
|
|
534
530
|
var events = Array.isArray(eventOrEvents) ? eventOrEvents : [eventOrEvents];
|
|
@@ -552,7 +548,7 @@ function renderKitchenSimulator(container) {
|
|
|
552
548
|
});
|
|
553
549
|
drain();
|
|
554
550
|
|
|
555
|
-
//
|
|
551
|
+
// resolve when marker cleared
|
|
556
552
|
return new Promise(function (resolve) {
|
|
557
553
|
var check = /*#__PURE__*/function () {
|
|
558
554
|
var _ref5 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
|