Skip to content

Commit

Permalink
Merge pull request #6158 from mozilla/bitecs-spawner-fix
Browse files Browse the repository at this point in the history
Fix spawner issues
  • Loading branch information
keianhzo authored Aug 9, 2023
2 parents fd95310 + 5f6e7a6 commit 1907267
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
23 changes: 14 additions & 9 deletions src/bit-systems/media-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,22 @@ export function* waitForMediaLoaded(world: HubsWorld, eid: EntityID) {

// prettier-ignore
const loaderForMediaType = {
[MediaType.IMAGE]: (world: HubsWorld, { accessibleUrl, contentType }: { accessibleUrl: string, contentType: string }) =>
loadImage(world, accessibleUrl, contentType),
[MediaType.VIDEO]: (world: HubsWorld, { accessibleUrl, contentType }: { accessibleUrl: string, contentType: string }) =>
loadVideo(world, accessibleUrl, contentType),
[MediaType.MODEL]: (world: HubsWorld, { accessibleUrl, contentType }: { accessibleUrl: string, contentType: string }) =>
loadModel(world, accessibleUrl, contentType, true),
[MediaType.PDF]: (world: HubsWorld, { accessibleUrl }: { accessibleUrl: string }) =>
loadPDF(world, accessibleUrl),
[MediaType.IMAGE]: (
world: HubsWorld,
{ accessibleUrl, contentType }: { accessibleUrl: string; contentType: string }
) => loadImage(world, accessibleUrl, contentType),
[MediaType.VIDEO]: (
world: HubsWorld,
{ accessibleUrl, contentType }: { accessibleUrl: string; contentType: string }
) => loadVideo(world, accessibleUrl, contentType),
[MediaType.MODEL]: (
world: HubsWorld,
{ accessibleUrl, contentType }: { accessibleUrl: string; contentType: string }
) => loadModel(world, accessibleUrl, contentType, true),
[MediaType.PDF]: (world: HubsWorld, { accessibleUrl }: { accessibleUrl: string }) => loadPDF(world, accessibleUrl),
[MediaType.AUDIO]: (world: HubsWorld, { accessibleUrl }: { accessibleUrl: string }) =>
loadAudio(world, accessibleUrl),
[MediaType.HTML]: (world: HubsWorld, { canonicalUrl, thumbnail }: { canonicalUrl: string, thumbnail: string }) =>
[MediaType.HTML]: (world: HubsWorld, { canonicalUrl, thumbnail }: { canonicalUrl: string; thumbnail: string }) =>
loadHtml(world, canonicalUrl, thumbnail)
};

Expand Down
16 changes: 3 additions & 13 deletions src/bit-systems/object-spawner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { addComponent, defineQuery, enterQuery, exitQuery } from "bitecs";
import { HubsWorld } from "../app";
import { FloatyObject, Held, HeldRemoteRight, Interacted, ObjectSpawner } from "../bit-components";
import { FLOATY_OBJECT_FLAGS } from "../systems/floaty-object-system";
import { sleep } from "../utils/async-utils";
import { coroutine } from "../utils/coroutine";
import { createNetworkedMedia } from "../utils/create-networked-entity";
import { EntityID } from "../utils/networking-types";
import { setMatrixWorld } from "../utils/three-utils";
import { animateScale, waitForMediaLoaded } from "./media-loading";

export enum OBJECT_SPAWNER_FLAGS {
/** Apply gravity to spawned objects */
Expand All @@ -17,9 +15,9 @@ export enum OBJECT_SPAWNER_FLAGS {
function* spawnObjectJob(world: HubsWorld, spawner: EntityID) {
const spawned = createNetworkedMedia(world, {
src: APP.getString(ObjectSpawner.src[spawner])!,
recenter: false,
resize: false,
animateLoad: false,
recenter: true,
resize: true,
animateLoad: true,
isObjectMenuTarget: true
});

Expand All @@ -34,14 +32,6 @@ function* spawnObjectJob(world: HubsWorld, spawner: EntityID) {
spawnerObj.updateMatrices();
const spawnedObj = world.eid2obj.get(spawned)!;
setMatrixWorld(spawnedObj, spawnerObj.matrixWorld);

yield* waitForMediaLoaded(world, spawned);
spawnerObj.visible = false;
yield sleep(1000);
spawnerObj.visible = true;

// TODO we should come up with a nicer way to get at the media that was loaded by a MediaLoader
yield* animateScale(world, spawnerObj.children[0]!.eid!);
}

// TODO type for coroutine
Expand Down
9 changes: 6 additions & 3 deletions src/inflators/spawner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {
HandCollisionTarget,
ObjectSpawner,
RemoteHoverTarget,
SingleActionButton
SingleActionButton,
TogglesHoveredActionSet
} from "../bit-components";
import { OBJECT_SPAWNER_FLAGS } from "../bit-systems/object-spawner";
import { COLLISION_LAYERS } from "../constants";
import { inflateMediaLoader } from "./media-loader";
import { inflateRigidBody } from "./rigid-body";
import { Type, inflateRigidBody } from "./rigid-body";

export interface SpawnerParams {
src: string;
Expand All @@ -22,7 +23,7 @@ export interface SpawnerParams {
export function inflateSpawner(world: HubsWorld, eid: number, props: SpawnerParams) {
inflateMediaLoader(world, eid, {
src: props.src,
recenter: false,
recenter: true,
resize: false,
animateLoad: false,
isObjectMenuTarget: false
Expand All @@ -32,13 +33,15 @@ export function inflateSpawner(world: HubsWorld, eid: number, props: SpawnerPara
addComponent(world, CursorRaycastable, eid);
addComponent(world, RemoteHoverTarget, eid);
addComponent(world, SingleActionButton, eid);
addComponent(world, TogglesHoveredActionSet, eid);

addComponent(world, ObjectSpawner, eid);
ObjectSpawner.src[eid] = APP.getSid(props.src);
ObjectSpawner.flags[eid] = props.mediaOptions?.applyGravity ? OBJECT_SPAWNER_FLAGS.APPLY_GRAVITY : 0;

inflateRigidBody(world, eid, {
mass: 0,
type: Type.STATIC,
collisionGroup: COLLISION_LAYERS.DEFAULT_SPAWNER,
collisionMask: COLLISION_LAYERS.INTERACTABLES,
disableCollision: true
Expand Down
11 changes: 5 additions & 6 deletions src/systems/hubs-systems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,18 @@ export function mainTick(xrFrame: XRFrame, renderer: WebGLRenderer, scene: Scene
sceneLoadingSystem(world, hubsSystems.environmentSystem, hubsSystems.characterController);
mediaLoadingSystem(world);

physicsCompatSystem(world, hubsSystems.physicsSystem);

networkedTransformSystem(world);

aframeSystems.userinput.tick2(xrFrame);

interactionSystem(world, hubsSystems.cursorTargettingSystem, t, aframeSystems);

buttonSystems(world);

physicsCompatSystem(world, hubsSystems.physicsSystem);
hubsSystems.physicsSystem.tick(dt);
constraintsSystem(world, hubsSystems.physicsSystem);
floatyObjectSystem(world);

// We run this earlier in the frame so things have a chance to override properties run by animations
hubsSystems.animationMixerSystem.tick(dt);
Expand All @@ -221,8 +223,6 @@ export function mainTick(xrFrame: XRFrame, renderer: WebGLRenderer, scene: Scene
hubsSystems.positionAtBorderSystem.tick();
hubsSystems.twoPointStretchingSystem.tick();

floatyObjectSystem(world);

hubsSystems.holdableButtonSystem.tick();
hubsSystems.hoverButtonSystem.tick();
hubsSystems.drawingMenuSystem.tick();
Expand All @@ -237,7 +237,6 @@ export function mainTick(xrFrame: XRFrame, renderer: WebGLRenderer, scene: Scene
hubsSystems.soundEffectsSystem.tick();
hubsSystems.scenePreviewCameraSystem.tick();
scenePreviewCameraSystem(world, hubsSystems.cameraSystem);
hubsSystems.physicsSystem.tick(dt);
hubsSystems.inspectYourselfSystem.tick(hubsSystems.el, aframeSystems.userinput, hubsSystems.cameraSystem);
hubsSystems.cameraSystem.tick(hubsSystems.el, dt);
cameraToolSystem(world);
Expand All @@ -263,7 +262,7 @@ export function mainTick(xrFrame: XRFrame, renderer: WebGLRenderer, scene: Scene
simpleWaterSystem(world);
linearTransformSystem(world);
quackSystem(world);

mixerAnimatableSystem(world);
loopAnimationSystem(world);

Expand Down

0 comments on commit 1907267

Please sign in to comment.