1e41f4b71Sopenharmony_ci# Scene 2e41f4b71Sopenharmony_ciThe Scene module is the basic module of ArkGraphics 3D and provides common data types such as **SceneResourceParamters** and **SceneNodeParamters**. It also provides basic methods such as glTF model loading, scene creation, and resource creation. 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci> **NOTE** 5e41f4b71Sopenharmony_ci> 6e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci## Modules to Import 9e41f4b71Sopenharmony_ci```ts 10e41f4b71Sopenharmony_ciimport { SceneResourceParameters, SceneNodeParameters, SceneResourceFactory, Scene } from '@kit.ArkGraphics3D'; 11e41f4b71Sopenharmony_ci``` 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## SceneResourceParameters 14e41f4b71Sopenharmony_ciDescribes the scene resource parameters, which are **name** and **uri**. The parameters describe the name of the scene resource and the path of the resource file required in the 3D scene. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 17e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description| 18e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | ---- | 19e41f4b71Sopenharmony_ci| name | string | No| No| Name of the scene resource. It is customizable.| 20e41f4b71Sopenharmony_ci| uri | [Resource](../apis-arkui/arkui-ts/ts-types.md#resource) | No| Yes| Path of the resource file required in the 3D scene. The default value is undefined.| 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**Example** 23e41f4b71Sopenharmony_ci```ts 24e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 25e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_cifunction createShaderPromise() : Promise<Shader> { 28e41f4b71Sopenharmony_ci return new Promise(() => { 29e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 30e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 31e41f4b71Sopenharmony_ci let sceneFactory: SceneResourceFactory = result.getResourceFactory(); 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci // Create a variable of the SceneResourceParameters type and use it to create a shader. 34e41f4b71Sopenharmony_ci let sceneResourceParameter: SceneResourceParameters = { name: "shaderResource", 35e41f4b71Sopenharmony_ci uri: $rawfile("shaders/custom_shader/custom_material_sample.shader") }; 36e41f4b71Sopenharmony_ci let shader: Promise<Shader> = sceneFactory.createShader(sceneResourceParameter); 37e41f4b71Sopenharmony_ci return shader; 38e41f4b71Sopenharmony_ci }); 39e41f4b71Sopenharmony_ci }); 40e41f4b71Sopenharmony_ci} 41e41f4b71Sopenharmony_ci``` 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci## SceneNodeParameters 44e41f4b71Sopenharmony_ciDescribes the scene node parameters, which are used to provide the name and path in the scene node tree. 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 47e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description| 48e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | ---- | 49e41f4b71Sopenharmony_ci| name | string | No| No| Name of the scene node. It is customizable. | 50e41f4b71Sopenharmony_ci| path | string | No| Yes| Path in the scene node tree. It specifies the position of the created camera, light, or node in the scene node tree. Each layer is separated by a slash (/). If no path is provided, the node is set as a child node of the root node. The default value is undefined.| 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci**Example** 53e41f4b71Sopenharmony_ci```ts 54e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 55e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_cifunction createNodePromise() : Promise<Node> { 58e41f4b71Sopenharmony_ci return new Promise(() => { 59e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 60e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 61e41f4b71Sopenharmony_ci let sceneFactory: SceneResourceFactory = result.getResourceFactory(); 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci // Create a variable of the SceneNodeParameters type and use it to create a node. 64e41f4b71Sopenharmony_ci let sceneNodeParameter: SceneNodeParameters = { name: "empty_node", 65e41f4b71Sopenharmony_ci path:"/rootNode_/empty_node" }; 66e41f4b71Sopenharmony_ci let node: Promise<Node> = sceneFactory.createNode(sceneNodeParameter); 67e41f4b71Sopenharmony_ci return node; 68e41f4b71Sopenharmony_ci }); 69e41f4b71Sopenharmony_ci }); 70e41f4b71Sopenharmony_ci} 71e41f4b71Sopenharmony_ci``` 72e41f4b71Sopenharmony_ci## SceneResourceFactory 73e41f4b71Sopenharmony_ciProvides APIs to create camera, light, and other resources required in the 3D scene. 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci### createCamera 76e41f4b71Sopenharmony_cicreateCamera(params: SceneNodeParameters): Promise\<Camera> 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ciCreates a camera based on scene node parameters. This API uses a promise to return the result. 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**Parameters** 83e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 84e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | 85e41f4b71Sopenharmony_ci| params | [SceneNodeParameters](#scenenodeparameters) | Yes| Scene node parameters.| 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci**Return value** 88e41f4b71Sopenharmony_ci| Type| Description| 89e41f4b71Sopenharmony_ci| ---- | ---- | 90e41f4b71Sopenharmony_ci| Promise\<[Camera](js-apis-inner-scene-nodes.md#camera)> | Promise used to return the **Camera** object created.| 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci**Example** 93e41f4b71Sopenharmony_ci```ts 94e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 95e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_cifunction createCameraPromise() : Promise<Camera> { 98e41f4b71Sopenharmony_ci return new Promise(() => { 99e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 100e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 101e41f4b71Sopenharmony_ci let sceneFactory: SceneResourceFactory = result.getResourceFactory(); 102e41f4b71Sopenharmony_ci let sceneCameraParameter: SceneNodeParameters = { name: "camera1" }; 103e41f4b71Sopenharmony_ci // Create a camera. 104e41f4b71Sopenharmony_ci let camera: Promise<Camera> = sceneFactory.createCamera(sceneCameraParameter); 105e41f4b71Sopenharmony_ci return camera; 106e41f4b71Sopenharmony_ci }); 107e41f4b71Sopenharmony_ci }); 108e41f4b71Sopenharmony_ci} 109e41f4b71Sopenharmony_ci``` 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci### createLight 112e41f4b71Sopenharmony_cicreateLight(params: SceneNodeParameters, lightType: LightType): Promise\<Light> 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ciCreates a light based on the scene node parameters and light type. This API uses a promise to return the result. 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci**Parameters** 119e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 120e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | 121e41f4b71Sopenharmony_ci| params | [SceneNodeParameters](#scenenodeparameters) | Yes| Scene node parameters.| 122e41f4b71Sopenharmony_ci| lightType | [LightType](js-apis-inner-scene-nodes.md#lighttype) | Yes| Light type.| 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci**Return value** 125e41f4b71Sopenharmony_ci| Type| Description| 126e41f4b71Sopenharmony_ci| ---- | ---- | 127e41f4b71Sopenharmony_ci| Promise\<[Light](js-apis-inner-scene-nodes.md#light)> | Promise used to return the **Light** object created.| 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci**Example** 130e41f4b71Sopenharmony_ci```ts 131e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 132e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_cifunction createLightPromise() : Promise<Light> { 135e41f4b71Sopenharmony_ci return new Promise(() => { 136e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 137e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 138e41f4b71Sopenharmony_ci let sceneFactory: SceneResourceFactory = result.getResourceFactory(); 139e41f4b71Sopenharmony_ci let sceneLightParameter: SceneNodeParameters = { name: "light" }; 140e41f4b71Sopenharmony_ci // Create directional light. 141e41f4b71Sopenharmony_ci let light: Promise<Light> = sceneFactory.createLight(sceneLightParameter, LightType.DIRECTIONAL); 142e41f4b71Sopenharmony_ci return light; 143e41f4b71Sopenharmony_ci }); 144e41f4b71Sopenharmony_ci }); 145e41f4b71Sopenharmony_ci} 146e41f4b71Sopenharmony_ci``` 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci### createNode 149e41f4b71Sopenharmony_cicreateNode(params: SceneNodeParameters): Promise\<Node> 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ciCreates a node. This API uses a promise to return the result. 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci**Parameters** 156e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 157e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | 158e41f4b71Sopenharmony_ci| params | [SceneNodeParameters](#scenenodeparameters) | Yes| Scene node parameters.| 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci**Return value** 161e41f4b71Sopenharmony_ci| Type| Description| 162e41f4b71Sopenharmony_ci| ---- | ---- | 163e41f4b71Sopenharmony_ci| Promise\<[Node](js-apis-inner-scene-nodes.md#node)> | Promise used to return the **Node** object.| 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci**Example** 166e41f4b71Sopenharmony_ci```ts 167e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 168e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_cifunction createNodePromise() : Promise<Node> { 171e41f4b71Sopenharmony_ci return new Promise(() => { 172e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 173e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 174e41f4b71Sopenharmony_ci let sceneFactory: SceneResourceFactory = result.getResourceFactory(); 175e41f4b71Sopenharmony_ci let sceneNodeParameter: SceneNodeParameters = { name: "empty_node", 176e41f4b71Sopenharmony_ci path:"/rootNode_/empty_node" }; 177e41f4b71Sopenharmony_ci // Create a node. 178e41f4b71Sopenharmony_ci let node: Promise<Node> = sceneFactory.createNode(sceneNodeParameter); 179e41f4b71Sopenharmony_ci return node; 180e41f4b71Sopenharmony_ci }); 181e41f4b71Sopenharmony_ci }); 182e41f4b71Sopenharmony_ci} 183e41f4b71Sopenharmony_ci``` 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci### createMaterial 186e41f4b71Sopenharmony_cicreateMaterial(params: SceneResourceParameters, materialType: MaterialType): Promise\<Material> 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ciCreates a material based on the scene resource parameters and material type. This API uses a promise to return the result. 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci**Parameters** 193e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 194e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | 195e41f4b71Sopenharmony_ci| params | [SceneResourceParameters](#sceneresourceparameters) | Yes| Scene resource parameters.| 196e41f4b71Sopenharmony_ci| materialType | [MaterialType](js-apis-inner-scene-resources.md#materialtype) | Yes| Material type.| 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci**Return value** 199e41f4b71Sopenharmony_ci| Type| Description| 200e41f4b71Sopenharmony_ci| ---- | ---- | 201e41f4b71Sopenharmony_ci| Promise\<[Material](js-apis-inner-scene-resources.md#material)> | Promise used to return the **Material** object.| 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci**Example** 204e41f4b71Sopenharmony_ci```ts 205e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 206e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_cifunction createMaterialPromise() : Promise<Material> { 209e41f4b71Sopenharmony_ci return new Promise(() => { 210e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 211e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 212e41f4b71Sopenharmony_ci let sceneFactory: SceneResourceFactory = result.getResourceFactory(); 213e41f4b71Sopenharmony_ci let sceneMaterialParameter: SceneResourceParameters = { name: "material" }; 214e41f4b71Sopenharmony_ci // Create a material. 215e41f4b71Sopenharmony_ci let material: Promise<Material> = sceneFactory.createMaterial(sceneMaterialParameter, MaterialType.SHADER); 216e41f4b71Sopenharmony_ci return material; 217e41f4b71Sopenharmony_ci }); 218e41f4b71Sopenharmony_ci }); 219e41f4b71Sopenharmony_ci} 220e41f4b71Sopenharmony_ci``` 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci### createShader 223e41f4b71Sopenharmony_cicreateShader(params: SceneResourceParameters): Promise\<Shader> 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ciCreates a shader based on the scene resource parameters. This API uses a promise to return the result. 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci**Parameters** 230e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 231e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | 232e41f4b71Sopenharmony_ci| params | [SceneResourceParameters](#sceneresourceparameters) | Yes| Scene resource parameters.| 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci**Return value** 235e41f4b71Sopenharmony_ci| Type| Description| 236e41f4b71Sopenharmony_ci| ---- | ---- | 237e41f4b71Sopenharmony_ci| Promise\<[Shader](js-apis-inner-scene-resources.md#shader)> | Promise used to return the **Shader** object created.| 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci**Example** 240e41f4b71Sopenharmony_ci```ts 241e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 242e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_cifunction createShaderPromise() : Promise<Shader> { 245e41f4b71Sopenharmony_ci return new Promise(() => { 246e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 247e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 248e41f4b71Sopenharmony_ci let sceneFactory: SceneResourceFactory = result.getResourceFactory(); 249e41f4b71Sopenharmony_ci let sceneResourceParameter: SceneResourceParameters = { name: "shaderResource", 250e41f4b71Sopenharmony_ci uri: $rawfile("shaders/custom_shader/custom_material_sample.shader") }; 251e41f4b71Sopenharmony_ci // Create a shader. 252e41f4b71Sopenharmony_ci let shader: Promise<Shader> = sceneFactory.createShader(sceneResourceParameter); 253e41f4b71Sopenharmony_ci return shader; 254e41f4b71Sopenharmony_ci }); 255e41f4b71Sopenharmony_ci }); 256e41f4b71Sopenharmony_ci} 257e41f4b71Sopenharmony_ci``` 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci### createImage 261e41f4b71Sopenharmony_cicreateImage(params: SceneResourceParameters): Promise\<Image> 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ciCreates an image. This API uses a promise to return the result. 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci**Parameters** 268e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 269e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | 270e41f4b71Sopenharmony_ci| params | [SceneResourceParameters](#sceneresourceparameters) | Yes| Scene resource parameters.| 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci**Return value** 273e41f4b71Sopenharmony_ci| Type| Description| 274e41f4b71Sopenharmony_ci| ---- | ---- | 275e41f4b71Sopenharmony_ci| Promise\<[Image](js-apis-inner-scene-resources.md#image)> | Promise used to return the **Image** object created.| 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci**Example** 278e41f4b71Sopenharmony_ci```ts 279e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 280e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_cifunction createImagePromise() : Promise<Image> { 283e41f4b71Sopenharmony_ci return new Promise(() => { 284e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 285e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 286e41f4b71Sopenharmony_ci let sceneFactory: SceneResourceFactory = result.getResourceFactory(); 287e41f4b71Sopenharmony_ci let sceneImageParameter: SceneResourceParameters = { name: "image", uri: $rawfile("bricks.jpg") }; 288e41f4b71Sopenharmony_ci // Create an image. 289e41f4b71Sopenharmony_ci let image: Promise<Image> = sceneFactory.createImage(sceneImageParameter); 290e41f4b71Sopenharmony_ci return image; 291e41f4b71Sopenharmony_ci }); 292e41f4b71Sopenharmony_ci }); 293e41f4b71Sopenharmony_ci} 294e41f4b71Sopenharmony_ci``` 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci### createEnvironment 297e41f4b71Sopenharmony_cicreateEnvironment(params: SceneResourceParameters): Promise\<Environment> 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ciCreates an environment based on the scene resource parameters. This API uses a promise to return the result. 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci**Parameters** 304e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 305e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | 306e41f4b71Sopenharmony_ci| params | [SceneResourceParameters](#sceneresourceparameters) | Yes| Scene resource parameters.| 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci**Return value** 309e41f4b71Sopenharmony_ci| Type| Description| 310e41f4b71Sopenharmony_ci| ---- | ---- | 311e41f4b71Sopenharmony_ci| Promise\<[Environment](js-apis-inner-scene-resources.md#environment)> | Promise used to return the **Environment** object created.| 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ci**Example** 314e41f4b71Sopenharmony_ci```ts 315e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 316e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_cifunction createEnvironmentPromise() : Promise<Environment> { 319e41f4b71Sopenharmony_ci return new Promise(() => { 320e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 321e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 322e41f4b71Sopenharmony_ci let sceneFactory: SceneResourceFactory = result.getResourceFactory(); 323e41f4b71Sopenharmony_ci let sceneEnvironmentParameter: SceneResourceParameters = { name: "env", uri: $rawfile("bricks.ktx") }; 324e41f4b71Sopenharmony_ci // Create an environment. 325e41f4b71Sopenharmony_ci let env: Promise<Environment> = sceneFactory.createEnvironment(sceneEnvironmentParameter); 326e41f4b71Sopenharmony_ci return env; 327e41f4b71Sopenharmony_ci }); 328e41f4b71Sopenharmony_ci }); 329e41f4b71Sopenharmony_ci} 330e41f4b71Sopenharmony_ci``` 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci## Scene 333e41f4b71Sopenharmony_ciUsed to set a scene. 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci### Properties 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description| 340e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | ---- | 341e41f4b71Sopenharmony_ci| environment | [Environment](js-apis-inner-scene-resources.md#environment) | No| No| Environment object.| 342e41f4b71Sopenharmony_ci| animations | [Animation](js-apis-inner-scene-resources.md#animation)[] | Yes| No| Animation array used to hold the animation objects in the 3D scene.| 343e41f4b71Sopenharmony_ci| root | [Node](js-apis-inner-scene-nodes.md#node) \| null | Yes| No| Root node in the 3D scene tree.| 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci### load 346e41f4b71Sopenharmony_cistatic load(uri?: Resource): Promise\<Scene> 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ciLoads a resource by path. 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ci**Parameters** 353e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 354e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | 355e41f4b71Sopenharmony_ci| uri | [Resource](../apis-arkui/arkui-ts/ts-types.md#resource) | No| Path of the model file resource to load. The default value is undefined.| 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci**Return value** 358e41f4b71Sopenharmony_ci| Type| Description| 359e41f4b71Sopenharmony_ci| ---- | ---- | 360e41f4b71Sopenharmony_ci| Promise\<[Scene](#scene)> | Promise used to return the **Scene** object created.| 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci**Example** 363e41f4b71Sopenharmony_ci```ts 364e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 365e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_cifunction loadModel() : void { 368e41f4b71Sopenharmony_ci // Load the model. 369e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 370e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => {}); 371e41f4b71Sopenharmony_ci} 372e41f4b71Sopenharmony_ci``` 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ci### getNodeByPath 375e41f4b71Sopenharmony_cigetNodeByPath(path: string, type?: NodeType): Node | null 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ciObtains a node by path. 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci**Parameters** 382e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 383e41f4b71Sopenharmony_ci| ---- | ---- | ---- | ---- | 384e41f4b71Sopenharmony_ci| path | string | Yes| Path in the scene node tree. Each layer is separated by a slash (/).| 385e41f4b71Sopenharmony_ci| type | [NodeType](js-apis-inner-scene-nodes.md#nodetype) | No| Type of the node expected. The default value is null.| 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci**Return value** 388e41f4b71Sopenharmony_ci| Type| Description| 389e41f4b71Sopenharmony_ci| ---- | ---- | 390e41f4b71Sopenharmony_ci| [Node](js-apis-inner-scene-nodes.md#node) \| null | Returns the **Node** object requested. If no node is found in the specified path or the found node type does not match the expected type, null is returned.| 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci**Example** 393e41f4b71Sopenharmony_ci```ts 394e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 395e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_cifunction getNode() : void { 398e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 399e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 400e41f4b71Sopenharmony_ci if (result) { 401e41f4b71Sopenharmony_ci // Search for a node in the specified path. 402e41f4b71Sopenharmony_ci let node : Node | null = result.getNodeByPath("rootNode_"); 403e41f4b71Sopenharmony_ci } 404e41f4b71Sopenharmony_ci }); 405e41f4b71Sopenharmony_ci} 406e41f4b71Sopenharmony_ci``` 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci### getResourceFactory 409e41f4b71Sopenharmony_cigetResourceFactory(): SceneResourceFactory 410e41f4b71Sopenharmony_ci 411e41f4b71Sopenharmony_ciObtains the scene resource factory. 412e41f4b71Sopenharmony_ci 413e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_ci**Return value** 416e41f4b71Sopenharmony_ci| Type| Description| 417e41f4b71Sopenharmony_ci| ---- | ---- | 418e41f4b71Sopenharmony_ci| [SceneResourceFactory](js-apis-inner-scene.md#sceneresourcefactory)| Scene resource factory.| 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci**Example** 421e41f4b71Sopenharmony_ci```ts 422e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 423e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_cifunction getFactory() : void { 426e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 427e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 428e41f4b71Sopenharmony_ci if (result) { 429e41f4b71Sopenharmony_ci // Obtain a SceneResourceFactory object. 430e41f4b71Sopenharmony_ci let sceneFactory: SceneResourceFactory = result.getResourceFactory(); 431e41f4b71Sopenharmony_ci } 432e41f4b71Sopenharmony_ci }); 433e41f4b71Sopenharmony_ci} 434e41f4b71Sopenharmony_ci``` 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_ci### destroy 437e41f4b71Sopenharmony_cidestroy(): void 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ciDestroys this scene and releases all scene resources. 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUi.Graphics3D 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ci**Example** 444e41f4b71Sopenharmony_ci```ts 445e41f4b71Sopenharmony_ciimport { Image, Shader, MaterialType, Material, ShaderMaterial, Animation, Environment, Container, SceneNodeParameters, 446e41f4b71Sopenharmony_ci LightType, Light, Camera, SceneResourceParameters, SceneResourceFactory, Scene, Node } from '@kit.ArkGraphics3D'; 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_cifunction destroy() : void { 449e41f4b71Sopenharmony_ci let scene: Promise<Scene> = Scene.load($rawfile("gltf/CubeWithFloor/glTF/AnimatedCube.gltf")); 450e41f4b71Sopenharmony_ci scene.then(async (result: Scene) => { 451e41f4b71Sopenharmony_ci if (result) { 452e41f4b71Sopenharmony_ci // Destroy the scene. 453e41f4b71Sopenharmony_ci result.destroy(); 454e41f4b71Sopenharmony_ci } 455e41f4b71Sopenharmony_ci }); 456e41f4b71Sopenharmony_ci} 457e41f4b71Sopenharmony_ci``` 458