|
#1
|
|||
|
|||
add text to sphere
hi,
I am very new to Vizard. I am facing difficulties with adding a 2D text to a sphere. I want the text to appear on the top of the sphere when the user enters 't' ,for example, from the keyboard. I have tried many tutorials but I did not know how to do it. your help is appreciated. |
#2
|
|||
|
|||
You can set the sphere to be the parent of the text:
Code:
import viz import vizshape import vizact viz.go() sphere = vizshape.addSphere(radius=0.2) text = viz.addText('Sphere',parent=sphere) text.setPosition([-0.3,0.3,0]) text.setScale([0.2]*3) text.visible(viz.OFF) vizact.onkeydown('t',text.visible,viz.TOGGLE) import vizcam cam = vizcam.PivotNavigate(distance=3) cam.centerNode(text) |
#3
|
|||
|
|||
thanks a lot it worked.
I have another question, how can I calculate the distance between 2 objects? for example, lets say that the position of the sphere is (0,0,20) and when the avatar reaches a distance 1 meter far from the sphere, I want the text to appear. |
#4
|
|||
|
|||
Hi Maya,
Sounds like you can use a proximity sensor. If you set your sphere as the source of the sensor in the example below, you can do something when someone enters the area (or leaves the area). See http://docs.worldviz.com/vizard/vizproximity.htm for more info. Code:
import viz import vizproximity viz.go() male = viz.addAvatar('vcc_male2.cfg', pos = [0,.15,.5], euler = [180,0,0]) #Create proximity manager manager = vizproximity.Manager() #Create target and add to manager target = vizproximity.Target(viz.MainView) manager.addTarget(target) #Create sensor and add to manager sensor = vizproximity.Sensor( vizproximity.CircleArea(1),source=male) manager.addSensor(sensor) def EnterProximity(e): """@args vizproximity.ProximityEvent()""" print 'entered',e.sensor def ExitProximity(e): """@args vizproximity.ProximityEvent()""" print 'exited',e.sensor manager.onEnter(None,EnterProximity) manager.onExit(None,ExitProximity) |
#5
|
|||
|
|||
hi,
thanks for ur replay. I get an error when I ran the example. this is the error: HTML Code:
sensor = vizproximity.Sensor( vizproximity.CircleArea(1),source=male) AttributeError: 'module' object has no attribute 'CircleArea' |
#6
|
|||
|
|||
Make sure you have the latest version of Vizard. Go to Help > Check for Updates.
|
#7
|
|||
|
|||
I installed the latest version and the code worked. thanx a lot.
I added this code in a multi user environment with 1 server and 2 clients. I added the code in client 1 specifically, but once I run the client, the message appears immediately even though the avatar is very far from the target (radiation source). could you help me with this issue plz? this is my code for client: Code:
import viz import viznet import vizinfo import vizinput import viztask import vizact import vizshape import vizproximity viz.go() viz.MainView.setPosition([0,0.1,0]) #viz.MainView.lookAt([50,25,-40]) #Enable full screen anti-aliasing (FSAA) to smooth edges viz.setMultiSample(4) #Increase the Field of View viz.MainWindow.fov(60) piazza = viz.add('piazza.osgb') #maze = viz.add('tankmaze.wrl') sphere = vizshape.addSphere(radius=0.2) sphere.setPosition(0,0,20) sphere.color(viz.RED) text = viz.addText('radiation source',parent=sphere) text.setPosition([-0.3,0.3,0]) text.setScale([0.2]*3) text.color(viz.RED) text.visible(viz.ON) text_2D = viz.addText('radiation source area', viz.SCREEN ) text_2D.setPosition(0,0,20) text_2D.color(viz.RED) objects = {} # UPDATE = viznet.id('update') CLIENT_DISCONNECTED = viznet.id('client_disconnected') CHAT = viznet.id('chat') # SERVER_NAME=vizinput.input('Enter Server Name') while not viznet.client.connect(SERVER_NAME,port_in=14951,port_out=14950): if vizinput.ask('Could not connect to ' + SERVER_NAME + ' would you like to try another?'): SERVER_NAME=vizinput.input('Enter Server Name') else: viz.quit() break # objectList = ['duck.wrl','logo.wrl','vcc_male.cfg','vcc_female.cfg'] obj_choice=vizinput.choose('Connected. Select your character',objectList) # #Create proximity manager manager = vizproximity.Manager() #manager.setDebug(viz.ON) #Add main viewpoint as proximity target target = vizproximity.Target(viz.MainView) manager.addTarget(target) #Create sensor using male avatar #avatar = viz.addAvatar('vcc_male2.cfg',pos=[0,0,4],euler=[180,0,0]) #avatar.state(1) #sensor = vizproximity.Sphere(0.2, centre=(0,0,0)) sensor = vizproximity.Sensor( vizproximity.CircleArea(0.1),source=sphere) manager.addSensor(sensor) #Change state of avatar to talking when the user gets near def EnterProximity(e): text_2D.visible(viz.ON) #text.visible(viz.ON) #Change state of avatar to idle when the user moves away def ExitProximity(e): #text.visible(viz.OFF) text_2D.visible(viz.OFF) manager.onEnter(sensor,EnterProximity) manager.onExit(sensor,ExitProximity) #vizact.onkeydown('d',manager.setDebug,viz.TOGGLE) # def sendUpdate(): ori= viz.MainView.getEuler() pos = viz.MainView.getPosition() viznet.client.sendAll(UPDATE,client=viz.getComputerName(),object=obj_choice,pos=pos,ori=ori) vizact.ontimer(.05,sendUpdate) # def update(e): if e.client != viz.getComputerName(): try: objects[e.client].setPosition(e.pos) objects[e.client].setEuler(e.ori) except KeyError: objects[e.client] = viz.add(objectList[e.object],scale=[2,2,2],pos=e.pos,euler=e.ori) objects[e.client].tooltip = e.client viz.callback(UPDATE,update) # def client_disconnected(e): objects[e.client].remove() del objects[e.client] viz.callback(CLIENT_DISCONNECTED,client_disconnected) def onStopServer(e): print 'Disconnected from server' viz.quit() viz.callback(viznet.SERVER_DISCONNECT_EVENT,onStopServer) # import viztip tth = viztip.ToolTip() tth.start() tth.setDelay(0) # def updateChat(msg): text.message('\n'.join(text.getMessage().split('\n')[1:])+'\n'+msg) text = viz.addText('\n\n\n\n',viz.SCREEN) text.alignment(viz.TEXT_LEFT_BOTTOM) text.fontSize(25) text.setPosition(.05,.08) input = viz.addText('> _',viz.SCREEN) input.fontSize(25) input.setPosition(.032,.05) input.visible(0) def onChat(e): updateChat(e.client+': '+e.chat) viz.callback(CHAT,onChat) talking = False def onKeyDown(key): global talking if key == 'y' and not talking: talking = True input.message('> _') input.visible(1) elif key == viz.KEY_ESCAPE and talking: talking = False input.visible(0) return True elif talking and key == viz.KEY_RETURN: talking = False viznet.client.sendAll(CHAT,client=viz.getComputerName(),chat=input.getMessage()[2:-1]) input.visible(0) elif talking and key == viz.KEY_BACKSPACE: if len(input.getMessage()) > 3: input.message(input.getMessage()[:-2]+'_') elif len(key) > 1: return False elif talking and 32 <= ord(key) <= 126: input.message(input.getMessage()[:-1]+key+'_') viz.callback(viz.KEYDOWN_EVENT,onKeyDown,priority=-6) thanx in advance. |
#8
|
|||
|
|||
Hi Maya,
You forgot to make text_2D invisible in the beginning. Code:
text_2D = viz.addText('radiation source area', viz.SCREEN ) text_2D.setPosition(0,0,20) text_2D.color(viz.RED) text_2D.visible(viz.OFF) |
#9
|
|||
|
|||
hi Frank,
thanx for ur replay. I made the text invisible. but now, the text does not appear at all. am I doing something wrong? one more thing. in my case I have 1 server and 2 clients, I want the text to appear when either one of the clients (or both) reaches the radiation source. where do u recommend me to add the code for the proximity? (in client1 and client2 or in server side)? |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
input from a text file | dig | Vizard | 5 | 10-20-2013 01:20 AM |
Lighting relevant text? | knightgba | Vizard | 1 | 01-26-2011 05:33 PM |
Informationboxes with text | snoopy78 | Vizard | 3 | 07-16-2009 10:23 AM |
Vizard tech tip: Text to Speech | Jeff | Vizard | 1 | 01-15-2009 09:39 PM |
3d Text with Transparent Borders | vjosh | Vizard | 3 | 12-01-2004 10:50 AM |