PDA

View Full Version : Is that possible to add some actions to the "grabbed object"


haohaoxuexi1
01-05-2016, 02:57 PM
Is that possible to add some actions to the "grabbed object"

the object is grabbed on the mouse or other equipment and I want to add some action to the grabbed object such as spinTo, sizeTo, but different signal input trigger different actions

it is not the "grabber.GRAB_EVENT", this event can only trigger one movement after it is grabbed.

I want to trigger different movement.

Thanks

Jeff
01-05-2016, 11:53 PM
You could set a flag when the object is grabbed. When the input signal is sent, check to see if the object is grabbed before applying the action:

import viz
import vizconnect
import vizshape
import vizact

vizconnect.go('vizconnect_config.py')

dojo = viz.addChild('dojo.osgb')

torus = vizshape.addTorus(radius=0.1,tubeRadius=0.015,axis =vizshape.AXIS_X, pos=[0,1.7,1])
torus.texture(viz.addTexture('images/tile_wood.jpg'))
torus.addAction(vizact.spin(0,1,0,15))
torus.grabbed = False

grabber = vizconnect.getRawTool('grabber')
grabber.setItems([torus])

def onGrab(e):
if e.grabbed == torus:
torus.grabbed = True

def onRelease(e):
if e.released == torus:
torus.grabbed = False

from tools import grabber
viz.callback(grabber.GRAB_EVENT, onGrab)
viz.callback(grabber.RELEASE_EVENT, onRelease)

scaleAction = vizact.sequence([vizact.sizeTo(size=[1.3,1.3,1.3],time=1),vizact.sizeTo(size=[1,1,1],time=1)], viz.FOREVER)

def applyScale():
if torus.grabbed:
torus.runAction(scaleAction,pool=1)

def removeScale():
if torus.grabbed:
torus.clearActions(pool=1)

vizact.onkeydown('1',applyScale)
vizact.onkeydown('2',removeScale)

haohaoxuexi1
01-06-2016, 11:04 AM
You could set a flag when the object is grabbed. When the input signal is sent, check to see if the object is grabbed before applying the action:

import viz
import vizconnect
import vizshape
import vizact

vizconnect.go('vizconnect_config.py')

dojo = viz.addChild('dojo.osgb')

torus = vizshape.addTorus(radius=0.1,tubeRadius=0.015,axis =vizshape.AXIS_X, pos=[0,1.7,1])
torus.texture(viz.addTexture('images/tile_wood.jpg'))
torus.addAction(vizact.spin(0,1,0,15))
torus.grabbed = False

grabber = vizconnect.getRawTool('grabber')
grabber.setItems([torus])

def onGrab(e):
if e.grabbed == torus:
torus.grabbed = True

def onRelease(e):
if e.released == torus:
torus.grabbed = False

from tools import grabber
viz.callback(grabber.GRAB_EVENT, onGrab)
viz.callback(grabber.RELEASE_EVENT, onRelease)

scaleAction = vizact.sequence([vizact.sizeTo(size=[1.3,1.3,1.3],time=1),vizact.sizeTo(size=[1,1,1],time=1)], viz.FOREVER)

def applyScale():
if torus.grabbed:
torus.runAction(scaleAction,pool=1)

def removeScale():
if torus.grabbed:
torus.clearActions(pool=1)

vizact.onkeydown('1',applyScale)
vizact.onkeydown('2',removeScale)


is that possible to do these in VizChild object like osgb file

haohaoxuexi1
01-06-2016, 12:07 PM
You could set a flag when the object is grabbed. When the input signal is sent, check to see if the object is grabbed before applying the action:

import viz
import vizconnect
import vizshape
import vizact

vizconnect.go('vizconnect_config.py')

dojo = viz.addChild('dojo.osgb')

torus = vizshape.addTorus(radius=0.1,tubeRadius=0.015,axis =vizshape.AXIS_X, pos=[0,1.7,1])
torus.texture(viz.addTexture('images/tile_wood.jpg'))
torus.addAction(vizact.spin(0,1,0,15))
torus.grabbed = False

grabber = vizconnect.getRawTool('grabber')
grabber.setItems([torus])

def onGrab(e):
if e.grabbed == torus:
torus.grabbed = True

def onRelease(e):
if e.released == torus:
torus.grabbed = False

from tools import grabber
viz.callback(grabber.GRAB_EVENT, onGrab)
viz.callback(grabber.RELEASE_EVENT, onRelease)

scaleAction = vizact.sequence([vizact.sizeTo(size=[1.3,1.3,1.3],time=1),vizact.sizeTo(size=[1,1,1],time=1)], viz.FOREVER)

def applyScale():
if torus.grabbed:
torus.runAction(scaleAction,pool=1)

def removeScale():
if torus.grabbed:
torus.clearActions(pool=1)

vizact.onkeydown('1',applyScale)
vizact.onkeydown('2',removeScale)

and also why it shows "VizPrimitive" object has no attribute "grabbed"

Jeff
01-07-2016, 05:00 AM
Yes, you can also define an attribute such as

torus.grabbed = False

for a node3D object created from an osgb file.

I'm not getting the same error. What version of Vizard are you running?

haohaoxuexi1
01-07-2016, 08:01 AM
Yes, you can also define an attribute such as

torus.grabbed = False

for a node3D object created from an osgb file.

I'm not getting the same error. What version of Vizard are you running?

I fixed the problem

I forgot to add the code "viz.callback(grab.GRAB_EVENT,onGrab)"