Browse Source

Added std.digest MD5/SHA1/SHA256

Mark Sibly 7 years ago
parent
commit
076bb63968
29 changed files with 411 additions and 1958 deletions
  1. 5 0
      modules/bullet/bullet.monkey2
  2. 6 0
      modules/mojo/app/app.monkey2
  3. 0 8
      modules/mojo3d-physics/module.json
  4. 0 17
      modules/mojo3d-physics/mojo3d-physics.monkey2
  5. 0 74
      modules/mojo3d-physics/physics/bttypeconvs.monkey2
  6. 0 550
      modules/mojo3d-physics/physics/collider.monkey2
  7. 0 212
      modules/mojo3d-physics/physics/fpscollider.monkey2
  8. 0 35
      modules/mojo3d-physics/physics/native/internaledges.cpp
  9. 0 12
      modules/mojo3d-physics/physics/native/internaledges.h
  10. 0 16
      modules/mojo3d-physics/physics/native/kinematicmotionstate.h
  11. 0 327
      modules/mojo3d-physics/physics/rigidbody.monkey2
  12. 0 163
      modules/mojo3d-physics/physics/world.monkey2
  13. 0 0
      modules/mojo3d-physics/tests/assets/dummy.txt
  14. 0 160
      modules/mojo3d-physics/tests/fpsthing.monkey2
  15. 0 128
      modules/mojo3d-physics/tests/qcollide.monkey2
  16. 0 145
      modules/mojo3d-physics/tests/shapes.monkey2
  17. 0 42
      modules/mojo3d-physics/tests/util.monkey2
  18. 29 0
      modules/mojo3d/entities/camera.monkey2
  19. 11 4
      modules/mojo3d/mojo3d.monkey2
  20. 19 0
      modules/mojo3d/render/renderer.monkey2
  21. 5 26
      modules/mojo3d/scene/component.monkey2
  22. 22 6
      modules/mojo3d/scene/entity.monkey2
  23. 44 24
      modules/mojo3d/scene/scene.monkey2
  24. 1 1
      modules/mojo3d/tests/donut.monkey2
  25. 2 6
      modules/mojo3d/tests/ducks.monkey2
  26. 1 1
      modules/std/misc/base64.monkey2
  27. 245 0
      modules/std/misc/digest.monkey2
  28. 2 1
      modules/std/std.monkey2
  29. 19 0
      modules/std/tests/digest.monkey2

+ 5 - 0
modules/bullet/bullet.monkey2

@@ -208,6 +208,11 @@ Class btCollisionWorld Extends btObject
 	Method rayTest( rayFromWorld:btVector3,rayToWorld:btVector3,resultCallback:RayResultCallback Ptr ) Extension="bbBullet::rayTest"
 	Method rayTest( rayFromWorld:btVector3,rayToWorld:btVector3,resultCallback:RayResultCallback Ptr ) Extension="bbBullet::rayTest"
 	
 	
 	Method convexSweepTest( castShape:btConvexShape,castFrom:btTransform,castTo:btTransform,resultCallback:ConvexResultCallback ptr,allowedCcdPenetration:btScalar=0 ) Extension="bbBullet::convexSweepTest"
 	Method convexSweepTest( castShape:btConvexShape,castFrom:btTransform,castTo:btTransform,resultCallback:ConvexResultCallback ptr,allowedCcdPenetration:btScalar=0 ) Extension="bbBullet::convexSweepTest"
+		
+	Method addCollisionObject( collisionObject:btCollisionObject )
+		
+	Method removeCollisionObject( collisionObject:btCollisionObject )
+				
 End
 End
 
 
 Class btDynamicsWorld Extends btCollisionWorld
 Class btDynamicsWorld Extends btCollisionWorld

+ 6 - 0
modules/mojo/app/app.monkey2

@@ -156,6 +156,12 @@ Class AppInstance
 		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE,Int( GetConfig( "MOJO_DEPTH_BUFFER_BITS" ) ) )
 		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE,Int( GetConfig( "MOJO_DEPTH_BUFFER_BITS" ) ) )
 		SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE,Int( GetConfig( "MOJO_STENCIL_BUFFER_BITS" ) ) )
 		SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE,Int( GetConfig( "MOJO_STENCIL_BUFFER_BITS" ) ) )
 		
 		
+		Local msaa_samples:=Int( GetConfig( "MOJO_MSAA_SAMPLES",0 ) )
+		If msaa_samples
+			SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS,1 )
+			SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES,msaa_samples )
+		Endif
+		
 #If __DESKTOP_TARGET__
 #If __DESKTOP_TARGET__
 
 
 		'WIP multiple windows...
 		'WIP multiple windows...

+ 0 - 8
modules/mojo3d-physics/module.json

@@ -1,8 +0,0 @@
-{
-	"module":"mojo3d-physics",
-	"about":"Mojo3d bullet support",
-	"author":"Mark Sibly",
-	"version":"1.0.0",
-	"support":"http://monkeycoder.co.nz",
-	"depends":["std","assimp","mojo3d"]
-}

+ 0 - 17
modules/mojo3d-physics/mojo3d-physics.monkey2

@@ -1,17 +0,0 @@
-
-Namespace mojo3d
-
-#Import "<std>"
-#Import "<mojo3d>"
-#Import "<bullet>"
-
-Using std..
-Using mojo3d..
-Using bullet..
-
-#Import "physics/bttypeconvs"
-#Import "physics/collider"
-#Import "physics/rigidbody"
-#Import "physics/world"
-#Import "physics/fpscollider"
-

+ 0 - 74
modules/mojo3d-physics/physics/bttypeconvs.monkey2

@@ -1,74 +0,0 @@
-
-Namespace mojo3d.physics
-
-Public
-
-Struct Vec3<T> Extension
-
-	Operator To:btVector3()
-
-		Return New btVector3( x,y,z )
-	End
-End
-
-Struct btVector3 Extension
-
-	Operator To:Vec3f()
-
-		Return New Vec3f( x,y,z )
-	End
-End
-
-Struct Vec4<T> Extension
-	Operator To:btVector4()
-
-		Return New btVector4( x,y,z,w )
-	End
-End
-
-Struct btVector4 Extension
-
-	Operator To:Vec4f()
-	
-		Return New Vec4f( x,y,z,w )
-	End
-End
-
-Struct Mat3f Extension
-
-	Operator To:btMatrix3x3()
-
-		Return New btMatrix3x3( i.x,j.x,k.x, i.y,j.y,k.y, i.z,j.z,k.z )
-	End
-End
-
-Struct btMatrix3x3 Extension
-
-	Operator To:Mat3f()
-	
-		Return New Mat3f( Cast<Vec3f>( getColumn(0) ),Cast<Vec3f>( getColumn(1) ),Cast<Vec3f>( getColumn(2) ) )
-	End
-End
-
-
-Struct AffineMat4f<T> Extension
-	
-	Operator To:btTransform()
-	
-		Return New btTransform( Cast<btMatrix3x3>( m ),Cast<btVector3>( t ) )
-	End
-
-End
-
-Struct btTransform Extension
-	
-	Operator To:AffineMat4f()
-	
-		Return New AffineMat4f( Cast<Mat3f>( getBasis() ),Cast<Vec3f>( getOrigin() ) )
-	End
-
-End
-
-
-
-

+ 0 - 550
modules/mojo3d-physics/physics/collider.monkey2

@@ -1,550 +0,0 @@
-
-Namespace mojo3d.physics
-
-#Import "native/internaledges.cpp"
-#Import "native/internaledges.h"
-
-Extern
-
-Function CreateInternalEdgeInfo( mesh:btBvhTriangleMeshShape )="bbBullet::createInternalEdgeInfo"
-	
-Public
-
-Class Entity Extension
-	
-	Property Collider:Collider()
-		
-		Return GetComponent<Collider>()
-	End
-	
-End
-
-Class Collider Extends Component
-	
-	Const Type:=New ComponentType( "Collider",-1,ComponentTypeFlags.Singleton )
-	
-	Method New( entity:Entity )
-		
-		Super.New( entity,Type )
-	End
-	
-	Property Margin:Float()
-		
-		Return btShape.getMargin()
-	
-	Setter( margin:Float )
-		
-		btShape.setMargin( margin )
-	End
-
-	Method CalculateLocalInertia:Vec3f( mass:Float )
-		
-		Return btShape.calculateLocalInertia( mass )
-	End
-
-	Property btShape:btCollisionShape()
-		
-		If Not _btshape _btshape=OnCreate()
-	
-		Return _btshape
-	End
-
-Protected
-
-	Method OnCreate:btCollisionShape() Abstract
-	
-	Method Invalidate()
-		
-		If Not _btshape Return
-		
-		_btshape.destroy()
-
-		_btshape=Null
-
-		Modified()
-	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 btVector3[vertices.Length]
-		
-		For Local i:=0 Until vertices.Length
-			_vertices[i].x=vertices[i].position.x
-			_vertices[i].y=vertices[i].position.y
-			_vertices[i].z=vertices[i].position.z
-		Next
-		
-		Local indices:=_mesh.GetAllIndices()
-		_indices=New Int[indices.Length]
-		For Local i:=0 Until indices.Length
-			_indices[i]=indices[i]
-		Next
-		
-		_btmesh=New btTriangleIndexVertexArray( _indices.Length/3,_indices.Data,12,_vertices.Length,Cast<btScalar Ptr>( _vertices.Data ),16 )
-		
-		Local shape:=New btBvhTriangleMeshShape( _btmesh,True,True )
-		
-		'CreateInternalEdgeInfo( shape )
-		
-		Return shape
-	End
-	
-	Private
-	
-	Field _mesh:Mesh
-	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

