From c619017df48b94ef8e992fe38a4aef067b9c3c37 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Mon, 2 Oct 2023 17:09:36 +0200 Subject: [PATCH] Move to using a MediaLink component --- src/bit-components.js | 7 +++++-- src/bit-systems/media-loading.ts | 6 +++--- src/components/gltf-model-plus.js | 4 +++- src/inflators/image-loader.ts | 5 +---- src/inflators/media-link.ts | 13 +++++++++++++ src/inflators/media-loader.ts | 6 +----- src/inflators/model-loader.ts | 4 +--- src/inflators/video-loader.ts | 4 +--- src/utils/jsx-entity.ts | 7 +++++-- 9 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 src/inflators/media-link.ts diff --git a/src/bit-components.js b/src/bit-components.js index e6cf767e68..61bddfc084 100644 --- a/src/bit-components.js +++ b/src/bit-components.js @@ -152,8 +152,7 @@ export const MyCameraTool = defineComponent(); export const MediaLoader = defineComponent({ src: Types.ui32, flags: Types.ui8, - fileId: Types.ui32, - linkSrc: Types.ui32 + fileId: Types.ui32 }); MediaLoader.src[$isStringType] = true; MediaLoader.fileId[$isStringType] = true; @@ -388,3 +387,7 @@ export const LinearScale = defineComponent({ export const Quack = defineComponent(); export const TrimeshTag = defineComponent(); export const HeightFieldTag = defineComponent(); +export const MediaLink = defineComponent({ + src: Types.ui32 +}); +MediaLink.src[$isStringType] = true; diff --git a/src/bit-systems/media-loading.ts b/src/bit-systems/media-loading.ts index 14515eb28a..73b11b89f4 100644 --- a/src/bit-systems/media-loading.ts +++ b/src/bit-systems/media-loading.ts @@ -7,6 +7,7 @@ import { MediaContentBounds, MediaImageLoaderData, MediaInfo, + MediaLink, MediaLoaded, MediaLoader, MediaVideoLoaderData, @@ -219,9 +220,8 @@ function* loadByMediaType( throw new UnsupportedMediaTypeError(eid, mediaType); } - const linkSrc = APP.getString(MediaLoader.linkSrc[eid]); - if (linkSrc) { - inflateLink(world, mediaEid, { href: linkSrc, type: LinkType.LINK }); + if (hasComponent(world, MediaLink, eid)) { + inflateLink(world, mediaEid, { href: APP.getString(MediaLink.src[eid])!, type: LinkType.LINK }); inflateGrabbable(world, mediaEid, { cursor: true, hand: false }); } diff --git a/src/components/gltf-model-plus.js b/src/components/gltf-model-plus.js index 5633d2ad12..12090f11b9 100644 --- a/src/components/gltf-model-plus.js +++ b/src/components/gltf-model-plus.js @@ -584,7 +584,9 @@ class GLTFHubsComponentsExtension { if (shouldUseNewLoader()) { if (Object.prototype.hasOwnProperty.call(ext, "link")) { if (["image", "video", "model"].includes(componentName)) { - props["linkSrc"] = ext.link.href; + ext["media-link"] = { + src: ext.link.href + }; delete ext.link; } } diff --git a/src/inflators/image-loader.ts b/src/inflators/image-loader.ts index b1ce90d675..580e00eb24 100644 --- a/src/inflators/image-loader.ts +++ b/src/inflators/image-loader.ts @@ -9,8 +9,6 @@ export interface ImageLoaderParams { projection: ProjectionModeName; alphaMode: AlphaModeName; alphaCutoff: number; - linkSrc?: string; - controls: true; } const DEFAULTS: Partial = { @@ -25,8 +23,7 @@ export function inflateImageLoader(world: HubsWorld, eid: number, params: ImageL recenter: false, resize: false, animateLoad: false, - isObjectMenuTarget: params.linkSrc && params.controls ? true : false, - linkSrc: params.controls ? params.linkSrc : undefined + isObjectMenuTarget: false }); const requiredParams = Object.assign({}, DEFAULTS, params) as Required; diff --git a/src/inflators/media-link.ts b/src/inflators/media-link.ts new file mode 100644 index 0000000000..3326f01a2d --- /dev/null +++ b/src/inflators/media-link.ts @@ -0,0 +1,13 @@ +import { addComponent } from "bitecs"; +import { HubsWorld } from "../app"; +import { EntityID } from "../utils/networking-types"; +import { MediaLink } from "../bit-components"; + +export type MediaLinkParams = { + src: string; +}; + +export function inflateMediaLink(world: HubsWorld, eid: EntityID, params: MediaLinkParams) { + addComponent(world, MediaLink, eid); + MediaLink.src[eid] = APP.getSid(params.src); +} diff --git a/src/inflators/media-loader.ts b/src/inflators/media-loader.ts index c3201aec39..b99cfa3f20 100644 --- a/src/inflators/media-loader.ts +++ b/src/inflators/media-loader.ts @@ -10,13 +10,12 @@ export type MediaLoaderParams = { animateLoad: boolean; fileId?: string; isObjectMenuTarget: boolean; - linkSrc?: string; }; export function inflateMediaLoader( world: HubsWorld, eid: number, - { src, recenter, resize, animateLoad, fileId, isObjectMenuTarget, linkSrc }: MediaLoaderParams + { src, recenter, resize, animateLoad, fileId, isObjectMenuTarget }: MediaLoaderParams ) { addComponent(world, MediaLoader, eid); let flags = 0; @@ -29,7 +28,4 @@ export function inflateMediaLoader( MediaLoader.fileId[eid] = APP.getSid(fileId)!; } MediaLoader.src[eid] = APP.getSid(src)!; - if (linkSrc) { - MediaLoader.linkSrc[eid] = APP.getSid(linkSrc)!; - } } diff --git a/src/inflators/model-loader.ts b/src/inflators/model-loader.ts index ddd576c661..a374f96112 100644 --- a/src/inflators/model-loader.ts +++ b/src/inflators/model-loader.ts @@ -3,7 +3,6 @@ import { inflateMediaLoader } from "./media-loader"; export type ModelLoaderParams = { src: string; - linkSrc?: string; }; export function inflateModelLoader(world: HubsWorld, eid: number, params: ModelLoaderParams) { @@ -12,7 +11,6 @@ export function inflateModelLoader(world: HubsWorld, eid: number, params: ModelL recenter: true, resize: false, animateLoad: false, - isObjectMenuTarget: params.linkSrc ? true : false, - linkSrc: params.linkSrc + isObjectMenuTarget: false }); } diff --git a/src/inflators/video-loader.ts b/src/inflators/video-loader.ts index 01fe832408..48351cdde8 100644 --- a/src/inflators/video-loader.ts +++ b/src/inflators/video-loader.ts @@ -9,7 +9,6 @@ export interface VideoLoaderParams { autoPlay: boolean; controls: boolean; loop: boolean; - linkSrc?: string; } const DEFAULTS: Partial = { @@ -25,8 +24,7 @@ export function inflateVideoLoader(world: HubsWorld, eid: number, params: VideoL recenter: false, resize: false, animateLoad: false, - isObjectMenuTarget: params.linkSrc && params.controls ? true : false, - linkSrc: params.controls ? params.linkSrc : undefined + isObjectMenuTarget: false }); const requiredParams = Object.assign({}, DEFAULTS, params) as Required; diff --git a/src/utils/jsx-entity.ts b/src/utils/jsx-entity.ts index f28210286d..fa517f8cdf 100644 --- a/src/utils/jsx-entity.ts +++ b/src/utils/jsx-entity.ts @@ -98,6 +98,7 @@ import { inflateTrimesh } from "../inflators/trimesh"; import { HeightFieldParams, inflateHeightField } from "../inflators/heightfield"; import { inflateAudioSettings } from "../inflators/audio-settings"; import { HubsVideoTexture } from "../textures/HubsVideoTexture"; +import { inflateMediaLink, MediaLinkParams } from "../inflators/media-link"; preload( new Promise(resolve => { @@ -380,6 +381,7 @@ export interface GLTFComponentData extends ComponentData { zoneAudioSource: AudioSourceParams; audioTarget: AudioTargetParams; audioSettings: SceneAudioSettings; + mediaLink: MediaLinkParams; // deprecated spawnPoint?: true; @@ -472,7 +474,7 @@ const jsxInflators: Required<{ [K in keyof JSXComponentData]: InflatorFn }> = { model: inflateModel, image: inflateImage, video: inflateVideo, - link: inflateLink, + link: inflateLink }; export const gltfInflators: Required<{ [K in keyof GLTFComponentData]: InflatorFn }> = { @@ -507,7 +509,8 @@ export const gltfInflators: Required<{ [K in keyof GLTFComponentData]: InflatorF boxCollider: inflateBoxCollider, trimesh: inflateTrimesh, heightfield: inflateHeightField, - audioSettings: inflateAudioSettings + audioSettings: inflateAudioSettings, + mediaLink: inflateMediaLink }; function jsxInflatorExists(name: string): name is keyof JSXComponentData {