-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6111 from mozilla/bitecs-media-video-params
Add support for media video and image parameters
- Loading branch information
Showing
21 changed files
with
288 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { addComponent } from "bitecs"; | ||
import { MediaImage } from "../bit-components"; | ||
import { addObject3DComponent } from "../utils/jsx-entity"; | ||
import { AlphaMode, create360ImageMesh, createImageMesh } from "../utils/create-image-mesh"; | ||
import { ProjectionMode } from "../utils/projection-mode"; | ||
import { Texture } from "three"; | ||
import { HubsWorld } from "../app"; | ||
import { EntityID } from "../utils/networking-types"; | ||
|
||
export interface ImageParams { | ||
cacheKey: string; | ||
texture: Texture; | ||
ratio: number; | ||
projection: ProjectionMode; | ||
alphaMode: AlphaMode; | ||
alphaCutoff: number; | ||
} | ||
|
||
const DEFAULTS: Partial<ImageParams> = { | ||
projection: ProjectionMode.FLAT, | ||
alphaMode: AlphaMode.OPAQUE, | ||
alphaCutoff: 0.5, | ||
ratio: 1 | ||
}; | ||
|
||
export function inflateImage(world: HubsWorld, eid: EntityID, params: ImageParams) { | ||
const { texture, ratio, projection, alphaMode, alphaCutoff, cacheKey } = params; | ||
const mesh = | ||
projection === ProjectionMode.SPHERE_EQUIRECTANGULAR | ||
? create360ImageMesh(texture, alphaMode, alphaCutoff) | ||
: createImageMesh(texture, ratio, alphaMode, alphaCutoff); | ||
addObject3DComponent(world, eid, mesh); | ||
addComponent(world, MediaImage, eid); | ||
|
||
const requiredParams = Object.assign({}, DEFAULTS, params) as Required<ImageParams>; | ||
MediaImage.projection[eid] = requiredParams.projection; | ||
MediaImage.alphaMode[eid] = requiredParams.alphaMode; | ||
MediaImage.alphaCutoff[eid] = requiredParams.alphaCutoff; | ||
MediaImage.cacheKey[eid] = APP.getSid(cacheKey); | ||
|
||
return eid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { create360ImageMesh, createImageMesh } from "../utils/create-image-mesh"; | ||
import { addComponent } from "bitecs"; | ||
import { addObject3DComponent } from "../utils/jsx-entity"; | ||
import { ProjectionMode } from "../utils/projection-mode"; | ||
import { MediaVideo, MediaVideoData } from "../bit-components"; | ||
import { HubsWorld } from "../app"; | ||
import { EntityID } from "../utils/networking-types"; | ||
import { Texture } from "three"; | ||
|
||
export const VIDEO_FLAGS = { | ||
CONTROLS: 1 << 0 | ||
}; | ||
|
||
export interface VideoParams { | ||
texture: Texture; | ||
ratio: number; | ||
projection: ProjectionMode; | ||
video: HTMLVideoElement; | ||
controls: boolean; | ||
} | ||
|
||
const DEFAULTS: Partial<VideoParams> = { | ||
projection: ProjectionMode.FLAT, | ||
controls: true, | ||
ratio: 1 | ||
}; | ||
|
||
export function inflateVideo(world: HubsWorld, eid: EntityID, params: VideoParams) { | ||
const { texture, ratio, projection, video } = params; | ||
const mesh = | ||
projection === ProjectionMode.SPHERE_EQUIRECTANGULAR | ||
? create360ImageMesh(texture) | ||
: createImageMesh(texture, ratio); | ||
addObject3DComponent(world, eid, mesh); | ||
addComponent(world, MediaVideo, eid); | ||
|
||
const requiredParams = Object.assign({}, DEFAULTS, params) as Required<VideoParams>; | ||
MediaVideo.flags[eid] = 0; | ||
if (!!requiredParams.controls) { | ||
MediaVideo.flags[eid] |= VIDEO_FLAGS.CONTROLS; | ||
} | ||
MediaVideo.projection[eid] = requiredParams.projection; | ||
MediaVideo.ratio[eid] = requiredParams.ratio; | ||
MediaVideoData.set(eid, video); | ||
return eid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.