WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Is that possible to add some actions to the "grabbed object" (https://forum.worldviz.com/showthread.php?t=5592)

haohaoxuexi1 01-05-2016 02:57 PM

Is that possible to add some actions to the "grabbed object"
 
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:

Code:

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

Quote:

Originally Posted by Jeff (Post 17845)
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:

Code:

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

Quote:

Originally Posted by Jeff (Post 17845)
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:

Code:

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

Code:

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

Quote:

Originally Posted by Jeff (Post 17849)
Yes, you can also define an attribute such as

Code:

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)"


All times are GMT -7. The time now is 04:29 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC