PDA

View Full Version : Collidemesh with Avatars


pbeeson
09-08-2006, 12:25 PM
It seems as if the mesh that collidemesh uses for the Male and Female avatars is the default pose (with their arms outstretched). This is true even is the avatars are in another state (e.g. lady.state(1)). Is there a way to get around this? Or am I doing somehting worng: I am calling collidemesh() after I set the avatar's state.

farshizzo
09-08-2006, 12:40 PM
Hi,

Setting the state of the avatar does not immediately affect its mesh state. You must wait until the next frame is drawn to ensure the mesh has been modified to reflect the new state. So you need to wait a frame and then call collideMesh() if you want it to reflect the new state.

Gladsomebeast
09-08-2006, 04:53 PM
Also, be sure to remove the previous mesh VizPhysicsShape object with <VizNode>.collideNone() if you don't want the old Shape colliding with things or adding to the Avatar's mass.

pbeeson
09-11-2006, 01:53 PM
There is no collideNone() function.

Plus, even if I wait 10 frames, occasionally, I still run into an avatar as if its arms were outstreched even though I waited 10 frames before calling collidemesh() after setting its to state(1) (standing with arms by side).

Gladsomebeast
09-11-2006, 03:22 PM
Here is a little script that keeps changing the collideMesh shape of the avatar. I think this is what you want to do. Run it with the latest Vizard Beta release.

import viz

CHANGE_STATE_TIMER = 0
SET_COLLIDE_SHAPE_TIMER = 1

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

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

male = viz.add( 'male.cfg' )
male.currentState = 1
male.state( male.currentState )

def onTimer(num):
if num == CHANGE_STATE_TIMER:
male.currentState = (male.currentState+1) % 2
male.state( male.currentState )
viz.starttimer( SET_COLLIDE_SHAPE_TIMER, .2, viz.FOREVER )
elif num == SET_COLLIDE_SHAPE_TIMER:
male.collideNone()
male.collideMesh()
male.disable( viz.DYNAMICS )

viz.callback(viz.TIMER_EVENT,onTimer)
viz.starttimer( CHANGE_STATE_TIMER, 3, viz.FOREVER )


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

def shootAhead():
ball.reset()
view = viz.get(viz.MAIN_VIEWPOINT)
ball.translate(view.get(viz.HEAD_POS))
vec = viz.Vector(view.get(viz.VIEW_LOOK)[:3])
ball.setVelocity(vec*20)
vizact.onkeydown(' ',shootAhead)

pbeeson
09-11-2006, 03:38 PM
I'm not using version 3.0. Thus, I don't have collideNone(). Can you provide me help with version 2.5? I've switched to using collidebox instead of collide mesh for the time being to get around this problem, but I'd like a better answer.

In v 2.5, if you do the following for two avatar then later use collidingwith(), sometimes the collisions occur as if the avatars are in state #1 (correct behavior), and sometimes one or both of the avatars provide collision info as if they were still in the idle pose (arms outstreatched). Can't get this to work properly every time.


def fixmesh(avatar):
viz.waitframe(10)
avatar.collidemesh()

avatar=viz.add('Female.cfg')
avatar.state(1)
avatar.visible(viz.ON)
avatar.translate(x,y,theta)
viz.director(fix_mesh,avatar)

Gladsomebeast
09-11-2006, 03:50 PM
I suggest that you start using Vizard 3.0. It has vastly improved physics support. You can download it here:

http://www.worldviz.com/download/?id=9

pbeeson
09-11-2006, 06:44 PM
Although I plan to switch to Vizard 3.0 at some point, given that I need to gather and analyze data for a grant proposal due next week, I'm sticking with version 2.5 for now. So, any help you can give men with my problem in version 2.5 would be welcome.

It's kind of distressing that several of my recent posts on Vizard 2.5 problems have been answered with "switch to version 3.0". If I want to switch to the 3.0 beta, I can only use this for a limited time, then I am unsure as to how much it will cost my supervisor to upgrade our entire lab.