+ 0 - 212
modules/mojo3d-physics/physics/fpscollider.monkey2

@@ -1,212 +0,0 @@
-
-Namespace mojo3d.physics
-
-Private
-
-Function F:String( f:Float )
-	If f>=0 
-		Local i:Int=Floor( f*100+.5 )
-		Return String( i / 100 ) + "." + ("00"+String( i Mod 100 )).Slice( -2 )
-	Else
-		Local i:Int=Floor( -f*100+.5 )
-		Return "-"+String( i / 100 ) + "." + ("00"+String( i Mod 100 )).Slice( -2 )
-	Endif
-End
-
-Function V:String( V:Vec3f )
-	'Return String(V)
-	Return "("+F(V.x)+","+F(V.y)+","+F(V.z)+")"
-End
-
-Function P:String( P:Planef )
-	Return "("+F(P.n.x)+","+F(P.n.y)+","+F(P.n.z)+","+F(P.d)+")"
-End
-
-Public
-
-Struct QResult
-	Field position:Vec3f
-	Field onground:Bool
-End
-
-Function QCollide:QResult( collider:ConvexCollider,src:Vec3f,dst:Vec3f )
-	
-	Local start:=src
-	
-	Local plane0:Planef,plane1:Planef,state:=0,casts:=0
-	
-	Local qresult:QResult
-	
-	Local debug:=""
-	
-	Repeat
-
-		If dst.Distance( src )<.001 Exit
-		
-		casts+=1
-		
-		Local world:=World.GetCurrent()
-		
-		Local cresult:=world.ConvexSweep( collider,src,dst )
-		If Not cresult Exit
-
-'		debug+=", "
-		
-		If cresult.normal.y>.7071 qresult.onground=True
-			
-		Local plane:=New Planef( cresult.point,cresult.normal )
-
-		plane.d-=collider.Margin
-		
-		Local tline:=New Linef( src,dst-src )
-		
-		Local t:=plane.TIntersect( tline )
-		
-		If t>=1 dst=tline * t ; Exit
-		
-		If t>0 src=tline * t
-		
-		Select state
-
-		Case 0
-			
-			dst=plane.Nearest( dst )
-			
-'			debug+="A "+P( plane )
-				
-			plane0=plane
-				
-			state=1
-		
-		Case 1
-
-			Local v:=plane0.n.Cross( plane.n )
-			
-			If v.Length>.0001
-				
-				Local groove:=New Linef( src,v )
-				
-'				Local d0:=plane0.Distance( dst )
-				
-				dst=groove.Nearest( dst )
-				
-'				debug+="B "+P( plane )+" d0="+F(d0)+" sd0="+F(plane0.Distance(src))+" dd0="+F(plane0.Distance(dst))
-				
-				plane1=plane
-				
-				state=2
-			
-			Else
-				
-'				debug+="C "+P( plane )
-
-				dst=plane.Nearest( dst )
-
-				plane0=plane
-				
-				state=1
-			
-			Endif
-				
-		Case 2
-
-'			Local d0:=plane0.Distance( dst )
-'			Local d1:=plane1.Distance( dst )
-'			debug+="D "+P( plane )+" d0="+F(d0)+" d1="+F(d1)
-				
-			dst=src
-			
-			Exit
-		End
-
-	Forever
-	
-'	If casts>2 Print debug.Slice( 2 )+" casts="+casts
-
-	qresult.position=dst
-	
-	Return qresult
-
-End
-
-Public
-
-Class FPSCollider Extends CapsuleCollider
-	
-	Method New( entity:Entity )
-		Super.New( entity )
-		
-		_src=Entity.Position
-	End
-	
-	Property Gravity:Float()
-		
-		Return _gravity
-	
-	Setter( gravity:Float )
-		
-		_gravity=gravity
-	End
-	
-	Property YVelocity:Float()
-		
-		Return _yvel
-		
-	Setter( yvel:Float )
-		
-		_onground=False
-			
-		_yvel=yvel
-	End
-	
-	Property OnGround:Bool()
-		
-		Return _onground
-	End
-	
-	Method Reset()
-		_src=Entity.Position
-		_yvel=0
-		_onground=False
-	End
-	
-	Method OnBeginUpdate() Override
-		
-		_src=Entity.Position
-	End
-	
-	Method OnUpdate( elapsed:Float ) Override
-		
-		Local qresult:=QCollide( Self,_src,Entity.Position )
-
-		Entity.Position=qresult.position
-		
-		_src=Entity.Position
-		
-		If _onground _yvel=-Margin
-			
-		_yvel-=_gravity/60.0/60.0
-
-		Entity.MoveY( _yvel )
-
-		qresult=QCollide( Self,_src,Entity.Position )
-
-		Entity.Position=qresult.position
-		
-		_yvel=Entity.Position.y-_src.y
-		
-		_onground=qresult.onground
-	End
-	
-	Private
-	
-	Field _gravity:Float=30
-	
-	Field _yvel:Float
-	
-	Field _onground:Bool
-	
-	Field _src:Vec3f
-	
-End
-

+ 0 - 35
modules/mojo3d-physics/physics/native/internaledges.cpp

@@ -1,35 +0,0 @@
-
-#include "internaledges.h"
-
-#include "BulletCollision/CollisionDispatch/btInternalEdgeUtility.h"
-
-namespace{
-
-	bool CustomMaterialCombinerCallback( btManifoldPoint& cp,const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper *colObj1Wrap,int partId1,int index1 ){
-	
-		btAdjustInternalEdgeContacts( cp,colObj1Wrap,colObj0Wrap,partId1,index1 );
-		
-//		cp.m_combinedRestitution=colObj0Wrap->getCollisionObject()->getRestitution() * colObj1Wrap->getCollisionObject()->getRestitution();
-		
-//		cp.m_combinedFriction=0;
-		
-		return false;
-	}
-}
-
-namespace bbBullet{
-
-	void createInternalEdgeInfo( btBvhTriangleMeshShape *mesh ){
-	
-		// enable callback
-		gContactAddedCallback=CustomMaterialCombinerCallback;
-
-		// create edge info
-		btTriangleInfoMap *info=new btTriangleInfoMap();
-		
-		btGenerateInternalEdgeInfo( mesh,info );
-
-		mesh->setTriangleInfoMap( info );
-	}
-
-}

+ 0 - 12
modules/mojo3d-physics/physics/native/internaledges.h

@@ -1,12 +0,0 @@
-
-#ifndef BB_INTERNAL_EDGES_H
-#define BB_INTERNAL_EDGES_H
-
-#include "btBulletDynamicsCommon.h"
-
-namespace bbBullet{
-
-	void createInternalEdgeInfo( btBvhTriangleMeshShape *mesh );
-}
-
-#endif

+ 0 - 16
modules/mojo3d-physics/physics/native/kinematicmotionstate.h

@@ -1,16 +0,0 @@
-
-#ifndef BB_KINEMATICMOTIONSTATE_H
-#define BB_KINEMATICMOTIONSTATE_H
-
-#include "btBulletDynamicsCommon.h"
-
-class bbKinematicMotionState : public btMotionState{
-	
-	virtual btTransform getWorldTransform()=0;
-	
-	virtual void setWorldTransform( const btTransform &tform ){}
-	
-	virtual void getWorldTransform( btTransform &tform )const{ tform=const_cast<bbKinematicMotionState*>( this )->getWorldTransform(); }
-};
-
-#endif

+ 0 - 327
modules/mojo3d-physics/physics/rigidbody.monkey2

