WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-12-2006, 09:47 AM
JvdBosch JvdBosch is offline
Member
 
Join Date: Sep 2006
Posts: 36
Collision with avatars and scene not working

Hi!

I import a scene from OSG (.ive file) into Vizard 3.0 and want to have avatars walking around in it. I have it working, but it takes to much calculation time, so I'm trying to make it better. It works fine with viz.intersect (calculating an intersection between the avatar and x meter in front of it), but I would like to use physics (hoping it would bet easier on the CPU).
I tried this method:
I assigned a collidemesh to the objects of the imported scene, which I want the avatars to collide with. The avatars have an avatar.collidebox around them, with the collision notify on.
I assigned an event which is triggered by a collision (like in the tutorial). But the avatar does not collide with the scene....

What am I doing wrong??
Any ideas??
Reply With Quote
  #2  
Old 09-12-2006, 10:37 AM
pbeeson pbeeson is offline
Member
 
Join Date: Aug 2006
Posts: 31
I know that collidemesh doesn't work with the physics dynamics, so I have to ddisable viz.DYNAMICS. I don't know if that helps you or not. Check out these recent threads, which may be of some help they discuss speeding up line intersection and doing collision in version 3.

http://www.worldviz.com/forum/showthread.php?t=729
http://www.worldviz.com/forum/showthread.php?t=725
Reply With Quote
  #3  
Old 09-12-2006, 11:31 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Here is how I got some collision events with an avatar. Perhaps you are missing one of the steps. (Forgot male.enable( viz.COLLIDE_NOTIFY ) perhaps?)

Code:
import viz

viz.go()
viz.MainView.setPosition( 0, 2, -5 )
viz.phys.enable()

ground = viz.add( 'tut_ground.wrl' )
ground.collidePlane()

logo = viz.add('logo.wrl')
logo.collideMesh()
logo.disable( viz.DYNAMICS )

ball = viz.add('ball.wrl')
g=ball.collideSphere()

male = viz.add( 'male.cfg' )
male.translate( 0, 1, 4 )
male.collideBox()

male.addAction( vizact.walkto( 0, 0, 0 ) )
male.enable( viz.COLLIDE_NOTIFY )

def onCollide(e):
	if e.obj2 == logo:
		print 'logo collide'
	elif e.obj2 == ground:
		print 'ground collide'
	elif e.obj2 == ball:
		print 'ball collide'

viz.callback( viz.COLLIDE_BEGIN_EVENT, onCollide )
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #4  
Old 09-12-2006, 12:43 PM
JvdBosch JvdBosch is offline
Member
 
Join Date: Sep 2006
Posts: 36
This seems to work, I'll try backing up a few steps and recreate this code in my model.
I added male.disable(viz.DYNAMICS), because else the avatar looks very blurry (drawing error or so?)
AlsoI added gravity and a mousedriven walkto to see how it works.
I'll try to incorporate it into my model tomorrow.

But if anyone has anymore bright ideas how to detect collision with low cpu usage, please share!

Here's the changed code:

Code:
import viz

viz.go()
viz.MainView.setPosition( 0, 2, -5 )
viz.phys.enable()
viz.phys.setGravity(0,-10,0)
viz.setMouseOverride()

ground = viz.add( 'tut_ground.wrl' )
ground.collidePlane()

logo = viz.add('logo.wrl')
logo.collideMesh()
logo.disable( viz.DYNAMICS )

ball = viz.add('ball.wrl')
g=ball.collideSphere()

male = viz.add( 'male.cfg' )
male.translate( 0, 1, 4 )
male.collideBox()
male.disable(viz.DYNAMICS)

male.addAction( vizact.walkto( 0, 0, 0 ) )
male.enable( viz.COLLIDE_NOTIFY )

def onCollide(e):
	if e.obj2 == logo:
		print 'logo collide'
	elif e.obj2 == ground:
		print 'ground collide'
	elif e.obj2 == ball:
		print 'ball collide'

viz.callback( viz.COLLIDE_BEGIN_EVENT, onCollide )

def onmousedown(button):
  if button == viz.MOUSEBUTTON_LEFT:
    info = viz.pick(1)
    if info.valid and info.object == ground:
      walk = vizact.walkto(info.point[0],0,info.point[2])
      male.runAction(walk)
	
viz.callback(viz.MOUSEDOWN_EVENT,onmousedown)
Reply With Quote
  #5  
Old 09-13-2006, 03:35 AM
JvdBosch JvdBosch is offline
Member
 
Join Date: Sep 2006
Posts: 36
I'm going mad....

I added a collidemesh to the scene objects, but I'm not sure that that went correctly, because I have a lot of objects with the same name and Vizard does not have a wildcard option to search all the children within a scene, based upon their name...
But with one object I'm sure about that there's only one (the edge of the scene, named 'Layer:Bak'), the &^%& avatars just walk through, without generating a collision event....
And sometimes they generate a collision event, where there are no objects...
I'm at a loss...

Any bright ideas about what I am doing wrong?
I'm using Vizard R3 Beta 2 (maybe that helps)

