Skip to content

Commit

Permalink
feat: 增加音视频数据规范 (#85)
Browse files Browse the repository at this point in the history
* feat(mdedia): 增加音视频规范

* chore(mdeida): 优化注释

* style: 调整音视频类型规范结构

---------

Co-authored-by: yiiqii <[email protected]>
  • Loading branch information
Sruimeng and yiiqii authored Sep 25, 2024
1 parent a3086af commit 63ab54c
Show file tree
Hide file tree
Showing 11 changed files with 326 additions and 154 deletions.
95 changes: 95 additions & 0 deletions src/assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type { RenderLevel } from './type';

/**
* 资源基类
*/
export interface AssetBaseOptions {
/**
* 资源 ID
*/
id: string,
/**
* 资源类型
*/
url: string,
/**
* 渲染等级
* 如果没有设置,按照 B+ 处理
*/
renderLevel?: RenderLevel,
}

/**
* 纹理贴图属性
*/
export interface Image extends AssetBaseOptions {
/**
* WebP 地址
* 如果运行时支持 WebP,则优先使用 WebP
*/
webp?: string,
/**
* AVIF 地址
* 如果运行时支持 AVIF,则优先使用 AVIF
* @since 2.0.0
*/
avif?: string,
/**
* 是否使用 mipmap
* loader 发布压缩纹理的时候会根据此参数决定是否生成压缩纹理
* @default false
*/
mipmap?: boolean,
/**
* 图片 Y 轴的方向,如果 Y 轴向上(与 OpenGL 相同)则为 1
* 如果 Y 轴向下(与 OpenGL 相反)则为 -1,图片再绘制数据模板的时候需要翻转绘制
* @default 1
*/
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[]>;

/**
* 模板贴图属性
*/
export interface TemplateImage extends Image {
template: TemplateContent,
}

/**
* 压缩贴图属性
*/
export interface CompressedImage extends Image {
/**
* 压缩贴图地址
*/
compressed: {
// 安卓
astc?: string,
pvrtc?: string,
},
}
8 changes: 2 additions & 6 deletions src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export enum DataType {
TreeComponent = 'TreeComponent',
AnimationComponent = 'AnimationComponent',
SpineComponent = 'SpineComponent',
VideoComponent = 'VideoComponent',
AudioComponent = 'AudioComponent',

// Non-EffectObject
TimelineClip = 'TimelineClip',
Expand Down Expand Up @@ -231,12 +233,6 @@ export interface ShaderData extends EffectsObjectData {
properties?: string,
}

export interface EffectComponentData extends ComponentData {
_priority: number,
materials: DataPath[],
geometry: DataPath,
}

export interface EffectsPackageData {
fileSummary: FileSummary,
exportObjects: EffectsObjectData[],
Expand Down
142 changes: 0 additions & 142 deletions src/image.ts

This file was deleted.

5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './type';
export * from './composition';
export * from './image';
export * from './texture';
export * from './constants';
export * from './number-expression';
export * from './scene';
Expand All @@ -17,6 +17,8 @@ export * from './item/sprite-item';
export * from './item/spine-item';
export * from './item/effect-item';
export * from './item/text-item';
export * from './item/video-item';
export * from './item/audio-item';
export * from './item/model';
export * from './vfx-item-data';
export * from './animation-clip-data';
Expand All @@ -26,3 +28,4 @@ export * from './components';
export * from './vfx-item-data';
export * from './buitin-object-guid';
export * from './timeline';
export * from './assets';
4 changes: 4 additions & 0 deletions src/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type { ModelCameraItem, ModelLightItem, ModelMeshItem, ModelSkyboxItem, M
import type { CameraItem } from './item/camera-item';
import type { CompositionItem } from './item/composition-item';
import type { TextItem } from './item/text-item';
import type { VideoItem } from './item/video-item';
import type { AudioItem } from './item/audio-item';

/**
* Item 基类,无对应元素
Expand All @@ -20,6 +22,8 @@ export type Item =
| InteractItem
| CameraItem
| TextItem
| VideoItem
| AudioItem
| ModelMeshItem<'json'>
| ModelSkyboxItem<'json'>
| ModelTreeItem<'json'>
Expand Down
49 changes: 49 additions & 0 deletions src/item/audio-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { ComponentData, DataPath } from '../components';
import type { ItemType } from '../type';
import type { BaseItem } from './base-item';

/**
* 音频元素
*/
export interface AudioItem extends BaseItem {
/**
* 元素类型(指定为 audio)
*/
type: ItemType.audio,
/**
* 音频元素基础属性
*/
content: AudioComponentData,
}

export interface AudioContentOptions {
/**
* 音频链接,索引到 scene 中的 audios 数组
*/
audio: DataPath,
/**
* 音频播放速度
* @default 1
*/
playbackRate?: number,
/**
* 是否静音播放
* @default false
*/
muted?: boolean,
/**
* 音频音量大小
* @default 1
*/
volume?: number,
}

/**
* 音频组件属性
*/
export interface AudioComponentData extends ComponentData {
/**
* 音频元素基础属性
*/
options: AudioContentOptions,
}
7 changes: 7 additions & 0 deletions src/item/effect-item.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ComponentData, DataPath } from '../components';
import type { ItemType, PositionOverLifetime, RotationOverLifetime, SizeOverLifetime } from '../type';
import type { BaseItem, EndBehavior } from './base-item';

Expand Down Expand Up @@ -35,3 +36,9 @@ export interface EffectContent {
*/
positionOverLifetime?: PositionOverLifetime,
}

export interface EffectComponentData extends ComponentData {
_priority: number,
materials: DataPath[],
geometry: DataPath,
}
Loading

0 comments on commit 63ab54c

Please sign in to comment.