@@ -1,327 +0,0 @@
-
-#rem
-
-Notes:
-
-* Have to remove/add bodies from world if collision shape changes. http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=5194
-
-* default btCollsionObject activationState=ACTIVE_TAG (1)?
-
-#end
-
-Namespace mojo3d.physics
-
-Private
-
-Class MotionState Extends btMotionState
-	
-	Method New( entity:Entity )
-		
-		_entity=entity
-	End
-	
-	Method getWorldTransform( tform:btTransform Ptr ) Override
-		
-		If Not _entity.RigidBody.Kinematic Print "Dynamic getWorldTransform! Position="+_entity.Position
-
-		tform->setOrigin( _entity.Position )
-		
-		tform->setBasis( _entity.Basis )
-	End
-	
-	Method setWorldTransform( tform:btTransform Ptr ) Override
-		
-		If _entity.RigidBody.Kinematic Print "Kinematic setWorldTransform!"
-		
-		_entity.Position=tform->getOrigin()
-		
-		_entity.Basis=tform->getBasis()
-	End
-	
-	Private
-	
-	Field _entity:Entity
-End
-
-Public
-
-Class Entity Extension
-	
-	Property RigidBody:RigidBody()
-		
-		Return GetComponent<RigidBody>()
-	End
-	
-End
-
-Class RigidBody Extends Component
-	
-	Const Type:=New ComponentType( "RigidBody",1,ComponentTypeFlags.Singleton )
-	
-	Method New( entity:Entity )
-		
-		Super.New( entity,Type )
-		
-		Local collider:=entity.Collider
-		Local inertia:btVector3=collider?.CalculateLocalInertia( _mass )
-		
-		_btmotion=New MotionState( entity )
-		
-		_btbody=New btRigidBody( _mass,_btmotion,collider.btShape,inertia )
-		
-		Kinematic=False
-		Mass=1
-		Friction=1
-		RollingFriction=1
-		Restitution=0
-		CollisionGroup=1
-		CollisionMask=1
-	End
-	
-	Method New( entity:Entity,body:RigidBody )
-		
-		Self.New( entity )
-		
-		Kinematic=body.Kinematic
-		Mass=body.Mass
-		Friction=body.Friction
-		RollingFriction=body.RollingFriction
-		Restitution=body.Restitution
-		CollisionGroup=body.CollisionGroup
-		CollisionMask=body.CollisionMask
-	End
-
-	Property World:World()
-		
-		Return World.GetWorld( Entity.Scene )
-	End
-	
-	Property Kinematic:Bool()
-		
-		Return _kinematic
-	
-	Setter( kinematic:Bool )
-		
-		If kinematic=_kinematic Return
-		
-		_kinematic=kinematic
-		
-		If _kinematic
-			_btbody.setCollisionFlags( _btbody.getCollisionFlags() | btCollisionObject.CF_KINEMATIC_OBJECT )
-			_btbody.setActivationState( DISABLE_DEACTIVATION )
-		Else
-			_btbody.setCollisionFlags( _btbody.getCollisionFlags() & ~btCollisionObject.CF_KINEMATIC_OBJECT )
-			_btbody.forceActivationState( ACTIVE_TAG )
-		Endif
-			
-'		_dirty|=Dirty.Kinematic
-	End
-	
-	Property Mass:Float()
-		
-		Return _mass
-		
-	Setter( mass:Float )
-		
-		If mass=_mass Return
-		
-		_mass=mass
-		
-		Local collider:=Entity.Collider
-		Local inertia:=collider?.CalculateLocalInertia( _mass )
-		_btbody.setMassProps( _mass,inertia )
-		
-'		_dirty|=Dirty.Mass
-	End
-
-	Property Friction:Float()
-		
-		Return _btbody.getFriction()
-	
-	Setter( friction:Float )
-		
-		_btbody.setFriction( friction )
-	End
-	
-	Property RollingFriction:Float()
-		
-		Return _btbody.getRollingFriction()
-	
-	Setter( friction:Float )
-		
-		_btbody.setRollingFriction( friction )
-	End
-	
-	Property Restitution:Float()
-		
-		Return _btbody.getRestitution()
-		
-	Setter( restitution:Float )
-		
-		_btbody.setRestitution( restitution )
-	End
-	
-	Property LinearVelocity:Vec3f()
-		
-		Return _btbody.getLinearVelocity()
-		
-	Setter( velocity:Vec3f )
-		
-		_btbody.setLinearVelocity( velocity )
-	End
-	
-	Property AngularVelocity:Vec3f()
-		
-		Return _btbody.getAngularVelocity()
-	
-	Setter( avelocity:Vec3f )
-		
-		_btbody.setAngularVelocity( avelocity )
-	End
-
-	Property CollisionGroup:Short()
-		
-		Return _collGroup
-		
-	Setter( collGroup:Short )
-		
-		_collGroup=collGroup
-	End
-	
-	Property CollisionMask:Short()
-		
-		Return _collMask
-		
-	Setter( collMask:Short )
-		
-		_collMask=collMask
-	End
-	
-	Property btBody:btRigidBody()
-	
-		Return _btbody
-	End
-	
-	Method ClearForces()
-
-		_btbody.clearForces()
-	End
-
-	Protected
-	
-	Method OnCopy:RigidBody( entity:Entity ) Override
-		
-		Return New RigidBody( entity,Self )
-	End
-
-	Method OnBeginUpdate() Override
-		
-'		Validate()
-		
-		Local collider:=Entity.Collider
-		
-		Local seq:=collider?.GuidSeq
-		
-		If seq<>_colliderseq
-			
-			If _rvisible
-				If Entity.ReallyVisible 
-					World.btWorld.removeRigidBody( _btbody )
-				Else
-					_rvisible=False
-					World.Remove( Self )
-				Endif
-			Endif
-			
-			_btbody.setCollisionShape( collider?.btShape )
-			Local inertia:btVector3=collider?.CalculateLocalInertia( _mass )
-			_btbody.setMassProps( _mass,inertia )
-			
-			If _rvisible World.btWorld.addRigidBody( _btbody )
-			
-			_colliderseq=seq
-			
-		Endif
-			
-		If Entity.ReallyVisible<>_rvisible
-			
-			_rvisible=Entity.ReallyVisible
-
-			If _rvisible World.Add( Self ) Else World.Remove( Self )
-				
-		Endif
-
-		If Not _kinematic And Entity.Seq<>_seq 
-			
-			_btbody.setWorldTransform( Entity.Matrix )
-		Endif
-		
-	End
-	
-	Method OnUpdate( elapsed:Float ) Override
-		
-'		If _kinematic Return
-		
-'		Local tform:=_btbody.getWorldTransform()
-		
-'		Entity.Position=tform.getOrigin()
-		
-'		Entity.Basis=tform.getBasis()
-		
-		_seq=Entity.Seq
-	End
-	
-	Method OnDestroy() Override
-		
-		If Not _rvisible Return
-		
-		_rvisible=False
-		
-		World.Remove( Self )
-	End
-	
-	Private
-	
-	Enum Dirty
-		Mass=1
-		Kinematic=2
-	End
-	
-	Field _kinematic:Bool=False
-	Field _mass:Float=1
-	Field _collGroup:Short=1
-	Field _collMask:Short=1
-
-	Field _btmotion:MotionState
-	Field _btbody:btRigidBody
-	Field _dirty:Dirty=Null
-	
-	Field _colliderseq:Int
-	Field _rvisible:Bool
-	Field _seq:Int
-	
-	Method Validate()
-		
-		If Not _dirty Return
-		
-		If _dirty & Dirty.Mass
-
-			Local collider:=Entity.Collider
-			Local inertia:btVector3=collider?.CalculateLocalInertia( _mass )
-			_btbody.setMassProps( _mass,inertia )
-		Endif
-		
-		If _dirty & Dirty.Kinematic
-			
-			If _kinematic
-				_btbody.setCollisionFlags( _btbody.getCollisionFlags() | btCollisionObject.CF_KINEMATIC_OBJECT )
-				_btbody.setActivationState( DISABLE_DEACTIVATION )
-			Else
-				_btbody.setCollisionFlags( _btbody.getCollisionFlags() & ~btCollisionObject.CF_KINEMATIC_OBJECT )
-				_btbody.forceActivationState( ACTIVE_TAG )
-			Endif
-		Endif
-		
-		_dirty=Null
-	End
-End

+ 0 - 163
modules/mojo3d-physics/physics/world.monkey2

