@galacean/effects-core 2.10.0-alpha.1 → 2.10.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -139,11 +139,11 @@ export declare class ParticleMesh implements ParticleMeshData {
139
139
  private cachedRotationMatrix;
140
140
  private cachedLinearMove;
141
141
  private tempMatrix3;
142
+ private readonly attributeData;
142
143
  VERT_MAX_KEY_FRAME_COUNT: number;
143
144
  constructor(engine: Engine, props: ParticleMeshProps);
144
145
  getPointColor(index: number): number[];
145
146
  clearPoints(): void;
146
- resetGeometryData(geometry: Geometry): void;
147
147
  onUpdate(dt: number): void;
148
148
  minusTime(time: number): void;
149
149
  removePoint(index: number): void;
@@ -151,6 +151,9 @@ export declare class ParticleMesh implements ParticleMeshData {
151
151
  private applyTranslation;
152
152
  private applyRotation;
153
153
  private applyLinearMove;
154
+ private getAttributeData;
155
+ private setAttributeData;
156
+ private setAttributeSubData;
154
157
  private expandArray;
155
158
  }
156
159
  export declare function getParticleMeshShader(item: spec.ParticleItem, gpuCapability: GPUCapability, env?: string): {
@@ -171,6 +171,13 @@ export declare class ParticleSystem extends Component implements Maskable {
171
171
  private update;
172
172
  drawStencilMask(maskRef: number): void;
173
173
  onDestroy(): void;
174
+ /**
175
+ * @hidden
176
+ * Internal utility.
177
+ * Not part of the public API — do not rely on this in your code.
178
+ */
179
+ rebuild(): void;
180
+ dispose(): void;
174
181
  getParticleBoxes(): {
175
182
  center: Vector3;
176
183
  size: Vector3;
@@ -41,6 +41,7 @@ export declare class TrailMesh {
41
41
  checkVertexDistance: boolean;
42
42
  private pointStart;
43
43
  private trailCursors;
44
+ private readonly attributeData;
44
45
  constructor(engine: Engine, props: TrailMeshProps);
45
46
  get time(): number;
46
47
  set time(t: number);
@@ -52,5 +53,8 @@ export declare class TrailMesh {
52
53
  getPointStartPos(index: number): Vector3;
53
54
  setPointStartPos(index: number, pos: Vector3): void;
54
55
  onUpdate(escapeTime: number): any;
56
+ private getAttributeData;
57
+ private setAttributeData;
58
+ private setAttributeSubData;
55
59
  }
56
60
  export declare function getTrailMeshShader(trails: spec.ParticleTrail, particleMaxCount: number, name: string, gpuCapability: GPUCapability, env?: string): ShaderWithSource;
@@ -158,6 +158,7 @@ export declare class ShapeComponent extends RendererComponent implements Maskabl
158
158
  getBoundingBox(): BoundingBoxTriangle;
159
159
  getBoundingBoxInfo(): BoundingBoxInfo;
160
160
  private buildGeometryFromPath;
161
+ private updateAttributeData;
161
162
  private computeScreenScale;
162
163
  private buildPath;
163
164
  private updateMaterials;
@@ -76,5 +76,6 @@ export declare class SpriteComponent extends MaskableGraphic {
76
76
  * 不依赖组件状态,splits 由参数传入(同时存在帧动画与多 split 的数据不存在)。
77
77
  */
78
78
  protected updateGeometryFromMultiSplit(splits: spec.SplitParameter[]): void;
79
+ private updateAttributeData;
79
80
  }
80
81
  export {};
@@ -0,0 +1,33 @@
1
+ import type { Engine } from '../engine';
2
+ import type { Disposable } from '../utils';
3
+ import type { DataArray } from './data-buffer';
4
+ import { DataBuffer } from './data-buffer';
5
+ import { VertexBuffer } from './vertex-buffer';
6
+ /**
7
+ * 管理顶点数据及其对应的后端缓冲区。
8
+ */
9
+ export declare class Buffer implements Disposable {
10
+ readonly engine: Engine;
11
+ readonly byteStride: number;
12
+ private data?;
13
+ private buffer?;
14
+ private readonly updatable;
15
+ private readonly instanced;
16
+ private readonly divisor;
17
+ private readonly label?;
18
+ private isAlreadyOwned;
19
+ private _isDisposed;
20
+ constructor(engine: Engine, data: DataArray | DataBuffer, updatable: boolean, stride?: number, postponeInternalCreation?: boolean, instanced?: boolean, useBytes?: boolean, divisor?: number, label?: string);
21
+ get isDisposed(): boolean;
22
+ get capacity(): number;
23
+ isUpdatable(): boolean;
24
+ getData(): DataArray | undefined;
25
+ getBuffer(): DataBuffer | undefined;
26
+ getStrideSize(): number;
27
+ createVertexBuffer(kind: string, offset: number, size: number, stride?: number, instanced?: boolean, useBytes?: boolean, divisor?: number): VertexBuffer;
28
+ create(data?: DataArray): void;
29
+ update(data: DataArray): void;
30
+ updateDirectly(data: DataArray, offset: number, vertexCount?: number, useBytes?: boolean): void;
31
+ dispose(): void;
32
+ private getDataBufferOptions;
33
+ }
@@ -0,0 +1,39 @@
1
+ import type * as spec from '@galacean/effects-specification';
2
+ export type DataArray = number[] | ArrayBuffer | ArrayBufferView;
3
+ export type IndicesArray = number[] | Int32Array | Uint32Array | Uint16Array;
4
+ export type IndexData = Int32Array | Uint32Array | Uint16Array;
5
+ export declare enum BufferUsage {
6
+ Stream = 35040,
7
+ Static = 35044,
8
+ Dynamic = 35048
9
+ }
10
+ export declare enum BufferDataType {
11
+ Byte = 5120,
12
+ UnsignedByte = 5121,
13
+ Short = 5122,
14
+ UnsignedShort = 5123,
15
+ Int = 5124,
16
+ UnsignedInt = 5125,
17
+ Float = 5126
18
+ }
19
+ export interface DataBufferOptions {
20
+ usage: number;
21
+ type: number;
22
+ byteStride: number;
23
+ instanceDivisor: number;
24
+ label?: string;
25
+ }
26
+ /**
27
+ * 后端缓冲区的最小抽象,只保存资源状态。
28
+ */
29
+ export declare class DataBuffer {
30
+ references: number;
31
+ capacity: number;
32
+ is32Bits: boolean;
33
+ get underlyingResource(): unknown;
34
+ }
35
+ export declare function getBytesPerElement(type: number): number;
36
+ export declare function getDataType(data: DataArray): BufferDataType;
37
+ export declare function getDataByteLength(data: DataArray): number;
38
+ export declare function toBufferView(data: DataArray): ArrayBufferView;
39
+ export declare function createTypedArray(type: number, length: number): spec.TypedArray;
@@ -1,26 +1,28 @@
1
- import type * as spec from '@galacean/effects-specification';
1
+ import * as spec from '@galacean/effects-specification';
2
2
  import type { Engine } from '../engine';
3
3
  import { EffectsObject } from '../effects-object';
4
- export declare const BYTES_TYPE_MAP: Record<string, number>;
5
- /**
6
- * Geometry 的绘制模式
7
- */
8
- export type GeometryDrawMode = WebGLRenderingContext['POINTS'] | WebGLRenderingContext['TRIANGLES'] | WebGLRenderingContext['TRIANGLE_STRIP'] | WebGLRenderingContext['TRIANGLE_FAN'] | WebGLRenderingContext['LINES'] | WebGLRenderingContext['LINE_STRIP'] | WebGLRenderingContext['LINE_LOOP'];
4
+ import { Buffer } from './buffer';
5
+ import type { DataBuffer, IndexData, IndicesArray } from './data-buffer';
6
+ import { VertexBuffer } from './vertex-buffer';
7
+ import type { ShaderVariant } from './shader';
8
+ export type GeometryDrawMode = number;
9
9
  export type Attribute = spec.AttributeWithData | spec.AttributeWithDataPointer | spec.AttributeWithType | spec.AttributeWithDataSource;
10
10
  export interface GeometryProps {
11
11
  name?: string;
12
12
  attributes: Record<string, Attribute>;
13
13
  indices?: {
14
- data: spec.TypedArray;
15
- releasable?: boolean;
14
+ data: IndexData;
16
15
  };
17
16
  mode?: GeometryDrawMode;
18
17
  drawCount?: number;
19
18
  drawStart?: number;
20
19
  instanceCount?: number;
21
- bufferUsage?: WebGLRenderingContext['STATIC_DRAW'] | WebGLRenderingContext['DYNAMIC_DRAW'];
22
20
  /**
23
- * 粒子最大数量,适用于无法更新 GPU 缓存长度的引擎接入
21
+ * 顶点和索引缓冲区的使用方式,默认使用静态缓冲区。
22
+ */
23
+ bufferUsage?: number;
24
+ /**
25
+ * 为初始空缓冲区预留的最大顶点数量。
24
26
  */
25
27
  maxVertex?: number;
26
28
  }
@@ -30,93 +32,69 @@ export interface SkinProps {
30
32
  inverseBindMatrices?: number[];
31
33
  }
32
34
  /**
33
- * Geometry 抽象类
35
+ * 几何数据、属性布局和绘制范围的后端无关实现。
34
36
  */
35
- export declare abstract class Geometry extends EffectsObject {
36
- /**
37
- * Geometry 的名称
38
- */
37
+ export declare class Geometry extends EffectsObject {
38
+ static create: (engine: Engine, props?: GeometryProps) => Geometry;
39
39
  name: string;
40
- /**
41
- * 子网格数据
42
- */
43
40
  subMeshes: spec.SubMesh[];
44
- /**
45
- * Geometry 创建函数
46
- */
47
- static create: (engine: Engine, opts?: GeometryProps) => Geometry;
48
- /**
49
- * 获取 Geometry 的 attribute 数据。
50
- * @param name - attribute 名称
51
- */
52
- abstract getAttributeData(name: string): spec.TypedArray | undefined;
53
- /**
54
- * 设置 Geometry 的 attribute 数据。
55
- * @param name - attribute 名称
56
- * @param data - 要设置的 attribute 数据
57
- */
58
- abstract setAttributeData(name: string, data: spec.TypedArray): void;
59
- /**
60
- * 设置 attribute 的部分数据,当 attribute 数据只有部分更新时,可调用此函数。
61
- * @param name - attribute 名称
62
- * @param offset - 更新数据在 attribute 数组的起始位置 index
63
- * @param data - 要设置的 attribute 数据
64
- */
65
- abstract setAttributeSubData(name: string, offset: number, data: spec.TypedArray): void;
66
- /**
67
- * 获取 attribute 的步长
68
- * @param name - attribute 名称
69
- */
70
- abstract getAttributeStride(name: string): number;
71
- /**
72
- * 获取当前 Geometry 所有的 attribute 名称。
73
- */
74
- abstract getAttributeNames(): string[];
75
- /**
76
- * 获取当前 Geometry 的 indices 数据。
77
- */
78
- abstract getIndexData(): spec.TypedArray | undefined;
79
- /**
80
- * 设置 Geometry indices 数据。
81
- * @param data - 要设置的 indices 数据
82
- */
83
- abstract setIndexData(data: spec.TypedArray): void;
84
- /**
85
- * 设置 indices 的部分数据,当 indices 数据只有部分更新时,可调用此函数。
86
- * @param offset - 更新数据在 indices 数组的起始位置 index
87
- * @param data - 要设置的 indices 数据
88
- */
89
- abstract setIndexSubData(offset: number, data: spec.TypedArray): void;
90
- /**
91
- * 设置 Geometry 绘制的 drawStart
92
- * @param value 要设置的 drawStart 值
93
- */
94
- abstract setDrawStart(count: number): void;
95
- /**
96
- * 获取当前 Geometry 的 drawStart
97
- */
98
- abstract getDrawStart(): number;
99
- /**
100
- * 设置 Geometry 绘制的 drawCount。
101
- * @param count 要设置的 drawCount 值
102
- */
103
- abstract setDrawCount(count: number): void;
104
- /**
105
- * 获取当前 Geometry 的 drawcount
106
- */
107
- abstract getDrawCount(): number;
108
- /**
109
- * 获取当前 Geometry 关联的蒙皮数据
110
- */
111
- abstract getSkinProps(): SkinProps;
112
- /**
113
- * 初始化 GPU 资源
114
- * @override
115
- */
41
+ /** @hide */
42
+ mode: GeometryDrawMode;
43
+ /** @hide */
44
+ instanceCount: number;
45
+ private vertexBuffers;
46
+ private indices;
47
+ private drawCount;
48
+ private drawStart;
49
+ private skin;
50
+ private indexBuffer?;
51
+ private disposed;
52
+ private initialized;
53
+ private options?;
54
+ private bufferUsage;
55
+ private vertexArrayObjects?;
56
+ /** @hide */
57
+ constructor(engine: Engine, props?: GeometryProps);
58
+ /** @hide */
59
+ isDisposed(): boolean;
60
+ /** @hide */
61
+ getVertexBuffer(name: string): VertexBuffer | undefined;
62
+ /** @hide */
63
+ setVerticesBuffer(vertexBuffer: VertexBuffer, disposeExistingBuffer?: boolean): void;
64
+ /** @hide */
65
+ getAttributeBuffer(name: string): Buffer | undefined;
66
+ getAttributeData(name: string): spec.TypedArray | undefined;
67
+ setAttributeData(name: string, data: spec.TypedArray): void;
68
+ setAttributeSubData(name: string, offset: number, data: spec.TypedArray): void;
69
+ getAttributeStride(name: string): number;
70
+ getAttributeNames(): string[];
71
+ /** @hide */
72
+ getIndexBuffer(): DataBuffer | undefined;
73
+ getIndexData(): IndexData;
74
+ /** @hide */
75
+ getIndexType(): number;
76
+ setIndexData(data: IndicesArray): void;
77
+ setIndexSubData(offset: number, data: IndicesArray): void;
78
+ setDrawStart(start: number): void;
79
+ getDrawStart(): number;
80
+ setDrawCount(count: number): void;
81
+ getDrawCount(): number;
82
+ getSkinProps(): SkinProps;
83
+ /** @hide */
84
+ bind(shader: ShaderVariant): void;
85
+ private releaseVertexArrayObject;
116
86
  initialize(): void;
117
- /**
118
- * 几何数据刷新
119
- */
120
87
  flush(): void;
88
+ /** @hide */
89
+ restore(): void;
90
+ fromData(data: spec.GeometryData): void;
91
+ dispose(): void;
92
+ private processProps;
93
+ private releaseCurrentBuffers;
94
+ private disposeVertexArrayObjects;
95
+ private createIndexBuffer;
96
+ private releaseIndexBuffer;
97
+ private forEachVertexBuffer;
121
98
  }
122
- export declare function generateEmptyTypedArray(type: number): Float32Array | Int16Array | Int32Array;
99
+ export declare const BYTES_TYPE_MAP: Record<string, number>;
100
+ export declare function generateEmptyTypedArray(type: number): spec.TypedArray;
@@ -14,6 +14,8 @@ export interface GPUCapabilityDetail {
14
14
  maxTextureAnisotropy: number;
15
15
  shaderTextureLod: boolean;
16
16
  instanceDraw?: boolean;
17
+ /** @hide */
18
+ vertexArrayObject?: boolean;
17
19
  ktx2Support: boolean;
18
20
  drawBuffers?: boolean;
19
21
  asyncShaderCompile: boolean;
@@ -62,6 +62,7 @@ export declare class Graphics {
62
62
  * 提交当前累积的顶点到 renderer,清空缓冲(批次内部 flush 不重置 batchType)
63
63
  */
64
64
  private flushBatch;
65
+ private updateAttributeData;
65
66
  /**
66
67
  * 线段顶点按顺序连接 (p0-p1, p1-p2, p2-p3, ...)
67
68
  * @param points - 点数组,格式 [x1,y1,x2,y2,...],至少需要2个点(4个数值)
@@ -7,6 +7,9 @@ export * from './shader';
7
7
  export * from './gpu-capability';
8
8
  export * from './mesh';
9
9
  export * from './geometry';
10
+ export * from './data-buffer';
11
+ export * from './buffer';
12
+ export * from './vertex-buffer';
10
13
  export * from './framebuffer';
11
14
  export * from './renderer';
12
15
  export * from './graphics';
@@ -57,8 +57,9 @@ export interface SharedShaderWithSource {
57
57
  export type ShaderWithSource = SharedShaderWithSource;
58
58
  export declare abstract class ShaderVariant extends EffectsObject {
59
59
  readonly source: ShaderWithSource;
60
+ readonly key: string;
60
61
  shader: Shader;
61
- constructor(engine: Engine, source: ShaderWithSource);
62
+ constructor(engine: Engine, source: ShaderWithSource, key: string);
62
63
  initialize(): void;
63
64
  abstract setFloat(name: string, value: number): void;
64
65
  abstract setInt(name: string, value: number): void;
@@ -0,0 +1,72 @@
1
+ import type * as spec from '@galacean/effects-specification';
2
+ import type { Engine } from '../engine';
3
+ import type { Disposable } from '../utils';
4
+ import { Buffer } from './buffer';
5
+ import type { DataArray, DataBuffer } from './data-buffer';
6
+ import { BufferDataType } from './data-buffer';
7
+ export interface VertexBufferProps {
8
+ updatable?: boolean;
9
+ postponeInternalCreation?: boolean;
10
+ stride?: number;
11
+ instanced?: boolean;
12
+ offset?: number;
13
+ size?: number;
14
+ type?: number;
15
+ normalized?: boolean;
16
+ useBytes?: boolean;
17
+ divisor?: number;
18
+ takeBufferOwnership?: boolean;
19
+ label?: string;
20
+ }
21
+ /**
22
+ * 描述一个顶点属性如何读取共享缓冲区。
23
+ */
24
+ export declare class VertexBuffer implements Disposable {
25
+ static readonly PositionKind = "aPos";
26
+ static readonly NormalKind = "aNormal";
27
+ static readonly TangentKind = "aTangent";
28
+ static readonly UVKind = "aUV";
29
+ static readonly UV2Kind = "aUV2";
30
+ static readonly UV3Kind = "aUV3";
31
+ static readonly UV4Kind = "aUV4";
32
+ static readonly UV5Kind = "aUV5";
33
+ static readonly UV6Kind = "aUV6";
34
+ static readonly ColorKind = "aColor";
35
+ static readonly JointsKind = "aJoints";
36
+ static readonly WeightsKind = "aWeights";
37
+ static readonly BYTE = BufferDataType.Byte;
38
+ static readonly UNSIGNED_BYTE = BufferDataType.UnsignedByte;
39
+ static readonly SHORT = BufferDataType.Short;
40
+ static readonly UNSIGNED_SHORT = BufferDataType.UnsignedShort;
41
+ static readonly INT = BufferDataType.Int;
42
+ static readonly UNSIGNED_INT = BufferDataType.UnsignedInt;
43
+ static readonly FLOAT = BufferDataType.Float;
44
+ readonly byteStride: number;
45
+ readonly byteOffset: number;
46
+ readonly normalized: boolean;
47
+ readonly type: spec.BufferType;
48
+ readonly engine: Engine;
49
+ private readonly kind;
50
+ private readonly size;
51
+ private _isDisposed;
52
+ private instanced;
53
+ private _instanceDivisor;
54
+ constructor(engine: Engine, data: DataArray | Buffer | DataBuffer, kind: string, props?: VertexBufferProps);
55
+ get isDisposed(): boolean;
56
+ get instanceDivisor(): number;
57
+ set instanceDivisor(value: number);
58
+ getKind(): string;
59
+ isUpdatable(): boolean;
60
+ getData(): DataArray | undefined;
61
+ getBuffer(): DataBuffer | undefined;
62
+ getWrapperBuffer(): Buffer;
63
+ getStrideSize(): number;
64
+ getOffset(): number;
65
+ getSize(sizeInBytes?: boolean): number;
66
+ getIsInstanced(): boolean;
67
+ getInstanceDivisor(): number;
68
+ create(data?: DataArray): void;
69
+ update(data: DataArray): void;
70
+ updateDirectly(data: DataArray, offset: number, useBytes?: boolean): void;
71
+ dispose(): void;
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/effects-core",
3
- "version": "2.10.0-alpha.1",
3
+ "version": "2.10.0-alpha.2",
4
4
  "description": "Galacean Effects runtime core for the web",
5
5
  "module": "./dist/index.mjs",
6
6
  "main": "./dist/index.js",