1e41f4b71Sopenharmony_ci# Component3D 2e41f4b71Sopenharmony_ciThe **\<Component3D>** component is used to load 3D model resources and create custom rendering. It is typically used to present 3D animations. 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci> **NOTE** 5e41f4b71Sopenharmony_ci> 6e41f4b71Sopenharmony_ci> This component is supported since API version 11. Updates will be marked with a superscript to indicate their earliest API version. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci## Child Components 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ciNot supported 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## APIs 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciComponent3D((sceneOptions?: SceneOptions)) 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci**Parameters** 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 21e41f4b71Sopenharmony_ci| ------------ | --------------------------------- | ---- | ---------------------------------------- | 22e41f4b71Sopenharmony_ci| sceneOptions | [SceneOptions](#sceneoptions) | No | 3D scene configuration.<br>**NOTE**<br> The 3D scene configuration cannot be dynamically modified after the component is created.| 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci## SceneOptions 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ciProvides the 3D scene configuration options. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 30e41f4b71Sopenharmony_ci| --------- | -------------------------------- | ---- | ---------------------------------------- | 31e41f4b71Sopenharmony_ci| scene | [Resource](ts-types.md#resource)\|[Scene](../../apis-arkgraphics3d/js-apis-inner-scene.md#scene-1)<sup>12+</sup> | No | 3D model resource file or scene object.<br>Default value: **undefined**<br>**NOTE**<br>Currently, only GLTF files are supported.| 32e41f4b71Sopenharmony_ci| modelType | [ModelType](#modeltype) | No | Composition mode of the 3D scene.<br>Default value: **ModelType.SURFACE**<br>**NOTE**<br>**ModelType.TEXTURE**: The GPU is used for composition.<br>**ModelType.SURFACE**: Dedicated hardware is used for composition.<br>In general cases, leave this parameter at its default settings.| 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci## ModelType 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci| Name | Description | 37e41f4b71Sopenharmony_ci| ------- | -------------- | 38e41f4b71Sopenharmony_ci| TEXTURE | The GPU is used for composition of the 3D scene.| 39e41f4b71Sopenharmony_ci| SURFACE | Dedicated hardware is used for composition of the 3D scene. | 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci## Attributes 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci### environment 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_cienvironment(uri: Resource) 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ciSets the 3D environment resource. Currently, only GLTF files are supported. Model resources cannot be dynamically modified after the component is created. 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**Parameters** 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 57e41f4b71Sopenharmony_ci| ------ | -------------------------------- | ---- | ------------ | 58e41f4b71Sopenharmony_ci| uri | [Resource](ts-types.md#resource) | Yes | 3D environment resource.| 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci### customRender 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_cicustomRender(uri: Resource, selfRenderUpdate: boolean) 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ciSets the custom 3D scene rendering pipeline. **uri** and **selfRenderUpdate** cannot be dynamically modified after the component is created. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**Parameters** 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 71e41f4b71Sopenharmony_ci| ---------------- | -------------------------------- | ---- | ------------------------------------------------------------ | 72e41f4b71Sopenharmony_ci| uri | [Resource](ts-types.md#resource) | Yes | Configuration file for creating a custom rendering pipeline. | 73e41f4b71Sopenharmony_ci| selfRenderUpdate | boolean | Yes | Whether rendering can be triggered when the external UI is not updated.<br>The value **true** means that rendering can be triggered when the external UI is not updated, and false means the opposite.| 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci### shader 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_cishader(uri: Resource) 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ciSets the shader file for custom rendering. The shader file cannot be dynamically modified after the component is created. 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**Parameters** 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 86e41f4b71Sopenharmony_ci| ------ | -------------------------------- | ---- | ---------------------------- | 87e41f4b71Sopenharmony_ci| uri | [Resource](ts-types.md#resource) | Yes | Shader file for custom rendering.| 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci### shaderImageTexture 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_cishaderImageTexture(uri: Resource) 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ciSets the texture resource used for custom rendering. To use multiple texture resources for custom rendering, call this API multiple times. The sequence in which the resources are used is the same as the call sequence. The texture resource cannot be dynamically modified after the component is created. 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci**Parameters** 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 100e41f4b71Sopenharmony_ci| ------ | -------------------------------- | ---- | -------------------------- | 101e41f4b71Sopenharmony_ci| uri | [Resource](ts-types.md#resource) | Yes | Texture resource used for custom rendering.| 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci### shaderInputBuffer 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_cishaderInputBuffer(buffer: Array<number>) 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ciSet the animation parameters used for custom rendering. 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci**Parameters** 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 114e41f4b71Sopenharmony_ci| ------ | -------------- | ---- | -------------------------- | 115e41f4b71Sopenharmony_ci| buffer | Array<number\> | Yes | Animation parameters used for custom rendering.| 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci### renderWidth 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_cirenderWidth(value: Dimension) 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ciSets the width of the 3D rendering resolution. The width and height of the rendering resolution may be different from those of the component. If this is the case, they are upsampled or downsampled to the component width and height. 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ciIf this attribute is not specified, the default width of the rendering resolution is used. 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ciThe rendering resolution cannot be dynamically changed after the component is created. 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci**Parameters** 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 132e41f4b71Sopenharmony_ci| ------ | ------------------------------------ | ---- | -------------------- | 133e41f4b71Sopenharmony_ci| value | [Dimension](ts-types.md#dimension10) | Yes | Width of the 3D rendering resolution.| 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci### renderHeight 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_cirenderHeight(value: Dimension) 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ciSets the height of the 3D rendering resolution. The width and height of the rendering resolution may be different from those of the component. If this is the case, they are upsampled or downsampled to the component width and height. 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ciIf this attribute is not specified, the default width of the rendering resolution is used. 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ciThe rendering resolution cannot be dynamically changed after the component is created. 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci**Parameters** 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 150e41f4b71Sopenharmony_ci| ------ | ------------------------------------ | ---- | -------------------- | 151e41f4b71Sopenharmony_ci| value | [Dimension](ts-types.md#dimension10) | Yes | Height of the 3D rendering resolution.| 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci## Events 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ciThe [universal events](ts-universal-events-click.md) are supported. 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci## Example 158e41f4b71Sopenharmony_ciYou can preview how this component looks on a real device, but not in DevEco Studio Previewer.<br> 159e41f4b71Sopenharmony_ciExample of loading a GLTF model:<br> 160e41f4b71Sopenharmony_ci```ts 161e41f4b71Sopenharmony_ci// xxx.ets 162e41f4b71Sopenharmony_ci@Entry 163e41f4b71Sopenharmony_ci@Component 164e41f4b71Sopenharmony_cistruct Index { 165e41f4b71Sopenharmony_ci scene: SceneOptions = { scene: $rawfile('gltf/DamageHemlt/glTF/DamagedHelmet.gltf'), modelType: ModelType.SURFACE}; 166e41f4b71Sopenharmony_ci build() { 167e41f4b71Sopenharmony_ci Row() { 168e41f4b71Sopenharmony_ci Column() { 169e41f4b71Sopenharmony_ci Text('GLTF Example') 170e41f4b71Sopenharmony_ci Component3D( this.scene ) 171e41f4b71Sopenharmony_ci .environment($rawfile('gltf/Environment/glTF/Environment.gltf')) 172e41f4b71Sopenharmony_ci .renderWidth('90%').renderHeight('90%') 173e41f4b71Sopenharmony_ci }.width('100%') 174e41f4b71Sopenharmony_ci } 175e41f4b71Sopenharmony_ci .height('100%') 176e41f4b71Sopenharmony_ci } 177e41f4b71Sopenharmony_ci} 178e41f4b71Sopenharmony_ci``` 179e41f4b71Sopenharmony_ciExample of custom rendering:<br> 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci```ts 182e41f4b71Sopenharmony_ciimport animator, { AnimatorResult } from '@ohos.animator'; 183e41f4b71Sopenharmony_ciclass EngineTime { 184e41f4b71Sopenharmony_ci totalTimeUs = 0; 185e41f4b71Sopenharmony_ci deltaTimeUs = 0; 186e41f4b71Sopenharmony_ci}; 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_cilet engineTime = new EngineTime(); 189e41f4b71Sopenharmony_cilet frameCount: number = 0; 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_cifunction TickFrame() { 192e41f4b71Sopenharmony_ci if (frameCount == 10) { 193e41f4b71Sopenharmony_ci engineTime.totalTimeUs += 1.0; 194e41f4b71Sopenharmony_ci engineTime.deltaTimeUs += 1.0; 195e41f4b71Sopenharmony_ci frameCount = 0; 196e41f4b71Sopenharmony_ci } else { 197e41f4b71Sopenharmony_ci frameCount++; 198e41f4b71Sopenharmony_ci } 199e41f4b71Sopenharmony_ci} 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci@Entry 202e41f4b71Sopenharmony_ci@Component 203e41f4b71Sopenharmony_cistruct Index { 204e41f4b71Sopenharmony_ci scene: SceneOptions = { scene: $rawfile('gltf/DamageHemlt/glTF/DamagedHelmet.gltf'), modelType: ModelType.SURFACE}; 205e41f4b71Sopenharmony_ci backAnimator: AnimatorResult = animator.create({ 206e41f4b71Sopenharmony_ci duration: 2000, 207e41f4b71Sopenharmony_ci easing: "ease", 208e41f4b71Sopenharmony_ci delay: 0, 209e41f4b71Sopenharmony_ci fill: "none", 210e41f4b71Sopenharmony_ci direction: "normal", 211e41f4b71Sopenharmony_ci iterations: -1, 212e41f4b71Sopenharmony_ci begin: 100, 213e41f4b71Sopenharmony_ci end: 200, 214e41f4b71Sopenharmony_ci }); 215e41f4b71Sopenharmony_ci @State timeDelta: number[] = [1.0, 2.0]; 216e41f4b71Sopenharmony_ci create() { 217e41f4b71Sopenharmony_ci this.backAnimator.onfinish = () => { 218e41f4b71Sopenharmony_ci console.log('backAnimator onfinish'); 219e41f4b71Sopenharmony_ci } 220e41f4b71Sopenharmony_ci this.backAnimator.onframe = value => { 221e41f4b71Sopenharmony_ci TickFrame(); 222e41f4b71Sopenharmony_ci this.timeDelta[0] = engineTime.deltaTimeUs; 223e41f4b71Sopenharmony_ci } 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci } 226e41f4b71Sopenharmony_ci build() { 227e41f4b71Sopenharmony_ci Row() { 228e41f4b71Sopenharmony_ci Column() { 229e41f4b71Sopenharmony_ci Text('custom rendering') 230e41f4b71Sopenharmony_ci Component3D() 231e41f4b71Sopenharmony_ci .shader($rawfile('assets/app/shaders/shader/London.shader')) 232e41f4b71Sopenharmony_ci .shaderImageTexture($rawfile('assets/London.jpg')) 233e41f4b71Sopenharmony_ci .shaderInputBuffer(this.timeDelta) 234e41f4b71Sopenharmony_ci .customRender($rawfile('assets/app/rendernodegraphs/London.rng'), true) 235e41f4b71Sopenharmony_ci .renderWidth('90%').renderHeight('90%') 236e41f4b71Sopenharmony_ci .onAppear(() => { 237e41f4b71Sopenharmony_ci this.create(); 238e41f4b71Sopenharmony_ci this.backAnimator.play(); 239e41f4b71Sopenharmony_ci }).width('50%').height('50%') 240e41f4b71Sopenharmony_ci }.width('100%') 241e41f4b71Sopenharmony_ci } 242e41f4b71Sopenharmony_ci .height('100%') 243e41f4b71Sopenharmony_ci } 244e41f4b71Sopenharmony_ci} 245e41f4b71Sopenharmony_ci``` 246e41f4b71Sopenharmony_ci<!--no_check-->