@@ -1,163 +0,0 @@
-
-Namespace mojo3d.physics
-
-Class RaycastResult
-
-	Field time:Float
-	Field body:RigidBody
-	Field point:Vec3f
-	Field normal:Vec3f
-	
-	Method New()
-	End
-	
-	Method New( btresult:btCollisionWorld.ClosestRayResultCallback Ptr )
-		time=btresult->m_closestHitFraction
-		body=Cast<RigidBody>( btresult->m_collisionObject.getUserPointer() )
-		point=btresult->m_hitPointWorld
-		normal=btresult->m_hitNormalWorld
-	End
-	
-	Method New( btresult:btCollisionWorld.ClosestConvexResultCallback Ptr )
-		
-		Local castFrom:=Cast<Vec3f>( btresult->m_convexFromWorld )
-		Local castTo:=Cast<Vec3f>( btresult->m_convexToWorld )
-		
-		time=btresult->m_closestHitFraction
-		body=Cast<RigidBody>( btresult->m_hitCollisionObject.getUserPointer() )
-		point=(castTo-castFrom) * btresult->m_closestHitFraction + castFrom
-		normal=btresult->m_hitNormalWorld
-	End
-	
-End
-
-Class World
-	
-	Method New( scene:Scene )
-		
-		Assert( scene.GetDynamicProperty<World>( "$world" )=Null,"World already exists" )
-	
-		_scene=scene
-		
-		_scene.SetDynamicProperty( "$world",Self )
-		
-		Local broadphase:=New btDbvtBroadphase()
-		
-		Local config:=New btDefaultCollisionConfiguration()
-
-		Local dispatcher:=New btCollisionDispatcher( config )
-		
-		Local solver:=New btSequentialImpulseConstraintSolver()
-		
-		_btworld=New btDiscreteDynamicsWorld( dispatcher,broadphase,solver,config )
-
-		Gravity=New Vec3f( 0,-9.81,0 )
-		
-		_scene.Updating+=OnUpdate
-	End
-	
-	Property Scene:Scene()
-	
-		Return _scene
-	End
-
-	Property Gravity:Vec3f()
-	
-		Return _btworld.getGravity()
-		
-	Setter( gravity:Vec3f )
-	
-		_btworld.setGravity( gravity )
-	End
-	
-	Method RayCast:RaycastResult( rayFrom:Vec3f,rayTo:Vec3f )
-		
-		Local btresult:=New btCollisionWorld.ClosestRayResultCallback( rayFrom,rayTo )
-		
-		_btworld.rayTest( rayFrom,rayTo,Cast<btCollisionWorld.RayResultCallback Ptr>( Varptr btresult ) )
-		
-		If Not btresult.hasHit() Return Null
-		
-		Return New RaycastResult( Varptr btresult )
-	End
-	
-	Method ConvexSweep:RaycastResult( collider:ConvexCollider,castFrom:AffineMat4f,castTo:AffineMat4f )
-		
-		Local btresult:=New btCollisionWorld.ClosestConvexResultCallback( castFrom.t,castTo.t )
-		
-		_btworld.convexSweepTest( Cast<btConvexShape>( collider.btShape ),castFrom,castTo,Cast<btCollisionWorld.ConvexResultCallback Ptr>( Varptr btresult ),0 )
-		
-		If Not btresult.hasHit() Return Null
-		
-		Return New RaycastResult( Varptr btresult )
-	End
-	
-	Method ConvexSweep:RaycastResult( collider:ConvexCollider,castFrom:Vec3f,castTo:Vec3f )
-		
-		Return ConvexSweep( collider,AffineMat4f.Translation( castFrom ),AffineMat4f.Translation( castTo ) )
-	End
-	
-	Function GetCurrent:World()
-		
-		Return GetWorld( mojo3d.Scene.GetCurrent() )
-	End
-	
-	Property btWorld:btDynamicsWorld()
-		
-		Return _btworld
-	End
-	
-	Internal
-	
-	Function GetWorld:World( scene:Scene )
-		
-		Local world:=scene.GetDynamicProperty<World>( "$world" )
-		
-		If Not world world=New World( scene )
-			
-		Return world
-	End
-	
-	Method Add( body:RigidBody )
-		
-		Print "World.Add( RigidBody )"
-		
-		_bodies.Add( body )
-		
-		Local btbody:=body.btBody
-		
-		btbody.setUserPointer( Cast<Void Ptr>( body ) )
-		
-		_btworld.addRigidBody( btbody,body.CollisionGroup,body.CollisionMask )
-	End
-	
-	Method Remove( body:RigidBody )
-		
-		Print "World.Remove( RigidBody )"
-		
-		Local btbody:=body.btBody
-		
-		_btworld.removeRigidBody( btbody )
-		
-		body.btBody.setUserPointer( Null )
-
-		_bodies.Remove( body )
-	End
-	
-	Private
-	
-	Field _scene:Scene
-	
-	Field _btworld:btDynamicsWorld
-	
-	Field _newBodies:=New Stack<RigidBody>
-	
-	Field _bodies:=New Stack<RigidBody>
-
-	Method OnUpdate( elapsed:Float )
-		
-		_btworld.stepSimulation( 1.0/60.0 )
-		
-	End
-	
-End

+ 0 - 0
modules/mojo3d-physics/tests/assets/dummy.txt


+ 0 - 160
modules/mojo3d-physics/tests/fpsthing.monkey2

@@ -1,160 +0,0 @@
-Namespace myapp
-
-#Import "<std>"
-#Import "<mojo>"
-#Import "<mojo3d>"
-#Import "<mojo3d-loaders>"
-#Import "<mojo3d-physics>"
-
-#Import "assets/"
-
-#Import "../../mojo3d/tests/assets/miramar-skybox.jpg"
-
-#Import "../../mojo3d-loaders/tests/assets/castle/@/castle"
-
-Using std..
-Using mojo..
-Using mojo3d..
-
-Class FPSPlayer Extends FPSCollider
-	
-	Method New( entity:Entity )
-		Super.New( entity )
-	End
-	
-	Method OnUpdate( elapsed:Float ) Override
-		
-		If Keyboard.KeyDown( Key.Left )
-			
-			Entity.RotateY( 2.5 )
-			
-		Else If Keyboard.KeyDown( Key.Right )
-			
-			Entity.RotateY( -2.5 )
-		Endif
-
-		If Keyboard.KeyDown( Key.Up )
-			
-			Entity.MoveY( .25 )
-			
-		Else If Keyboard.KeyDown( Key.Down )
-			
-			Entity.MoveY( -.25 )
-			
-		Endif
-		
-		If Keyboard.KeyDown( Key.A )
-			
-			Entity.MoveZ( .15 )
-			
-		Else If Keyboard.KeyDown( Key.Z )
-			
-			Entity.MoveZ( -.15 )
-		Endif
-		
-		If Keyboard.KeyDown( Key.Space )
-			
-			YVelocity=.25
-			
-		Endif
-
-		'Update actual collider.
-		'
-		'Extending FPSCollider is probably not a great idea, this lot should really be in its own
-		'component, but haven't thought much about how to access YVelocity etc yet so this'll do for now.
-		'
-		Super.OnUpdate( elapsed )
-		
-	End
-	
-	
-End
-
-Class MyWindow Extends Window
-	
-	Field _scene:Scene
-	
-	Field _camera:Camera
-	
-	Field _light:Light
-	
-	Field _castle:Model
-	
-	Field _player:FPSPlayer
-	
-	Field _sphere:SphereCollider
-	
-	Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
-
-		Super.New( title,width,height,flags )
-		
-		Print New Vec3f( 0,1,0 ).Cross( New Vec3f( 0,1,0 ) )
-		
-		_scene=Scene.GetCurrent()
-		
-		_scene.SkyTexture=Texture.Load( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap )
-		
-		'create camera
-		'
-		_camera=New Camera
-		_camera.Near=.1
-		_camera.Far=200
-		
-		'create light
-		'
-		_light=New Light
-		_light.Rotate( 60,60,0 )	'aim directional light 'down' - Pi/2=90 degrees.
-		_light.CastsShadow=True
-		
-		'Load castle
-		'
-		Local sz:=50
-		
-'		_castle=Model.Load( "asset::E1M1_clean.obj" )	'On the off chance you've got this...have no idea of license issues though.
-		_castle=Model.Load( "asset::castle/CASTLE1.X" )
-		_castle.Mesh.FitVertices( New Boxf( -sz,sz ),True )
-		
-		Local collider:=New MeshCollider( _castle )
-		collider.Mesh=_castle.Mesh
-		
-		Local body:=New RigidBody( _castle )
-		body.Mass=0
-		
-		Local model:=Model.CreateCapsule( .5,.75,Axis.Y,24,New PbrMaterial( Color.Sky ) )
-		
-		_player=model.AddComponent<FPSPlayer>()
-		_player.Margin=.01
-		_player.Radius=.5
-		_player.Length=.75
-		
-	End
-	
-	Method OnRender( canvas:Canvas ) Override
-		
-		RequestRender()
-		
-		_scene.Update()
-		
-		Local src:=_player.Entity.Matrix * New Vec3f( 0,1,0 )
-		
-		Local dst:=_player.Entity.Matrix * New Vec3f( 0,1.5,-2.5 )
-		
-		_camera.Position=dst
-		
-		_camera.PointAt( _player.Entity.Position+New Vec3f( 0,1.5,0 ) )
-		
-		_scene.Render( canvas,_camera )
-		
-'		canvas.DrawText( "position="+_player._model.Position+", Rx="+_player._model.Rx+", Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )
-	End
-	
-End
-
-Function Main()
-	
-	New AppInstance
-	
-	New MyWindow
-	
-	App.Run()
-End

+ 0 - 128
modules/mojo3d-physics/tests/qcollide.monkey2

@@ -1,128 +0,0 @@
-
-Namespace qcollide
-
-Private
-
-Function F:String( f:Float )
-	If f>=0 
-		Local i:Int=Floor( f*100+.5 )
-		Return String( i / 100 ) + "." + ("00"+String( i Mod 100 )).Slice( -2 )
-	Else
-		Local i:Int=Floor( -f*100+.5 )
-		Return "-"+String( i / 100 ) + "." + ("00"+String( i Mod 100 )).Slice( -2 )
-	Endif
-End
-
-Function V:String( V:Vec3f )
-	'Return String(V)
-	Return "("+F(V.x)+","+F(V.y)+","+F(V.z)+")"
-End
-
-Function P:String( P:Planef )
-	Return "("+F(P.n.x)+","+F(P.n.y)+","+F(P.n.z)+","+F(P.d)+")"
-End
-
-Public
-
-Struct QResult
-	Field position:Vec3f
-	Field onground:Bool
-End
-
-Function QCollide:QResult( collider:ConvexCollider,src:Vec3f,dst:Vec3f )
-	
-	Local start:=src
-	
-	Local plane0:Planef,plane1:Planef,state:=0,casts:=0
-	
-	Local qresult:QResult
-	
-	Local debug:=""
-	
-	Repeat
-
-		If dst.Distance( src )<.001 Exit
-		
-		casts+=1
-		
-		Local cresult:=Scene.GetCurrent().World.ConvexSweep( collider,src,dst )
-		If Not cresult Exit
-
-'		debug+=", "
-		
-		If cresult.normal.y>.7071 qresult.onground=True
-			
-		Local plane:=New Planef( cresult.point,cresult.normal )
-
-		plane.d-=collider.Margin
-		
-		Local tline:=New Linef( src,dst-src )
-		
-		Local t:=plane.TIntersect( tline )
-		
-		If t>=1 dst=tline * t ; Exit
-		
-		If t>0 src=tline * t
-		
-		Select state
-
-		Case 0
-			
-			dst=plane.Nearest( dst )
-			
-'			debug+="A "+P( plane )
-				
-			plane0=plane
-				
-			state=1
-		
-		Case 1
-
-			Local v:=plane0.n.Cross( plane.n )
-			
-			If v.Length>.0001
-				
-				Local groove:=New Linef( src,v )
-				
-'				Local d0:=plane0.Distance( dst )
-				
-				dst=groove.Nearest( dst )
-				
-'				debug+="B "+P( plane )+" d0="+F(d0)+" sd0="+F(plane0.Distance(src))+" dd0="+F(plane0.Distance(dst))
-				
-				plane1=plane
-				
-				state=2
-			
-			Else
-				
-'				debug+="C "+P( plane )
-
-				dst=plane.Nearest( dst )
-
-				plane0=plane
-				
-				state=1
-			
-			Endif
-				
-		Case 2
-
-'			Local d0:=plane0.Distance( dst )
-'			Local d1:=plane1.Distance( dst )
-'			debug+="D "+P( plane )+" d0="+F(d0)+" d1="+F(d1)
-				
-			dst=src
-			
-			Exit
-		End
-
-	Forever
-	
-'	If casts>2 Print debug.Slice( 2 )+" casts="+casts
-
-	qresult.position=dst
-	
-	Return qresult
-
-End

