forked from cocos/cocos-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefine.ts
328 lines (291 loc) · 6.79 KB
/
define.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { PrimitiveMode, Attribute } from '../gfx';
/**
* @en
* The definition of the parameter for building a primitive geometry.
* @zh
* 几何体参数选项。
*/
export interface IGeometryOptions {
/**
* @en
* Whether to include normal. Default to true.
* @zh
* 是否包含法线。默认为true。
*/
includeNormal: boolean;
/**
* @en
* Whether to include uv. Default to true.
* @zh
* 是否包含UV。默认为true。
*/
includeUV: boolean;
}
/**
* @en
* Apply the options to default.
* @zh
* 应用默认的几何参数选项。
*/
export function applyDefaultGeometryOptions<GeometryOptions = IGeometryOptions> (
options?: RecursivePartial<IGeometryOptions>,
): GeometryOptions {
options = options || {};
if (options.includeNormal === undefined) {
options.includeNormal = true;
}
if (options.includeUV === undefined) {
options.includeUV = true;
}
return options as GeometryOptions;
}
/**
* @en
* The definition of the geometry, this struct can build a mesh.
* @zh
* 几何体信息。
*/
export interface IGeometry {
/**
* @en
* Vertex positions.
* @zh
* 顶点位置。
*/
positions: number[];
/**
* @en
* Vertex normals.
* @zh
* 顶点法线。
*/
normals?: number[];
/**
* @en
* Texture coordinates.
* @zh
* 纹理坐标。
*/
uvs?: number[];
/**
* @en
* Vertex Tangents.
* @zh
* 顶点切线。
*/
tangents?: number[];
/**
* @en
* Vertex colors.
* @zh
* 顶点颜色。
*/
colors?: number[];
/**
* @en
* specify vertex attributes, use (positions|normals|uvs|colors) as keys
* @zh
* 顶点属性。
*/
attributes?: Attribute[];
customAttributes?: {
attr: Attribute,
values: number[],
}[];
/**
* @en
* Bounding sphere radius.
* @zh
* 包围球半径。
*/
boundingRadius?: number;
/**
* @en
* Min position.
* @zh
* 最小位置。
*/
minPos?: {
x: number;
y: number;
z: number;
};
/**
* @en
* Max position.
* @zh
* 最大位置。
*/
maxPos?: {
x: number;
y: number;
z: number;
};
/**
* @en
* Geometry indices, if one needs indexed-draw.
* @zh
* 几何索引,当使用索引绘制时。
*/
indices?: number[];
/**
* @en
* Topology of the geometry vertices. Default is TRIANGLE_LIST.
* @zh
* 几何顶点的拓扑图元。默认值是TRIANGLE_LIST。
*/
primitiveMode?: PrimitiveMode;
/**
* @en
* whether rays casting from the back face of this geometry could collide with it
* @zh
* 是否是双面,用于判断来自于几何体背面的射线检测。
*/
doubleSided?: boolean;
}
/**
* @en
* The definition of the dynamic geometry, this struct can build a dynamic mesh.
* @zh
* 几何体信息。
*/
export interface IDynamicGeometry {
/**
* @en
* Vertex positions: 3 float components.
* @zh
* 顶点位置:3个float分量。
*/
positions: Float32Array;
/**
* @en
* Vertex normals: 3 float components.
* @zh
* 顶点法线:3个float分量。
*/
normals?: Float32Array;
/**
* @en
* Texture coordinates: 2 float components.
* @zh
* 纹理坐标:2个float分量。
*/
uvs?: Float32Array;
/**
* @en
* Vertex Tangents: 4 float components.
* @zh
* 顶点切线:4个float分量。
*/
tangents?: Float32Array;
/**
* @en
* Vertex colors: 4 float components.
* @zh
* 顶点颜色:4个float分量。
*/
colors?: Float32Array;
/**
* @en
* Custom attributes
* @zh
* 定制属性列表。
*/
customAttributes?: {
attr: Attribute,
values: Float32Array,
}[];
/**
* @en
* Min position.
* @zh
* 最小位置。
*/
minPos?: {
x: number;
y: number;
z: number;
};
/**
* @en
* Max position.
* @zh
* 最大位置。
*/
maxPos?: {
x: number;
y: number;
z: number;
};
/**
* @en
* 16 bits Geometry indices, if one needs indexed-draw.
* @zh
* 16位几何索引,当使用索引绘制时。
*/
indices16?: Uint16Array;
/**
* @en
* 32 bits Geometry indices, if one needs indexed-draw.
* @zh
* 32位几何索引,当使用索引绘制时。
*/
indices32?: Uint32Array;
/**
* @en
* Topology of the geometry vertices. Default is TRIANGLE_LIST.
* @zh
* 几何顶点的拓扑图元。默认值是TRIANGLE_LIST。
*/
primitiveMode?: PrimitiveMode;
/**
* @en
* whether rays casting from the back face of this geometry could collide with it
* @zh
* 是否是双面,用于判断来自于几何体背面的射线检测。
*/
doubleSided?: boolean;
}
export interface ICreateMeshOptions {
/**
* @en calculate mesh's aabb or not
* @zh 是否计算模型的包围盒。
*/
calculateBounds?: boolean;
}
export interface ICreateDynamicMeshOptions {
/**
* @en max sub mesh count
* @zh 最大子模型个数。
*/
maxSubMeshes: number;
/**
* @en max sub mesh vertex count
* @zh 子模型最大顶点个数。
*/
maxSubMeshVertices: number;
/**
* @en max sub mesh index count
* @zh 子模型最大索引个数。
*/
maxSubMeshIndices: number;
}