![]() |
|
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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? |
|
#6
|
|||
|
|||
|
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? |
![]() |
|
|