+ 0 - 145
modules/mojo3d-physics/tests/shapes.monkey2

@@ -1,145 +0,0 @@
-
-Namespace myapp
-
-#Import "<std>"
-#Import "<mojo>"
-#Import "<mojo3d>"
-#Import "<mojo3d-physics>"
-
-#Import "assets/"
-
-#Import "util"
-
-Using std..
-Using mojo..
-Using mojo3d..
-
-Class MyWindow Extends Window
-	
-	Field _scene:Scene
-	
-	Field _camera:Camera
-	
-	Field _light:Light
-	
-	Field _ground:Model
-	
-	Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
-
-		Super.New( title,width,height,flags )
-		
-		_scene=Scene.GetCurrent()
-		
-		'create camera
-		'
-		_camera=New Camera
-		_camera.Near=.1
-		_camera.Far=60
-		_camera.Move( 0,10,-10 )
-		New FlyBehaviour( _camera )
-		
-		Local camCollider:=New SphereCollider( _camera )
-		camCollider.Radius=1
-		Local camBody:=New RigidBody( _camera )
-		camBody.Kinematic=True
-		camBody.Mass=0
-		
-		'create light
-		'
-		_light=New Light
-		_light.RotateX( 75,15 )
-		
-		'create ground
-		'
-		Local groundBox:=New Boxf( -60,-1,-60,60,0,60 )
-		
-		_ground=Model.CreateBox( groundBox,16,16,16,New PbrMaterial( Color.Green ) )
-		
-		Local groundCollider:=New BoxCollider( _ground )
-		groundCollider.Box=groundBox
-		
-		Local groundBody:=New RigidBody( _ground )
-		groundBody.Mass=0
-		
-		Local material:=New PbrMaterial( Color.White )
-
-		Local box0:=New Boxf( -1,-5,-1,1,5,1 )		
-		Local model0:=Model.CreateBox( box0,1,1,1,material )
-		Local collider0:=New BoxCollider( model0 )
-		collider0.Box=box0
-		Local body0:=New RigidBody( model0 )
-		
-		Local model1:=Model.CreateSphere( 1,32,16,material )
-		Local collider1:=New SphereCollider( model1 )
-		Local body1:=New RigidBody( model1 )
-
-		Local model2:=Model.CreateCylinder( 1,8,Axis.Y,32,material )
-		Local collider2:=New CylinderCollider( model2 )
-		collider2.Radius=1
-		collider2.Length=8
-		Local body2:=New RigidBody( model2 )
-
-		Local model3:=Model.CreateCapsule( 1,10,Axis.Y,32,material )
-		Local collider3:=New CapsuleCollider( model3 )
-		collider3.Radius=1
-		collider3.Length=10
-		Local body3:=New RigidBody( model3 )
-
-		Local model4:=Model.CreateCone( 2.5,5,Axis.Y,32,material )
-		Local collider4:=New ConeCollider( model4 )
-		collider4.Radius=2.5
-		collider4.Length=5
-		Local body4:=New RigidBody( model4 )
-		
-		Local models:=New Model[]( model0,model1,model2,model3,model4 )
-		
-		#rem
-		For Local x:=-40 To 40 Step 8
-			
-			For Local z:=-40 To 40 Step 8
-				
-				Local i:=Int( Rnd(5) )
-				
-				Local model:=models[i].Copy()
-				
-				model.Materials=New Material[]( New PbrMaterial( New Color( Rnd(),Rnd(),Rnd() ) ) )
-				
-				model.Move( x,10,z )
-			Next
-		
-		Next
-		#end
-		
-		Local x:=0.0
-		
-		For Local model:=Eachin models
-			
-			model.Move( x,10,0 )
-			
-			x+=5.0
-			
-			'model.Destroy()
-		Next
-	End
-	
-	Method OnRender( canvas:Canvas ) Override
-		
-		RequestRender()
-		
-		_scene.Update()
-		
-		_scene.Render( canvas,_camera )
-		
-		canvas.DrawText( "Camera pos="+_camera.Position+", Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )
-	End
-	
-End
-
-Function Main()
-
-	New AppInstance
-	
-	New MyWindow
-	
-	App.Run()
-End

+ 0 - 42
modules/mojo3d-physics/tests/util.monkey2

@@ -1,42 +0,0 @@
-
-Namespace util
-
-Function Fly( entity:Entity,view:View )
-	
-	Const rspeed:=2.0
-
-	If Keyboard.KeyDown( Key.Up )
-		entity.RotateX( rspeed )
-	Else If Keyboard.KeyDown( Key.Down )
-		entity.RotateX( -rspeed )
-	Endif
-	
-	If Keyboard.KeyDown( Key.Q )
-		entity.RotateZ( rspeed )
-	Else If Keyboard.KeyDown( Key.W )
-		entity.RotateZ( -rspeed )
-	Endif
-	
-	If Keyboard.KeyDown( Key.Left )
-		entity.RotateY( rspeed,True )
-	Else If Keyboard.KeyDown( Key.Right )
-		entity.RotateY( -rspeed,True )
-	Endif
-
-	If Mouse.ButtonDown( MouseButton.Left )
-		If Mouse.X<view.Width/3
-			entity.RotateY( rspeed,True )
-		Else If Mouse.X>view.Width/3*2
-			entity.RotateY( -rspeed,True )
-		Else
-			entity.Move( New Vec3f( 0,0,.1 ) )
-		Endif
-	Endif
-	
-	If Keyboard.KeyDown( Key.A )
-		entity.MoveZ( .1 )	'( New Vec3f( 0,0,.1 ) )
-	Else If Keyboard.KeyDown( Key.Z )
-		entity.MoveZ( -.1 )	'( New Vec3f( 0,0,-.1 ) )
-	Endif
-		
-End

+ 29 - 0
modules/mojo3d/entities/camera.monkey2

@@ -148,6 +148,35 @@ Class Camera Extends Entity
 		Return world_coords
 		Return world_coords
 	End
 	End
 	
 	
+	Method Pick:RayCastResult( viewportCoords:Vec2f,collisionMask:Int=-1 )
+		
+		If viewportCoords.x<0 Or viewportCoords.y<0 Or viewportCoords.x>=_viewport.Width Or viewportCoords.y>=_viewport.Height Return Null
+		
+		Local vpcoords:=viewportCoords
+		
+		vpcoords.x=vpcoords.x/_viewport.Width*2-1
+		vpcoords.y=vpcoords.y/_viewport.Height*2-1
+		
+		Local iproj:=-ProjectionMatrix
+		
+		Local rayFrom:=Matrix * (iproj * New Vec3f( vpcoords,-1 ))
+		Local rayTo:=Matrix * (iproj * New Vec3f( vpcoords,1 ))
+		
+		Return Scene.RayCast( rayFrom,rayTo,collisionMask )
+	End
+	
+	Method MousePick:RayCastResult( collisionMask:Int=-1 )
+	
+		Local mouse:=Cast<Vec2f>( Mouse.Location )
+
+		If App.ActiveWindow mouse.y=App.ActiveWindow.Height-mouse.y
+			
+		mouse.x-=Viewport.min.x
+		mouse.y-=Viewport.min.y
+		
+		Return Pick( mouse,collisionMask )
+	End
+	
 	Protected
 	Protected
 
 
 	Method New( camera:Camera,parent:Entity )
 	Method New( camera:Camera,parent:Entity )

+ 11 - 4
modules/mojo3d/mojo3d.monkey2

@@ -4,11 +4,19 @@ Namespace mojo3d
 #Import "<std>"
 #Import "<std>"
 #Import "<mojo>"
 #Import "<mojo>"
 #Import "<opengl>"
 #Import "<opengl>"
+#import "<bullet>"
+
+Using std..
+Using mojo..
+Using opengl..
+Using bullet..
 
 
 #Import "assets/"
 #Import "assets/"
 
 
 #Import "components/animation"
 #Import "components/animation"
 #Import "components/animator"
 #Import "components/animator"
+#Import "components/rigidbody"
+#Import "components/collider"
 #Import "components/behaviour"
 #Import "components/behaviour"
 #Import "components/flybehaviour"
 #Import "components/flybehaviour"
 
 
@@ -37,11 +45,13 @@ Namespace mojo3d
 #Import "render/effects/monochromeeffect"
 #Import "render/effects/monochromeeffect"
 #Import "render/effects/bloomeffect"
 #Import "render/effects/bloomeffect"
 
 
+#Import "scene/raycastresult"
 #Import "scene/component"
 #Import "scene/component"
 #Import "scene/dynamicobject"
 #Import "scene/dynamicobject"
 #Import "scene/entity"
 #Import "scene/entity"
 #Import "scene/entityexts"
 #Import "scene/entityexts"
 #Import "scene/scene"
 #Import "scene/scene"
+#Import "scene/world"
 
 
 #Import "loader/loader"
 #Import "loader/loader"
 #Import "loader/gltf2"
 #Import "loader/gltf2"
@@ -50,10 +60,7 @@ Namespace mojo3d
 #Import "geometry/mesh"
 #Import "geometry/mesh"
 #Import "geometry/meshprims"
 #Import "geometry/meshprims"
 '#Import "geometry/util3d"
 '#Import "geometry/util3d"
-
-Using std..
-Using mojo..
-Using opengl..
+#Import "geometry/bttypeconvs"
 
 
 Function Main()
 Function Main()
 	
 	

+ 19 - 0
modules/mojo3d/render/renderer.monkey2

@@ -89,6 +89,25 @@ Class Renderer
 		Return _current
 		Return _current
 	End
 	End
 	
 	
+	#rem monkeydoc @hidden DON'T USE! WILL CHANGE!
+	#end
+	Method Render( scene:Scene,canvas:Canvas )
+		
+		Local viewport:=canvas.Viewport
+		
+		For Local camera:=Eachin scene.Cameras
+			
+			canvas.Viewport=camera.Viewport
+			
+			canvas.Flush()
+			
+			Render( scene,camera,canvas.GraphicsDevice )
+		Next
+		
+		canvas.Viewport=viewport
+	End
+	
+	
 	#rem monkeydoc @hidden DON'T USE! WILL CHANGE!
 	#rem monkeydoc @hidden DON'T USE! WILL CHANGE!
 	#end
 	#end
 	Method Render( scene:Scene,camera:Camera,device:GraphicsDevice ) Virtual
 	Method Render( scene:Scene,camera:Camera,device:GraphicsDevice ) Virtual

+ 5 - 26
modules/mojo3d/scene/component.monkey2

@@ -48,7 +48,6 @@ Class Component
 		_entity=entity
 		_entity=entity
 		_type=type
 		_type=type
 		_entity.AddComponent( Self )
 		_entity.AddComponent( Self )
-		Modified()
 	End
 	End
 	
 	
 	Property Entity:Entity()
 	Property Entity:Entity()
@@ -61,26 +60,7 @@ Class Component
 		Return _type
 		Return _type
 	End
 	End
 	
 	
-	Property GuidSeq:Int()
-		
-		Return _guidseq
-	End
-	
-	Property Seq:Int()
-		
-		Return _seq
-	End
-	
-	Protected
-	
-	Method Modified()
-		
-		_nextguidseq+=1
-		_guidseq=_nextguidseq
-		_seq+=1
-	End
-		
-	Internal
+Internal
 
 
 	Method OnCopy:Component( entity:Entity ) Virtual
 	Method OnCopy:Component( entity:Entity ) Virtual
 
 
@@ -94,7 +74,7 @@ Class Component
 	
 	
 	Method OnHide() Virtual
 	Method OnHide() Virtual
 	End
 	End
-		
+	
 	Method OnBeginUpdate() Virtual
 	Method OnBeginUpdate() Virtual
 	End
 	End
 	
 	
@@ -104,14 +84,13 @@ Class Component
 	Method OnDestroy() Virtual
 	Method OnDestroy() Virtual
 	End
 	End
 	
 	
-	Private
+	Method OnCollide( body:RigidBody ) virtual
+	End
 	
 	
-	Global _nextguidseq:=0
+	Private
 	
 	
 	Field _entity:Entity
 	Field _entity:Entity
 	Field _type:ComponentType
 	Field _type:ComponentType
-	Field _guidseq:=0
-	Field _seq:=0
 End
 End
 
 
 
 

+ 22 - 6
modules/mojo3d/scene/entity.monkey2

@@ -33,6 +33,13 @@ Class Entity Extends DynamicObject
 	#end
 	#end
 	Field Shown:Void()
 	Field Shown:Void()
 	
 	
+	#rem monkeydoc Collided signal.
+	
+	After after an entity has collided with a rigidbody.
+	
+	#end
+	Field Collided:Void( rigidBody:RigidBody )
+	
 	#rem monkeydoc Creates a new entity.
 	#rem monkeydoc Creates a new entity.
 	#end
 	#end
 	Method New( parent:Entity=Null )
 	Method New( parent:Entity=Null )
@@ -113,7 +120,7 @@ Class Entity Extends DynamicObject
 			_scene.RootEntities.Add( Self )
 			_scene.RootEntities.Add( Self )
 		Endif
 		Endif
 		
 		
-		ValidateVisibility()
+		UpdateVisibility()
 			
 			
 		Invalidate()
 		Invalidate()
 	End
 	End
@@ -144,7 +151,7 @@ Class Entity Extends DynamicObject
 		
 		
 		_visible=visible
 		_visible=visible
 		
 		
-		ValidateVisibility()
+		UpdateVisibility()
 	End
 	End
 	
 	
 	#rem monkeydoc True if entity and all parents are visible.
 	#rem monkeydoc True if entity and all parents are visible.
@@ -312,7 +319,7 @@ Class Entity Extends DynamicObject
 		
 		
 		Invalidate()
 		Invalidate()
 	End
 	End
-	
+
 	#rem monkeydoc Destroys the entity and all of its children.
 	#rem monkeydoc Destroys the entity and all of its children.
 	#end
 	#end
 	Method Destroy()
 	Method Destroy()
@@ -323,7 +330,7 @@ Class Entity Extends DynamicObject
 		
 		
 		_visible=False
 		_visible=False
 		
 		
-		ValidateVisibility()
+		UpdateVisibility()
 		
 		
 		For Local c:=Eachin _components
 		For Local c:=Eachin _components
 			c.OnDestroy()
 			c.OnDestroy()
@@ -483,6 +490,15 @@ Class Entity Extends DynamicObject
 			e.Update( elapsed )
 			e.Update( elapsed )
 		Next
 		Next
 	End
 	End
+	
+	Method Collide( body:RigidBody )
+		
+		For Local c:=Eachin _components
+			c.OnCollide( body )
+		Next
+		
+		Collided( body )
+	End
 
 
 Private
 Private
 	
 	
@@ -533,7 +549,7 @@ Private
 		InvalidateWorld()
 		InvalidateWorld()
 	End
 	End
 	
 	
-	Method ValidateVisibility()
+	Method UpdateVisibility()
 		
 		
 		If _visible And (Not _parent Or _parent._rvisible)
 		If _visible And (Not _parent Or _parent._rvisible)
 			
 			
@@ -562,7 +578,7 @@ Private
 		
 		
 		For Local child:=Eachin _children
 		For Local child:=Eachin _children
 			
 			
-			child.ValidateVisibility()
+			child.UpdateVisibility()
 		Next
 		Next
 	
 	
 	End
 	End

+ 44 - 24
modules/mojo3d/scene/scene.monkey2

@@ -3,9 +3,7 @@ Namespace mojo3d
 
 
 #rem monkeydoc The Scene class.
 #rem monkeydoc The Scene class.
 #end
 #end
-Class Scene Extends DynamicObject
-	
-	Field Updating:Void( elapsed:Float )
+Class Scene
 
 
 	#rem monkeydoc Creates a new scene.
 	#rem monkeydoc Creates a new scene.
 	#end
 	#end
@@ -16,6 +14,8 @@ Class Scene Extends DynamicObject
 		_ambientDiffuse=Color.DarkGrey
 		_ambientDiffuse=Color.DarkGrey
 		
 		
 		_envColor=Color.White
 		_envColor=Color.White
+		
+		_world=New World( Self )
 	End
 	End
 	
 	
 	#rem monkeydoc The sky texture.
 	#rem monkeydoc The sky texture.
@@ -128,19 +128,6 @@ Class Scene Extends DynamicObject
 	
 	
 	#rem monkeydoc Updates the scene.
 	#rem monkeydoc Updates the scene.
 	#end
 	#end
-	Method Update( elapsed:Float )
-		
-		For Local e:=Eachin _rootEntities
-			e.BeginUpdate()
-		Next
-		
-		Updating( elapsed )
-		
-		For Local e:=Eachin _rootEntities
-			e.Update( elapsed )
-		Next
-	End
-	
 	Method Update()
 	Method Update()
 		
 		
 		Global time:=0.0
 		Global time:=0.0
@@ -159,15 +146,32 @@ Class Scene Extends DynamicObject
 	
 	
 	#rem monkeydoc Renders the scene to	a canvas.
 	#rem monkeydoc Renders the scene to	a canvas.
 	#end
 	#end
-	Method Render( canvas:Canvas,camera:Camera )
+	Method Render( canvas:Canvas,camera:Camera=Null )
+		
+		If camera
 			
 			
-		camera.Viewport=canvas.Viewport
+			camera.Viewport=canvas.Viewport
+			
+			canvas.Flush()
+		
+			Local renderer:=Renderer.GetCurrent()
+		
+			renderer.Render( Self,camera,canvas.GraphicsDevice )	
 			
 			
+			Return
+			
+		Endif
+		
 		canvas.Flush()
 		canvas.Flush()
 		
 		
 		Local renderer:=Renderer.GetCurrent()
 		Local renderer:=Renderer.GetCurrent()
 		
 		
-		renderer.Render( Self,camera,canvas.GraphicsDevice )
+		renderer.Render( Self,canvas )
+	End
+	
+	Method RayCast:RayCastResult( rayFrom:Vec3f,rayTo:Vec3f,collisionMask:Int )
+		
+		Return _world.RayCast( rayFrom,rayTo,collisionMask )
 	End
 	End
 
 
 	#rem monkeydoc Enumerates all entities in the scene with null parents.
 	#rem monkeydoc Enumerates all entities in the scene with null parents.
@@ -181,8 +185,6 @@ Class Scene Extends DynamicObject
 	#end
 	#end
 	Function SetCurrent( scene:Scene )
 	Function SetCurrent( scene:Scene )
 		
 		
-'		DebugAssert( Not _current,"Scene.Current already set" )
-		
 		_current=scene
 		_current=scene
 	End
 	End
 	
 	
@@ -222,6 +224,11 @@ Class Scene Extends DynamicObject
 		Return _renderables
 		Return _renderables
 	End
 	End
 	
 	
+	Property World:World()
+		
+		Return _world
+	End
+	
 	Private
 	Private
 	
 	
 	Global _current:Scene
 	Global _current:Scene
@@ -236,12 +243,25 @@ Class Scene Extends DynamicObject
 	Field _clearColor:Color
 	Field _clearColor:Color
 	Field _ambientDiffuse:Color
 	Field _ambientDiffuse:Color
 	
 	
-	Field _postEffects:=New Stack<PostEffect>
-	
 	Field _rootEntities:=New Stack<Entity>
 	Field _rootEntities:=New Stack<Entity>
-	
 	Field _cameras:=New Stack<Camera>
 	Field _cameras:=New Stack<Camera>
 	Field _lights:=New Stack<Light>
 	Field _lights:=New Stack<Light>
 	Field _renderables:=New Stack<Renderable>()
 	Field _renderables:=New Stack<Renderable>()
+	Field _postEffects:=New Stack<PostEffect>
+	
+	Field _world:World
+	
+	Method Update( elapsed:Float )
+		
+		For Local e:=Eachin _rootEntities
+			e.BeginUpdate()
+		Next
+		
+		_world.Update( elapsed )
+		
+		For Local e:=Eachin _rootEntities
+			e.Update( elapsed )
+		Next
+	End
 			
 			
 End
 End

+ 1 - 1
modules/mojo3d/tests/donut.monkey2

@@ -62,7 +62,7 @@ Class MyWindow Extends Window
 		
 		
 		util.Fly( _camera,Self )
 		util.Fly( _camera,Self )
 		
 		
-		_scene.Render( canvas,_camera )
+		_scene.Render( canvas )',_camera )
 		
 		
 		canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )
 		canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )
 	End
 	End

