WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 11-08-2013, 08:27 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
Smile 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.
Reply With Quote
  #2  
Old 11-14-2013, 06:55 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,461
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)
Reply With Quote
  #3  
Old 11-17-2013, 02:20 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
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.
Reply With Quote
  #4  
Old 11-18-2013, 02:56 PM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
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)
Reply With Quote
  #5  
Old 11-19-2013, 03:35 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
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'
Reply With Quote
  #6  
Old 11-19-2013, 11:54 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,461
Make sure you have the latest version of Vizard. Go to Help > Check for Updates.
Reply With Quote
  #7  
Old 11-26-2013, 05:01 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
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.
Reply With Quote
  #8  
Old 11-26-2013, 07:01 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
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)
Furthermore: note that your indentation of your EnterProximity and ExitProximity functions is not a tab, but two spaces. Python does not mind it that much, but it would be more consistent to use one tab as indentation level throughout your code.
Reply With Quote
  #9  
Old 11-27-2013, 11:31 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
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)?
Reply With Quote
  #10  
Old 11-27-2013, 12:13 PM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
I have tested it with the code below. With that code, the text appears when you enter the small red sphere.
Code:
import viz
import vizshape
import vizproximity

viz.go()
viz.MainView.setPosition([0,0.1,0])
#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')

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)
text_2D.visible(viz.OFF)

#Create proximity manager
manager = vizproximity.Manager()

#Add main viewpoint as proximity target
target = vizproximity.Target(viz.MainView)
manager.addTarget(target)
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)
  print 'enter'

#Change state of avatar to idle when the user moves away
def ExitProximity(e):
  text_2D.visible(viz.OFF)
  print 'exit'

manager.onEnter(sensor,EnterProximity)
manager.onExit(sensor,ExitProximity)
Seems like your setup is a little more complicated than what I'm used to. So are we talking about three different computers connected with each other and communicating via a network? With 1 computer being the server, and 2 computers being the client?

Either way, the code for making the text appear should be on every party that needs to see the text. For instance, if the text has to appear on both clients, then both clients need the code for making the text visible and invisible. It seems like the condition to show the text on any machine is that one of the two clients enter the radiation zone. So in that case, you should at least communicate the state of each client to each other, and make the text appear when either one of them enters the radiation zone.

You could also let each client communicate to the server whether they are in the radiation zone or not, and if one of the clients enters the radiation zone, you could let the server send a message to both clients.

In both cases, you need a proximity sensor in client1 and client2, and somehow communicate the states of those clients to each other (either directly, or through the server).

Please elaborate more on your specific problem if these suggestions do not point you in the desired direction.
Reply With Quote
  #11  
Old 11-27-2013, 01:25 PM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
uh ok it's working. but, I wanted the text to appear when the avatar is for example 1 meter far from the radiation source. this is supposed to be a dangerous area and the message is there to warn the avatar that this is an affected area with radiation. so, he is not supposed to get close from it.

I am using only 1 PC, it is the server and the 2 clients at the same time.
there is a communication between server and clients:
1. server can communicate with client 1
2.server can communicate with client 2, but client 2 can't read its messages
3. client1 can communicate with client 2, but client 2 does not c the messages
4. client 1 communicate with 2, but again client2 can't c the messages

client 2 can't c messages sent by server and client 1.

mmm.. I think I will just add the text code in both clients and i want them to communicate with each other.

thanx
Reply With Quote
  #12  
Old 11-28-2013, 03:55 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Quote:
Originally Posted by maya View Post
uh ok it's working. but, I wanted the text to appear when the avatar is for example 1 meter far from the radiation source. this is supposed to be a dangerous area and the message is there to warn the avatar that this is an affected area with radiation. so, he is not supposed to get close from it
Simply change
Code:
sensor = vizproximity.Sensor( vizproximity.CircleArea(0.1),source=sphere)
to:
Code:
sensor = vizproximity.Sensor( vizproximity.CircleArea(1),source=sphere)
Now, the warning should appear whenever you approach the center of the sphere within 1 meter. If you want the warning area to be 1 meter surrounding the outside of the sphere, simply add the radius of the sphere to the number you pass to vizproximity.CircleArea().
Reply With Quote
  #13  
