• 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 node related interfaces
18 * @kit ArkGraphics3D
19 */
20
21import { SceneResource, Mesh } from './SceneResources';
22import { Position3, Quaternion, Scale3, Color } from './SceneTypes';
23import { PostProcessSettings } from './ScenePostProcessSettings';
24
25/**
26 * Defines the layer mask of the node.
27 *
28 * @interface LayerMask
29 * @syscap SystemCapability.ArkUi.Graphics3D
30 * @since 12
31 */
32export interface LayerMask {
33  /**
34   * Get whether layer mask is enabled.
35   *
36   * @param { number } index - the layer mask
37   * @returns { boolean } whether layer mask is enabled
38   * @syscap SystemCapability.ArkUi.Graphics3D
39   * @since 12
40   */
41  getEnabled(index: number): boolean;
42
43  /**
44   * Set whether the layer mask is enabled.
45   *
46   * @param { number } index - the layer mask
47   * @param { boolean } enabled - whether layer mask is enabled
48   * @syscap SystemCapability.ArkUi.Graphics3D
49   * @since 12
50   */
51  setEnabled(index: number, enabled: boolean): void;
52}
53
54/**
55 * The enum of node type.
56 *
57 * @enum { number }
58 * @syscap SystemCapability.ArkUi.Graphics3D
59 * @since 12
60 */
61export enum NodeType {
62  /**
63   * The node is an empty node.
64   *
65   * @syscap SystemCapability.ArkUi.Graphics3D
66   * @since 12
67   */
68  NODE = 1,
69
70  /**
71   * The node is a geometry node.
72   *
73   * @syscap SystemCapability.ArkUi.Graphics3D
74   * @since 12
75   */
76  GEOMETRY = 2,
77
78  /**
79   * The node is a camera node.
80   *
81   * @syscap SystemCapability.ArkUi.Graphics3D
82   * @since 12
83   */
84  CAMERA = 3,
85
86  /**
87   * The node is a light node.
88   *
89   * @syscap SystemCapability.ArkUi.Graphics3D
90   * @since 12
91   */
92  LIGHT = 4
93}
94
95/**
96 * Defines a scene object container.
97 *
98 * @interface Container
99 * @syscap SystemCapability.ArkUi.Graphics3D
100 * @since 12
101 */
102export interface Container<T> {
103  /**
104   * Append a item to the container.
105   *
106   * @param { T } item - the item append to the end of container
107   * @syscap SystemCapability.ArkUi.Graphics3D
108   * @since 12
109   */
110  append(item: T): void;
111
112  /**
113   * Insert a item.
114   *
115   * @param { T } item - the item insert to the container
116   * @param { T | null } sibling - insert after this item, insert to the head if sibling is null
117   * @syscap SystemCapability.ArkUi.Graphics3D
118   * @since 12
119   */
120  insertAfter(item: T, sibling: T | null): void;
121
122  /**
123   * Remove a item from Container's children.
124   *
125   * @param { T } item - the item to be removed
126   * @syscap SystemCapability.ArkUi.Graphics3D
127   * @since 12
128   */
129  remove(item: T): void;
130
131  /**
132   * Returns a child at given index from this Container's child list.
133   *
134   * @param { number } index - the index of the child to return
135   * @returns { T | null } return the item specified by the index
136   * @syscap SystemCapability.ArkUi.Graphics3D
137   * @since 12
138   */
139  get(index: number): T | null;
140
141  /**
142   * Clear all children.
143   *
144   * @syscap SystemCapability.ArkUi.Graphics3D
145   * @since 12
146   */
147  clear(): void;
148
149  /**
150   * Returns the number of items in the container.
151   *
152   * @returns { number } the number of the container
153   * @syscap SystemCapability.ArkUi.Graphics3D
154   * @since 12
155   */
156  count(): number;
157}
158
159/**
160 * Defines Node interface.
161 *
162 * @interface Node
163 * @syscap SystemCapability.ArkUi.Graphics3D
164 * @since 12
165 */
166export interface Node extends SceneResource {
167  /**
168   * position of the node.
169   *
170   * @type { Position3 }
171   * @syscap SystemCapability.ArkUi.Graphics3D
172   * @since 12
173   */
174  position: Position3;
175
176  /**
177   * Rotation of the node.
178   *
179   * @type { Quaternion }
180   * @syscap SystemCapability.ArkUi.Graphics3D
181   * @since 12
182   */
183  rotation: Quaternion;
184
185  /**
186   * Scale of the node.
187   *
188   * @type { Scale3 }
189   * @syscap SystemCapability.ArkUi.Graphics3D
190   * @since 12
191   */
192  scale: Scale3;
193
194  /**
195   * Visibility flag for the node.
196   *
197   * @type { boolean }
198   * @syscap SystemCapability.ArkUi.Graphics3D
199   * @since 12
200   */
201  visible: boolean;
202
203  /**
204   * Type of the node.
205   *
206   * @type { NodeType }
207   * @readonly
208   * @syscap SystemCapability.ArkUi.Graphics3D
209   * @since 12
210   */
211  readonly nodeType: NodeType;
212
213  /**
214   * Layer mask of the node.
215   *
216   * @type { LayerMask }
217   * @readonly
218   * @syscap SystemCapability.ArkUi.Graphics3D
219   * @since 12
220   */
221  readonly layerMask: LayerMask;
222
223  /**
224   * Path of the node.
225   *
226   * @type { string }
227   * @readonly
228   * @syscap SystemCapability.ArkUi.Graphics3D
229   * @since 12
230   */
231  readonly path: string;
232
233  /**
234   * Parent of the node.
235   *
236   * @type { Node | null }
237   * @readonly
238   * @syscap SystemCapability.ArkUi.Graphics3D
239   * @since 12
240   */
241  readonly parent: Node | null;
242
243  /**
244   * Get node by path.
245   *
246   * @param { string } path - the path of the node queried
247   * @returns { Node | null }
248   * @syscap SystemCapability.ArkUi.Graphics3D
249   * @since 12
250   */
251  getNodeByPath(path: string): Node | null;
252
253  /**
254   * Children of the node.
255   *
256   * @type { Container<Node> }
257   * @readonly
258   * @syscap SystemCapability.ArkUi.Graphics3D
259   * @since 12
260   */
261  readonly children: Container<Node>
262}
263
264/**
265 * Defines Geometry interface.
266 *
267 * @interface Geometry
268 * @syscap SystemCapability.ArkUi.Graphics3D
269 * @since 12
270 */
271export interface Geometry extends Node {
272  /**
273   * Mesh of the node.
274   *
275   * @type { Mesh }
276   * @readonly
277   * @syscap SystemCapability.ArkUi.Graphics3D
278   * @since 12
279   */
280  readonly mesh: Mesh;
281}
282
283/**
284 * The enum of light type.
285 *
286 * @enum { number }
287 * @syscap SystemCapability.ArkUi.Graphics3D
288 * @since 12
289 */
290export enum LightType {
291  /**
292   * Directional light.
293   *
294   * @syscap SystemCapability.ArkUi.Graphics3D
295   * @since 12
296   */
297  DIRECTIONAL = 1,
298
299  /**
300   * Spot light.
301   *
302   * @syscap SystemCapability.ArkUi.Graphics3D
303   * @since 12
304   */
305  SPOT = 2,
306}
307
308/**
309 * Defines light interface.
310 *
311 * @interface Light
312 * @syscap SystemCapability.ArkUi.Graphics3D
313 * @since 12
314 */
315export interface Light extends Node {
316  /**
317   * The type of the light.
318   *
319   * @type { LightType }
320   * @readonly
321   * @syscap SystemCapability.ArkUi.Graphics3D
322   * @since 12
323   */
324  readonly lightType: LightType;
325
326  /**
327   * The color of the light.
328   *
329   * @type { Color }
330   * @syscap SystemCapability.ArkUi.Graphics3D
331   * @since 12
332   */
333  color: Color;
334
335  /**
336   * The intensity of the light.
337   *
338   * @type { number }
339   * @syscap SystemCapability.ArkUi.Graphics3D
340   * @since 12
341   */
342  intensity: number;
343
344  /**
345   * Whether casting shadows.
346   *
347   * @type { boolean }
348   * @syscap SystemCapability.ArkUi.Graphics3D
349   * @since 12
350   */
351  shadowEnabled: boolean;
352
353  /**
354   * Whether enable the light.
355   *
356   * @type { boolean }
357   * @syscap SystemCapability.ArkUi.Graphics3D
358   * @since 12
359   */
360  enabled: boolean;
361}
362
363/**
364 * Defines spot light.
365 *
366 * @interface SpotLight
367 * @syscap SystemCapability.ArkUi.Graphics3D
368 * @since 12
369 */
370export interface SpotLight extends Light {
371}
372
373/**
374 * Defines directional light.
375 *
376 * @interface DirectionalLight
377 * @syscap SystemCapability.ArkUi.Graphics3D
378 * @since 12
379 */
380export interface DirectionalLight extends Light {
381}
382
383/**
384 * Defines camera.
385 *
386 * @interface Camera
387 * @syscap SystemCapability.ArkUi.Graphics3D
388 * @since 12
389 */
390export interface Camera extends Node {
391  /**
392   * Field of view of the camera.
393   *
394   * @type { number }
395   * @syscap SystemCapability.ArkUi.Graphics3D
396   * @since 12
397   */
398  fov: number;
399
400  /**
401   * Near plane of the directional light.
402   *
403   * @type { number }
404   * @syscap SystemCapability.ArkUi.Graphics3D
405   * @since 12
406   */
407  nearPlane: number;
408
409  /**
410   * Far plane of the directional light.
411   *
412   * @type { number }
413   * @syscap SystemCapability.ArkUi.Graphics3D
414   * @since 12
415   */
416  farPlane: number;
417
418  /**
419   * Whether enabled the camera.
420   *
421   * @type { boolean }
422   * @syscap SystemCapability.ArkUi.Graphics3D
423   * @since 12
424   */
425  enabled: boolean;
426
427  /**
428   * The post processing settings of the camera.
429   *
430   * @type { PostProcessSettings | null }
431   * @syscap SystemCapability.ArkUi.Graphics3D
432   * @since 12
433   */
434  postProcess: PostProcessSettings | null;
435
436  /**
437   * Background clear color (environment background overrides this color,
438   * BACKGROUND_NONE is needed for this to actually take effect).
439   *
440   * @type { Color | null }
441   * @syscap SystemCapability.ArkUi.Graphics3D
442   * @since 12
443   */
444  clearColor: Color | null;
445}
446