+ 2 - 6
modules/mojo3d/tests/ducks.monkey2

@@ -44,6 +44,7 @@ Class MyWindow Extends Window
 		'create camera
 		'create camera
 		'
 		'
 		_camera=New Camera
 		_camera=New Camera
+		_camera.Viewport=New Recti( 0,0,640,480 )
 		_camera.Near=.1
 		_camera.Near=.1
 		_camera.Far=50
 		_camera.Far=50
 		_camera.FOV=90
 		_camera.FOV=90
@@ -53,7 +54,6 @@ Class MyWindow Extends Window
 		
 		
 		'create light
 		'create light
 		_light=New Light
 		_light=New Light
-'		_light.Type=LightType.Point
 		_light.Rotate( 75,15,0 )
 		_light.Rotate( 75,15,0 )
 		_light.Move( 0,20,0 )
 		_light.Move( 0,20,0 )
 		_light.Range=40
 		_light.Range=40
@@ -75,8 +75,6 @@ Class MyWindow Extends Window
 		
 		
 		_ducks.Push( root )
 		_ducks.Push( root )
 		
 		
-		'#rem
-		
 		For Local m:=0.0 To 1.0 Step .125
 		For Local m:=0.0 To 1.0 Step .125
 		
 		
 			For Local i:=0.0 Until 360.0 Step 24
 			For Local i:=0.0 Until 360.0 Step 24