Old 11-28-2013, 04:15 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
Smile

Thanx a lot. It worked.
Reply With Quote
  #14  
Old 12-01-2013, 11:25 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
hi Frank,

I have one more question related to the proximity sensor.

I want the 2 clients (avatars) to see each other in the multi user environment.
also, I want to calculate the distance between the 2 clients and make them do some thing when they are 5 meters far from each other.

thanx.
I appreciate ur help.
Reply With Quote
  #15  
Old 12-02-2013, 08:57 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
I think you can just apply a vizproximity sensor with a circlearea of 5 (meters) to one (moving) avatar, and add a vizproximity target to the other (moving) avatar. When the avatars are within 5 meters from each other, the sensor (avatar1) should sense the target (avatar), and then you can respond to that event.

See the example below
Code:
import viz
import vizact
import vizshape
import vizproximity

viz.go()

sphere = vizshape.addSphere(radius=1)
sphere.setPosition(0,0,20)
sphere.color(viz.GREEN)

box = viz.add('box.wrl')
box.color(viz.ORANGE)

def moveObjects():
  boxPos = box.getPosition()
  boxPos[2] += .1
  box.setPosition(boxPos)
  spherePos = sphere.getPosition()
  spherePos[2] += .01
  sphere.setPosition(spherePos)

vizact.ontimer(.1, moveObjects)

manager = vizproximity.Manager()

target = vizproximity.Target(sphere)
manager.addTarget(target)
sensor = vizproximity.Sensor( vizproximity.CircleArea(5),source=box)
manager.addSensor(sensor)

def EnterProximity(e):
  print 'enter'

def ExitProximity(e):
  print 'exit'

manager.onEnter(sensor,EnterProximity)
manager.onExit(sensor,ExitProximity)
Reply With Quote
  #16  
Old 12-02-2013, 12:51 PM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
thanx for ur replay.

I have tried the example. but, the problem is that client1 can't see client2 in its environment. I only can see the 2 clients in the server environment.

is there a way that I can make client2 appears in client1's environment?

I hope that my question is clear.

thanx.
Reply With Quote
  #17  
Old 12-02-2013, 03:47 PM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
If I understand correctly, avatar2 is not updated in client1, and avatar1 is not updated in client2?

If avatar1 is controlled by client1 and avatar2 is controlled by client2, then you should pass information about the position of avatar1 to client2, and of avatar2 to client1.

I don't understand the part of client2 not visible in client1's environment. At every client side, you should render 2 avatars (avatar1 & avatar2), and also get the information to make them move. Apparently, both avatars are rendered on the server side. So you should use similar code on both clients to make both avatars visible for both clients.

I cannot help you further without more information, e.g. sample code showing the example without the need for extra files/models/setups.
Reply With Quote
  #18  
Old 12-03-2013, 01:32 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
basically, what I have is a multi user environment that consists of 1 server and 2 clients. what I mean by a client is the avatar. and I am using 1 pc as the server and the client.
client 1 will do a specific task (search for radiation source) where as client2 will identify the radiation source.
both clients can exchange messages between them and with the server.

I, as client1, while performing my task and navigating through the environment, I want to c client 2 (avatar2).

this is the code:
just run the server and then the 2 clients. try to control the movement of avatar1 and c if u can find avatar2 while navigating.

######server code#############
Code:
import viz
import viznet
import viztask
import vizmat
import vizact
import vizshape
import vizinfo
#add the required imports, start the Vizard engine, set the background, and position the display so that the full map will be visible 
viz.go()
#viz.MainView.setPosition([50,25,-40])
#viz.MainView.lookAt([0,0,0])
#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')

#create a list of objects which must be identical to the list of objects on the client.These are the allowable character displays for each client. We then add the map, and finally an empty dictionary to store client information in.
objectList = ['duck.wrl','logo.wrl','vcc_male.cfg','vcc_female.cfg'] 
#maze = viz.add('tankmaze.wrl') 
objects = {}

#events which will be used in the interaction between the client and the server.must be defined in the same way on each client.
UPDATE = viznet.id('update') 
CLIENT_DISCONNECTED = viznet.id('client_disconnected') 
CHAT = viznet.id('chat') 

