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 basic types 18 * @kit ArkGraphics3D 19 */ 20 21/** 22 * Defines Vec2. 23 * 24 * @typedef Vec2 25 * @syscap SystemCapability.ArkUi.Graphics3D 26 * @since 12 27 */ 28export interface Vec2 { 29 /** 30 * X component of the vec2. 31 * 32 * @type { number } 33 * @syscap SystemCapability.ArkUi.Graphics3D 34 * @since 12 35 */ 36 x: number; 37 38 /** 39 * Y component of the vec2. 40 * 41 * @type { number } 42 * @syscap SystemCapability.ArkUi.Graphics3D 43 * @since 12 44 */ 45 y: number; 46} 47 48/** 49 * Defines Vec3. 50 * 51 * @typedef Vec3 52 * @syscap SystemCapability.ArkUi.Graphics3D 53 * @since 12 54 */ 55export interface Vec3 { 56 /** 57 * X component of the vec3. 58 * 59 * @type { number } 60 * @syscap SystemCapability.ArkUi.Graphics3D 61 * @since 12 62 */ 63 x: number; 64 65 /** 66 * Y component of the vec3. 67 * 68 * @type { number } 69 * @syscap SystemCapability.ArkUi.Graphics3D 70 * @since 12 71 */ 72 y: number; 73 74 /** 75 * Z component of the vec3. 76 * 77 * @type { number } 78 * @syscap SystemCapability.ArkUi.Graphics3D 79 * @since 12 80 */ 81 z: number; 82} 83 84/** 85 * Defines Vec4. 86 * 87 * @typedef Vec4 88 * @syscap SystemCapability.ArkUi.Graphics3D 89 * @since 12 90 */ 91export interface Vec4 { 92 /** 93 * X component of the vec4. 94 * 95 * @type { number } 96 * @syscap SystemCapability.ArkUi.Graphics3D 97 * @since 12 98 */ 99 x: number; 100 101 /** 102 * Y component of the vec4. 103 * 104 * @type { number } 105 * @syscap SystemCapability.ArkUi.Graphics3D 106 * @since 12 107 */ 108 y: number; 109 110 /** 111 * Z component of the vec4. 112 * 113 * @type { number } 114 * @syscap SystemCapability.ArkUi.Graphics3D 115 * @since 12 116 */ 117 z: number; 118 119 /** 120 * W component of the vec4. 121 * 122 * @type { number } 123 * @syscap SystemCapability.ArkUi.Graphics3D 124 * @since 12 125 */ 126 w: number; 127} 128 129/** 130 * Quaternion representing a rotation. 131 * 132 * @typedef Quaternion 133 * @syscap SystemCapability.ArkUi.Graphics3D 134 * @since 12 135 */ 136export interface Quaternion { 137 /** 138 * X component of the quaternion. 139 * 140 * @type { number } 141 * @syscap SystemCapability.ArkUi.Graphics3D 142 * @since 12 143 */ 144 x: number; 145 146 /** 147 * Y component of the quaternion. 148 * 149 * @type { number } 150 * @syscap SystemCapability.ArkUi.Graphics3D 151 * @since 12 152 */ 153 y: number; 154 155 /** 156 * Z component of the quaternion. 157 * 158 * @type { number } 159 * @syscap SystemCapability.ArkUi.Graphics3D 160 * @since 12 161 */ 162 z: number; 163 164 /** 165 * W component of the quaternion. 166 * 167 * @type { number } 168 * @syscap SystemCapability.ArkUi.Graphics3D 169 * @since 12 170 */ 171 w: number; 172} 173 174/** 175 * Axis aligned bounding box. 176 * 177 * @typedef Aabb 178 * @syscap SystemCapability.ArkUi.Graphics3D 179 * @since 12 180 */ 181export interface Aabb { 182 /** 183 * Coordinates of the AABB minimum corner. 184 * 185 * @type { Vec3 } 186 * @syscap SystemCapability.ArkUi.Graphics3D 187 * @since 12 188 */ 189 aabbMin: Vec3; 190 191 /** 192 * Coordinates of the AABB maximum corner. 193 * 194 * @type { Vec3 } 195 * @syscap SystemCapability.ArkUi.Graphics3D 196 * @since 12 197 */ 198 aabbMax: Vec3; 199} 200 201/** 202 * Defines Color. 203 * 204 * @typedef Color 205 * @syscap SystemCapability.ArkUi.Graphics3D 206 * @since 12 207 */ 208export interface Color { 209 /** 210 * R component of the color. 211 * 212 * @type { number } 213 * @syscap SystemCapability.ArkUi.Graphics3D 214 * @since 12 215 */ 216 r: number; 217 218 /** 219 * G component of the color. 220 * 221 * @type { number } 222 * @syscap SystemCapability.ArkUi.Graphics3D 223 * @since 12 224 */ 225 g: number; 226 227 /** 228 * B component of the color. 229 * 230 * @type { number } 231 * @syscap SystemCapability.ArkUi.Graphics3D 232 * @since 12 233 */ 234 b: number; 235 236 /** 237 * A component of the color. 238 * 239 * @type { number } 240 * @syscap SystemCapability.ArkUi.Graphics3D 241 * @since 12 242 */ 243 a: number; 244} 245 246/** 247 * Defines rectangle. 248 * 249 * @typedef Rect 250 * @syscap SystemCapability.ArkUi.Graphics3D 251 * @since 12 252 */ 253export interface Rect { 254 /** 255 * Left up x coordinate. 256 * 257 * @type { number } 258 * @syscap SystemCapability.ArkUi.Graphics3D 259 * @since 12 260 */ 261 x: number; 262 263 /** 264 * Left up y coordinate. 265 * 266 * @type { number } 267 * @syscap SystemCapability.ArkUi.Graphics3D 268 * @since 12 269 */ 270 y: number; 271 272 /** 273 * The width of the rectangle. 274 * 275 * @type { number } 276 * @syscap SystemCapability.ArkUi.Graphics3D 277 * @since 12 278 */ 279 width: number; 280 281 /** 282 * The height of the rectangle. 283 * 284 * @type { number } 285 * @syscap SystemCapability.ArkUi.Graphics3D 286 * @since 12 287 */ 288 height: number; 289} 290 291/** 292 * Types of geometric shapes. 293 * 294 * @enum { number } 295 * @syscap SystemCapability.ArkUi.Graphics3D 296 * @since 18 297 */ 298export enum GeometryType { 299 /** 300 * A custom geometric shape. 301 * 302 * @syscap SystemCapability.ArkUi.Graphics3D 303 * @since 18 304 */ 305 CUSTOM = 0, 306 307 /** 308 * A cube. 309 * 310 * @syscap SystemCapability.ArkUi.Graphics3D 311 * @since 18 312 */ 313 CUBE = 1, 314 315 /** 316 * A plane. 317 * 318 * @syscap SystemCapability.ArkUi.Graphics3D 319 * @since 18 320 */ 321 PLANE = 2, 322 323 /** 324 * A sphere. 325 * 326 * @syscap SystemCapability.ArkUi.Graphics3D 327 * @since 18 328 */ 329 SPHERE = 3 330} 331 332/** 333 * Define a geometric shape for mesh creation. 334 * 335 * @syscap SystemCapability.ArkUi.Graphics3D 336 * @since 18 337 */ 338export declare abstract class GeometryDefinition { 339 /** 340 * Which geometry shape to interpret from this definition. 341 * 342 * @type { GeometryType } 343 * @readonly 344 * @syscap SystemCapability.ArkUi.Graphics3D 345 * @since 18 346 */ 347 readonly geometryType: GeometryType; 348} 349 350/** 351 * How vertices in a sequence form triangles. 352 * 353 * @enum { number } 354 * @syscap SystemCapability.ArkUi.Graphics3D 355 * @since 18 356 */ 357export enum PrimitiveTopology { 358 /** 359 * The vertices form a set of independent triangle. Vertices (0, 1, 2), (3, 4, 5), ... define separate triangles. 360 * 361 * @syscap SystemCapability.ArkUi.Graphics3D 362 * @since 18 363 */ 364 TRIANGLE_LIST = 0, 365 366 /** 367 * The vertices form a triangle strip. Starting from the 3rd, each vertex defines a triangle with the previous two. 368 * 369 * @syscap SystemCapability.ArkUi.Graphics3D 370 * @since 18 371 */ 372 TRIANGLE_STRIP = 1 373} 374 375/** 376 * An array of vertices and their data defining a custom geometric shape. 377 * 378 * @extends GeometryDefinition 379 * @syscap SystemCapability.ArkUi.Graphics3D 380 * @since 18 381 */ 382export declare class CustomGeometry extends GeometryDefinition { 383 /** 384 * How to form mesh triangles from the indexed vertices. 385 * 386 * @type { ?PrimitiveTopology } 387 * @default PrimitiveTopology.TRIANGLE_LIST 388 * @syscap SystemCapability.ArkUi.Graphics3D 389 * @since 18 390 */ 391 topology?: PrimitiveTopology; 392 393 /** 394 * An array of vertices. 395 * 396 * @type { Vec3[] } 397 * @syscap SystemCapability.ArkUi.Graphics3D 398 * @since 18 399 */ 400 vertices: Vec3[]; 401 402 /** 403 * Indices of those vertices that form triangles. PrimitiveTopology is applied to the sequence defined by indices. 404 * 405 * An example of creating an identical pair of triangles, given vertices = [a, b, c, d]: 406 * topology = PrimitiveTopology.TRIANGLE_LIST 407 * indices = [0, 1, 2, 2, 1, 3] 408 * resulting triangles: abc, cbd 409 * 410 * topology = PrimitiveTopology.TRIANGLE_STRIP 411 * indices = [0, 1, 2, 3] 412 * resulting triangles: abc, cbd (b and c are reversed in cbd, to match the face direction of the first triangle) 413 * 414 * @type { ?number[] } 415 * @default indices: [0, 1 ,2,..., vertices.size() - 1] 416 * @syscap SystemCapability.ArkUi.Graphics3D 417 * @since 18 418 */ 419 indices?: number[]; 420 421 /** 422 * Vertex normal. If normals is not null. normals[N] is for vertices[N] and generateNormals is ignored. 423 * 424 * @type { ?Vec3[] } 425 * @syscap SystemCapability.ArkUi.Graphics3D 426 * @since 18 427 */ 428 normals?: Vec3[]; 429 430 /** 431 * Vertex texture mapping UV coordinate. If uvs is not null, uvs[N] is for vertices[N] 432 * 433 * @type { ?Vec2[] } 434 * @syscap SystemCapability.ArkUi.Graphics3D 435 * @since 18 436 */ 437 uvs?: Vec2[]; 438 439 /** 440 * Vertex color. If colors is not null, colors[N] is for vertices[N]. 441 * 442 * @type { ?Color[] } 443 * @syscap SystemCapability.ArkUi.Graphics3D 444 * @since 18 445 */ 446 colors?: Color[]; 447} 448 449/** 450 * Define a rectangular cuboid. 451 * 452 * @extends GeometryDefinition 453 * @syscap SystemCapability.ArkUi.Graphics3D 454 * @since 18 455 */ 456export declare class CubeGeometry extends GeometryDefinition { 457 /** 458 * The width, height and depth of the cube. 459 * 460 * @type { Vec3 } 461 * @syscap SystemCapability.ArkUi.Graphics3D 462 * @since 18 463 */ 464 size: Vec3; 465} 466 467/** 468 * Define a plane. 469 * 470 * @extends GeometryDefinition 471 * @syscap SystemCapability.ArkUi.Graphics3D 472 * @since 18 473 */ 474export declare class PlaneGeometry extends GeometryDefinition { 475 /** 476 * The width and length of the plane. 477 * 478 * @type { Vec2 } 479 * @syscap SystemCapability.ArkUi.Graphics3D 480 * @since 18 481 */ 482 size: Vec2; 483} 484 485/** 486 * Define a sphere. 487 * 488 * @extends GeometryDefinition 489 * @syscap SystemCapability.ArkUi.Graphics3D 490 * @since 18 491 */ 492export declare class SphereGeometry extends GeometryDefinition { 493 /** 494 * The radius of the sphere. 495 * 496 * @type { number } 497 * @syscap SystemCapability.ArkUi.Graphics3D 498 * @since 18 499 */ 500 radius: number; 501 502 /** 503 * Divide the sphere latitudinally into this many circles and each circle longitudinally into this many segments. 504 * 505 * @type { number } 506 * @syscap SystemCapability.ArkUi.Graphics3D 507 * @since 18 508 */ 509 segmentCount: number; 510} 511/** 512 * 3D position information. 513 * 514 * @typedef { Vec3 } 515 * @syscap SystemCapability.ArkUi.Graphics3D 516 * @since 12 517 */ 518export type Position3 = Vec3; 519 520/** 521 * 3D rotation info as euler angles. 522 * 523 * @typedef { Vec3 } 524 * @syscap SystemCapability.ArkUi.Graphics3D 525 * @since 12 526 */ 527export type Rotation3 = Vec3; 528 529/** 530 * 3D scale information. 531 * 532 * @typedef { Vec3 } 533 * @syscap SystemCapability.ArkUi.Graphics3D 534 * @since 12 535 */ 536export type Scale3 = Vec3; 537