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 * @extends SceneResource 163 * @interface Node 164 * @syscap SystemCapability.ArkUi.Graphics3D 165 * @since 12 166 */ 167export interface Node extends SceneResource { 168 /** 169 * position of the node. 170 * 171 * @type { Position3 } 172 * @syscap SystemCapability.ArkUi.Graphics3D 173 * @since 12 174 */ 175 position: Position3; 176 177 /** 178 * Rotation of the node. 179 * 180 * @type { Quaternion } 181 * @syscap SystemCapability.ArkUi.Graphics3D 182 * @since 12 183 */ 184 rotation: Quaternion; 185 186 /** 187 * Scale of the node. 188 * 189 * @type { Scale3 } 190 * @syscap SystemCapability.ArkUi.Graphics3D 191 * @since 12 192 */ 193 scale: Scale3; 194 195 /** 196 * Visibility flag for the node. 197 * 198 * @type { boolean } 199 * @syscap SystemCapability.ArkUi.Graphics3D 200 * @since 12 201 */ 202 visible: boolean; 203 204 /** 205 * Type of the node. 206 * 207 * @type { NodeType } 208 * @readonly 209 * @syscap SystemCapability.ArkUi.Graphics3D 210 * @since 12 211 */ 212 readonly nodeType: NodeType; 213 214 /** 215 * Layer mask of the node. 216 * 217 * @type { LayerMask } 218 * @readonly 219 * @syscap SystemCapability.ArkUi.Graphics3D 220 * @since 12 221 */ 222 readonly layerMask: LayerMask; 223 224 /** 225 * Path of the node. 226 * 227 * @type { string } 228 * @readonly 229 * @syscap SystemCapability.ArkUi.Graphics3D 230 * @since 12 231 */ 232 readonly path: string; 233 234 /** 235 * Parent of the node. 236 * 237 * @type { Node | null } 238 * @readonly 239 * @syscap SystemCapability.ArkUi.Graphics3D 240 * @since 12 241 */ 242 readonly parent: Node | null; 243 244 /** 245 * Get node by path. 246 * 247 * @param { string } path - the path of the node queried 248 * @returns { Node | null } 249 * @syscap SystemCapability.ArkUi.Graphics3D 250 * @since 12 251 */ 252 getNodeByPath(path: string): Node | null; 253 254 /** 255 * Children of the node. 256 * 257 * @type { Container<Node> } 258 * @readonly 259 * @syscap SystemCapability.ArkUi.Graphics3D 260 * @since 12 261 */ 262 readonly children: Container<Node> 263} 264 265/** 266 * Defines Geometry interface. 267 * 268 * @extends Node 269 * @interface Geometry 270 * @syscap SystemCapability.ArkUi.Graphics3D 271 * @since 12 272 */ 273export interface Geometry extends Node { 274 /** 275 * Mesh of the node. 276 * 277 * @type { Mesh } 278 * @readonly 279 * @syscap SystemCapability.ArkUi.Graphics3D 280 * @since 12 281 */ 282 readonly mesh: Mesh; 283} 284 285/** 286 * The enum of light type. 287 * 288 * @enum { number } 289 * @syscap SystemCapability.ArkUi.Graphics3D 290 * @since 12 291 */ 292export enum LightType { 293 /** 294 * Directional light. 295 * 296 * @syscap SystemCapability.ArkUi.Graphics3D 297 * @since 12 298 */ 299 DIRECTIONAL = 1, 300 301 /** 302 * Spot light. 303 * 304 * @syscap SystemCapability.ArkUi.Graphics3D 305 * @since 12 306 */ 307 SPOT = 2, 308} 309 310/** 311 * Defines light interface. 312 * 313 * @extends Node 314 * @interface Light 315 * @syscap SystemCapability.ArkUi.Graphics3D 316 * @since 12 317 */ 318export interface Light extends Node { 319 /** 320 * The type of the light. 321 * 322 * @type { LightType } 323 * @readonly 324 * @syscap SystemCapability.ArkUi.Graphics3D 325 * @since 12 326 */ 327 readonly lightType: LightType; 328 329 /** 330 * The color of the light. 331 * 332 * @type { Color } 333 * @syscap SystemCapability.ArkUi.Graphics3D 334 * @since 12 335 */ 336 color: Color; 337 338 /** 339 * The intensity of the light. 340 * 341 * @type { number } 342 * @syscap SystemCapability.ArkUi.Graphics3D 343 * @since 12 344 */ 345 intensity: number; 346 347 /** 348 * Whether casting shadows. 349 * 350 * @type { boolean } 351 * @syscap SystemCapability.ArkUi.Graphics3D 352 * @since 12 353 */ 354 shadowEnabled: boolean; 355 356 /** 357 * Whether enable the light. 358 * 359 * @type { boolean } 360 * @syscap SystemCapability.ArkUi.Graphics3D 361 * @since 12 362 */ 363 enabled: boolean; 364} 365 366/** 367 * Defines spot light. 368 * 369 * @extends Light 370 * @interface SpotLight 371 * @syscap SystemCapability.ArkUi.Graphics3D 372 * @since 12 373 */ 374export interface SpotLight extends Light { 375} 376 377/** 378 * Defines directional light. 379 * 380 * @extends Light 381 * @interface DirectionalLight 382 * @syscap SystemCapability.ArkUi.Graphics3D 383 * @since 12 384 */ 385export interface DirectionalLight extends Light { 386} 387 388/** 389 * Defines camera. 390 * 391 * @extends Node 392 * @interface Camera 393 * @syscap SystemCapability.ArkUi.Graphics3D 394 * @since 12 395 */ 396export interface Camera extends Node { 397 /** 398 * Field of view of the camera. 399 * 400 * @type { number } 401 * @syscap SystemCapability.ArkUi.Graphics3D 402 * @since 12 403 */ 404 fov: number; 405 406 /** 407 * Near plane of the directional light. 408 * 409 * @type { number } 410 * @syscap SystemCapability.ArkUi.Graphics3D 411 * @since 12 412 */ 413 nearPlane: number; 414 415 /** 416 * Far plane of the directional light. 417 * 418 * @type { number } 419 * @syscap SystemCapability.ArkUi.Graphics3D 420 * @since 12 421 */ 422 farPlane: number; 423 424 /** 425 * Whether enabled the camera. 426 * 427 * @type { boolean } 428 * @syscap SystemCapability.ArkUi.Graphics3D 429 * @since 12 430 */ 431 enabled: boolean; 432 433 /** 434 * The post processing settings of the camera. 435 * 436 * @type { PostProcessSettings | null } 437 * @syscap SystemCapability.ArkUi.Graphics3D 438 * @since 12 439 */ 440 postProcess: PostProcessSettings | null; 441 442 /** 443 * Background clear color (environment background overrides this color, 444 * BACKGROUND_NONE is needed for this to actually take effect). 445 * 446 * @type { Color | null } 447 * @syscap SystemCapability.ArkUi.Graphics3D 448 * @since 12 449 */ 450 clearColor: Color | null; 451} 452