Skip to content

Commit

Permalink
style: 整理 assets 相关类型
Browse files Browse the repository at this point in the history
  • Loading branch information
yiiqii committed Sep 29, 2024
1 parent a5d0942 commit ee49c16
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 32 deletions.
65 changes: 38 additions & 27 deletions src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { RenderLevel } from './type';
/**
* 资源基类
*/
export interface AssetBaseOptions {
export interface AssetBase {
/**
* 资源 ID
*/
Expand All @@ -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<string, string | string[] | HTMLImageElement | HTMLImageElement[]>;

export type ImageSource = Image | TemplateImage | CompressedImage;

/**
* 纹理贴图属性
*/
export interface Image extends AssetBaseOptions {
export interface Image extends AssetBase {
/**
* WebP 地址
* 如果运行时支持 WebP,则优先使用 WebP
Expand All @@ -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<string, string | string[] | HTMLImageElement | HTMLImageElement[]>;

/**
* 模板贴图属性
*/
Expand Down
1 change: 1 addition & 0 deletions src/buitin-object-guid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const BuiltinObjectGUID = {
WhiteTexture: 'whitetexture00000000000000000000',
TransparentTexture: 'transparenttexture00000000000000000000',
PBRShader: 'pbr00000000000000000000000000000',
UnlitShader: 'unlit000000000000000000000000000',
};
10 changes: 5 additions & 5 deletions src/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 之前的场景信息
Expand Down Expand Up @@ -52,7 +52,7 @@ export interface JSONSceneLegacy {
/**
* 贴图信息
*/
images: (TemplateImage | Image | CompressedImage)[],
images: ImageSource[],
/**
* 根据合成ID,每个合成用到的 image 的数组索引
*/
Expand Down Expand Up @@ -136,7 +136,7 @@ export interface JSONScene {
/**
* 贴图信息
*/
images: (TemplateImage | Image | CompressedImage)[],
images: ImageSource[],
/**
* 根据合成 ID,每个合成用到的 image 的数组索引
*/
Expand All @@ -163,12 +163,12 @@ export interface JSONScene {
* 视频资源
* @since 2.0.0
*/
videos?: AssetBaseOptions[],
videos?: AssetBase[],
/**
* 音频资源
* @since 2.0.0
*/
audios?: AssetBaseOptions[],
audios?: AssetBase[],
/**
* 二进制文件地址
*/
Expand Down
2 changes: 2 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,5 @@ export enum RenderFace {
Back = 'Back',
Front = 'Front',
}

export type HTMLImageLike = HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;

0 comments on commit ee49c16

Please sign in to comment.