EntitySoftBody
Makes a mesh soft: cloth, jelly or a balloon.
EntitySoftBody ( entity[,mass#][,stiffness#][,pressure#] )
Parameters
- entity
- a mesh entity
- mass# (optional)
- the mass of the whole body. Defaults to 1
- stiffness# (optional)
- from 0 (stretchy) to 1 (stiff). Defaults to 0.5
- pressure# (optional)
- the air pressure inside a closed mesh. 0 (the default) has none; 1 just about holds it up against its own weight, higher is firmer
Description
Makes a mesh soft, so each of its vertices moves with physics: cloth, flags and curtains from flat meshes, and balloons, jelly and squashy balls from closed ones. It falls, bends, collides with physics bodies and is pushed by ApplyForce (wind) and ApplyImpulse. The mesh changes shape as it moves, so VertexX and the other vertex commands read where its vertices are.
A soft body bends at its vertices, so it needs enough of them: a cube has only 8 corners and stays nearly rigid, while a sphere or a grid of many vertices bends smoothly. Only the first surface is simulated. Fix vertices in place with SoftBodyPin. GetEntityPhysics returns 6 for a soft body.
Example
; Physics soft bodies example (an ArcBasic extension); A flag of cloth pinned to a pole, a balloon and a blob of jelly.; Space: a gust of wind B: drop the balloon again J: squash the jellyGraphics3D 640,480SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,4,-11TurnEntity camera,12,0,0light=CreateLight()RotateEntity light,50,30,0ground=CreatePlane()EntityColor ground,70,90,70EntityPhysics ground,1; the flag: a grid of vertices, pinned along the edge at the polepole=CreateCylinder(8)ScaleEntity pole,.08,3,.08PositionEntity pole,-4,3,0EntityPhysics pole,1Const N=12flag=CreateMesh()surf=CreateSurface(flag)For y=0 To N For x=0 To N AddVertex surf,-3.9+x*3.0/N,5.8-y*2.0/N,0,x/Float(N),y/Float(N) NextNextFor y=0 To N-1 For x=0 To N-1 v=y*(N+1)+x AddTriangle surf,v,v+1,v+N+2 AddTriangle surf,v,v+N+2,v+N+1 NextNextUpdateNormals flagEntityColor flag,230,60,80EntityFX flag,16EntitySoftBody flag,1,.9For y=0 To N SoftBodyPin flag,y*(N+1)Next; a balloon: a closed mesh with air pressure inside, and a shelf for it to land onshelf=CreateCube()ScaleEntity shelf,.6,.6,.6PositionEntity shelf,1.5,.6,0EntityPhysics shelf,1balloon=CreateSphere(12)PositionEntity balloon,1.5,5,0EntityColor balloon,80,160,255EntitySoftBody balloon,1,.6,3; jelly: a squashed ball, soft and only lightly filled, so it wobbles; (soft bodies bend at their vertices: a plain cube has too few to wobble)jelly=CreateSphere(12)ScaleEntity jelly,1,.6,1PositionEntity jelly,4.5,.6,0EntityColor jelly,120,255,120EntityAlpha jelly,.8EntitySoftBody jelly,1,.4,2.5While Not KeyHit(1) ; a light breeze all the time, and a gust while Space is held If KeyDown(57) Then ApplyForce flag,0,0,6 Else ApplyForce flag,1,0,.6 If KeyHit(48) FreeEntity balloon balloon=CreateSphere(12) PositionEntity balloon,1.5,5,0 EntityColor balloon,80,160,255 EntitySoftBody balloon,1,.6,3 EndIf If KeyHit(36) Then ApplyImpulse jelly,0,-8,0 UpdateWorld RenderWorld Text 0,0,"Space: gust of wind B: drop the balloon again J: squash the jelly" FlipWendEnd
