|
shape - live physics-shape handle slot - 1-based material table entry friction# - finite non-negative friction coefficient restitution# (optional) - finite non-negative restitution coefficient; 0 (default) rolling# (optional) - finite non-negative rolling-resistance coefficient; 0 (default) tangent_x# (optional) - local surface velocity X in m/s; 0 (default) tangent_y# (optional) - local surface velocity Y in m/s; 0 (default) tangent_z# (optional) - local surface velocity Z in m/s; 0 (default) material_low (optional) - low 32-bit ID word; 0 (default) material_high (optional) - high 32-bit ID word; 0 (default) |
|
Sets every property of one material slot on a shape. Sets all physical properties and the 64-bit application ID of one material slot as one validated edit. Omitted optional values become zero. This does not change native debug colour. Handles must be live and of the correct kind. Material slots are 1-based; slot 1 is the base material and the first table entry, not an independent fallback. Mesh and terrain tables belong to each shape. Material edits retain density, body mass, filtering, event flags, shape tags and the public shape handle. Friction, restitution and rolling resistance must be finite and non-negative. Values above one are permitted. Friction products and the squared tangent-velocity length must be representable. Invalid ranges or allocations fail before replacing the material/geometry. Readbacks do not wake bodies. Edits invalidate cached contact material sampling and wake affected enabled bodies; disabled bodies stay disabled. Replacing the native shape for table resizing/painting invalidates its current contacts. Ray and contact-query material numbers are copied snapshots; later painting, table edits or shape destruction do not alter them. A current-contact query samples each point's assigned material when queried, which can differ from cached coefficients of the last solve after an edit. Native mesh/terrain contact response can average several touched triangle materials. Material IDs in hit events are copied at the hit. Material table entries, painting, refresh and resulting wake operations record/replay through Blitz3D+. Table edits use an added native recording opcode, so such recordings require the patched Blitz3D+ player; older opcodes are unchanged. Terrain preferences under holes are wrapper metadata; later recorded refresh captures the resulting collision geometry. Physics replay does not restore render meshes or this editable authoring metadata. See also: PhysicsShapeMaterials, PhysicsShapeTangentVelocity, PhysicsMeshTriangleMaterial, PhysicsTerrainCellMaterial, PhysicsQueryMaterialSlot. |
; PhysicsShapeMaterial Example
; ----------------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2
camera=CreateCamera()
PositionEntity camera,0,3,-7
RotateEntity camera,20,0,0
light=CreateLight()
RotateEntity light,45,-30,0
AmbientLight 60,60,60
; An independent Box3D world with standard gravity
world=CreatePhysicsWorld()
; Blue static floor
ground=CreateCube()
ScaleEntity ground,6,0.5,6
PositionEntity ground,0,-0.5,0
EntityColor ground,80,160,255
ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC)
ground_shape=PhysicsBodyBox(ground_body,12,1,12)
; Three test objects side by side, each with a different material
Dim things(3)
Dim bodies(3)
Dim shapes(3)
For i=1 To 3
things(i)=CreateSphere(16)
ScaleEntity things(i),0.4,0.4,0.4
bodies(i)=CreatePhysicsBody(world,things(i),PHYSICS_DYNAMIC)
shapes(i)=PhysicsBodySphere(bodies(i),0.8)
EntityColor things(i),255,120,70
; Set slot 1 in one call: friction 0.6 and a different restitution each
PhysicsShapeMaterial shapes(i),1,0.6,(i-1)*0.45
Next
Launch()
While Not KeyDown(1)
; R launches them again
If KeyHit(19) Then Launch()
StepPhysics world,1.0/60.0,4
; Arrow keys move the camera
If KeyDown(200) Then MoveEntity camera,0,0,0.1
If KeyDown(208) Then MoveEntity camera,0,0,-0.1
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
RenderWorld
Text 0,0,"Arrow keys: move camera R: launch again Esc: exit"
Text 0,20,"PhysicsShapeMaterial shape,1,0.6,restitution"
For i=1 To 3
Text (i-1)*210,40,"Restitution "+PhysicsShapeGetRestitution(shapes(i))
Next
Flip
Wend
FreePhysicsWorld world
End
Function Launch()
For i=1 To 3
ResetPhysicsBody bodies(i),i*2-4,4,0,0,0,0
Next
End Function