Skip to content

Commit

Permalink
fix: defer static/dynamic-body component set
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-liang committed May 23, 2024
1 parent cad37e3 commit 00538cc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/constants/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const ARENA_EVENTS = Object.freeze({
STARTPOS_LOADED: 'onarenastartposloaded',
RUNTIME_MNGR_LOADED: 'onarenaruntimemanagerloaded',
CV_INITIALIZED: 'onarenacvinitialized',
PHYSICS_LOADED: 'onarenaphysicsinitialized',
});

export const JITSI_EVENTS = Object.freeze({
Expand Down
1 change: 1 addition & 0 deletions src/systems/core/arena.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ AFRAME.registerSystem('arena-scene', {
if (AFRAME.components['static-body']) {
clearInterval(physicsWait);
document.getElementById('groundPlane').setAttribute('static-body', 'type', 'static');
this.events.emit(ARENA_EVENTS.PHYSICS_LOADED, true);
}
}, 10);
}
Expand Down
14 changes: 13 additions & 1 deletion src/systems/core/message-actions/create-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* global AFRAME, ARENA, THREE */

import { ARENAUtils } from '../../../utils';
import { ACTIONS } from '../../../constants';
import { ACTIONS, ARENA_EVENTS } from '../../../constants';

// default render order of objects; reserve 0 for occlusion
const RENDER_ORDER = 1;
Expand Down Expand Up @@ -452,6 +452,18 @@ export default class CreateUpdate {
// handle some special cases for attributes (e.g. attributes set directly to the THREE.js object);
// default is to let aframe handle attributes directly
switch (attribute) {
// Defer until physics is loaded. If it never loads...trigger load??
case 'static-body':
case 'dynamic-body':
ARENA.events.addEventListener(ARENA_EVENTS.PHYSICS_LOADED, () => {
if (value === null) {
// if null, remove attribute
entityEl.removeAttribute(attribute);
} else {
entityEl.setAttribute(attribute, value);
}
});
break;
case 'rotation':
// rotation is set directly in the THREE.js object, for performance reasons
if (Object.hasOwn(value, 'w')) {
Expand Down

0 comments on commit 00538cc

Please sign in to comment.