LINK TO IVE FILE
Code:
import viz
import random
viz.go()

# Set physicss
viz.phys.enable()
viz.phys.setGravity( 0, 0, 0 )

# Set start position
viz.MainView.setPosition([20,2.7,20])
viz.clip(0.1,10000)
viz.fov(70)
viz.eyeheight(1.6)
viz.stepsize(0.3)

# add sky
env = viz.add(viz.ENVIRONMENT_MAP,'temp0000.jpg')
sky = viz.add('skydome.dlc')
sky.texture(env)

# disable headlight
viz.disable(viz.LIGHT0)

# add our light
light=viz.addLight()
light.position(0,20,0)
light.intensity(1)
light.ambient(.5,.5,.5)
light.enable()

# Set collision parameters for scene objects
MallNames = ['Layer:Obstacle','Layer:Bak','Layer:VolBlokGevel','Layer:lm1','Layer:lm2','Layer:lm3','Layer:lm4','Layer:lm5','Layer:lm6','Layer:lm7','Layer:lm8','Layer:lm9','Layer:lm10']
MallObjects= []
for i in range(0,len(MallNames)):
	Bigobj = mall.getchild(MallNames[i])
	Bigobj.collideMesh()
	Bigobj.disable(viz.DYNAMICS)
	MallObjects.append(Bigobj) #APPEND AND COLLIDEMESH OBJECTS FROM SCENE

# place avatars
avatars = []
#spawn = [[120,29,1],[60,67,1],[68,60,5],[109,70,5],[52,45,9],[105,21,9],[81,69,13],[92,13,13],[36,45,17],[91,38,17],[98,43,21],[71,85,21],[61,29,25],[61,74,25],[103,62,25],[112,91,25],[43,8,29],[76,63,29],[89,22,33],[74,85,33],[71,67,37],[117,36,37]]
spawn = [[20,30,1]] # TEST LOCATION
for i in range(0,10): #number of avatars
	mf = random.choice([0, 1]) # Random Male/Female
	location = random.choice(spawn)	# Random pick spawn position
	rotation = random.choice([0,45,90,135,180,225,270,315]) #Random starting rotation
	avatarspeed = 0.5 + random.random() # random speed
	if mf==1: 
		avatar = viz.add('male.cfg')
	else:
		avatar = viz.add('female.cfg')
	avatar.translate(location[0]+2*random.random()-1,location[2],location[1]+2*random.random()-1) #SPAWN
	avatar.rotate(0,1,0,rotation) #ROTATE
	avatar.speed(avatarspeed) # Set speed
	vector = avatar.get(viz.LOOK) # Get directional vector
	avatar.collideBox()	#Physics
	avatar.disable(viz.DYNAMICS) #Physics
	avatar.enable(viz.COLLIDE_NOTIFY) #Physics
	avatar.addAction( vizact.walkto(location[0] + vector[0]*60,location[2],location[1] +vector[2]*60) ) #START WALKING
	avatars.append(avatar) #append avatar to array

# Collision-routine
def onCollide(e):
	if e.obj2 in avatars:
		print "avatar-avatar collision"
	if e.obj2 in MallObjects:
		print "avatar-object collision"
		e.obj1.endAction(pool=0)
		
viz.callback( viz.COLLIDE_BEGIN_EVENT, onCollide )

Last edited by JvdBosch; 09-13-2006 at 08:31 AM.
Reply With Quote
  #6  
Old 09-13-2006, 03:55 AM
JvdBosch JvdBosch is offline
Member
 
Join Date: Sep 2006
Posts: 36
Quick question: Can I make the collisionMeshes visible in some way? To see where the avatars should collide? F3 Shows only the geometry I believe.
Reply With Quote
  #7  
Old 09-13-2006, 10:14 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Of course, the visual geometry should be the collide mesh. You can visualize the bounding boxes around the avatars with this code:

Code:
import viz
import vizact

viz.go()
viz.clearcolor(viz.SKYBLUE)

box = viz.add( 'box.wrl' )
box.alpha( .2 )
box.color( viz.RED )

def drawborder( obj ):	
	savedEuler = obj.get( viz.EULER )
	obj.rotate( 0, 0, 0 )
	bb = obj.get( viz.BOUNDING_BOX )
	obj.rotate( savedEuler )
	box.translate( bb[3:6] )
	box.rotate( obj.get( viz.EULER ) )
	box.scale( bb[0:3] )

male = viz.add( 'male.cfg' )
male.add( vizact.goto( 0, 0, 10, 10 ) )
male.add( vizact.spin( 0, 1, 0, 45, viz.FOREVER ), 1 )

def onTimer(num):
	drawborder( male )

viz.callback(viz.TIMER_EVENT,onTimer)
viz.starttimer( 0, 0, viz.FOREVER )
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #8  
Old 09-13-2006, 02:32 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
I have experimented with your script and model. There seems to be invisible physics shapes in your model.

Instead of calling collideMesh on the child objects I just called it on the root "mall" node. This seems to work well. Would this be a solution for you?