#start the server and handle client joining and client leaving events. The onStopClient function preforms some cleanup actions as described in the comments
viznet.server.start(port_in=14950,port_out=14951) 

def onStartClient(e): 
    print '** Client joined:',e.sender 
viz.callback(viznet.CLIENT_CONNECT_EVENT,onStartClient) 

def onStopClient(e): 
    print '** Client left:',e.sender 
    viznet.server.send(CLIENT_DISCONNECTED,client=e.sender) # Alert other clients 
    objects[e.sender].remove() # Remove object from our map 
    del objects[e.sender] # Delete user from array 
viz.callback(viznet.CLIENT_DISCONNECT_EVENT,onStopClient) 

#The update function essentially updates a client's position, 
#however if this is the first time the client's position is updated, it also adds the client to the map. 
#Adding the user this way makes it so we don't have to have another event to handle when the client has picked a character. 
#Further more this way we don't have to send a list of already connected clients to all new clients.
def update(e): 
    try: 
        objects[e.sender].setPosition(e.pos) 
        objects[e.sender].setEuler(e.ori) 
    except KeyError: # If key doesn't exist add the user's object 
        objects[e.sender] = viz.add(objectList[e.object],scale=[2,2,2],pos=e.pos,euler=e.ori) 
        objects[e.sender].tooltip = e.sender # Sets the tool tip for this object 
viz.callback(UPDATE,update) 

# Tool Tip 
import viztip 
tth = viztip.ToolTip() 
tth.start() 
tth.setDelay(0)

# Chat Stuff 
def updateChat(msg): # Function to update the chat display 
    text.message('\n'.join(text.getMessage().split('\n')[1:])+'\n'+msg) 
text = viz.addText('\n\n\n\n',viz.SCREEN) # Add to screen 
text.alignment(viz.TEXT_LEFT_BOTTOM) 
text.fontSize(25) 
text.setPosition(.05,.08) 
input = viz.addText('> _',viz.SCREEN) # Add to screen 
input.fontSize(25); 
input.setPosition(.032,.05) 
input.visible(0) # We only want visible when in type mode 
def onChat(e): # Update the message display 
    updateChat(e.client+': '+e.chat) 
viz.callback(CHAT,onChat) 

#
talking = False 
def onKeyDown(key): 
    global talking 
    if key == 'y' and not talking: # Start talking mode 
        talking = True 
        input.message('> _') 
        input.visible(1) 
    elif key == viz.KEY_ESCAPE and talking: # Exit talking mode 
        talking = False 
        input.visible(0) 
        return True 
    elif talking and key == viz.KEY_RETURN: # Send message 
        talking = False 
        viznet.server.send(CHAT,client='SERVER',chat=input.getMessage()[2:-1]) 
        input.visible(0) 
        # Update display with our message 
        updateChat('SERVER'+': '+input.getMessage()[2:-1]) 
    elif talking and key == viz.KEY_BACKSPACE: # Delete a character 
        if len(input.getMessage()) > 3: 
            input.message(input.getMessage()[:-2]+'_') 
    elif len(key) > 1: # Handle special keys 
        return False 
    elif talking and 32 <= ord(key) <= 126: # Input message 
        input.message(input.getMessage()[:-1]+key+'_') 
viz.callback(viz.KEYDOWN_EVENT,onKeyDown,priority=-6)
######client1############

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)
text_2D.visible(viz.OFF)


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(5),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)


hope it is clear now.

thanx
Reply With Quote
  #19  
Old 12-03-2013, 01:33 AM
maya maya is offline
Member
 
Join Date: Nov 2013
Location: United Arab Emirates
Posts: 21
the replay is too long so I had to divided into 2. sorry for that.


######client2#######

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)
text_2D.visible(viz.OFF)


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(5),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)
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
input from a text file dig Vizard 5 10-20-2013 02:20 AM
Lighting relevant text? knightgba Vizard 1 01-26-2011 06:33 PM
Informationboxes with text snoopy78 Vizard 3 07-16-2009 11:23 AM
Vizard tech tip: Text to Speech Jeff Vizard 1 01-15-2009 10:39 PM
3d Text with Transparent Borders vjosh Vizard 3 12-01-2004 11:50 AM


All times are GMT -7. The time now is 05:13 AM.


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