• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file Defines 3D resource related interfaces
18 * @kit ArkGraphics3D
19 */
20
21import { Vec2, Vec3, Vec4, Aabb } from './SceneTypes';
22import { Callback } from '../@ohos.base';
23
24/**
25 * The enum of SceneResource type.
26 *
27 * @enum { number }
28 * @syscap SystemCapability.ArkUi.Graphics3D
29 * @since 12
30 */
31export enum SceneResourceType {
32  /**
33   * The resource is an Unknown.
34   *
35   * @syscap SystemCapability.ArkUi.Graphics3D
36   * @since 12
37   */
38  UNKNOWN = 0,
39
40  /**
41   * The resource is a Node.
42   *
43   * @syscap SystemCapability.ArkUi.Graphics3D
44   * @since 12
45   */
46  NODE = 1,
47
48  /**
49   * The resource is an Environment.
50   *
51   * @syscap SystemCapability.ArkUi.Graphics3D
52   * @since 12
53   */
54  ENVIRONMENT = 2,
55
56  /**
57   * The resource is a Material.
58   *
59   * @syscap SystemCapability.ArkUi.Graphics3D
60   * @since 12
61   */
62  MATERIAL = 3,
63
64  /**
65   * The resource is a Mesh.
66   *
67   * @syscap SystemCapability.ArkUi.Graphics3D
68   * @since 12
69   */
70  MESH = 4,
71
72  /**
73   * The resource is an Animation.
74   *
75   * @syscap SystemCapability.ArkUi.Graphics3D
76   * @since 12
77   */
78  ANIMATION = 5,
79
80  /**
81   * The resource is a Shader.
82   *
83   * @syscap SystemCapability.ArkUi.Graphics3D
84   * @since 12
85   */
86  SHADER = 6,
87
88  /**
89   * The resource is an Image.
90   *
91   * @syscap SystemCapability.ArkUi.Graphics3D
92   * @since 12
93   */
94  IMAGE = 7,
95}
96
97/**
98 * Define scene resource extended by other 3d resource.
99 *
100 * @interface SceneResource
101 * @syscap SystemCapability.ArkUi.Graphics3D
102 * @since 12
103 */
104export interface SceneResource {
105  /**
106   * Scene resource name.
107   *
108   * @type { string }
109   * @syscap SystemCapability.ArkUi.Graphics3D
110   * @since 12
111   */
112  name: string;
113
114  /**
115   * Scene resource type.
116   *
117   * @type { SceneResourceType }
118   * @readonly
119   * @syscap SystemCapability.ArkUi.Graphics3D
120   * @since 12
121   */
122  readonly resourceType: SceneResourceType;
123
124  /**
125   * Scene resource uri.
126   *
127   * @type { ?ResourceStr }
128   * @readonly
129   * @syscap SystemCapability.ArkUi.Graphics3D
130   * @since 12
131   */
132  readonly uri?: ResourceStr;
133
134
135  /**
136   * Release scene resource.
137   *
138   * @syscap SystemCapability.ArkUi.Graphics3D
139   * @since 12
140   */
141  destroy(): void;
142}
143
144/**
145 * Shader resource.
146 *
147 * @extends SceneResource
148 * @interface Shader
149 * @syscap SystemCapability.ArkUi.Graphics3D
150 * @since 12
151 */
152export interface Shader extends SceneResource {
153  /**
154   * Shader inputs.
155   *
156   * @type { Record<string, number | Vec2 | Vec3 | Vec4 | Image> }
157   * @readonly
158   * @syscap SystemCapability.ArkUi.Graphics3D
159   * @since 12
160   */
161  readonly inputs: Record<string, number | Vec2 | Vec3 | Vec4 | Image>;
162}
163
164/**
165 * The enum of material type.
166 *
167 * @enum { number }
168 * @syscap SystemCapability.ArkUi.Graphics3D
169 * @since 12
170 */
171export enum MaterialType {
172  /**
173   * The material type is a Shader.
174   *
175   * @syscap SystemCapability.ArkUi.Graphics3D
176   * @since 12
177   */
178  SHADER = 1,
179}
180
181/**
182 * Material resource.
183 *
184 * @extends SceneResource
185 * @interface Material
186 * @syscap SystemCapability.ArkUi.Graphics3D
187 * @since 12
188 */
189export interface Material extends SceneResource {
190  /**
191   * Material resource type.
192   *
193   * @type { MaterialType }
194   * @readonly
195   * @syscap SystemCapability.ArkUi.Graphics3D
196   * @since 12
197   */
198  readonly materialType: MaterialType;
199}
200
201/**
202 * Shader material resource.
203 *
204 * @extends Material
205 * @interface ShaderMaterial
206 * @syscap SystemCapability.ArkUi.Graphics3D
207 * @since 12
208 */
209export interface ShaderMaterial extends Material {
210  /**
211   * Color shader of material.
212   *
213   * @type { ?Shader }
214   * @syscap SystemCapability.ArkUi.Graphics3D
215   * @since 12
216   */
217  colorShader?: Shader;
218}
219
220/**
221 * Sub mesh resource.
222 *
223 * @interface SubMesh
224 * @syscap SystemCapability.ArkUi.Graphics3D
225 * @since 12
226 */
227export interface SubMesh {
228  /**
229   * The name of the sub mesh.
230   *
231   * @type { string }
232   * @syscap SystemCapability.ArkUi.Graphics3D
233   * @since 12
234   */
235  name: string;
236
237  /**
238   * The material of the sub mesh.
239   *
240   * @type { Material }
241   * @syscap SystemCapability.ArkUi.Graphics3D
242   * @since 12
243   */
244  material: Material;
245
246  /**
247   * The axis aligned bounding box of the sub mesh.
248   *
249   * @type { Aabb }
250   * @readonly
251   * @syscap SystemCapability.ArkUi.Graphics3D
252   * @since 12
253   */
254  readonly aabb: Aabb;
255}
256
257/**
258 * Mesh resource.
259 *
260 * @extends SceneResource
261 * @interface Mesh
262 * @syscap SystemCapability.ArkUi.Graphics3D
263 * @since 12
264 */
265export interface Mesh extends SceneResource {
266  /**
267   * The sub meshes of the mesh.
268   *
269   * @type { SubMesh[] }
270   * @readonly
271   * @syscap SystemCapability.ArkUi.Graphics3D
272   * @since 12
273   */
274  readonly subMeshes: SubMesh[];
275
276  /**
277   * The axis aligned bounding box of the mesh.
278   *
279   * @type { Aabb }
280   * @readonly
281   * @syscap SystemCapability.ArkUi.Graphics3D
282   * @since 12
283   */
284  readonly aabb: Aabb;
285
286  /**
287   * The material override sub mesh's material.
288   *
289   * @type { ?Material }
290   * @syscap SystemCapability.ArkUi.Graphics3D
291   * @since 12
292   */
293  materialOverride?: Material;
294}
295
296/**
297 * Animation resource.
298 *
299 * @extends SceneResource
300 * @interface Animation
301 * @syscap SystemCapability.ArkUi.Graphics3D
302 * @since 12
303 */
304export interface Animation extends SceneResource {
305  /**
306   * The animation is enabled.
307   *
308   * @type { boolean }
309   * @syscap SystemCapability.ArkUi.Graphics3D
310   * @since 12
311   */
312  enabled: boolean;
313
314  /**
315   * The duration of the animation.
316   *
317   * @type { number }
318   * @readonly
319   * @syscap SystemCapability.ArkUi.Graphics3D
320   * @since 12
321   */
322  readonly duration: number;
323
324  /**
325   * Whether the animation is running.
326   *
327   * @type { boolean }
328   * @readonly
329   * @syscap SystemCapability.ArkUi.Graphics3D
330   * @since 12
331   */
332  readonly running: boolean;
333
334  /**
335   * The progress of the animation between 0~1.
336   *
337   * @type { number }
338   * @readonly
339   * @syscap SystemCapability.ArkUi.Graphics3D
340   * @since 12
341   */
342  readonly progress: number;
343
344  /**
345   * Register a callback when animation finished.
346   *
347   * @param { Callback<void> } callback - the callback invoked when animation finished
348   * @syscap SystemCapability.ArkUi.Graphics3D
349   * @since 12
350   */
351  onFinished(callback: Callback<void>): void;
352
353  /**
354   * Register a callback when animation started.
355   *
356   * @param { Callback<void> } callback - the callback invoked when animation started
357   * @syscap SystemCapability.ArkUi.Graphics3D
358   * @since 12
359   */
360  onStarted(callback: Callback<void>): void;
361
362  /**
363   * Pause the animation.
364   *
365   * @syscap SystemCapability.ArkUi.Graphics3D
366   * @since 12
367   */
368  pause(): void;
369
370  /**
371   * Restart the animation.
372   *
373   * @syscap SystemCapability.ArkUi.Graphics3D
374   * @since 12
375   */
376  restart(): void;
377
378  /**
379   * Seek the animation to the position.
380   *
381   * @param { number } position - the position seek between 0~1
382   * @syscap SystemCapability.ArkUi.Graphics3D
383   * @since 12
384   */
385  seek(position: number): void;
386
387  /**
388   * Start the animation.
389   *
390   * @syscap SystemCapability.ArkUi.Graphics3D
391   * @since 12
392   */
393  start(): void;
394
395  /**
396   * Stop the animation and seek the position to the beginning.
397   *
398   * @syscap SystemCapability.ArkUi.Graphics3D
399   * @since 12
400   */
401  stop(): void;
402
403  /**
404   * Finish the animation and seek the position to the end.
405   *
406   * @syscap SystemCapability.ArkUi.Graphics3D
407   * @since 12
408   */
409  finish(): void;
410}
411
412/**
413 * The enum of environment background type.
414 * @enum { number }
415 * @syscap SystemCapability.ArkUi.Graphics3D
416 * @since 12
417 */
418export enum EnvironmentBackgroundType {
419  /**
420   * The background is none.
421   *
422   * @syscap SystemCapability.ArkUi.Graphics3D
423   * @since 12
424   */
425  BACKGROUND_NONE = 0,
426
427  /**
428   * The background is image.
429   *
430   * @syscap SystemCapability.ArkUi.Graphics3D
431   * @since 12
432   */
433  BACKGROUND_IMAGE = 1,
434
435  /**
436   * The background is cubemap.
437   *
438   * @syscap SystemCapability.ArkUi.Graphics3D
439   * @since 12
440   */
441  BACKGROUND_CUBEMAP = 2,
442
443  /**
444   * The background is equirectangular.
445   *
446   * @syscap SystemCapability.ArkUi.Graphics3D
447   * @since 12
448   */
449  BACKGROUND_EQUIRECTANGULAR = 3,
450}
451
452/**
453 * Environment resource.
454 *
455 * @extends SceneResource
456 * @interface Environment
457 * @syscap SystemCapability.ArkUi.Graphics3D
458 * @since 12
459 */
460export interface Environment extends SceneResource {
461  /**
462   * The background type of the environment.
463   *
464   * @type { EnvironmentBackgroundType }
465   * @syscap SystemCapability.ArkUi.Graphics3D
466   * @since 12
467   */
468  backgroundType: EnvironmentBackgroundType;
469
470  /**
471   * The indirect diffuse factor of the environment.
472   *
473   * @type { Vec4 }
474   * @syscap SystemCapability.ArkUi.Graphics3D
475   * @since 12
476   */
477  indirectDiffuseFactor: Vec4;
478
479  /**
480   * The indirect specular factor of the environment.
481   *
482   * @type { Vec4 }
483   * @syscap SystemCapability.ArkUi.Graphics3D
484   * @since 12
485   */
486  indirectSpecularFactor: Vec4;
487
488  /**
489   * The environment map factor of the environment.
490   *
491   * @type { Vec4 }
492   * @syscap SystemCapability.ArkUi.Graphics3D
493   * @since 12
494   */
495  environmentMapFactor: Vec4;
496
497  /**
498   * The environment image of the environment.
499   *
500   * @type { ?(Image | null) }
501   * @syscap SystemCapability.ArkUi.Graphics3D
502   * @since 12
503   */
504  environmentImage?: Image | null;
505
506  /**
507   * The radiance image of the environment.
508   *
509   * @type { ?(Image | null) }
510   * @syscap SystemCapability.ArkUi.Graphics3D
511   * @since 12
512   */
513  radianceImage?: Image | null;
514
515  /**
516   * The irradiance coefficients (array of nine Vec3).
517   *
518   * @type { ?Vec3[] }
519   * @syscap SystemCapability.ArkUi.Graphics3D
520   * @since 12
521   */
522  irradianceCoefficients?: Vec3[];
523}
524
525/**
526 * Image resource.
527 *
528 * @extends SceneResource
529 * @interface Image
530 * @syscap SystemCapability.ArkUi.Graphics3D
531 * @since 12
532 */
533export interface Image extends SceneResource {
534  /**
535   * The width of the image.
536   *
537   * @type { number }
538   * @readonly
539   * @syscap SystemCapability.ArkUi.Graphics3D
540   * @since 12
541   */
542  readonly width: number;
543
544  /**
545   * The height of the image.
546   *
547   * @type { number }
548   * @readonly
549   * @syscap SystemCapability.ArkUi.Graphics3D
550   * @since 12
551   */
552  readonly height: number;
553}
554