Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spawner issues #6158

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question for my study: Here can be removed because of animateLoad: true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as we are already animating the spawned object I don't see the point on animating explicitly.

}

// 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,
Copy link
Contributor

@takahirox takahirox Jul 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question for my study: Spawner object should be static (no local matrix update except for initialization) so rigid body type should be static. Is my understanding correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my understanding. Spawners are static as their main action is to spawn an object and are not draggable. Also that's how we were setting them up in AFrame:
https://github.com/mozilla/hubs/blob/5f6e7a62ab998a60895a30dc686ae6db94fe9c5b/src/gltf-component-mappings.js#L323

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
Loading