@@ -104,8 +102,6 @@ Class MyWindow Extends Window
 			Next
 			Next
 		Next
 		Next
 		
 		
-		'#End
-		
 		duck.Destroy()
 		duck.Destroy()
 	End
 	End
 	
 	
@@ -115,7 +111,7 @@ Class MyWindow Extends Window
 		
 		
 		_scene.Update()
 		_scene.Update()
 		
 		
-		_scene.Render( canvas,_camera )
+		_scene.Render( canvas )
 
 
 		canvas.Scale( Width/640.0,Height/480.0 )
 		canvas.Scale( Width/640.0,Height/480.0 )
 		
 		

+ 1 - 1
modules/std/misc/base64.monkey2

@@ -1,5 +1,5 @@
 
 
-Namespace std.stringio
+Namespace std.base64
 
 
 Private
 Private
 
 

+ 245 - 0
modules/std/misc/digest.monkey2

@@ -0,0 +1,245 @@
+
+Namespace std.digest
+
+'Thanks to mx2 user Jesse for converting the original bmx code by bmx user Yan!
+
+Private
+
+Function Hex:String(val:UInt)
+	Local hex:=("00000000"+stringio.ULongToString(val,16)).Right(8)
+	Return hex
+End Function
+ 
+Function Rol:UInt(val:UInt, shift:Int)
+	Return (val Shl shift) | (val Shr (32 - shift))
+End Function
+ 
+Function Ror:UInt(val:UInt, shift:Int)
+	Return (val Shr shift) | (val Shl (32 - shift))
+End Function
+
+'Todo: should this be an operator?
+Function UShr:UInt(val:UInt, shift:Int)
+	Return val Shr shift
+End
+ 
+Function LEHex:String(val:UInt)
+	Local out:String = Hex(val)
+	Return out.Slice(6,8) + out.Slice(4,6) + out.Slice(2,4) + out.Slice(0,2)
+End Function
+ 
+Public
+
+Function MD5:String( in:String )
+	
+	Local h0:Int = $67452301, h1:Int = $EFCDAB89, h2:Int = $98BADCFE, h3:Int = $10325476
+    
+	Local r:Int[] = New Int[](
+		7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,
+		5,  9, 14, 20,  5,  9, 14, 20,  5,  9, 14, 20,  5,  9, 14, 20,
+		4, 11, 16, 23,  4, 11, 16, 23,  4, 11, 16, 23,  4, 11, 16, 23,
+		6, 10, 15, 21,  6, 10, 15, 21,  6, 10, 15, 21,  6, 10, 15, 21)
+                
+	Local k:Int[] = New Int[](
+		$D76AA478, $E8C7B756, $242070DB, $C1BDCEEE, $F57C0FAF, $4787C62A,
+		$A8304613, $FD469501, $698098D8, $8B44F7AF, $FFFF5BB1, $895CD7BE,
+		$6B901122, $FD987193, $A679438E, $49B40821, $F61E2562, $C040B340,
+		$265E5A51, $E9B6C7AA, $D62F105D, $02441453, $D8A1E681, $E7D3FBC8,
+		$21E1CDE6, $C33707D6, $F4D50D87, $455A14ED, $A9E3E905, $FCEFA3F8,
+		$676F02D9, $8D2A4C8A, $FFFA3942, $8771F681, $6D9D6122, $FDE5380C,
+		$A4BEEA44, $4BDECFA9, $F6BB4B60, $BEBFBC70, $289B7EC6, $EAA127FA,
+		$D4EF3085, $04881D05, $D9D4D039, $E6DB99E5, $1FA27CF8, $C4AC5665,
+		$F4292244, $432AFF97, $AB9423A7, $FC93A039, $655B59C3, $8F0CCC92,
+		$FFEFF47D, $85845DD1, $6FA87E4F, $FE2CE6E0, $A3014314, $4E0811A1,
+		$F7537E82, $BD3AF235, $2AD7D2BB, $EB86D391)
+                
+	Local intCount:Int = (((in.Length + 8) Shr 6) + 1) Shl 4
+  	Local data:Int[] = New Int[intCount]
+  
+	For Local c:Int=0 Until in.Length
+		data[c Shr 2] = data[c Shr 2] | ((in[c] & $FF) Shl ((c & 3) Shl 3))
+  	Next
+  	
+	data[in.Length Shr 2] = data[in.Length Shr 2] | ($80 Shl ((in.Length & 3) Shl 3)) 
+	data[data.Length - 2] = (Long(in.Length) * 8) & $FFFFFFFF
+	data[data.Length - 1] = (Long(in.Length) * 8) Shr 32
+  
+	For Local chunkStart:Int=0 Until intCount Step 16
+		
+		Local a:Int = h0, b:Int = h1, c:Int = h2, d:Int = h3
+    
+	    For Local i:Int=0 To 15
+		    
+			Local f:Int = d ~ (b & (c ~ d))
+			Local t:Int = d
+      
+			d = c ; c = b
+			b = Rol((a + f + k[i] + data[chunkStart + i]), r[i]) + b
+			a = t
+		Next
+    
+		For Local i:Int=16 To 31
+			
+			Local f:Int = c ~ (d & (b ~ c))
+      		Local t:Int = d
+ 
+			d = c ; c = b
+			b = Rol((a + f + k[i] + data[chunkStart + (((5 * i) + 1) & 15)]), r[i]) + b
+			a = t
+		Next
+    
+		For Local i:Int=32 To 47
+			
+			Local f:Int = b ~ c ~ d
+			Local t:Int = d
+      
+			d = c ; c = b
+			b = Rol((a + f + k[i] + data[chunkStart + (((3 * i) + 5) & 15)]), r[i]) + b
+			a = t
+		Next
+    
+		For Local i:Int=48 To 63
+			
+			Local f:Int = c ~ (b | ~d)
+			Local t:Int = d
+      
+			d = c ; c = b
+			b = Rol((a + f + k[i] + data[chunkStart + ((7 * i) & 15)]), r[i]) + b
+			a = t
+		Next
+    
+		h0 += a 
+		h1 += b
+		h2 += c 
+		h3 += d
+
+	Next
+  
+	Return (LEHex(h0) + LEHex(h1) + LEHex(h2) + LEHex(h3)).ToLower()
+
+End
+ 
+Function SHA1:String( in:String )
+	
+	Local h0:Int = $67452301, h1:Int = $EFCDAB89, h2:Int = $98BADCFE, h3:Int = $10325476, h4:Int = $C3D2E1F0
+  
+	Local intCount:Int = (((in.Length + 8) Shr 6) + 1) Shl 4
+	Local data:Int[] = New Int[intCount]
+  
+	For Local c:Int=0 Until in.Length
+		data[c Shr 2] = (data[c Shr 2] Shl 8) | (in[c] & $FF)
+ 	Next
+ 	
+	data[in.Length Shr 2] = ((data[in.Length Shr 2] Shl 8) | $80) Shl ((3 - (in.Length & 3)) Shl 3) 
+	data[data.Length - 2] = (Long(in.Length) * 8) Shr 32
+	data[data.Length - 1] = (Long(in.Length) * 8) & $FFFFFFFF
+  
+	For Local chunkStart:Int=0 Until intCount Step 16
+		
+		Local a:Int = h0, b:Int = h1, c:Int = h2, d:Int = h3, e:Int = h4
+ 
+		Local w := data.Slice(chunkStart,chunkStart+16).Resize(80)
+    
+		For Local i:Int=16 To 79
+			w[i] = Rol(w[i - 3] ~ w[i - 8] ~ w[i - 14] ~ w[i - 16], 1)
+		Next
+    
+		For Local i:Int=0 To 19
+			Local t:Int = Rol(a, 5) + (d ~ (b & (c ~ d))) + e + $5A827999 + w[i]
+      
+			e = d ; d = c
+			c = Rol(b, 30)
+			b = a ; a = t
+		Next
+    
+		For Local i:Int=20 To 39
+			Local t:Int = Rol(a, 5) + (b ~ c ~ d) + e + $6ED9EBA1 + w[i]
+      
+			e = d ; d = c
+			c = Rol(b, 30)
+			b = a ; a = t
+		Next
+    
+		For Local i:Int=40 To 59
+			Local t:Int = Rol(a, 5) + ((b & c) | (d & (b | c))) + e + $8F1BBCDC + w[i]
+      
+			e = d ; d = c
+			c = Rol(b, 30)
+			b = a ; a = t
+		Next
+ 
+		For Local i:Int=60 To 79
+			Local t:Int = Rol(a, 5) + (b ~ c ~ d) + e + $CA62C1D6 + w[i]
+      
+			e = d ; d = c
+			c = Rol(b, 30)
+			b = a ; a = t
+		Next
+    
+		h0 += a
+		h1 += b
+		h2 += c
+		h3 += d
+		h4 += e
+	Next
+  
+	Return (Hex(h0) + Hex(h1) + Hex(h2) + Hex(h3) + Hex(h4)).ToLower()
+
+End
+ 
+Function SHA256:String( in:String )
+	
+	Local h0:Int = $6A09E667, h1:Int = $BB67AE85, h2:Int = $3C6EF372, h3:Int = $A54FF53A
+	Local h4:Int = $510E527F, h5:Int = $9B05688C, h6:Int = $1F83D9AB, h7:Int = $5BE0CD19
+  
+	Local k:Int[] = New Int[](
+		$428A2F98, $71374491, $B5C0FBCF, $E9B5DBA5, $3956C25B, $59F111F1,
+		$923F82A4, $AB1C5ED5, $D807AA98, $12835B01, $243185BE, $550C7DC3,
+		$72BE5D74, $80DEB1FE, $9BDC06A7, $C19BF174, $E49B69C1, $EFBE4786,
+		$0FC19DC6, $240CA1CC, $2DE92C6F, $4A7484AA, $5CB0A9DC, $76F988DA,
+		$983E5152, $A831C66D, $B00327C8, $BF597FC7, $C6E00BF3, $D5A79147,
+		$06CA6351, $14292967, $27B70A85, $2E1B2138, $4D2C6DFC, $53380D13,
+		$650A7354, $766A0ABB, $81C2C92E, $92722C85, $A2BFE8A1, $A81A664B,
+		$C24B8B70, $C76C51A3, $D192E819, $D6990624, $F40E3585, $106AA070,
+		$19A4C116, $1E376C08, $2748774C, $34B0BCB5, $391C0CB3, $4ED8AA4A,
+		$5B9CCA4F, $682E6FF3, $748F82EE, $78A5636F, $84C87814, $8CC70208,
+		$90BEFFFA, $A4506CEB, $BEF9A3F7, $C67178F2)
+ 
+	Local intCount:Int = (((in.Length + 8) Shr 6) + 1) Shl 4
+	Local data:Int[] = New Int[intCount]
+  
+	For Local c:Int=0 Until in.Length
+		data[c Shr 2] = (data[c Shr 2] Shl 8) | (in[c] & $FF)
+	Next
+	
+	data[in.Length Shr 2] = ((data[in.Length Shr 2] Shl 8) | $80) Shl ((3 - (in.Length & 3)) Shl 3) 
+	data[data.Length - 2] = (Long(in.Length) * 8) Shr 32
+	data[data.Length - 1] = (Long(in.Length) * 8) & $FFFFFFFF
+  
+	For Local chunkStart:Int=0 Until intCount Step 16
+		
+		Local a:Int = h0, b:Int = h1, c:Int = h2, d:Int = h3, e:Int = h4, f:Int = h5, g:Int = h6, h:Int = h7
+ 
+		Local w:=data.Slice(chunkStart,chunkStart+16).Resize(64)
+    
+		For Local i:Int=16 To 63
+			w[i] = w[i - 16] + (Ror(w[i - 15], 7) ~ Ror(w[i - 15], 18) ~ ( UShr(w[i - 15],3) ))+
+            w[i - 7] + (Ror(w[i - 2], 17) ~ Ror(w[i - 2], 19) ~ ( UShr(w[i - 2],10) ))
+		Next
+    
+		For Local i:Int=0 To 63
+			Local t0:Int = (Ror(a, 2) ~ Ror(a, 13) ~ Ror(a, 22)) + ((a & b) | (b & c) | (c & a))
+			Local t1:Int = h + (Ror(e, 6) ~ Ror(e, 11) ~ Ror(e, 25)) + ((e & f) | (~e & g)) + k[i] + w[i]
+      
+			h = g ; g = f ; f = e ; e = d + t1
+			d = c ; c = b ; b = a ;  a = t0 + t1  
+		Next
+    
+		h0 += a ; h1 += b ; h2 += c ; h3 += d
+		h4 += e ; h5 += f ; h6 += g ; h7 += h
+	Next
+  
+	Return (Hex(h0) + Hex(h1) + Hex(h2) + Hex(h3) + Hex(h4) + Hex(h5) + Hex(h6) + Hex(h7)).ToLower()
+	
+End
+ 

