Add child nodes¶
addChildren.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2
3# clean the scene
4newScene()
5
6# This example creates nodes and adds them as children to a
7# parent node with API v2.
8#
9# Please note, the create functions have a parent parameter that lets
10# you specify the target parent directly but for demonstration purposes
11# the nodes are created under root and then reparented in this script.
12
13root = vrScenegraphService.getRootNode()
14
15# create planet and moons
16planetNode = vrGeometryService.createSphere(root, 3.0, 32, 32, QColor.fromRgbF(0.0, 0.1, 0.6))
17planetNode.setName("Planet")
18
19moonColor = QColor.fromRgbF(0.0, 0.0, 0.0)
20moon1Node = vrGeometryService.createSphere(root, 0.5, 16, 16, moonColor)
21moon1Node.setName("Moon")
22moon1Node.setTranslation(QVector3D(5.0,3.0,5.0))
23
24moon2Node = vrGeometryService.createSphere(root, 0.2, 16, 16, moonColor)
25moon2Node.setName("Moon2")
26moon2Node.setTranslation(QVector3D(-1.0,6.0,0.0))
27
28# create a list of the moon nodes
29moonlist = []
30moonlist.append(moon1Node)
31moonlist.append(moon2Node)
32
33# create a new group for the moons
34moonGroup = vrScenegraphService.createNode(vrScenegraphTypes.TransformNode, root, "Moons")
35
36# add moons as children to the group
37moonGroup.children.append(moonlist)
38
39# create a new group for the planet and the moon group
40planetGroup = vrScenegraphService.createNode(vrScenegraphTypes.TransformNode, root, "Planet")
41
42# add the planet and the moon group to the planet group
43planetGroup.children.append([moonGroup, planetNode])
44
45# moving the planet group with all children
46planetGroup.setTranslation(QVector3D(5.0,5.0,0.0))
47
48# hide the environment
49environment = vrMaterialService.findMaterial("Studio")
50environment.setVisible(False)
51environment.setShadowPlaneVisible(False)
52