Community
VRED Forum
Welcome to Autodesk’s VRED Forums. Share your knowledge, ask questions, and explore popular VRED topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VRED Collision for VR (HTC Vive)

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Anonymous
2496 Views, 8 Replies

VRED Collision for VR (HTC Vive)

Hi there

 

Another question about Virtual Reality!

 

I'm wanting to program in some Collision to activate, say, a colour switch when you touch a cube with your controller.

 

So far I've parented a sphere to my motion controller and tried using the python code to reference that and the VSets I have set up to activate the switch.

 

So, my sphere is the 'PickerL'
The 'Blue_Box' etc are my geometry

and the 'Blue' etc are the VSets.

 

 

## Collision Activation

Picker = findNode("PickerL")
Blue_Box = findNode("Blue_Box")
Green_Box = findNode("Green_Box")
Red_Box = findNode("Red_Box")

def Boxes():
	global CollisionBlue_Box
	global CollisionGreen_Box
	global CollisionRed_Box

	CollisionBlue_Box = vrCollision([Picker], [Blue_Box])
	CollisionBlue_Box.connect(Blue_Switch)
	CollisionGreen_Box = vrCollision([Picker], [Green_Box])
	CollisionGreen_Box.connect(Green_Switch)
	CollisionRed_Box = vrCollision([Picker], [Red_Box])
	CollisionRed_Box.connect(Red_Switch)
    

def Blue_Switch():
    selectVariantSet("Blue")

def Green_Switch():
    selectVariantSet("Green")

def Red_Switch():
    selectVariantSet("Red")


Boxes()

Attached is a screen grab of my project!

 

Any help on this would be great!

 

Thanks

8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

I solved it in the end! So much simpler than I thought!

 

## Collision Activation

PickerR = findNode ("PickerR")
PickerL =findNode ("PickerL")
Red_Box = findNode ("Red_Box")

coll = vrCollision([PickerR, PickerL], [Red_Box])
coll.connect(Red_Switch)
controller1.triggerHapticPulse(0,1000)

def Red_Switch():
    selectVariantSet("Red")
Message 3 of 9
Anonymous
in reply to: Anonymous

Hi,

 

Your code was  useful . I just tried with your method but its showing  not defined (error).

Message 4 of 9
Anonymous
in reply to: Anonymous

Hello!

Yes, I had this same issue and it still occurs, the way I worked around it was by typing in quotation marks in the following section like so:

coll.connect(“Red_Switch”)

I then run the script and take out the quotation marks and run it again - and it works, there’s obviously something I’ve missed but that’s got it working for me.

Also, the triggerHapticPulse command should go under where you define the switch instead!

def Red-Switch():

I hope this helps
Harry
Message 5 of 9
Anonymous
in reply to: Anonymous

#PickerR = findNode("PickerR")
PickerL = findNode("PickerL")
plane = findNode("Planegreen")
plane = findNode("Planeblue")

def Boxes():
global CollisionPlanegreen
global CollisionPlaneblue

CollisionPlanegreen = vrCollision([PickerL],[Planegreen])
CollisionPlanegreen.connect(box_blue)
CollisionPlaneblue = vrCollision([PickerL],[Planeblue])
CollisionPlaneblue.connect(box_green)
controller0.triggerHapticPulse(0,1000)

def box_blue():
selectVaraintSet("box_blue")
def box_green():
selectVaraintSet("box_green")

def trigger0Pressed():
controller0.setPickingAxis(0)
controller0.showPickingAxis(true)

def trigger0Released():
pickedNode = controller0.pickNode()
selectNode(pickedNode)
controller0.showPickingAxis(false)
def controller0Moved():
if controller0.isTouchpadPressed():
leftNode = findNode("MatrixLeft")
leftNode.setTransformMatrix( controller0.getWorldMatrix(), false)

#controller main function

controller0 = vrOpenVRController("Controller0")
controller0.connectSignal("controllerMoved", controller0Moved)
controller0.connectSignal("triggerPressed", trigger0Pressed)
controller0.connectSignal("triggerReleased", trigger0Released)
#controller0.connectSignal("touchpadPressed", touchpad0Pressed)
#controller0.connectSignal("touchpadReleased", touchpad0Released
#controller0.connectSignal("gripPressed", grip0Pressed)


#controller1 = vrOpenVRController("Controller1")
#controller1.connectSignal("controllerMoved", controller1Moved)
#controller1.connectSignal("triggerPressed", trigger1Pressed)
#controller1.connectSignal("triggerReleased", trigger1Released)
#controller1.connectSignal("touchpadPressed", touchpad1Pressed)
#controller1.connectSignal("touchpadReleased", touchpad1Released
#controller1.connectSignal("gripPressed", grip1Pressed)
This was my code . But I got error controller 1 not defined and I dont know
where to correct myself.

Message 6 of 9
Anonymous
in reply to: Anonymous

Hello

 

Looking at your code, you should remove the hashtag '#' at the start of your controller0 and controller1 signals, as well as your PickerR Variable.

 

Python doesn't read anything after a hashtag '#' as useable code, anything after that are deemed comments for reference purposes only. 

 

Try removing those, and see if that works! (See example below)

 

#controller main function

controller0 = vrOpenVRController("Controller0")
controller0.connectSignal("controllerMoved", controller0Moved)
controller0.connectSignal("triggerPressed", trigger0Pressed)
controller0.connectSignal("triggerReleased", trigger0Released)
controller0.connectSignal("touchpadPressed", touchpad0Pressed)
controller0.connectSignal("touchpadReleased", touchpad0Released
controller0.connectSignal("gripPressed", grip0Pressed)


controller1 = vrOpenVRController("Controller1")
controller1.connectSignal("controllerMoved", controller1Moved)
controller1.connectSignal("triggerPressed", trigger1Pressed)
controller1.connectSignal("triggerReleased", trigger1Released)
controller1.connectSignal("touchpadPressed", touchpad1Pressed)
controller1.connectSignal("touchpadReleased", touchpad1Released
controller1.connectSignal("gripPressed", grip1Pressed)

 

Thanks

Harry

Message 7 of 9
Anonymous
in reply to: Anonymous

  I couldnt understand the meaning of these lines .

 

 

moveScaleSideways = -2.0 * touchPos.x() *touchPos.x() *touchPos.x()
moveScaleForward = -0.05 * touchPos.y() * touchPos.y() * touchPos.y() *touchPos.y()*touchPos.y()

 

clipPos = Pnt3f( cMatrix[3], cMatrix[7], cMatrix[11])
clipNor = Vec3f( cMatrix[2], cMatrix[6], cMatrix[10])

 

I have attached file , where I took these lines from those script .

 

 

Message 8 of 9
lbs_markus_s
in reply to: Anonymous

Hi

 

the script is always executed from top to bottom

 

so you first have to define Red_Switch

 

 

def Red_Switch():
    selectVariantSet("Red")

 

and use the name afterwards in the script

 

coll.connect(Red_Switch)
controller1.triggerHapticPulse(0,1000)

 

 

right now it executes the variant set as long it detects a collision. So if you have a Color Switch material which is Looping it is changing the colors very fast and you cant really see it. It's just flickering . Is there a way of Scripting a time Frame for the collision duration until it switches to the next Color

 

regards

Markus

Message 9 of 9
Anonymous
in reply to: lbs_markus_s

Hello, 

Is possible to deactivate the Collision with the controllers????

I only want to change the object when I press the trigger, but when I am close, the object change.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report