On a more positive note, I have received excellent support on many of the previous problems/questions I've had with Vizard 2.5.

Gladsomebeast
09-11-2006, 07:09 PM
Let me try and address your very reasonable 3.0 concerns.

--There will be beta licenses avalable until 3.0 is released.
--Upgrading will be free.
--Vizard 3.0 is very backwards compatable. Just give your script a quick spin in 3.0. Even if your project is quite complex I doubt it would take more than an hour of work to migrate over.

pbeeson
09-11-2006, 07:36 PM
So, in desparation, I installed version 3.0, and as I suspected, enough has changed to make it appear infeasible to port my code in 1 day (I am on a bit of a time crunch here).

Mainly, collidingwith doesn't work.


for x in self.collidables:
info = x.collidingwith(obj,1)
print info.intersected


Returns:
True
False
True
False
.
.
.
It flips back and forth between true and false for the entire list of objects.
But, the same code works fine in version 2.5 (note I added the collideNone() commands before the collidemesh() commands before running in v3).

So, given that I can't refactor thousands of lines of code in a day, I was hoping you could solve the original version 2.5 problem. Or fill me in on how to EASILY get v3.0 working --- by easily I mean 1-2 lines of changes (I don't have time to play with the new physics engine and collision events, though they look cool).

Thanks for all the help

pbeeson
09-11-2006, 07:55 PM
EXAMPLE of bug with v3.0 and collidingwith()


import viz

CHANGE_STATE_TIMER = 0
SET_COLLIDE_SHAPE_TIMER = 1
CHECK_COLLIDE=2

viz.go()
viz.MainView.setPosition( 0, 0, -25 )

male = viz.add( 'male.cfg' )
male.state(1)
male.translate(10,0,0)

male2 = viz.add( 'male.cfg' )
male2.state(1)
male2.translate(-10,0,0)

def onTimer(num):
if num == SET_COLLIDE_SHAPE_TIMER:
male.collideNone()
male.collideMesh()
male.disable( viz.DYNAMICS )
male2.collideNone()
male2.collideMesh()
male2.disable( viz.DYNAMICS )
elif num==CHECK_COLLIDE:
info=male.collidingwith(male2,1)
print info.intersected

viz.callback(viz.TIMER_EVENT,onTimer)
viz.starttimer( SET_COLLIDE_SHAPE_TIMER, 1, 1 )
viz.starttimer( CHECK_COLLIDE, 2, viz.FOREVER )

Gladsomebeast
09-11-2006, 07:59 PM
You can replace the collidewith function with viz.phys.intersectNode()

For your previous for loop collidewith code replace with:

if x in viz.phys.intersectNode( obj ):
print 'intersected'
else:
print 'not intersected'

Gladsomebeast
09-11-2006, 08:02 PM
Any other 3.0 migration problems?

pbeeson
09-11-2006, 08:26 PM
It looks like viz.phys.intersectLine is faster than the old viz.intersect. But, the old intersect would ignore objects that were not visible.

1) Is there any way to tell viz.phys.intersectLine to ignore certain objects? object.disable(viz.COLLISION) doesn't seem to work, neither does turning off visibilty.
I can run viz.phys.intersectLine(begin,end,True) to get a list and then check object IDs, but I don't know if there is an easier way (especially considering that if you have many objects, it might be an optimzation to not check for intersections with particular objects at certain times). (This is also where thread 729 (http://www.worldviz.com/forum/showthread.php?t=729) ended up).

2) Is there any way to get better documentation on these commands that he skeletal docs in the Vizard Help or in Python help()?

Gladsomebeast
09-12-2006, 09:51 AM
1) viz.phys.intersectLine() works on the physics simulation level so it only intersects with physics shapes. To have it ignore nodes, remove their VizPhysicsShape with a call to collideNone().

2) Vizard Help is the best option right now. Of course the forum is fairly good too:)