diff --git a/src/assets.ts b/src/assets.ts index af375a6..2a9a71a 100644 --- a/src/assets.ts +++ b/src/assets.ts @@ -3,7 +3,7 @@ import type { RenderLevel } from './type'; /** * 资源基类 */ -export interface AssetBaseOptions { +export interface AssetBase { /** * 资源 ID */ @@ -19,10 +19,46 @@ export interface AssetBaseOptions { renderLevel?: RenderLevel, } +/** + * 动态换图类型 + * @since 1.1.0 + */ +export enum BackgroundType { + video = 'video', + image = 'image', +} + +/** + * 多媒体资源类型 + * @since 2.1.0 + */ +export enum MultimediaType { + video = 'video', + audio = 'audio', +} + +export interface TemplateContent { + /** + * 当 template 宽高和 image 不相同时,会对 template 进行缩放,使其和 image 相同。 + */ + width: number, + height: number, + // 绘制 canvas 的背景图片,替换掉原来的那张图片,如果没有就不替换 + background?: { + type: BackgroundType, + name: string, + url: string | HTMLImageElement, + }, +} + +export type TemplateVariables = Record; + +export type ImageSource = Image | TemplateImage | CompressedImage; + /** * 纹理贴图属性 */ -export interface Image extends AssetBaseOptions { +export interface Image extends AssetBase { /** * WebP 地址 * 如果运行时支持 WebP,则优先使用 WebP @@ -48,31 +84,6 @@ export interface Image extends AssetBaseOptions { oriY?: 1 | -1, } -/** - * 动态换图类型 - * @since 1.1.0 - */ -export enum BackgroundType { - video = 'video', - image = 'image', -} - -export interface TemplateContent { - /** - * 当 template 宽高和 image 不相同时,会对 template 进行缩放,使其和 image 相同。 - */ - width: number, - height: number, - // 绘制 canvas 的背景图片,替换掉原来的那张图片,如果没有就不替换 - background?: { - type: BackgroundType, - name: string, - url: string | HTMLImageElement, - }, -} - -export type TemplateVariables = Record; - /** * 模板贴图属性 */ diff --git a/src/buitin-object-guid.ts b/src/buitin-object-guid.ts index b9ffef9..f3cf9bc 100644 --- a/src/buitin-object-guid.ts +++ b/src/buitin-object-guid.ts @@ -1,5 +1,6 @@ export const BuiltinObjectGUID = { WhiteTexture: 'whitetexture00000000000000000000', + TransparentTexture: 'transparenttexture00000000000000000000', PBRShader: 'pbr00000000000000000000000000000', UnlitShader: 'unlit000000000000000000000000000', }; diff --git a/src/scene.ts b/src/scene.ts index 79b03c8..f1bc80f 100644 --- a/src/scene.ts +++ b/src/scene.ts @@ -7,7 +7,7 @@ import type { BinaryFile } from './binary'; import type { ComponentData, EffectsObjectData, GeometryData, MaterialData, ShaderData } from './components'; import type { VFXItemData } from './vfx-item-data'; import type { AnimationClipData } from './animation-clip-data'; -import type { TemplateImage, Image, CompressedImage, AssetBaseOptions } from './assets'; +import type { AssetBase, ImageSource } from './assets'; /** * runtime 2.0 之前的场景信息 @@ -52,7 +52,7 @@ export interface JSONSceneLegacy { /** * 贴图信息 */ - images: (TemplateImage | Image | CompressedImage)[], + images: ImageSource[], /** * 根据合成ID,每个合成用到的 image 的数组索引 */ @@ -136,7 +136,7 @@ export interface JSONScene { /** * 贴图信息 */ - images: (TemplateImage | Image | CompressedImage)[], + images: ImageSource[], /** * 根据合成 ID,每个合成用到的 image 的数组索引 */ @@ -163,12 +163,12 @@ export interface JSONScene { * 视频资源 * @since 2.0.0 */ - videos?: AssetBaseOptions[], + videos?: AssetBase[], /** * 音频资源 * @since 2.0.0 */ - audios?: AssetBaseOptions[], + audios?: AssetBase[], /** * 二进制文件地址 */ diff --git a/src/type.ts b/src/type.ts index 29d2d30..fde458f 100644 --- a/src/type.ts +++ b/src/type.ts @@ -712,3 +712,5 @@ export enum RenderFace { Back = 'Back', Front = 'Front', } + +export type HTMLImageLike = HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;