Code:
import viz
import random
viz.go()

# Set physicss
viz.phys.enable()
viz.phys.setGravity( 0, 0, 0 )

# Set start position
viz.MainView.setPosition([20,2.7,20])
viz.clip(0.1,10000)
viz.fov(70)
viz.eyeheight(1.6)
viz.stepsize(0.3)

# add sky
env = viz.add(viz.ENVIRONMENT_MAP,'temp0000.jpg')
sky = viz.add('skydome.dlc')
sky.texture(env)

# disable headlight
viz.disable(viz.LIGHT0)

# add our light
light=viz.addLight()
light.position(0,20,0)
light.intensity(1)
light.ambient(.5,.5,.5)
light.enable()

mall = viz.add( 'test.ive' )
mall.collideMesh()
mall.disable( viz.DYNAMICS )

# place avatars
avatars = []
#spawn = [[120,29,1],[60,67,1],[68,60,5],[109,70,5],[52,45,9],[105,21,9],[81,69,13],[92,13,13],[36,45,17],[91,38,17],[98,43,21],[71,85,21],[61,29,25],[61,74,25],[103,62,25],[112,91,25],[43,8,29],[76,63,29],[89,22,33],[74,85,33],[71,67,37],[117,36,37]]
spawn = [[20,30,2]] # TEST LOCATION
for i in range(0,10): #number of avatars
	mf = random.choice([0, 1]) # Random Male/Female
	location = random.choice(spawn)	# Random pick spawn position
	rotation = random.choice([0,45,90,135,180,225,270,315]) #Random starting rotation
	avatarspeed = 10 + random.random() # random speed
	if mf==1: 
		avatar = viz.add('male.cfg')
	else:
		avatar = viz.add('female.cfg')
	avatar.translate(location[0]+2*random.random()-1,location[2],location[1]+2*random.random()-1) #SPAWN
	avatar.rotate(0,1,0,rotation) #ROTATE
	avatar.speed(avatarspeed) # Set speed
	vector = avatar.get(viz.LOOK) # Get directional vector
	avatar.collideBox()	#Physics
	avatar.disable(viz.DYNAMICS) #Physics
	avatar.enable(viz.COLLIDE_NOTIFY) #Physics
	avatar.addAction( vizact.walkto(location[0] + vector[0]*60,location[2],location[1] +vector[2]*60) ) #START WALKING
	avatars.append(avatar) #append avatar to array

# Collision-routine
def onCollide(e):
	if e.obj2 in avatars:
		print "avatar-avatar collision"
	if e.obj2 == mall:
		print "avatar-object collision"
		e.obj1.endAction(pool=0)
		
viz.callback( viz.COLLIDE_BEGIN_EVENT, onCollide )
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #9  
Old 09-13-2006, 03:17 PM
JvdBosch JvdBosch is offline
Member
 
Join Date: Sep 2006
Posts: 36
OK, importing the scene this way works, but importing it as a stage doesn't. Now I know... I'll play with it some more tomorrow at 'work'. Thanks a lot for your help!!!

BTW:Is this a bug, or a feature? Yesterday I also tried adding a collidemesh to the scene, but then it was a stage object and not a viz.add object (node3d?). That didn't work, this does.
Reply With Quote
  #10  
Old 09-13-2006, 03:26 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
The key difference between the code is that I do mall.collideMesh() instead of calling collideMesh() on children of the mall.

I had your problem with applying collideMesh() to children even when I added the mall via script.
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #11  
Old 09-14-2006, 04:35 AM
JvdBosch JvdBosch is offline
Member
 
Join Date: Sep 2006
Posts: 36
OK, so the problem is calling a collidemesh on a child. Knowing this I tried to detach the children I need to collide with from the mall object with Object.parent(viz.WORLD), but they just disappear. Apparently viz.World is not the current scene. How do I detach children from this node and attach them to the main scene? I tried viz.SCENE and viz.HEAD and viz.MAIN_SCENE, but none work)
I don't want to collide with the whole mall object, because it's rather large and I just need to collide with 14 objects to have the avatars walking in the right places.

The sky for example is a child of the main scene (it's added with viz.add), but when I request the parent of the sky with sky.getParents() it's empty... So how to attach a child to the main?
Reply With Quote
  #12  
Old 09-14-2006, 07:38 AM
JvdBosch JvdBosch is offline
Member
 
Join Date: Sep 2006
Posts: 36
Update:

I encountered something strange: I cannot extract a list of children from my .ive file, although I can acces the children by name.

So:

ObjectsinMall = mall.getChildren() is an empty list,
but
tub = mall.getChild('Layer:Bak") is a valid object
And when I open the Properties of the stage, or .ive object, I see all the children.... Strange....

Does an .ive file not support this? Or is there something else I am overlooking?
Reply With Quote
  #13  
Old 09-14-2006, 07:01 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
<VizNode>.getChildren() only returns VizNodes, not nodes that are in the model but have not had getChild() called on them. Reverse the order you call the two functions and you will see something.
__________________
Paul Elliott
WorldViz LLC
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 11:40 AM.


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