View Full Version : Mainview head connection
TrashcanPatrol
04-07-2009, 03:50 PM
I've been trying networking scripts lately, and it seems whenever I look around on one computer, the avatar that's shown in the second computer moves the same direction as the mouse is looking.
Is there any way I can make it so that instead of the whole avatar moving the direction of the mouse, just the head moves? So they can actually look around without, say, looking up and having the whole body lift off the ground and face upwards...?
You could send the orientation of the viewpoint from one machine and then grab the headbone of the avatar, and set its orientation to that. Something like this.
def sendData():
target_mailbox.send(euler = viz.MainView.getEuler())
and on the other machine
head = avatar.getBone('Bip01 Head')
head.lock()
def onNetwork(e):
head.setEuler(e.euler, viz.AVATAR_WORLD)
TrashcanPatrol
04-09-2009, 02:59 PM
You could send the orientation of the viewpoint from one machine and then grab the headbone of the avatar, and set its orientation to that. Something like this.
def sendData():
target_mailbox.send(euler = viz.MainView.getEuler())
and on the other machine
head = avatar.getBone('Bip01 Head')
head.lock()
def onNetwork(e):
head.setEuler(e.euler, viz.AVATAR_WORLD)
I tried that and I repeatedly get a few errors:
Traceback (most recent call last):
File "Vizard16356785347376.py", line 51, in onNetwork
person1.setPosition(e.pos)
AttributeError: 'NetworkEvent' object has no attribute 'pos'
Traceback (most recent call last):
File "Vizard16356785347376.py", line 53, in onNetwork
head.setEuler(e.euler, viz.AVATAR_WORLD)
AttributeError: 'NetworkEvent' object has no attribute 'euler'
My code is as follows; the beginning only has a few notes for me to get started and to work on. :
#This demo is for testing online interactions between two players.
#The players will spawn up and be able to see each other's avatars.
#Both players will be able to select an avatar by a dropdown menu
#similar to the one in quest.viz.
#A chat will be enabled, the color of the inbox text will be light blue,
#and the color of the outbox text will be darker blue.
#The chat will reside on the right side of the screen. The dropdown menu
#will also be able to hide or show the chat by selecting the option
#similar again in quest.viz.
#I want to have it be a co-operative mission, where one person will talk
#to the patient and the other will be able to get supplies and hand them
#to the first person.
#Names are also something to look into. Maybe in the future,
#when you spawn up, there will be a floating name above your character.
#The prefix "Dr. " is desirable in the names.
################################################
##### CURRENTLY NEEDING WORK: #####
##### dropdown menu to change avatar #####
################################################
import viz
viz.go()
ground=viz.add('room.wrl')
person1=viz.add('male.cfg')
#subject = viz.input('What is your name?')
target_machine = viz.input('Enter the name of the other machine').upper()
target_mailbox = viz.addNetwork(target_machine)
out_text = ''
def SendData():
mat = viz.MainView.getMatrix()
# mat.preEuler(180,0,0)
mat.preTrans(0,-1.8,0)
target_mailbox.send(euler = viz.MainView.getEuler())
target_mailbox.send(quat=mat.getQuat(),pos=mat.get Position(),message=out_text)
vizact.ontimer(0,SendData)
head = person1.getBone('skel_Head')
head.lock()
def onNetwork(e):
person1.setPosition(e.pos)
person1.setQuat(e.quat)
head.setEuler(e.euler, viz.AVATAR_WORLD)
inbox.message(e.message)
viz.callback(viz.NETWORK_EVENT, onNetwork)
draft_text = ' '
def mykeyboard(key):
global out_text, draft_text
if len(key) == 1:
draft_text += key
elif key == viz.KEY_RETURN:
out_text = draft_text
draft_text = ' '
elif key == viz.KEY_BACKSPACE:
draft_text = draft_text[:-1]
if len(draft_text) == .5:
draft_text += '\n '
outbox.message(draft_text)
viz.callback(viz.KEYBOARD_EVENT,mykeyboard)
##
import vizmenu
menu = vizmenu.add()
menu.setAlignment( vizmenu.LEFT )
ToolMenu = menu.add( 'Tools' )
OptiesMenu = menu.add( 'Options' )
DropDown = ToolMenu.add( viz.DROPLIST, 'Equip' )
DropDown.addItems( ['Empty Hands','Stethoscope', 'Anasthetic', 'Medicine', 'Scalpel'] )
DropDown.getSelection()
DropDown.getItems()[ DropDown.getSelection() ]
AviMenu = OptiesMenu.add( vizmenu.MENU, 'Avatar' )
Duck = AviMenu.add( viz.RADIO, 0, 'Red' )
Guy1 = AviMenu.add( viz.RADIO, 0, 'White' )
Guy2 = AviMenu.add( viz.RADIO, 0, 'Blue' )
import vizcam
vizcam.FlyNavigate()
viz.collision(viz.ON)
person1.disable(viz.COLLISION)
You either have to send all that data with one send command or you need to check in the network callback function that the data is valid. The way it is there, sometimes there is no pos value sent and sometimes there in no euler value sent, but in onNetwork you are looking for both.
Gladsomebeast
04-09-2009, 11:27 PM
As Jeff pointed out, the message receiver needs to do different things depending on the message type.
For flexibility, try adding a 'messageType' variable to all your <mailbox>.send() calls. That way you can check the 'messageType' in your 'onNetwork' function then access the variables you know come with specific message types.
CREATE_PERSON_NETWORK_EVENT = 1
UPDATE_PERSON_NETWORK_EVENT = 2
def personJoined():
mailbox.send(messageType=CREATE_PERSON_NETWORK_EVE NT, avatarFileName='blabla.cfg')
def sendPersonData(person):
mailbox.send(messageType=UPDATE_PERSON_NETWORK_EVE NT, euler=...
def onNetwork(e):
if e.messageType == CREATE_PERSON_NETWORK_EVENT:
viz.add(e.avatarFileName)
....
elif e.messageType == UPDATE_PERSON_NETWORK_EVENT:
otherPerson.setEuler(e.euler)
Also, the viznet.py module will help you create more robust networked applications.
Jeff or Farshizo can you post that *sweet* viznet demo with the boxes and springs?
TrashcanPatrol
05-05-2009, 01:37 PM
Sounds a bit confusing... looks like I've got some things to look into.
What is the example you speak of with springs and such?
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.