Samuli
09-24-2015, 01:08 AM
Hi,
I'm trying to convert WorldViz Highlighter tool example code (http://docs.worldviz.com/vizard/Tools_Highlighter.htm) into a script that uses wand as input (rather than mouse scrollwheel) and changes texture of an object. Here's the code:
import viz
import vizfx
import vizconnect
import vizact
import vizshape
viz.antialias = 4
viz.fullscreen = 1
viz.clearcolor = (0.5, 0.5, 0.5 )
if __name__ == "__main__":
vizconnect.go('./vizconnect_config.py')
viz.MainView.getHeadLight().disable()
else:
vizconnect.go('./multiscript_vizconnect_config.py')
#Add wand
wand= vizconnect.getTracker('r_hand_tracker').getNode3d( )
wandInput=vizconnect.getInput('r_hand_tracker')
#Add a sky with an environment map
env = viz.add(viz.ENVIRONMENT_MAP, 'sky.jpg')
dome = viz.add('skydome.dlc')
dome.texture(env)
#Add showroom osgb file
showroom=viz.add('Showroom1.osgb')
for window in viz.getWindowList():
window.getView().getHeadLight().disable()
#Add video texture
video=viz.addVideo('VisualisationDemoVideo_v2.mov' )
video.play()
video.loop()
videowall=showroom.getChild('projection.002')
videowall.texture(video)
#Get a handle to a texture
texture1=viz.addTexture('VisualisationPic.png')
#Get and set highlighter tool
from tools import highlighter
tool=highlighter.Highlighter(highlightOnCollision= False,highlightMode=highlighter.MODE_OUTLINE)
tool.setItems([videowall])
viewGroup=viz.addGroup()
viewGroupLink=viz.link(viz.MainView,viewGroup)
viewGroupLink.preTrans([0, 0, 1])
arrow = vizshape.addArrow(length=0.2, color = viz.ORANGE,parent=viewGroup)
arrowLink = viz.link(wand,arrow,mask=viz.LINK_ORI)
arrowLink.postMultLinkable(viz.MainView)
viz.link(arrowLink,tool)
def updateHighlighter(tool):
tool.highlight()
tool.setUpdateFunction(updateHighlighter)
def onHighlight(e):
if e.new == videowall:
print 'videowall is highlighted'
tex1=videowall.getTexture()
if tex1==video:
print 'change'
videowall.texture(texture1)
else:
videowall.texture(video)
viz.callback(highlighter.HIGHLIGHT_EVENT,onHighlig ht)
showroom.disable(viz.LIGHTING)
headlight=viz.MainView.getHeadLight()
headlight.disable()
viz.MainView.setPosition(-5,2,-5)
We use wand 2014 local with PPT tracking.
The above mentioned code works, but not the way I want it to work. The beam of the highlighter tool starts from a fixed point and it doesn't follow the main view. How could the beam start point be main view and how would the target follow the wand?
I'm trying to convert WorldViz Highlighter tool example code (http://docs.worldviz.com/vizard/Tools_Highlighter.htm) into a script that uses wand as input (rather than mouse scrollwheel) and changes texture of an object. Here's the code:
import viz
import vizfx
import vizconnect
import vizact
import vizshape
viz.antialias = 4
viz.fullscreen = 1
viz.clearcolor = (0.5, 0.5, 0.5 )
if __name__ == "__main__":
vizconnect.go('./vizconnect_config.py')
viz.MainView.getHeadLight().disable()
else:
vizconnect.go('./multiscript_vizconnect_config.py')
#Add wand
wand= vizconnect.getTracker('r_hand_tracker').getNode3d( )
wandInput=vizconnect.getInput('r_hand_tracker')
#Add a sky with an environment map
env = viz.add(viz.ENVIRONMENT_MAP, 'sky.jpg')
dome = viz.add('skydome.dlc')
dome.texture(env)
#Add showroom osgb file
showroom=viz.add('Showroom1.osgb')
for window in viz.getWindowList():
window.getView().getHeadLight().disable()
#Add video texture
video=viz.addVideo('VisualisationDemoVideo_v2.mov' )
video.play()
video.loop()
videowall=showroom.getChild('projection.002')
videowall.texture(video)
#Get a handle to a texture
texture1=viz.addTexture('VisualisationPic.png')
#Get and set highlighter tool
from tools import highlighter
tool=highlighter.Highlighter(highlightOnCollision= False,highlightMode=highlighter.MODE_OUTLINE)
tool.setItems([videowall])
viewGroup=viz.addGroup()
viewGroupLink=viz.link(viz.MainView,viewGroup)
viewGroupLink.preTrans([0, 0, 1])
arrow = vizshape.addArrow(length=0.2, color = viz.ORANGE,parent=viewGroup)
arrowLink = viz.link(wand,arrow,mask=viz.LINK_ORI)
arrowLink.postMultLinkable(viz.MainView)
viz.link(arrowLink,tool)
def updateHighlighter(tool):
tool.highlight()
tool.setUpdateFunction(updateHighlighter)
def onHighlight(e):
if e.new == videowall:
print 'videowall is highlighted'
tex1=videowall.getTexture()
if tex1==video:
print 'change'
videowall.texture(texture1)
else:
videowall.texture(video)
viz.callback(highlighter.HIGHLIGHT_EVENT,onHighlig ht)
showroom.disable(viz.LIGHTING)
headlight=viz.MainView.getHeadLight()
headlight.disable()
viz.MainView.setPosition(-5,2,-5)
We use wand 2014 local with PPT tracking.
The above mentioned code works, but not the way I want it to work. The beam of the highlighter tool starts from a fixed point and it doesn't follow the main view. How could the beam start point be main view and how would the target follow the wand?