+ 2 - 1
modules/std/std.monkey2

@@ -74,10 +74,11 @@ Namespace std
 #Import "misc/random"
 #Import "misc/random"
 #Import "misc/chartype"
 #Import "misc/chartype"
 #Import "misc/stringio"
 #Import "misc/stringio"
-#Import "misc/base64"
 #Import "misc/json"
 #Import "misc/json"
 #Import "misc/jsonify"
 #Import "misc/jsonify"
 #Import "misc/zipfile"
 #Import "misc/zipfile"
+#Import "misc/base64"
+#Import "misc/digest"
 
 
 #Import "socket/socket"
 #Import "socket/socket"
 #Import "socket/socketstream"
 #Import "socket/socketstream"

+ 19 - 0
modules/std/tests/digest.monkey2

@@ -0,0 +1,19 @@
+
+#Import "<std>"
+
+Using std..
+
+Function Main()
+	Print ""
+	Print "==== MD5 ===="
+	Print MD5("The quick brown fox jumps over the lazy dog")
+	Print "9e107d9d372bb6826bd81d3542a419d6 <- Should be this"
+	Print ""
+	Print "===== SHA-1 ====="
+	Print SHA1("The quick brown fox jumps over the lazy dog")
+	Print "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12 <- Should be this"
+	Print ""
+	Print "===== SHA-256 ====="
+	Print SHA256("The quick brown fox jumps over the lazy dog")
+	Print "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592 <- Should be this"
+End