WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-05-2016, 02:57 PM
haohaoxuexi1 haohaoxuexi1 is offline
Member
 
Join Date: Sep 2015
Posts: 81
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
Reply With Quote
  #2  
Old 01-05-2016, 11:53 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,465
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)
Reply With Quote
  #3  
Old 01-06-2016, 11:04 AM
haohaoxuexi1 haohaoxuexi1 is offline
Member
 
Join Date: Sep 2015
Posts: 81
Quote:
Originally Posted by Jeff View Post
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
Reply With Quote
  #4  
Old 01-06-2016, 12:07 PM
haohaoxuexi1 haohaoxuexi1 is offline
Member
 
Join Date: Sep 2015
Posts: 81
Quote:
Originally Posted by Jeff View Post
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"
Reply With Quote
  #5  
Old 01-07-2016, 05:00 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,465
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?
Reply With Quote
  #6  
Old 01-07-2016, 08:01 AM
haohaoxuexi1 haohaoxuexi1 is offline
Member
 
Join Date: Sep 2015
Posts: 81
Quote:
Originally Posted by Jeff View Post
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)"
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simultaneous Actions on Multiple Objects javadi Vizard 2 07-19-2013 03:54 PM
adding actions in front of actionlist IGoudt Vizard 1 01-25-2010 10:55 AM
Trouble with adding actions vijaykiran Vizard 0 10-05-2009 03:18 PM
Speech during actions zoltantoth Vizard 2 05-02-2007 03:11 PM
Weird lagging/choppiness when avatars perform actions vjonshih Vizard 8 11-30-2004 04:08 PM


All times are GMT -7. The time now is 03:26 PM.


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