WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-01-2006, 01:20 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

I'm still not clear on what you are trying to accomplish. Calling object.remove() will permanently remove the object. Once it is removed you can't use it anymore. If you only plan on having 4 avatars at a time, I suggest you add them all at the beginning of your script. Then instead of removing them permanently, just make them invisible. Then when you want to reuse them later on make them visible again. I would provide sample code if you explained exactly what you want to do.
Reply With Quote
  #2  
Old 03-01-2006, 01:27 PM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
Ok, what happens is that this is a shooting scenario where the subject is presented with a new avatar every certain interval of time (say 2 seconds). Currently, this occurs until 4 avatars have appeared. Now, each time a user shoots an avatar, I would like for the avatar to fall, disappear, and be ready to restart from the original position. We have not decided whether this should happen automatically or if they should re-appear after a stimulus (say keyboard entry). We are leaning towards the re-appearing happening automatically. I thought I would have to remove the avatar from the array and re-append him after he was removed. Am I looking at this the wrong way?
Reply With Quote
  #3  
Old 03-01-2006, 01:50 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

That sounds fine. Here is really simple script that allows you to click an avatar. When it is clicked it will fall to the ground and disappear. Press the spacebar to bring the next available avatar back to life. What you want is something like the RemoveAvatar and RestoreAvatar functions. Instead of calling the function in response to a keyboard press you can call it in response to a stimuli or whatever you want. Let me know if this isn't what you wanted:
Code:
import viz
viz.go()

avatars = []
dead_list = []

#Create six avatars
for i in range(6):
	male = viz.add('male.cfg')
	male.translate(i,0,0)
	male.rotate(180,0,0)
	male.state(1)
	avatars.append(male) #Save avatar in list

def RemoveAvatar(avatar):
	avatar.visible(0) #Hide avatar
	avatar.speed(1) #Restore speed
	avatars.remove(avatar) #Remove from list
	dead_list.append(avatar) #Add to dead list

def RestoreAvatar():
	if len(dead_list):
		avatar = dead_list.pop() #Ressurrect dead avatar
		avatar.visible(1) #Make it visible
		avatars.append(avatar) #Add it to avatar list

def onmousedown(button):
	if button == viz.MOUSEBUTTON_LEFT:
		node = viz.pick() #Get object that was clicked
		if node in avatars: #Check if object is one of the avatars
			node.execute(7) #Execute the "shot" animation
			#Create action to wait for the animation duration then freeeze the avatar
			WaitThenFreeze = vizact.sequence( vizact.waittime(node.getduration(7)-0.2), vizact.speed_node(0) )
			node.add(WaitThenFreeze) #Add the action to the avatar
			RemoveAvatarAction = vizact.call(RemoveAvatar,node)
			node.add(RemoveAvatarAction) #Add action to remove avatar
viz.callback(viz.MOUSEDOWN_EVENT,onmousedown)

#Restore next available avatar
vizact.onkeydown(' ',RestoreAvatar)

#Move viewpoint so that all avatars are visible
viz.move(2.5,0,-10)

#Disable mouse navigation
viz.mouse(0)
Reply With Quote
  #4  
Old 03-07-2006, 09:43 AM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
Works great. I did however want to ask you, is there a way to say "if the number of avatars does not equal 4, restore the avatar. I tried using
Code:
#Restore next available avatar
vizact.sequence(vizact.waittime(4),RestoreAvatar)
#instead of using onkeydown
#vizact.onkeydown(' ',RestoreAvatar)
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


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


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