From 5f6e7a62ab998a60895a30dc686ae6db94fe9c5b Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Mon, 10 Jul 2023 17:26:55 +0200 Subject: [PATCH] Fix spawner issues --- src/bit-systems/media-loading.ts | 23 ++++++++++++++--------- src/bit-systems/object-spawner.ts | 16 +++------------- src/inflators/spawner.ts | 9 ++++++--- src/systems/hubs-systems.ts | 11 +++++------ 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/bit-systems/media-loading.ts b/src/bit-systems/media-loading.ts index bf69c217d0..542be46efb 100644 --- a/src/bit-systems/media-loading.ts +++ b/src/bit-systems/media-loading.ts @@ -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) }; diff --git a/src/bit-systems/object-spawner.ts b/src/bit-systems/object-spawner.ts index 7c6713974d..a532ccd945 100644 --- a/src/bit-systems/object-spawner.ts +++ b/src/bit-systems/object-spawner.ts @@ -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 */ @@ -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 }); @@ -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 diff --git a/src/inflators/spawner.ts b/src/inflators/spawner.ts index 5944c72ddc..d921b3cb23 100644 --- a/src/inflators/spawner.ts +++ b/src/inflators/spawner.ts @@ -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; @@ -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 @@ -32,6 +33,7 @@ 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); @@ -39,6 +41,7 @@ export function inflateSpawner(world: HubsWorld, eid: number, props: SpawnerPara inflateRigidBody(world, eid, { mass: 0, + type: Type.STATIC, collisionGroup: COLLISION_LAYERS.DEFAULT_SPAWNER, collisionMask: COLLISION_LAYERS.INTERACTABLES, disableCollision: true diff --git a/src/systems/hubs-systems.ts b/src/systems/hubs-systems.ts index b41b16db40..5ae272a467 100644 --- a/src/systems/hubs-systems.ts +++ b/src/systems/hubs-systems.ts @@ -189,8 +189,6 @@ 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); @@ -198,7 +196,11 @@ export function mainTick(xrFrame: XRFrame, renderer: WebGLRenderer, scene: Scene 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); @@ -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(); @@ -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); @@ -263,7 +262,7 @@ export function mainTick(xrFrame: XRFrame, renderer: WebGLRenderer, scene: Scene simpleWaterSystem(world); linearTransformSystem(world); quackSystem(world); - + mixerAnimatableSystem(world); loopAnimationSystem(world);