Adding Variants

 

Creating the Variant Sets

We will now create some Variant Sets. Click on the VSets icon on the lower center of your screen. Press on the plus sign to create a new Variant. Make a Variant called Light and click on the light tab. Go to the scenegraph and drag the spotlight we made into the variant. Make sure state is set to !Toggle. Make another Variant set called Paint and click on the Material tab. Open your material editor and drag the new switch material we made into the variant. Make sure the state is set to !Next(Loop) 

Finding the Terminal

The terminal is the easiest way to try out different python codes in VRED. It is located on the bottom of the user interface right under all those icons. This is the place where we will learn the basics of python. So let's get started with some super simple stuff. Right next to root is the place where we will write some code.

If you have never written any code it is necessary to indoctrinate you with the standard first code. Type the following into the terminal and press enter

print "Hello World"

Congratulations you just wrote your first bit of code. Some easy lesson to notice, Hello World is in quotations. This is because it is a string. Print is a command that type anything you want onto the terminal. Type the following

print Hello World 

Oh oh, we got a syntax error. This means we didn't follow the rules of python. This will be a very common and frustrating occurrence so get use to it. Lets try something else, copy the next two lines to the terminal and press enter. 

x = "I am confused"

print x

I know you are confused. I was too, but slowly this will all make sense with practice. 

Talking to VRED

Now it's time to use some of VRED's API to talk to VRED. If you don't know where it is please go through my intro to python lesson. Now lets make something change in VRED with this Terminal. Write the following 

 selectVariantSet('Paint')

What we did here is we called a function called selectVariantSet. This function lets us activate a Variant inside of VRED. If we wanted to activate the variant set called Light, what would it look like? 

 

Copy and Paste

Experience it First than we learn

Copy the code below into our terminal and press enter. Then turn on your VIVE and run the file in VR. We are only using one controller so just turn one on. When you are moving around the trigger should make the sphere change color and the trackpad button will turn on the headlight. I break down the code and get into detail on how to write it yourself in the following pages. 


Main_Hand = findNode('Main_Hand')

def AttachLight():
    Main_Hand.setTransformMatrix(Maincontroller.getWorldMatrix(), false)

def PowerLight():
    selectVariantSet('Light')

def ChangeColor():
    selectVariantSet('Paint')
    print "Color Changed"


Maincontroller = vrOpenVRController("Controller0")
Maincontroller.connectSignal("controllerMoved", AttachLight)
Maincontroller.connectSignal("triggerPressed", ChangeColor)
Maincontroller.connectSignal("touchpadPressed", PowerLight)

print "VR Loaded"