Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

Commit 07eca70

Browse files
committed
fix nits
1 parent e74c68e commit 07eca70

File tree

9 files changed

+46
-44
lines changed

9 files changed

+46
-44
lines changed

fixtures/html-in-spatial/text-button.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ for (let sub of subChildren) {
6868
subElement.addEventListener('mouseup', () => {
6969
subElement.style.backgroundColor = 'rgba(30,33,33,.95)';
7070
if (subElement.textContent == null) {
71+
console.warn(`No text content found in the element`);
7172
return;
7273
}
7374
const playAudio = audios[subElement.textContent];

fixtures/spatial-lion.js

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class FanController {
6969
#targetPositionX = 0;
7070
#targetPositionY = 0;
7171

72+
constructor() {
73+
this.#container.isPickable = true;
74+
}
75+
7276
update(x, y) {
7377
this.#container.lookAt(this.lion.head.position);
7478
this.#targetPositionX = -rule3(x, -200, 200, -250, 250);
@@ -275,49 +279,42 @@ async function createAudioPlayer(name) {
275279
};
276280
}
277281

282+
let playBlowingAudio;
283+
let blowingAudio;
284+
285+
function stopBlowingAudio() {
286+
if (blowingAudio) {
287+
blowingAudio.pause();
288+
blowingAudio = null;
289+
}
290+
}
291+
278292
const fanElement = document.querySelector('#fan_sphere');
293+
const fanNode = fanElement.asNativeType();
294+
fanNode.isPickable = true;
279295
fanElement.addEventListener('rayenter', () => {
280-
fanElement.asNativeType().renderOutline = true;
281-
fanElement.asNativeType().outlineWidth = 2;
296+
fanNode.renderOverlay = true;
282297
});
283298
fanElement.addEventListener('rayleave', () => {
284-
fanElement.asNativeType().renderOutline = false;
299+
fanNode.renderOverlay = false;
300+
isBlowing = false;
301+
stopBlowingAudio();
285302
});
286303

287-
let blowingAudio;
288304
fanElement.addEventListener('raydown', async () => {
289305
isBlowing = true;
290-
if (blowingAudio) {
291-
blowingAudio.load();
292-
blowingAudio.play();
293-
} else {
294-
const play = await createAudioPlayer('fan.mp3');
295-
blowingAudio = play(1.0);
306+
if (typeof playBlowingAudio !== 'function') {
307+
playBlowingAudio = await createAudioPlayer('fan.mp3');
296308
}
309+
blowingAudio = playBlowingAudio(1.0);
297310
});
298311
fanElement.addEventListener('rayup', () => {
299312
isBlowing = false;
300-
if (blowingAudio) {
301-
blowingAudio.pause();
302-
}
313+
stopBlowingAudio();
303314
});
304315

305-
// spaceDocument.watchInputEvent();
306-
// spaceDocument.addEventListener('mouse', (event) => {
307-
// const { inputData } = event;
308-
// if (inputData.Action === 'move') {
309-
// targetX = inputData.PositionX - screenWidth / 2;
310-
// targetY = inputData.PositionY - screenHeight / 2;
311-
// } else if (inputData.Action === 'down') {
312-
// isBlowing = true;
313-
// } else if (inputData.Action === 'up') {
314-
// isBlowing = false;
315-
// }
316-
// });
317-
318316
// let lastIndexFingerTipX = 0;
319317
// let lastUpdateTimestamp = 0;
320-
321318
// spaceDocument.addEventListener('handtracking', (event) => {
322319
// const { inputData } = event;
323320
// if (inputData.Type === 1) {

fixtures/spatial-lion.xsml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<xsml version="1.0">
22
<head>
33
<title>Spatial Lion Example</title>
4-
<meta name="viewport" content="bounding-size=0.3" />
54
<style type="text/scss">
65
@material yellow {
76
diffuse-color: #fdd276;
@@ -325,7 +324,7 @@
325324
<cube id="fan_prop4" width="10" height="30" depth="2" />
326325
</bound>
327326
</bound>
328-
<cube id="fan_sphere" width="10" height="10" depth="3" />
327+
<cube id="fan_sphere" width="20" height="20" depth="3" />
329328
</bound>
330329
</space>
331330
</xsml>

jest.setup.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
Error.stackTraceLimit = Infinity;
22
// Since many modules require babylonjs and jest does not have it, which must be imported globally.
33
global.BABYLON = require('babylonjs');
4+
5+
// Patch requestAnimationFrame to run all animations synchronously
6+
global.requestAnimationFrame = function (callback) {
7+
setTimeout(callback, 0);
8+
};

package-lock.json

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/living/nodes/HTMLMediaElement.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,10 @@ export default class HTMLMediaElementImpl extends HTMLElementImpl implements HTM
172172
protected async _play(when: number): Promise<void> {
173173
if (this.readyState < MediaReadyState.HAVE_CURRENT_DATA) {
174174
return new Promise<void>((resolve) => {
175-
const _play = () => {
176-
this.removeEventListener('loadeddata', _play);
175+
this.addEventListener('loadeddata', () => {
177176
this._playerNative.play(when);
178177
resolve();
179-
};
180-
this.addEventListener('loadeddata', _play);
178+
}, { once: true });
181179
});
182180
} else {
183181
this._playerNative.play(when);

src/living/nodes/SpatialDocument.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ export class SpatialDocumentImpl<T extends NativeDocument = NativeDocument> exte
421421
const recommendedContentSize = nativeDocument.getRecommendedBoudingSize?.() || 1.0;
422422
this._fitSpaceTo(this._spaceViewportBoundingSize * recommendedContentSize);
423423
}
424+
this.space.enabled = true;
424425
}, { once: true });
425426

426427
// Bypass the GOMContentLoaded event from the XSML document.

src/living/nodes/SpatialElement.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ export class SpatialElement extends ElementImpl {
144144
this._internalObject.scaling = new BABYLON.Vector3(value.x, value.y, value.z);
145145
}
146146

147+
get enabled(): boolean {
148+
return this._internalObject?.isEnabled() || false;
149+
}
150+
set enabled(value: boolean) {
151+
if (this._internalObject) {
152+
this._internalObject.setEnabled(value);
153+
}
154+
}
155+
147156
/**
148157
* Set the value of a spatial attribute, it will throw an error if the spatial element is attached.
149158
*

src/living/nodes/SpatialSpaceElement.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export default class SpatialSpaceElement extends SpatialElement {
1313
}
1414

1515
_attach(): void {
16-
super._attach(new BABYLON.TransformNode(this._getInternalNodeNameOrId(), this._scene));
16+
const spaceNode = new BABYLON.TransformNode(this._getInternalNodeNameOrId(), this._scene);
17+
spaceNode.setEnabled(false); // Disable the <space /> node by default.
18+
super._attach(spaceNode);
1719
}
1820
}

0 commit comments

Comments
 (0)