From a612030592b4df6174bf41ade1e20e8fac927fea Mon Sep 17 00:00:00 2001 From: Takahiro Date: Fri, 18 Aug 2023 16:35:01 -0700 Subject: [PATCH] bitECS: Support glTF link component --- src/inflators/link-loader.ts | 18 ++++++++++++++++++ src/utils/jsx-entity.ts | 9 ++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/inflators/link-loader.ts diff --git a/src/inflators/link-loader.ts b/src/inflators/link-loader.ts new file mode 100644 index 0000000000..7c1a8d6ac6 --- /dev/null +++ b/src/inflators/link-loader.ts @@ -0,0 +1,18 @@ +import { HubsWorld } from "../app"; +import { inflateMediaLoader } from "./media-loader"; + +export type LinkLoaderParams = { + href: string; +}; + +export function inflateLinkLoader(world: HubsWorld, eid: number, params: LinkLoaderParams): number { + inflateMediaLoader(world, eid, { + src: params.href, + resize: false, + recenter: true, + animateLoad: false, + isObjectMenuTarget: true + }); + + return eid; +} diff --git a/src/utils/jsx-entity.ts b/src/utils/jsx-entity.ts index b395e3ad88..524a95fca8 100644 --- a/src/utils/jsx-entity.ts +++ b/src/utils/jsx-entity.ts @@ -52,6 +52,7 @@ import { inflateVideoLoader, VideoLoaderParams } from "../inflators/video-loader import { inflateImageLoader, ImageLoaderParams } from "../inflators/image-loader"; import { inflateModelLoader, ModelLoaderParams } from "../inflators/model-loader"; import { inflateLink, LinkParams } from "../inflators/link"; +import { inflateLinkLoader, LinkLoaderParams } from "../inflators/link-loader"; import { inflateLoopAnimationInitialize, LoopAnimationParams } from "../inflators/loop-animation"; import { inflateSlice9 } from "../inflators/slice9"; import { TextParams, inflateText } from "../inflators/text"; @@ -252,7 +253,6 @@ export interface ComponentData { spotLight?: SpotLightParams; grabbable?: GrabbableParams; billboard?: { onlyY: boolean }; - link?: LinkParams; mirror?: MirrorParams; audioZone?: AudioZoneParams; audioParams?: AudioSettings; @@ -276,6 +276,7 @@ export interface JSXComponentData extends ComponentData { cacheKey: string; }; video?: VideoParams; + link?: LinkParams; networkedVideo?: true; videoMenu?: { sliderRef: Ref; @@ -365,6 +366,7 @@ export interface GLTFComponentData extends ComponentData { audio?: VideoLoaderParams; video?: VideoLoaderParams; image?: ImageLoaderParams; + link?: LinkLoaderParams; model?: ModelLoaderParams; environmentSettings?: EnvironmentSettingsParams; reflectionProbe?: ReflectionProbeParams; @@ -409,7 +411,6 @@ declare global { export const commonInflators: Required<{ [K in keyof ComponentData]: InflatorFn }> = { grabbable: inflateGrabbable, billboard: createDefaultInflator(Billboard), - link: inflateLink, // inflators that create Object3Ds ambientLight: inflateAmbientLight, @@ -468,7 +469,8 @@ const jsxInflators: Required<{ [K in keyof JSXComponentData]: InflatorFn }> = { slice9: inflateSlice9, model: inflateModel, image: inflateImage, - video: inflateVideo + video: inflateVideo, + link: inflateLink, }; export const gltfInflators: Required<{ [K in keyof GLTFComponentData]: InflatorFn }> = { @@ -481,6 +483,7 @@ export const gltfInflators: Required<{ [K in keyof GLTFComponentData]: InflatorF audio: inflateVideoLoader, video: inflateVideoLoader, image: inflateImageLoader, + link: inflateLinkLoader, model: inflateModelLoader, reflectionProbe: inflateReflectionProbe, navMesh: createDefaultInflator(NavMesh),