diff --git a/packages/components/src/api/media_files/GetMedia.ts b/packages/components/src/api/media_files/GetMedia.ts index 17b635b811..6ac38903fe 100644 --- a/packages/components/src/api/media_files/GetMedia.ts +++ b/packages/components/src/api/media_files/GetMedia.ts @@ -3,10 +3,12 @@ import { UserDetailsLight } from "../_common/UserDetailsLight"; import { MediaFileType } from "../_common/enums/MediaFileType"; import { WeightCategory } from "../_common/enums/WeightCategory"; import { WeightType } from "../_common/enums/WeightType"; +import { MediaFileSubtype } from "../enums/MediaFileSubtype"; export interface MediaFile { token: string; media_type: MediaFileType; + maybe_media_subtype: MediaFileSubtype | null; public_bucket_path: string; maybe_batch_token: string; maybe_creator_user: UserDetailsLight | null; diff --git a/packages/components/src/api/media_files/GetMediaFile.ts b/packages/components/src/api/media_files/GetMediaFile.ts index 3d59eb5d6e..2930b87778 100644 --- a/packages/components/src/api/media_files/GetMediaFile.ts +++ b/packages/components/src/api/media_files/GetMediaFile.ts @@ -3,11 +3,13 @@ import { UserDetailsLight } from "../_common/UserDetailsLight"; import { MediaFileType } from "../_common/enums/MediaFileType"; import { WeightCategory } from "../_common/enums/WeightCategory"; import { WeightType } from "../_common/enums/WeightType"; +import { MediaFileSubtype } from "../enums/MediaFileSubtype"; // import { Weight } from "../weights/GetWeight"; export interface MediaFile { token: string; media_type: MediaFileType; + maybe_media_subtype: MediaFileSubtype | null; public_bucket_path: string; maybe_creator_user: UserDetailsLight | null; creator_set_visibility: string; diff --git a/packages/fakeyou.com/src/components/common/Scene3D/Scene3D.tsx b/packages/fakeyou.com/src/components/common/Scene3D/Scene3D.tsx index 4057817297..d30377ee2e 100644 --- a/packages/fakeyou.com/src/components/common/Scene3D/Scene3D.tsx +++ b/packages/fakeyou.com/src/components/common/Scene3D/Scene3D.tsx @@ -8,27 +8,42 @@ import "./Scene3D.scss"; // You can supply either an `objectId` or a `sceneMediaFileToken` when loading in studio mode. interface Scene3DProps { mode: string; + skybox?: string; fullScreen?: boolean; urlParams?: string; - objectId?: string; - sceneMediaFileToken?: string; className?: string; onSceneSavedCallback?: (mediaToken: string) => void; + + // NB: The following parameters are mutally exclusive. + // We should use Typescript to enforce this. + objectId?: string; // built-in objects + sceneMediaFileToken?: string; // scn.ron native storyteller engine scenes + mixamoUrl?: string; // a mixamo animation + bvhUrl?: string; // a MocapNet animation in BVH format + sceneImportUrl?: string; // a generic (non-storyteller) scene: GLB, GLTF, etc. } export default function Scene3D({ mode, + skybox, fullScreen = false, - objectId, - sceneMediaFileToken, - urlParams, className, onSceneSavedCallback, + + // NB: The following parameters are mutally exclusive. + // We should use Typescript to enforce this. + objectId, + sceneMediaFileToken, + mixamoUrl, + bvhUrl, + sceneImportUrl, + }: Scene3DProps) { const engineBaseUrl = "https://engine.fakeyou.com"; const iframeRef = useRef(null); + const onMessage = useCallback((event: MessageEvent) => { console.log("engine message received", event.data, event); @@ -43,7 +58,8 @@ export default function Scene3D({ console.log("studio-ready message (2)"); - studio.postMessage("save-scene", engineBaseUrl); + // NB: Example of how to call the API in the other direction: + // studio.postMessage("save-scene", engineBaseUrl); } else if ( typeof event.data === "string" && event.data.startsWith("scene-saved:") @@ -58,57 +74,50 @@ export default function Scene3D({ } else if (event.data === "scene-save-failed") { console.error("Failed to save the scene!"); } - }, []); + }, [onSceneSavedCallback]); useEffect(() => { - /* - if (iframeRef && iframeRef.current) { - console.log("installing event listener for messages"); - - // NB: Compiler complains about ref going out of scope before destructor is called. - let ref = iframeRef.current; - - // TODO(bt,2024-03-08): Fix typescript 'any' hack - (ref as any).addEventListener("message", onMessage); - - return () => { - console.log("uninstalling event listener for messages"); - - // TODO(bt,2024-03-08): Fix typescript 'any' hack - (ref as any).removeEventListener("message", onMessage); - } - } - */ - - console.log("installing event listener for messages"); window.addEventListener("message", onMessage, false); - return () => { - console.log("uninstalling event listener for messages"); window.removeEventListener("message", onMessage, false); } }, [onMessage]); - //}, [onMessage, iframeRef]); let engineUrl = `${engineBaseUrl}/?mode=${mode}`; + if (skybox) { + engineUrl += `&skybox=${skybox}`; + } + if (sceneMediaFileToken) { + // NB: Storyteller Engine makes the API call to load the scene. + // We don't need to pass the bucket path. + // The engine, does, however, need a `.scn.ron` file extension. const sceneUrlRef = `remote://${sceneMediaFileToken}.scn.ron`; engineUrl += `&scene=${sceneUrlRef}`; } else if (objectId) { + // NB: This is an engine built-in, eg. `couch.gltf` or `sample-room.gltf`. engineUrl += `&objectId=${objectId}`; + } else if (mixamoUrl) { + // NB: This should be a full bucket path to an asset. + engineUrl += `&mixamo=${mixamoUrl}`; + } else if (bvhUrl) { + // NB: This should be a full bucket path to an asset. + engineUrl += `&bvh=${bvhUrl}`; + } else if (sceneImportUrl) { + // TODO: Not sure what the format of this should be. + engineUrl += `&sceneImport=${sceneImportUrl}`; } - console.log('installing iframe engine and callbacks'); - return (
+ {/* IframeResizer was causing some glitches passing messages. Need to test more. */} {/**/}