Skip to content

Commit

Permalink
Move to using a MediaLink component
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Oct 2, 2023
1 parent 6f76917 commit c619017
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 23 deletions.
7 changes: 5 additions & 2 deletions src/bit-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
6 changes: 3 additions & 3 deletions src/bit-systems/media-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
MediaContentBounds,
MediaImageLoaderData,
MediaInfo,
MediaLink,
MediaLoaded,
MediaLoader,
MediaVideoLoaderData,
Expand Down Expand Up @@ -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 });
}

Expand Down
4 changes: 3 additions & 1 deletion src/components/gltf-model-plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/inflators/image-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export interface ImageLoaderParams {
projection: ProjectionModeName;
alphaMode: AlphaModeName;
alphaCutoff: number;
linkSrc?: string;
controls: true;
}

const DEFAULTS: Partial<ImageLoaderParams> = {
Expand All @@ -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<ImageLoaderParams>;
Expand Down
13 changes: 13 additions & 0 deletions src/inflators/media-link.ts
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 1 addition & 5 deletions src/inflators/media-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)!;
}
}
4 changes: 1 addition & 3 deletions src/inflators/model-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
});
}
4 changes: 1 addition & 3 deletions src/inflators/video-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export interface VideoLoaderParams {
autoPlay: boolean;
controls: boolean;
loop: boolean;
linkSrc?: string;
}

const DEFAULTS: Partial<VideoLoaderParams> = {
Expand All @@ -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<VideoLoaderParams>;
Expand Down
7 changes: 5 additions & 2 deletions src/utils/jsx-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -380,6 +381,7 @@ export interface GLTFComponentData extends ComponentData {
zoneAudioSource: AudioSourceParams;
audioTarget: AudioTargetParams;
audioSettings: SceneAudioSettings;
mediaLink: MediaLinkParams;

// deprecated
spawnPoint?: true;
Expand Down Expand Up @@ -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 }> = {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c619017

Please sign in to comment.