Visualize user positions

This example shows how Python can be used to query positions of all users in a collaboration session. With the help of the positions a very simple overview map with all users is generated.

vr/showVRCollabUserPositions.py
 1# © 2024 Autodesk, Inc. All rights reserved.
 2
 3# This scripts shows an overview of user positions in a collaboration sesion
 4class UserMap(vrAEBase):
 5    def __init__(self):
 6        vrAEBase.__init__(self)
 7        self.spheres = {}
 8        self.addLoop()
 9        # callback sesson start/stop
10        vrSessionService.sessionJoined.connect(self.started)
11        vrSessionService.sessionLeft.connect(self.ended)
12        # callback user joins/leaves session
13        vrSessionService.userArrives.connect(self.userArrived)
14        vrSessionService.userLeaves.connect(self.userLeaves)
15    def loop(self):
16        # this is my local camera position
17        myPos = getTransformNodeTranslation(vrSessionService.getUser().getHeadNode(),True)
18        for user in vrSessionService.getRemoteUsers():
19            sphere = self.spheres[user.getUserId()]
20            # this is the users head transformation node
21            pos = getTransformNodeTranslation(user.getHeadNode(),True)
22            # move indicator for user position
23            setTransformNodeTranslation(sphere,(pos.x()-myPos.x())/100,(pos.y()-myPos.y())/100,-500,False)
24    def started(self):
25        self.group = createNode("Group", "UserMap", vrCameraService.getActiveCamera())
26        self.plane = createCylinder(2, 100, 50, True, True, True, .0, .1, .0)
27        self.setTransparent(self.plane)
28        addChilds(self.group,[self.plane])
29        color = vrSessionService.getUser().getUserColor()
30        sphere = createSphere(3, 2, color.redF(), color.greenF(), color.blueF())
31        addChilds(self.group,[sphere])
32        setTransformNodeTranslation(sphere,0,0,-500,False)
33        setTransformNodeRotation(self.plane, 90, 0, 0)
34        setTransformNodeTranslation(self.plane, 0, 0, -500, False)
35        self.setActive(True)
36    def ended(self):
37        subChilds(self.group,[self.plane])
38        subChilds(vrCameraService.getActiveCamera(),[self.group])
39        self.setActive(False)
40    def userArrived(self,user):
41        color = user.getUserColor()
42        sphere = createSphere(2, 2, color.redF(), color.greenF(), color.blueF())
43        addChilds(self.group,[sphere])
44        self.spheres[user.getUserId()] = sphere
45    def userLeaves(self,user):
46        sphere = self.spheres[user.getUserId()]
47        subChilds(self.group,[sphere])
48    def setTransparent(self,node):
49        node.getMaterial().fields().setVec3f("seeThrough",.95,.95,.95)
50                
51map = UserMap()