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 * The resource is a mesh resource 98 * 99 * @syscap SystemCapability.ArkUi.Graphics3D 100 * @since 18 101 */ 102 MESH_RESOURCE = 8, 103} 104 105/** 106 * Define scene resource extended by other 3d resource. 107 * 108 * @interface SceneResource 109 * @syscap SystemCapability.ArkUi.Graphics3D 110 * @since 12 111 */ 112export interface SceneResource { 113 /** 114 * Scene resource name. 115 * 116 * @type { string } 117 * @syscap SystemCapability.ArkUi.Graphics3D 118 * @since 12 119 */ 120 name: string; 121 122 /** 123 * Scene resource type. 124 * 125 * @type { SceneResourceType } 126 * @readonly 127 * @syscap SystemCapability.ArkUi.Graphics3D 128 * @since 12 129 */ 130 readonly resourceType: SceneResourceType; 131 132 /** 133 * Scene resource uri. 134 * 135 * @type { ?ResourceStr } 136 * @readonly 137 * @syscap SystemCapability.ArkUi.Graphics3D 138 * @since 12 139 */ 140 readonly uri?: ResourceStr; 141 142 143 /** 144 * Release scene resource. 145 * 146 * @syscap SystemCapability.ArkUi.Graphics3D 147 * @since 12 148 */ 149 destroy(): void; 150} 151 152/** 153 * Shader resource. 154 * 155 * @extends SceneResource 156 * @interface Shader 157 * @syscap SystemCapability.ArkUi.Graphics3D 158 * @since 12 159 */ 160export interface Shader extends SceneResource { 161 /** 162 * Shader inputs. 163 * 164 * @type { Record<string, number | Vec2 | Vec3 | Vec4 | Image> } 165 * @readonly 166 * @syscap SystemCapability.ArkUi.Graphics3D 167 * @since 12 168 */ 169 readonly inputs: Record<string, number | Vec2 | Vec3 | Vec4 | Image>; 170} 171 172/** 173 * The enum of material type. 174 * 175 * @enum { number } 176 * @syscap SystemCapability.ArkUi.Graphics3D 177 * @since 12 178 */ 179export enum MaterialType { 180 /** 181 * The material type is a Shader. 182 * 183 * @syscap SystemCapability.ArkUi.Graphics3D 184 * @since 12 185 */ 186 SHADER = 1, 187} 188 189/** 190 * Material resource. 191 * 192 * @extends SceneResource 193 * @interface Material 194 * @syscap SystemCapability.ArkUi.Graphics3D 195 * @since 12 196 */ 197export interface Material extends SceneResource { 198 /** 199 * Material resource type. 200 * 201 * @type { MaterialType } 202 * @readonly 203 * @syscap SystemCapability.ArkUi.Graphics3D 204 * @since 12 205 */ 206 readonly materialType: MaterialType; 207} 208 209/** 210 * Shader material resource. 211 * 212 * @extends Material 213 * @interface ShaderMaterial 214 * @syscap SystemCapability.ArkUi.Graphics3D 215 * @since 12 216 */ 217export interface ShaderMaterial extends Material { 218 /** 219 * Color shader of material. 220 * 221 * @type { ?Shader } 222 * @syscap SystemCapability.ArkUi.Graphics3D 223 * @since 12 224 */ 225 colorShader?: Shader; 226} 227 228/** 229 * Sub mesh resource. 230 * 231 * @interface SubMesh 232 * @syscap SystemCapability.ArkUi.Graphics3D 233 * @since 12 234 */ 235export interface SubMesh { 236 /** 237 * The name of the sub mesh. 238 * 239 * @type { string } 240 * @syscap SystemCapability.ArkUi.Graphics3D 241 * @since 12 242 */ 243 name: string; 244 245 /** 246 * The material of the sub mesh. 247 * 248 * @type { Material } 249 * @syscap SystemCapability.ArkUi.Graphics3D 250 * @since 12 251 */ 252 material: Material; 253 254 /** 255 * The axis aligned bounding box of the sub mesh. 256 * 257 * @type { Aabb } 258 * @readonly 259 * @syscap SystemCapability.ArkUi.Graphics3D 260 * @since 12 261 */ 262 readonly aabb: Aabb; 263} 264 265/** 266 * Mesh resource. 267 * 268 * @extends SceneResource 269 * @interface Mesh 270 * @syscap SystemCapability.ArkUi.Graphics3D 271 * @since 12 272 */ 273export interface Mesh extends SceneResource { 274 /** 275 * The sub meshes of the mesh. 276 * 277 * @type { SubMesh[] } 278 * @readonly 279 * @syscap SystemCapability.ArkUi.Graphics3D 280 * @since 12 281 */ 282 readonly subMeshes: SubMesh[]; 283 284 /** 285 * The axis aligned bounding box of the mesh. 286 * 287 * @type { Aabb } 288 * @readonly 289 * @syscap SystemCapability.ArkUi.Graphics3D 290 * @since 12 291 */ 292 readonly aabb: Aabb; 293 294 /** 295 * The material override sub mesh's material. 296 * 297 * @type { ?Material } 298 * @syscap SystemCapability.ArkUi.Graphics3D 299 * @since 12 300 */ 301 materialOverride?: Material; 302} 303 304/** 305 * Mesh resource. 306 * 307 * 308 * @extends SceneResource 309 * @interface MeshResource 310 * @syscap SystemCapability.ArkUi.Graphics3D 311 * @since 18 312 */ 313export interface MeshResource extends SceneResource { 314} 315 316/** 317 * Animation resource. 318 * 319 * @extends SceneResource 320 * @interface Animation 321 * @syscap SystemCapability.ArkUi.Graphics3D 322 * @since 12 323 */ 324export interface Animation extends SceneResource { 325 /** 326 * The animation is enabled. 327 * 328 * @type { boolean } 329 * @syscap SystemCapability.ArkUi.Graphics3D 330 * @since 12 331 */ 332 enabled: boolean; 333 334 /** 335 * The duration of the animation. 336 * 337 * @type { number } 338 * @readonly 339 * @syscap SystemCapability.ArkUi.Graphics3D 340 * @since 12 341 */ 342 readonly duration: number; 343 344 /** 345 * Whether the animation is running. 346 * 347 * @type { boolean } 348 * @readonly 349 * @syscap SystemCapability.ArkUi.Graphics3D 350 * @since 12 351 */ 352 readonly running: boolean; 353 354 /** 355 * The progress of the animation between 0~1. 356 * 357 * @type { number } 358 * @readonly 359 * @syscap SystemCapability.ArkUi.Graphics3D 360 * @since 12 361 */ 362 readonly progress: number; 363 364 /** 365 * Register a callback when animation finished. 366 * 367 * @param { Callback<void> } callback - the callback invoked when animation finished 368 * @syscap SystemCapability.ArkUi.Graphics3D 369 * @since 12 370 */ 371 onFinished(callback: Callback<void>): void; 372 373 /** 374 * Register a callback when animation started. 375 * 376 * @param { Callback<void> } callback - the callback invoked when animation started 377 * @syscap SystemCapability.ArkUi.Graphics3D 378 * @since 12 379 */ 380 onStarted(callback: Callback<void>): void; 381 382 /** 383 * Pause the animation. 384 * 385 * @syscap SystemCapability.ArkUi.Graphics3D 386 * @since 12 387 */ 388 pause(): void; 389 390 /** 391 * Restart the animation. 392 * 393 * @syscap SystemCapability.ArkUi.Graphics3D 394 * @since 12 395 */ 396 restart(): void; 397 398 /** 399 * Seek the animation to the position. 400 * 401 * @param { number } position - the position seek between 0~1 402 * @syscap SystemCapability.ArkUi.Graphics3D 403 * @since 12 404 */ 405 seek(position: number): void; 406 407 /** 408 * Start the animation. 409 * 410 * @syscap SystemCapability.ArkUi.Graphics3D 411 * @since 12 412 */ 413 start(): void; 414 415 /** 416 * Stop the animation and seek the position to the beginning. 417 * 418 * @syscap SystemCapability.ArkUi.Graphics3D 419 * @since 12 420 */ 421 stop(): void; 422 423 /** 424 * Finish the animation and seek the position to the end. 425 * 426 * @syscap SystemCapability.ArkUi.Graphics3D 427 * @since 12 428 */ 429 finish(): void; 430} 431 432/** 433 * The enum of environment background type. 434 * @enum { number } 435 * @syscap SystemCapability.ArkUi.Graphics3D 436 * @since 12 437 */ 438export enum EnvironmentBackgroundType { 439 /** 440 * The background is none. 441 * 442 * @syscap SystemCapability.ArkUi.Graphics3D 443 * @since 12 444 */ 445 BACKGROUND_NONE = 0, 446 447 /** 448 * The background is image. 449 * 450 * @syscap SystemCapability.ArkUi.Graphics3D 451 * @since 12 452 */ 453 BACKGROUND_IMAGE = 1, 454 455 /** 456 * The background is cubemap. 457 * 458 * @syscap SystemCapability.ArkUi.Graphics3D 459 * @since 12 460 */ 461 BACKGROUND_CUBEMAP = 2, 462 463 /** 464 * The background is equirectangular. 465 * 466 * @syscap SystemCapability.ArkUi.Graphics3D 467 * @since 12 468 */ 469 BACKGROUND_EQUIRECTANGULAR = 3, 470} 471 472/** 473 * Environment resource. 474 * 475 * @extends SceneResource 476 * @interface Environment 477 * @syscap SystemCapability.ArkUi.Graphics3D 478 * @since 12 479 */ 480export interface Environment extends SceneResource { 481 /** 482 * The background type of the environment. 483 * 484 * @type { EnvironmentBackgroundType } 485 * @syscap SystemCapability.ArkUi.Graphics3D 486 * @since 12 487 */ 488 backgroundType: EnvironmentBackgroundType; 489 490 /** 491 * The indirect diffuse factor of the environment. 492 * 493 * @type { Vec4 } 494 * @syscap SystemCapability.ArkUi.Graphics3D 495 * @since 12 496 */ 497 indirectDiffuseFactor: Vec4; 498 499 /** 500 * The indirect specular factor of the environment. 501 * 502 * @type { Vec4 } 503 * @syscap SystemCapability.ArkUi.Graphics3D 504 * @since 12 505 */ 506 indirectSpecularFactor: Vec4; 507 508 /** 509 * The environment map factor of the environment. 510 * 511 * @type { Vec4 } 512 * @syscap SystemCapability.ArkUi.Graphics3D 513 * @since 12 514 */ 515 environmentMapFactor: Vec4; 516 517 /** 518 * The environment image of the environment. 519 * 520 * @type { ?(Image | null) } 521 * @syscap SystemCapability.ArkUi.Graphics3D 522 * @since 12 523 */ 524 environmentImage?: Image | null; 525 526 /** 527 * The radiance image of the environment. 528 * 529 * @type { ?(Image | null) } 530 * @syscap SystemCapability.ArkUi.Graphics3D 531 * @since 12 532 */ 533 radianceImage?: Image | null; 534 535 /** 536 * The irradiance coefficients (array of nine Vec3). 537 * 538 * @type { ?Vec3[] } 539 * @syscap SystemCapability.ArkUi.Graphics3D 540 * @since 12 541 */ 542 irradianceCoefficients?: Vec3[]; 543} 544 545/** 546 * Image resource. 547 * 548 * @extends SceneResource 549 * @interface Image 550 * @syscap SystemCapability.ArkUi.Graphics3D 551 * @since 12 552 */ 553export interface Image extends SceneResource { 554 /** 555 * The width of the image. 556 * 557 * @type { number } 558 * @readonly 559 * @syscap SystemCapability.ArkUi.Graphics3D 560 * @since 12 561 */ 562 readonly width: number; 563 564 /** 565 * The height of the image. 566 * 567 * @type { number } 568 * @readonly 569 * @syscap SystemCapability.ArkUi.Graphics3D 570 * @since 12 571 */ 572 readonly height: number; 573} 574