• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 */
15import { ToneMappingType, ToneMappingSettings, PostProcessSettings, Vec3, Vec4, Color, Quaternion, Position3,  Scale3, NodeType, Container, Node, Geometry, LightType, Light, SpotLight, DirectionalLight,
16  SceneResourceFactory, Scene } from '@ohos.graphics.scene'
17import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, TestType, Level, Size } from '@ohos/hypium'
18import * as scene3d from '@ohos.graphics.scene'
19import { lookAt } from '../common/utils';
20
21export default function sceneNodeTest() {
22  describe('sceneNodeTest', ()=> {
23    let scene: Scene | null = null;
24    let scene1: Scene | null = null;
25    let node: Node | null = null;
26    let geom: Geometry | null = null;
27    let rf: SceneResourceFactory;
28    let cam: scene3d.Camera | null = null;
29    let lig: Light | null = null;
30    let spotLight: SpotLight;
31    let directionalLight: DirectionalLight;
32
33    /**
34     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0100
35     * @tc.name      : testGetNodeByPath
36     * @tc.desc      : Used to obtain the node according to the path, and return empty if it cannot be obtained
37     * @tc.size      : MediumTest
38     * @tc.type      : Function
39     * @tc.level     : Level 3
40     */
41    it('testGetNodeByPath', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function)=> {
42      let msg = "============================testGetNodeByPath";
43      console.info(msg + ' begin ');
44      try {
45        scene = await Scene.load($rawfile("gltf/DamagedHelmet/glTF/DamagedHelmet.glb"));
46        expect(scene != undefined).assertTrue();
47        console.info(msg + " get scene success ");
48        node = scene?.root?.getNodeByPath('Scene/node_damagedHelmet_-6514') as Node;
49        expect(node != null).assertTrue();
50        console.info(msg + " Succeed in scene.root?.getNodeByPath('Scene/node_damagedHelmet_-6514') ");
51        done();
52      } catch (err) {
53        console.info(msg + " Failed in scene.root?.getNodeByPath('Scene/node_damagedHelmet_-6514') " +
54        JSON.stringify(err));
55        expect().assertFail();
56        done();
57      }
58    })
59    /**
60     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0080
61     * @tc.name      : testPath
62     * @tc.desc      : Used to get node path
63     * @tc.size      : MediumTest
64     * @tc.type      : Function
65     * @tc.level     : Level 3
66     */
67    it('testPath', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
68      let msg = "============================testPath";
69      console.info(msg + ' begin ');
70      try {
71        let path = node?.path;
72        expect(path).assertEqual("/rootNode_/Scene/");
73        console.info(msg + " Succeed in path = node?.path ");
74        done();
75      } catch (err) {
76        console.info(msg + " Failed in path = node?.path " + JSON.stringify(err));
77        expect().assertFail();
78        done();
79      }
80    })
81    /**
82     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0090
83     * @tc.name      : testParent
84     * @tc.desc      : Used to get node Parent
85     * @tc.size      : MediumTest
86     * @tc.type      : Function
87     * @tc.level     : Level 3
88     */
89    it('testParent', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
90      let msg = "============================testParent";
91      console.info(msg + ' begin ');
92      try {
93        let parentName = node?.parent?.name;
94        expect(parentName).assertEqual("Scene");
95        console.info(msg + " Succeed in parentName = node?.parent?.name ");
96        done();
97      } catch (err) {
98        console.info(msg + " Failed in parentName = node?.parent?.name " + JSON.stringify(err));
99        expect().assertFail();
100        done();
101      }
102    })
103    /**
104     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0110
105     * @tc.name      : testRemove
106     * @tc.desc      : Used to remove specified object
107     * @tc.size      : MediumTest
108     * @tc.type      : Function
109     * @tc.level     : Level 3
110     */
111    it('testRemove', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
112      let msg = "============================testRemove";
113      console.info(msg + ' begin ');
114      try {
115        let count = scene?.root?.children.count() as number;
116        let container: Container<Node>;
117        container = scene?.root?.children as Container<Node>;
118        container.append(node);
119        expect(container.count()).assertEqual(count + 1);
120        console.info(msg + " Succeed in scene.root?.children.append(node) ");
121        container.remove(node);
122        expect(container.count()).assertEqual(count);
123        console.info(msg + " Succeed in scene.root?.children.remove(node) ");
124        done();
125      } catch (err) {
126        console.info(msg + " Failed in scene.root?.children.remove(node) " + JSON.stringify(err));
127        expect().assertFail();
128        done();
129      }
130    })
131    /**
132     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0120
133     * @tc.name      : testInsertAfter
134     * @tc.desc      : Used to insert an object after the sibling node
135     * @tc.size      : MediumTest
136     * @tc.type      : Function
137     * @tc.level     : Level 3
138     */
139    it('testInsertAfter', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
140      let msg = "============================testInsertAfter";
141      console.info(msg + ' begin ');
142      try {
143        let count = scene?.root?.children.count() as number;
144        scene?.root?.children.insertAfter(node, null);
145        expect(scene?.root?.children.count()).assertEqual(count + 1);
146        console.info(msg + " Succeed in scene.root?.children.insertAfter(node,null) ");
147        done();
148      } catch (err) {
149        console.info(msg + " Failed in scene.root?.children.insertAfter(node,null) " + JSON.stringify(err));
150        expect().assertFail();
151        done();
152      }
153    })
154    /**
155     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0130
156     * @tc.name      : testGet
157     * @tc.desc      : Used to gets the specified subscript object and returns empty if it cannot be obtained
158     * @tc.size      : MediumTest
159     * @tc.type      : Function
160     * @tc.level     : Level 3
161     */
162    it('testGet', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
163      let msg = "============================testGet";
164      console.info(msg + ' begin ');
165      try {
166        scene?.root?.children.remove(node);
167        scene?.root?.children.append(node);
168        let count = scene?.root?.children.count() as number;
169        let node1 = scene?.root?.children.get(count - 1) as Node;
170        console.info(msg + " Succeed in scene.root?.children.get(count - 1) ");
171        expect(node1).assertEqual(node);
172        done();
173      } catch (err) {
174        console.info(msg + " Failed in scene.root?.children.get(count - 1) " + JSON.stringify(err));
175        expect().assertFail();
176        done();
177      }
178    })
179
180    /**
181     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0140
182     * @tc.name      : testLayerMask
183     * @tc.desc      : The layer mask used to define the node
184     * @tc.size      : MediumTest
185     * @tc.type      : Function
186     * @tc.level     : Level 3
187     */
188    it('testLayerMask', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
189      let msg = "============================testLayerMask";
190      console.info(msg + ' begin ');
191      try {
192        let layerMask = node?.layerMask;
193        expect(layerMask != null).assertTrue();
194        console.info(msg + " layerMask is not null ");
195        node?.layerMask.setEnabled(3, false);
196        expect(node?.layerMask.getEnabled(3)).assertFalse();
197        console.info(msg + " Succeed in node?.layerMask.setEnabled(3, false) ");
198        node?.layerMask.setEnabled(3, true);
199        expect(node?.layerMask.getEnabled(3)).assertTrue();
200        console.info(msg + " Succeed in node?.layerMask.setEnabled(3, true) ");
201        done();
202      } catch (err) {
203        console.info(msg + " Failed in node?.layerMask.setEnabled(3, false) " + JSON.stringify(err));
204        expect().assertFail();
205        done();
206      }
207    })
208    /**
209     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0150
210     * @tc.name      : testPosition
211     * @tc.desc      : Used to set node position
212     * @tc.size      : MediumTest
213     * @tc.type      : Function
214     * @tc.level     : Level 3
215     */
216    it('testPosition', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
217      let msg = "============================testPosition";
218      console.info(msg + ' begin ');
219      try {
220        let vec3: Vec3;
221        let position: Position3;
222        vec3 = { x: 5, y: 5, z: 5 };
223        position = vec3;
224        if (node) {
225          node.position = position;
226        }
227        expect(node?.position.x).assertEqual(5);
228        expect(node?.position.y).assertEqual(5);
229        expect(node?.position.z).assertEqual(5);
230        console.info(msg + " Succeed in node?.position ");
231        done();
232      } catch (err) {
233        console.info(msg + " Failed in node?.position " + JSON.stringify(err));
234        expect().assertFail();
235        done();
236      }
237    })
238    /**
239     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0160
240     * @tc.name      : testRotation
241     * @tc.desc      : Used to set node Rotation
242     * @tc.size      : MediumTest
243     * @tc.type      : Function
244     * @tc.level     : Level 3
245     */
246    it('testRotation', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
247      let msg = "============================testRotation";
248      console.info(msg + ' begin ');
249      try {
250        let rotation: Quaternion;
251        let vec4: Vec4;
252        vec4 = {
253          x: 5,
254          y: 5,
255          z: 5,
256          w: 5
257        };
258        rotation = vec4;
259        if (node) {
260          node.rotation = rotation;
261        }
262        expect(node?.rotation.x).assertEqual(5);
263        expect(node?.rotation.y).assertEqual(5);
264        expect(node?.rotation.z).assertEqual(5);
265        expect(node?.rotation.w).assertEqual(5);
266        console.info(msg + " Succeed in node.rotation ");
267        done();
268      } catch (err) {
269        console.info(msg + " Failed in node?.rotation " + JSON.stringify(err));
270        expect().assertFail();
271        done();
272      }
273    })
274    /**
275     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0170
276     * @tc.name      : testScale
277     * @tc.desc      : Used to set node scale
278     * @tc.size      : MediumTest
279     * @tc.type      : Function
280     * @tc.level     : Level 3
281     */
282    it('testScale', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
283      let msg = "============================testScale";
284      console.info(msg + ' begin ');
285      try {
286        let scale: Scale3 = {
287          x: 5, y: 5, z: 5
288        };
289        if (node) {
290          node.scale = scale;
291        }
292        expect(node?.scale.x).assertEqual(5);
293        expect(node?.scale.y).assertEqual(5);
294        expect(node?.scale.z).assertEqual(5);
295        console.info(msg + " Succeed in node.scale = scale ");
296        done();
297      } catch (err) {
298        console.info(msg + " Failed in node.scale = scale " + JSON.stringify(err));
299        expect().assertFail();
300        done();
301      }
302    })
303    /**
304     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0180
305     * @tc.name      : testVisible
306     * @tc.desc      : Used to set weather the node is visible
307     * @tc.size      : MediumTest
308     * @tc.type      : Function
309     * @tc.level     : Level 3
310     */
311    it('testVisible', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
312      let msg = "============================testVisible";
313      console.info(msg + ' begin ');
314      try {
315        expect(node?.visible).assertTrue();
316        console.info(msg + " node?.visible is true ");
317        if (node) {
318          node.visible = false;
319        }
320        expect(node?.visible).assertFalse();
321        console.info(msg + " Succeed in node.visible set false");
322        done();
323      } catch (err) {
324        console.info(msg + " Failed in node.visible set false " + JSON.stringify(err));
325        expect().assertFail();
326        done();
327      }
328    })
329    /**
330     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0190
331     * @tc.name      : testFov
332     * @tc.desc      : Used to set field of view
333     * @tc.size      : MediumTest
334     * @tc.type      : Function
335     * @tc.level     : Level 3
336     */
337    it('testFov', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function)=> {
338      let msg = "============================testFov";
339      console.info(msg + ' begin ');
340      try {
341        expect(scene != null).assertTrue();
342        console.info(msg + " scene is not null ");
343        if (scene) {
344          rf = scene.getResourceFactory();
345          cam = await rf.createCamera({ name: "Camera1" });
346        }
347        expect(cam != null).assertTrue();
348        console.info(msg + " cam is not null ");
349        if (cam) {
350          cam.fov = 2;
351        }
352        expect(cam?.fov).assertEqual(2);
353        console.info(msg + " Succeed in cam.fov = 2 ");
354        done();
355      } catch (err) {
356        console.info(msg + " Failed in cam.fov = 2 " + JSON.stringify(err));
357        expect().assertFail();
358        done();
359      }
360    })
361    /**
362     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0200
363     * @tc.name      : testNearPlane
364     * @tc.desc      : Used to set nearPlane The value ranges from 0 to 1
365     * @tc.size      : MediumTest
366     * @tc.type      : Function
367     * @tc.level     : Level 3
368     */
369    it('testNearPlane', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
370      let msg = "============================testNearPlane";
371      console.info(msg + ' begin ');
372      try {
373        expect(cam != null).assertTrue();
374        console.info(msg + " cam is not null ");
375        if (cam) {
376          cam.nearPlane = 0.5;
377        }
378        expect(cam?.nearPlane).assertEqual(0.5);
379        console.info(msg + " Succeed in cam.nearPlane = 0.5 ");
380        done();
381      } catch (err) {
382        console.info(msg + " Failed in cam.nearPlane = 0.5 " + JSON.stringify(err));
383        expect().assertFail();
384        done();
385      }
386    })
387    /**
388     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0210
389     * @tc.name      : testFarPlane
390     * @tc.desc      : Used to set farPlane The value ranges from 0 to 1
391     * @tc.size      : MediumTest
392     * @tc.type      : Function
393     * @tc.level     : Level 3
394     */
395    it('testFarPlane', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
396      let msg = "============================testFarPlane";
397      console.info(msg + ' begin ');
398      try {
399        expect(cam != null).assertTrue();
400        console.info(msg + " cam is not null ");
401        if (cam) {
402          cam.farPlane = 0.5;
403        }
404        expect(cam?.farPlane).assertEqual(0.5);
405        console.info(msg + " Succeed in cam.farPlane = 0.5 ");
406        done();
407      } catch (err) {
408        console.info(msg + " Failed in cam.farPlane = 0.5 " + JSON.stringify(err));
409        expect().assertFail();
410        done();
411      }
412    })
413    /**
414     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0220
415     * @tc.name      : testCamEnabled
416     * @tc.desc      : Used to set whether the camera is visible
417     * @tc.size      : MediumTest
418     * @tc.type      : Function
419     * @tc.level     : Level 3
420     */
421    it('testCamEnabled', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
422      let msg = "============================testCamEnabled";
423      console.info(msg + ' begin ');
424      try {
425        expect(cam != null).assertTrue();
426        console.info(msg + " cam is not null ");
427        if (cam) {
428          cam.enabled = true;
429          expect(cam?.enabled).assertTrue();
430          cam.enabled = false;
431        }
432        expect(cam?.enabled).assertFalse();
433        console.info(msg + " Succeed in cam.enabled = false ");
434        done();
435      } catch (err) {
436        console.info(msg + " Failed in cam.enabled = false " + JSON.stringify(err));
437        expect().assertFail();
438        done();
439      }
440    })
441    /**
442     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0230
443     * @tc.name      : testClearColor
444     * @tc.desc      : The specific color used to empty the render target
445     * @tc.size      : MediumTest
446     * @tc.type      : Function
447     * @tc.level     : Level 3
448     */
449    it('testClearColor', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
450      let msg = "============================testClearColor";
451      console.info(msg + ' begin ');
452      try {
453        let color: Color | null;
454        color = { r: 2, g: 2, b: 2, a: 2 };
455        expect(cam != null).assertTrue();
456        console.info(msg + " cam is not null ");
457        if (cam) {
458          cam.enabled = true;
459          cam.clearColor = color;
460        }
461        expect(cam?.clearColor?.r).assertEqual(2);
462        expect(cam?.clearColor?.g).assertEqual(2);
463        expect(cam?.clearColor?.b).assertEqual(2);
464        expect(cam?.clearColor?.a).assertEqual(2);
465        console.info(msg + " Succeed in cam.clearColor = color ");
466        done();
467      } catch (err) {
468        console.info(msg + " Failed in cam.clearColor = color " + JSON.stringify(err));
469        expect().assertFail();
470        done();
471      }
472    })
473    /**
474     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0240
475     * @tc.name      : testPostProcess
476     * @tc.desc      : Used to post-processing Settings
477     * @tc.size      : MediumTest
478     * @tc.type      : Function
479     * @tc.level     : Level 3
480     */
481    it('testPostProcess', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
482      let msg = "============================testPostProcess";
483      console.info(msg + ' begin ');
484      try {
485        let toneMapType: ToneMappingType;
486        let toneMap: ToneMappingSettings;
487        let post: PostProcessSettings | null;
488        let exposure = 0.5 as number;
489        toneMapType = ToneMappingType.ACES;
490        toneMapType = ToneMappingType.ACES_2020;
491        toneMapType = ToneMappingType.FILMIC;
492        toneMap = { type: toneMapType, exposure };
493        post = { toneMapping: toneMap }
494        expect(cam != null).assertTrue();
495        console.info(msg + " cam is not null ");
496        if (cam) {
497          cam.postProcess = post;
498        }
499        expect(cam?.postProcess?.toneMapping?.exposure).assertEqual(0.5);
500        console.info(msg + " Succeed in cam.postProcess = post ");
501        done();
502      } catch (err) {
503        console.info(msg + " Failed in cam.postProcess = post " + JSON.stringify(err));
504        expect().assertFail();
505        done();
506      }
507    })
508    /**
509     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0250
510     * @tc.name      : testLightColor
511     * @tc.desc      : Used to set light color
512     * @tc.size      : MediumTest
513     * @tc.type      : Function
514     * @tc.level     : Level 3
515     */
516    it('testLightColor', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function)=> {
517      let msg = "============================testLightColor";
518      console.info(msg + ' begin ');
519      try {
520        lig = await rf.createLight({ name: "Light" }, LightType.DIRECTIONAL);
521        expect(lig != null).assertTrue();
522        console.info(msg + " lig is not null ");
523        if (lig) {
524          lig.color = { r: 2, g: 2, b: 2, a: 2 };
525          expect(lig.color.r).assertEqual(2);
526          console.info(msg + " Succeed in lig.color = { r: 2, g: 2, b: 2, a: 2 } ");
527        }
528        done();
529      } catch (err) {
530        console.info(msg + " Failed in lig.color = { r: 2, g: 2, b: 2, a: 2 } " + JSON.stringify(err));
531        expect().assertFail();
532        done();
533      }
534    })
535    /**
536     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0260
537     * @tc.name      : testLigEnabled
538     * @tc.desc      : Used to set whether the light is visible
539     * @tc.size      : MediumTest
540     * @tc.type      : Function
541     * @tc.level     : Level 3
542     */
543    it('testLigEnabled', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
544      let msg = "============================testLigEnabled";
545      console.info(msg + ' begin ');
546      try {
547        expect(lig != null).assertTrue();
548        console.info(msg + " lig is not null ");
549        if (lig) {
550          lig.enabled = true;
551          expect(lig?.enabled).assertTrue();
552          console.info(msg + " Succeed in lig.enabled = false ");
553          lig.enabled = false;
554          expect(lig?.enabled).assertFalse();
555          console.info(msg + " Succeed in lig.enabled = false ");
556        }
557        done();
558      } catch (err) {
559        console.info(msg + " Failed in lig.enabled = false " + JSON.stringify(err));
560        expect().assertFail();
561        done();
562      }
563    })
564    /**
565     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0270
566     * @tc.name      : testShadowEnabled
567     * @tc.desc      : Used to set whether the shadow is visible
568     * @tc.size      : MediumTest
569     * @tc.type      : Function
570     * @tc.level     : Level 3
571     */
572    it('testShadowEnabled', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
573      let msg = "============================testShadowEnabled";
574      console.info(msg + ' begin ');
575      try {
576        expect(lig != null).assertTrue();
577        console.info(msg + " lig is not null ");
578        if (lig) {
579          lig.shadowEnabled = true;
580          expect(lig?.shadowEnabled).assertTrue();
581          console.info(msg + " Succeed in lig.shadowEnabled = true ");
582          lig.shadowEnabled = false;
583          expect(lig?.shadowEnabled).assertFalse();
584          console.info(msg + " Succeed in lig.shadowEnabled = false ");
585        }
586        done();
587      } catch (err) {
588        console.info(msg + " Failed in lig.shadowEnabled = false " + JSON.stringify(err));
589        expect().assertFail();
590        done();
591      }
592    })
593    /**
594     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0280
595     * @tc.name      : testLightType
596     * @tc.desc      : Used to get light type
597     * @tc.size      : MediumTest
598     * @tc.type      : Function
599     * @tc.level     : Level 3g
600     */
601    it('testLightType', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function)=> {
602      let msg = "============================testLightType";
603      console.info(msg + ' begin ');
604      try {
605        directionalLight = await rf.createLight({ name: "Light1" }, LightType.DIRECTIONAL)
606        expect(directionalLight.lightType).assertEqual(LightType.DIRECTIONAL);
607        console.info(msg + " Succeed in createLight LightType.DIRECTIONAL ");
608        spotLight = await rf.createLight({ name: "Light2" }, LightType.SPOT)
609        expect(spotLight.lightType).assertEqual(LightType.SPOT);
610        console.info(msg + " Succeed in createLight LightType.SPOT ");
611        done();
612      } catch (err) {
613        console.info(msg +
614          ' Failed in lig = await directionalLight.createLight({name: "Light1"},  LightType.SPOT) ' +
615        JSON.stringify(err));
616        expect().assertFail();
617        done();
618      }
619    })
620    /**
621     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0290
622     * @tc.name      : testIntensity
623     * @tc.desc      : Used to set light intensity
624     * @tc.size      : MediumTest
625     * @tc.type      : Function
626     * @tc.level     : Level 3
627     */
628    it('testIntensity', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
629      let msg = "============================testIntensity";
630      console.info(msg + ' begin ');
631      try {
632        expect(lig != null).assertTrue();
633        console.info(msg + " lig is not null ");
634        if (lig) {
635          lig.intensity = 1000;
636          expect(lig.intensity).assertEqual(1000);
637          console.info(msg + " Succeed in lig.intensity = 1000 ");
638        }
639        done();
640      } catch (err) {
641        console.info(msg + " Failed in lig.intensity = 1000 " + JSON.stringify(err));
642        expect().assertFail();
643        done();
644      }
645    })
646    /**
647     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0300
648     * @tc.name      : testNodeType
649     * @tc.desc      : Used to get nodeType
650     * @tc.size      : MediumTest
651     * @tc.type      : Function
652     * @tc.level     : Level 3
653     */
654    it('testNodeType', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function)=> {
655      let msg = "============================testNodeType";
656      console.info(msg + ' begin ');
657      try {
658        let node1 = await rf.createNode({ name: "createNode1" })
659        scene1 = await Scene.load($rawfile("gltf/Cube/glTF/Cube.glb"));
660        expect(scene1 != undefined).assertTrue();
661        console.info(msg + " succeed in load ");
662        geom = scene1.getNodeByPath("rootNode_/Unnamed Node 1/Cube") as Geometry;
663        expect(geom != null).assertTrue();
664        console.info(msg + " succeed in getNodeByPath ");
665        expect(node1?.nodeType).assertEqual(NodeType.NODE);
666        console.info(msg + " node1?.nodeType is " + JSON.stringify(node1?.nodeType));
667        expect(geom?.nodeType).assertEqual(NodeType.GEOMETRY);
668        console.info(msg + " geom?.nodeType is " + JSON.stringify(geom?.nodeType));
669        expect(lig?.nodeType).assertEqual(NodeType.LIGHT);
670        console.info(msg + " lig?.nodeType is " + JSON.stringify(lig?.nodeType));
671        expect(cam?.nodeType).assertEqual(NodeType.CAMERA);
672        console.info(msg + " cam?.nodeType is " + JSON.stringify(cam?.nodeType));
673        done();
674      } catch (err) {
675        console.info(msg + " Failed in node?.nodeType " + JSON.stringify(err));
676        expect().assertFail();
677        done();
678      }
679    })
680    /**
681     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0310
682     * @tc.name      : testClear
683     * @tc.desc      : Used to empty all objects in the container
684     * @tc.size      : MediumTest
685     * @tc.type      : Function
686     * @tc.level     : Level 3
687     */
688    it('testClear', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
689      let msg = "============================testClear";
690      console.info(msg + ' begin ');
691      try {
692        scene?.root?.children.append(node);
693        scene?.root?.children.clear();
694        console.info(msg + " Succeed in scene.root?.children.clear() ");
695        done();
696      } catch (err) {
697        console.info(msg + " Failed in scene.root?.children.clear() " + JSON.stringify(err));
698        expect().assertFail();
699        done();
700      }
701    })
702    /**
703     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0570
704     * @tc.name      : testSphereGeometry
705     * @tc.desc      : Used to set the properties of the bloom
706     * @tc.size      : MediumTest
707     * @tc.type      : Function
708     * @tc.level     : Level 3
709     */
710    it('testBloomSettings', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
711      let msg = "============================testBloomSettings";
712      console.info(msg + ' begin ');
713      try {
714        expect(cam != null).assertTrue();
715        console.info(msg + " cam is not null ");
716        expect(cam?.postProcess != null).assertTrue();
717        console.info(msg + " cam?.postProcess is not null ");
718        if (cam?.postProcess) {
719          cam.postProcess.bloom = { thresholdHard: 1.0, thresholdSoft: 1.0, scaleFactor: 0.5, scatter: 2.0 };
720          expect(cam.postProcess.bloom.thresholdHard).assertEqual(1.0);
721          console.info(msg + " Succeed in cam.postProcess.bloom.thresholdHard ");
722          expect(cam.postProcess.bloom.thresholdSoft).assertEqual(1.0);
723          console.info(msg + " Succeed in cam.postProcess.bloom.thresholdSoft ");
724          expect(cam.postProcess.bloom.scaleFactor).assertEqual(0.5);
725          console.info(msg + " Succeed in cam.postProcess.bloom.scaleFactor ");
726          expect(cam.postProcess.bloom.scatter).assertEqual(2.0);
727          console.info(msg + " Succeed in cam.postProcess.bloom.scatter ");
728        }
729        done();
730      } catch (err) {
731        console.info(msg + " Failed in testBloomSettings " + JSON.stringify(err));
732        expect().assertFail();
733        done();
734      }
735    })
736    /**
737     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0580
738     * @tc.name      : testSphereGeometry
739     * @tc.desc      : Used to create a cube
740     * @tc.size      : MediumTest
741     * @tc.type      : Function
742     * @tc.level     : Level 3
743     */
744    it('testCreateGeometryCUBE', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function)=> {
745      let msg = "============================testCreateGeometryCUBE";
746      console.info(msg + ' begin ');
747      try {
748        let cubeGeom = new scene3d.CubeGeometry();
749        expect(cubeGeom != null).assertTrue();
750        console.info(msg + " cubeGeom is not null ");
751        expect(cubeGeom.geometryType).assertEqual(scene3d.GeometryType.CUBE);
752        cubeGeom.size = {x: 0.8, y: 0.4, z: 0.6}
753        let meshRes1 = await rf.createMesh({ name: "resource name not used at the moment "}, cubeGeom);
754        expect(meshRes1 != null).assertTrue();
755        console.info(msg + " Succeed in createMesh ");
756        let geometry1 = await rf.createGeometry({ name: "cuubio" }, meshRes1);
757        expect(geometry1 != null).assertTrue();
758        console.info(msg + " Succeed in createGeometry ");
759        scene?.root?.children.append(geometry1);
760        done();
761      } catch (err) {
762        console.info(msg + " Failed in testCreateGeometryCUBE " + JSON.stringify(err));
763        expect().assertFail();
764        done();
765      }
766    })
767    /**
768     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0590
769     * @tc.name      : testSphereGeometry
770     * @tc.desc      : Used to create a plane
771     * @tc.size      : MediumTest
772     * @tc.type      : Function
773     * @tc.level     : Level 3
774     */
775    it('testCreateGeometryPLANE', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function)=> {
776      let msg = "============================testCreateGeometryPLANE";
777      console.info(msg + ' begin ');
778      try {
779        let planeGeom = new scene3d.PlaneGeometry();
780        expect(planeGeom != null).assertTrue();
781        console.info(msg + " planeGeom is not null ");
782        expect(planeGeom.geometryType).assertEqual(scene3d.GeometryType.PLANE);
783        planeGeom.size = {x: 1, y: 1};
784        let meshRes2 = await rf.createMesh({ name: "resource name not used at the moment "}, planeGeom);
785        expect(meshRes2 != null).assertTrue();
786        console.info(msg + " Succeed in createMesh ");
787        let geometry2 = await rf.createGeometry({ name: "plaanio" }, meshRes2);
788        expect(geometry2 != null).assertTrue();
789        console.info(msg + " Succeed in createGeometry ");
790        scene?.root?.children.append(geometry2);
791        done();
792      } catch (err) {
793        console.info(msg + " Failed in testCreateGeometryPLANE " + JSON.stringify(err));
794        expect().assertFail();
795        done();
796      }
797    })
798    /**
799     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0600
800     * @tc.name      : testSphereGeometry
801     * @tc.desc      : Used to import a node
802     * @tc.size      : MediumTest
803     * @tc.type      : Function
804     * @tc.level     : Level 3
805     */
806    it('testImportNode', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
807      let msg = "============================testImportNode";
808      console.info(msg + ' begin ');
809      try {
810        let node1 = scene1?.getNodeByPath("rootNode_/Unnamed Node 1/Cube") as Node;
811        let node2: scene3d.Node | null | undefined = null;
812        node2 = scene?.importNode("scene2", node1, scene.root);
813        expect(node2 != null).assertTrue();
814        done();
815      } catch (err) {
816        console.info(msg + " Failed in testImportNode " + JSON.stringify(err));
817        expect().assertFail();
818        done();
819      }
820    })
821    /**
822     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0610
823     * @tc.name      : testSphereGeometry
824     * @tc.desc      : Used to import a scene
825     * @tc.size      : MediumTest
826     * @tc.type      : Function
827     * @tc.level     : Level 3
828     */
829    it('testImportScene', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (done:Function)=> {
830      let msg = "============================testImportScene";
831      console.info(msg + ' begin ');
832      try {
833        let node2: scene3d.Node | null | undefined = null;
834        node2 = scene?.importScene("scene1", scene1, null);
835        expect(node2 != null).assertTrue();
836        done();
837      } catch (err) {
838        console.info(msg + " Failed in testImportScene " + JSON.stringify(err));
839        expect().assertFail();
840        done();
841      }
842    })
843
844    /**
845     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0740
846     * @tc.name      : testGeometry_Morpher
847     * @tc.desc      : Verifies that a Geometry node can have an optional Morpher
848     * @tc.size      : MediumTest
849     * @tc.type      : Function
850     * @tc.level     : Level 3
851     */
852    it('testGeometry_Morpher', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function)=> {
853      let msg = "============================testGeometry_Morpher";
854      console.info(msg + ' begin ');
855      try {
856
857        let scene = await Scene.load($rawfile('gltf/Morpher/MorphStressTest.glb'));
858        console.info(msg, 'scene loaded:', scene != null);
859        expect(scene != null).assertTrue();
860
861        let rootNode: Node | null = scene.root;
862        console.info(msg, 'rootNode:', rootNode != null);
863        expect(rootNode != null).assertTrue();
864
865        let geometryNode = scene.getNodeByPath('rootNode_/Scene/Main');
866        console.info(msg, 'geometryNode:', geometryNode != null);
867        expect(geometryNode != null).assertTrue();
868
869        if (geometryNode != null) {
870          let morpher: scene3d.Morpher | undefined = (geometryNode as Geometry).morpher;
871          console.info(msg, 'morpher:', morpher != null);
872          expect(morpher != null).assertTrue();
873
874          if (morpher != null) {
875            let targets = morpher.targets;
876            console.info(msg, 'morpher.targets:', targets != null);
877            expect(targets != null).assertTrue();
878            Object.values(targets).forEach(weight => {
879              expect(weight >= 0.0 && weight <= 1.0).assertTrue();
880            });
881          }
882        }
883        console.info(msg + " test completed successfully");
884        done();
885      } catch (err) {
886        console.info(msg + " Failed in testGeometry_Morpher " + JSON.stringify(err));
887        expect().assertFail();
888        done();
889      }
890    })
891
892    /**
893     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_GRAPHIC3D_JS_API_0750
894     * @tc.name      : testCamera_raycast
895     * @tc.desc      : Verifies Camera raycast returns valid hit results with node, centerDistance,
896     *                 and hitPosition using a screen-space ray
897     * @tc.size      : MediumTest
898     * @tc.type      : Function
899     * @tc.level     : Level 3
900     */
901    it('testCamera_raycast', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done: Function) => {
902      let msg = "============================testCamera_raycast";
903      console.info(msg + ' begin');
904      try {
905        let scene = await Scene.load($rawfile('gltf/CubeWithFloor/glTF/AnimatedCube.glb'));
906        console.info(msg, 'scene loaded:', scene != null);
907        expect(scene != null).assertTrue();
908
909        let rootNode: Node | null = scene.root;
910        console.info(msg + " root node:", rootNode);
911        expect(rootNode != null).assertTrue();
912
913        let raycastNode = scene.getNodeByPath('rootNode_/Unnamed Node 1/AnimatedCube') as scene3d.Node;
914        console.info(msg + " target node obtained:", raycastNode?.name ?? "null");
915        expect(raycastNode != null).assertTrue();
916
917        let factory: SceneResourceFactory = scene.getResourceFactory();
918        let cameraParams: scene3d.SceneNodeParameters = { name: "camera1" };
919        let camera = await factory.createCamera(cameraParams);
920        camera.enabled = true;
921
922        lookAt(camera, { x: 15, y: 10, z: 20 }, { x: 0, y: 0, z: 0 }, { x: 0, y: 1, z: 0 });
923        let viewPos: scene3d.Vec2 = { x: 0.5, y: 0.5 };
924
925        let results: scene3d.RaycastResult[] = await camera.raycast(viewPos, { rootNode: raycastNode });
926        expect(results != null && results.length > 0).assertTrue();
927        let hit = results[0];
928
929        expect(hit.node != null).assertTrue();
930        console.info(msg + " Hit node name:", hit.node.name);
931
932        expect(typeof hit.centerDistance === 'number' && hit.centerDistance > 0).assertTrue();
933        console.info(msg + " Hit centerDistance:", hit.centerDistance);
934
935        expect(hit.hitPosition != null).assertTrue();
936        console.info(msg + " Hit position:", JSON.stringify(hit.hitPosition));
937
938        console.info(msg + " test completed successfully");
939        done();
940      } catch (err) {
941        console.error(msg + " Failed in testCamera_raycast: " + JSON.stringify(err));
942        expect().assertFail();
943        done();
944      }
945    });
946  })
947}