PDA

View Full Version : Applying Gravity to a Mesh


handerson11
12-12-2016, 05:23 AM
Hi,

I am looking to use a mesh on a box and I need it to fall as if being acted on by gravity. What is the best way to trigger the fall action after the box has been picked up and keep the action occurring over a certain height? Also how do I make it stop falling whenever it collides with another object?

This is the simple setup I have at the moment:

import viz
import vizact
import vizconnect
import vizshape

viz.fov(60)
viz.go()

#fall action
fallAction=vizact.fall(0.75,gravity=9.81)

#adding ground
ground = viz.add('ground.osgb')
ground.collidePlane()

#add cubes
cube1=vizshape.addCube(size=0.5)
cube1.collidemesh()
cube1.setPosition(0,1,1)
cube1.add(fallAction)

cube2=viz.shape.addCube(size=0.5)
cube2.collidemesh()
cube2.setPosition(0,0.5,1)

#define grabbable parts
parts=[cube1]

#using vizconnect
vizconnect.go('vizconnect_config.py')
#grabber
grabber=vizconnect.getRawTool('grabber')
grabber.setItems(parts)
from tools import grabber
tool = grabber.Grabber(usingPhysics=True, usingSprings=True)
tool.setItems(parts)


The technique will later be applied to more complex shapes which is why I am using the mesh instead of the box method.

Thanks

Jeff
12-13-2016, 05:14 PM
What is the best way to trigger the fall action after the box has been picked up and keep the action occurring over a certain height?

You could set up a callback function for the grabber's release event. In the callback function, apply the falling (http://docs.worldviz.com/vizard/#commands/vizact/fall.htm) action to the object.

Also how do I make it stop falling whenever it collides with another object?

This seems like it could get complicated. You could try using collision detection (http://docs.worldviz.com/vizard/#Callbacks_and_Complex_Shapes.htm) to detect if the collision has occured. Then use the node.endAction (http://docs.worldviz.com/vizard/#commands/node3d/endAction.htm) command to end the falling action and have the object stop immediately.