123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555 |
- Namespace mojo3d
- #Import "native/internaledges.cpp"
- #Import "native/internaledges.h"
- Extern Private
-
- Function CreateInternalEdgeInfo( mesh:btBvhTriangleMeshShape )="bbBullet::createInternalEdgeInfo"
-
- Public
-
- Class Entity Extension
-
- Property Collider:Collider()
-
- Return Cast<Collider>( GetComponent( Collider.Type ) )
- End
-
- End
- Class Collider Extends Component
-
- Const Type:=New ComponentType( "Collider",10,ComponentTypeFlags.Singleton )
-
- Method New( entity:Entity )
-
- Super.New( entity,Type )
- End
-
- Property Margin:Float()
-
- Return Validate().getMargin()
-
- Setter( margin:Float )
-
- Validate().setMargin( margin )
- End
- Method CalculateLocalInertia:Vec3f( mass:Float )
-
- Return Validate().calculateLocalInertia( mass )
- End
-
- Method Validate:btCollisionShape()
- If Not _btshape _btshape=OnCreate()
-
- Return _btshape
- End
-
- Protected
- Method OnCreate:btCollisionShape() Abstract
-
- Method Invalidate()
-
- If Not _btshape Return
-
- _btshape.destroy()
-
- _btshape=Null
-
- Entity.RigidBody?.ColliderInvalidated()
- End
-
- function SetOrigin:btCollisionShape( shape:btCollisionShape,origin:Vec3f )
-
- If origin=Null Return shape
-
- Local tshape:=New btCompoundShape( False,1 )
-
- tshape.addChildShape( AffineMat4f.Translation( origin ),shape )
-
- Return tshape
- End
-
- Private
-
- Field _btshape:btCollisionShape
-
- End
- Class ConvexCollider Extends Collider
-
- Method New( Entity:Entity )
- Super.New( Entity )
- End
-
- End
- Class BoxCollider Extends ConvexCollider
-
- Method New( Entity:Entity )
- Super.New( Entity )
-
- Box=New Boxf( -1,1 )
- End
-
- Property Box:Boxf()
-
- Return _box
-
- Setter( box:Boxf )
-
- _box=box
-
- Invalidate()
- End
-
- Protected
-
- Method OnCopy:BoxCollider( entity:Entity ) Override
-
- Local collider:=New BoxCollider( entity )
-
- collider.Box=Box
-
- Return collider
- End
-
- Method OnCreate:btCollisionShape() Override
- Local shape:=New btBoxShape( _box.Size/2 )
-
- Return SetOrigin( shape,_box.Center )
- End
-
- Private
-
- Field _box:=New Boxf( -1,1 )
- End
- Class SphereCollider Extends ConvexCollider
-
- Method New( Entity:Entity )
-
- Super.New( Entity )
- End
-
- Property Radius:Float()
-
- Return _radius
-
- Setter( radius:Float )
-
- _radius=radius
-
- Invalidate()
- End
-
- Property Origin:Vec3f()
-
- Return _origin
-
- Setter( origin:Vec3f )
-
- _origin=origin
-
- Invalidate()
- End
-
- Protected
-
- Method OnCopy:SphereCollider( entity:Entity ) Override
-
- Local collider:=New SphereCollider( entity )
-
- collider.Radius=Radius
- collider.Origin=Origin
-
- Return collider
- End
-
- Method OnCreate:btCollisionShape() Override
-
- Local shape:=New btSphereShape( _radius )
-
- return SetOrigin( shape,_origin )
- End
-
- Private
-
- Field _radius:Float=1
-
- Field _origin:Vec3f
-
- End
- Class CylinderCollider Extends ConvexCollider
-
- Method New( entity:Entity )
- Super.New( entity )
- End
-
- Property Radius:Float()
-
- Return _radius
-
- Setter( radius:Float )
-
- _radius=radius
-
- Invalidate()
- End
-
- Property Length:Float()
-
- Return _length
-
- Setter( length:Float )
-
- _length=length
-
- Invalidate()
- End
-
- Property Axis:Axis()
-
- Return _axis
-
- Setter( axis:Axis )
-
- _axis=axis
-
- Invalidate()
- End
-
- Property Origin:Vec3f()
-
- Return _origin
-
- Setter( origin:Vec3f )
-
- _origin=origin
-
- Invalidate()
- End
- Protected
- Method OnCopy:CylinderCollider( entity:Entity ) Override
-
- Local collider:=New CylinderCollider( entity )
-
- collider.Radius=Radius
- collider.Length=Length
- collider.Axis=Axis
- collider.Origin=Origin
-
- Return collider
- End
-
- Method OnCreate:btCollisionShape() Override
- Local shape:btCollisionShape
-
- Select _axis
- case Axis.X
- shape=New btCylinderShapeX( New btVector3( _length/2,_radius,_radius ) )
- Case Axis.Y
- shape=New btCylinderShape ( New btVector3( _radius,_length/2,_radius ) )
- case Axis.Z
- shape=New btCylinderShapeZ( New btVector3( _radius,_radius,_length/2 ) )
- Default
- RuntimeError( "Invalid Cylinder Axis" )
- End
-
- Return SetOrigin( shape,_origin )
- End
-
- Private
-
- Field _radius:Float=0.5
- Field _length:Float=1.0
- Field _axis:Axis=geom.Axis.Y
- Field _origin:Vec3f
- End
- Class CapsuleCollider Extends ConvexCollider
-
- Method New( entity:Entity )
- Super.New( entity )
- End
-
- Property Radius:Float()
-
- Return _radius
-
- Setter( radius:Float )
-
- _radius=radius
-
- Invalidate()
- End
-
- Property Length:Float()
-
- Return _length
-
- Setter( length:Float )
-
- _length=length
-
- Invalidate()
- End
-
- Property Axis:Axis()
-
- Return _axis
-
- Setter( axis:Axis )
-
- _axis=axis
-
- Invalidate()
- End
-
- Property Origin:Vec3f()
-
- Return _origin
-
- Setter( origin:Vec3f )
-
- _origin=origin
-
- Invalidate()
- End
- Protected
-
- Method OnCopy:CapsuleCollider( entity:Entity ) Override
-
- Local collider:=New CapsuleCollider( entity )
-
- collider.Radius=Radius
- collider.Length=Length
- collider.Axis=Axis
- collider.Origin=Origin
-
- Return collider
- End
-
- Method OnCreate:btCollisionShape() Override
-
- Local shape:btCollisionShape
-
- Select _axis
- Case Axis.X
- shape=New btCapsuleShapeX( _radius,_length )
- Case Axis.Y
- shape=New btCapsuleShape ( _radius,_length )
- Case Axis.Z
- shape=New btCapsuleShapeZ( _radius,_length )
- Default
- RuntimeError( "Invalid Capsule Axis" )
- End
-
- Return SetOrigin( shape,_origin )
- End
-
- Private
-
- Field _radius:Float=0.5
- Field _length:Float=1.0
- Field _axis:Axis=geom.Axis.Y
- Field _origin:Vec3f
- End
- Class ConeCollider Extends ConvexCollider
-
- Method New( entity:Entity )
- Super.New( entity )
- End
-
- Property Radius:Float()
-
- Return _radius
-
- Setter( radius:Float )
-
- _radius=radius
-
- Invalidate()
- End
-
- Property Length:Float()
-
- Return _length
-
- Setter( length:Float )
-
- _length=length
-
- Invalidate()
- End
-
- Property Axis:Axis()
-
- Return _axis
-
- Setter( axis:Axis )
-
- _axis=axis
-
- Invalidate()
- End
-
- Property Origin:Vec3f()
-
- Return _origin
-
- Setter( origin:Vec3f )
-
- _origin=origin
-
- Invalidate()
- End
- Protected
-
- Method OnCopy:ConeCollider( entity:Entity ) Override
-
- Local collider:=New ConeCollider( entity )
-
- collider.Radius=Radius
- collider.Length=Length
- collider.Axis=Axis
- collider.Origin=Origin
-
- Return collider
- End
-
- Method OnCreate:btCollisionShape() Override
-
- Local shape:btCollisionShape
-
- Select _axis
- Case Axis.X
- shape=New btConeShapeX( _radius,_length )
- Case Axis.Y
- shape=New btConeShape ( _radius,_length )
- Case Axis.Z
- shape=New btConeShapeZ( _radius,_length )
- Default
- RuntimeError( "Invalid Cone Axis" )
- End
- Return SetOrigin( shape,_origin )
- End
-
- Private
-
- Field _radius:Float=0.5
- Field _length:Float=1.0
- Field _axis:Axis=geom.Axis.Y
- Field _origin:Vec3f
-
- End
- Class ConcaveCollider Extends Collider
- Method New( entity:Entity )
- Super.New( entity )
- End
-
- End
- Class MeshCollider Extends ConcaveCollider
-
- Method New( entity:Entity )
- Super.New( entity )
- End
-
- Property Mesh:Mesh()
-
- Return _mesh
-
- Setter( mesh:Mesh )
-
- _mesh=mesh
-
- Invalidate()
- End
- Protected
-
- Method OnCopy:MeshCollider( entity:Entity ) Override
-
- Local collider:=New MeshCollider( entity )
-
- collider.Mesh=Mesh
-
- Return collider
- End
-
- Method OnCreate:btCollisionShape() Override
-
- Local vertices:=_mesh.GetVertices()
- _vertices=New btScalar[vertices.Length*3]
-
- For Local i:=0 Until vertices.Length
- _vertices[i*3]=vertices[i].position.x
- _vertices[i*3+1]=vertices[i].position.y
- _vertices[i*3+2]=vertices[i].position.z
- Next
-
- Local indices:=_mesh.GetAllIndices()
- _indices=New Int[indices.Length]
-
- For Local i:=0 Until indices.Length Step 3
- _indices[i+0]=indices[1]
- _indices[i+1]=indices[i+1]
- _indices[i+2]=indices[i+2]
- Next
-
- _btmesh=New btTriangleIndexVertexArray( _indices.Length/3,_indices.Data,12,_vertices.Length,_vertices.Data,12 )
-
- Local shape:=New btBvhTriangleMeshShape( _btmesh,True,True )
-
- ' CreateInternalEdgeInfo( shape )
-
- Return shape
- End
-
- Private
-
- Field _mesh:Mesh
- Field _vertices:btScalar[]
- 'Field _vertices:btVector3[]
- Field _indices:Int[]
- Field _btmesh:btTriangleIndexVertexArray
-
- End
- #rem
- Class TerrainCollider Extends ConcaveCollider
- Method New( box:Boxf,data:Pixmap )
-
- Local shape:=New btHeightfieldTerrainShape( data.Width,data.Height,data.Data,1.0/255.0,0.0,1.0,1,PHY_UCHAR,False )
-
- shape.setUseDiamondSubdivision( True )
-
- _btshape=shape
-
- _btshape.setLocalScaling( New Vec3f( box.Width/data.Width,box.Height,box.Depth/data.Height ) )
-
- SetOrigin( box.Center )
- End
- End
- #end
|