0

Here is my code:

import time
import viz
import oculus

class virtualWorld:
    
    def __init__(self, virtualFileInd = 0, usingHeadset = False):
        # Parameters of the virtual world
        self.virtualDisplay = None             
        self.virtualEnviroments = ["piazza.osgb", "lobby.osgb", "gallery.osgb"]
        
        # Set the parameters for VR rendering.
        viz.setMultiSample(4)  
        
        # Create a new VR window.
        viz.go(mode = viz.HMD)   

        self.link = viz.link(oculus.Rift(2).getSensor(), viz.MainView)
        viz.setOption('viz.mode', oculus.Rift)         
    
    def displayEnviroment(self, virtualFileInd):        
        # Remove the old enviroment if present.
        if self.virtualDisplay != None:
            self.virtualDisplay.remove()
            
        # Display the current enviroment.
        self.virtualDisplay = viz.add(self.virtualEnviroments[virtualFileInd])
        self.virtualDisplay.visible(viz.ON)
        
        # Update the scene immediately.
        viz.update(viz.SCREEN)
        self.link.update()
        
# Specify the VR File and Create the VR World
controlVR = virtualWorld(virtualFileInd = 0, usingHeadset = True)

time.sleep(3)
controlVR.displayEnviroment(1)

time.sleep(3)
controlVR.displayEnviroment(2)

The problem is that when I run this code, I only display the final enviroment AFTER the program finishes. I want to display each of these enviroments. Note, this is boiler plate code. My eventual goal is to run another codepiece that changes the enviroment randomly (which is why I cant hardcode a schedule to change them on a timer). I need to have the enviroment display while the code is running.

I am not sure what else to try.

0 Answers0