Parcourir la source

Added components and rearranged namespaces.

Mark Sibly il y a 7 ans
Parent
commit
05cba1164c
57 fichiers modifiés avec 653 ajouts et 207 suppressions
  1. 0 0
      modules/mojo3d/assets/shaders/copy.glsl
  2. 0 0
      modules/mojo3d/assets/shaders/effect-bloom.glsl
  3. 0 0
      modules/mojo3d/assets/shaders/effect-fog.glsl
  4. 0 0
      modules/mojo3d/assets/shaders/effect-monochrome.glsl
  5. 0 0
      modules/mojo3d/assets/shaders/lighting-deferred.glsl
  6. 0 0
      modules/mojo3d/assets/shaders/material-particle.glsl
  7. 0 0
      modules/mojo3d/assets/shaders/material-pbr-deferred.glsl
  8. 0 0
      modules/mojo3d/assets/shaders/material-pbr-forward.glsl
  9. 0 0
      modules/mojo3d/assets/shaders/material-sprite.glsl
  10. 0 0
      modules/mojo3d/assets/shaders/material-water.glsl
  11. 0 0
      modules/mojo3d/assets/shaders/skybox.glsl
  12. 0 0
      modules/mojo3d/assets/textures/env_default.jpg
  13. 1 1
      modules/mojo3d/components/animation.monkey2
  14. 101 0
      modules/mojo3d/components/animator.monkey2
  15. 13 0
      modules/mojo3d/components/behaviour.monkey2
  16. 68 0
      modules/mojo3d/components/flycomponent.monkey2
  17. 33 0
      modules/mojo3d/components/gamecontroller.monkey2
  18. 38 0
      modules/mojo3d/components/keyboardcontroller.monkey2
  19. 1 1
      modules/mojo3d/entities/camera.monkey2
  20. 1 1
      modules/mojo3d/entities/light.monkey2
  21. 1 1
      modules/mojo3d/entities/model.monkey2
  22. 10 26
      modules/mojo3d/entities/particlebuffer.monkey2
  23. 1 1
      modules/mojo3d/entities/particlematerial.monkey2
  24. 1 1
      modules/mojo3d/entities/particlesystem.monkey2
  25. 1 1
      modules/mojo3d/entities/renderable.monkey2
  26. 1 1
      modules/mojo3d/entities/sprite.monkey2
  27. 1 1
      modules/mojo3d/geometry/gltf2.monkey2
  28. 1 1
      modules/mojo3d/geometry/gltf2loader.monkey2
  29. 1 1
      modules/mojo3d/geometry/loader.monkey2
  30. 2 4
      modules/mojo3d/geometry/mesh.monkey2
  31. 8 8
      modules/mojo3d/geometry/meshprims.monkey2
  32. 1 1
      modules/mojo3d/geometry/util3d.monkey2
  33. 0 55
      modules/mojo3d/graphics/animator.monkey2
  34. 47 50
      modules/mojo3d/mojo3d.monkey2
  35. 22 0
      modules/mojo3d/newdocs/manual.md
  36. 1 1
      modules/mojo3d/render/deferredrenderer.monkey2
  37. 1 1
      modules/mojo3d/render/effects/bloomeffect.monkey2
  38. 1 1
      modules/mojo3d/render/effects/fogeffect.monkey2
  39. 1 1
      modules/mojo3d/render/effects/monochromeeffect.monkey2
  40. 1 1
      modules/mojo3d/render/forwardrenderer.monkey2
  41. 1 1
      modules/mojo3d/render/material.monkey2
  42. 1 1
      modules/mojo3d/render/materials/pbrmaterial.monkey2
  43. 1 1
      modules/mojo3d/render/materials/spritematerial.monkey2
  44. 1 1
      modules/mojo3d/render/materials/watermaterial.monkey2
  45. 1 1
      modules/mojo3d/render/posteffect.monkey2
  46. 2 4
      modules/mojo3d/render/renderer.monkey2
  47. 25 27
      modules/mojo3d/render/renderqueue.monkey2
  48. 1 1
      modules/mojo3d/render/spritebuffer.monkey2
  49. 95 0
      modules/mojo3d/scene/component.monkey2
  50. 0 0
      modules/mojo3d/scene/dynamicobject.monkey2
  51. 120 2
      modules/mojo3d/scene/entity.monkey2
  52. 1 1
      modules/mojo3d/scene/entityexts.monkey2
  53. 34 1
      modules/mojo3d/scene/scene.monkey2
  54. 1 1
      modules/mojo3d/tests/cubes.monkey2
  55. 8 3
      modules/mojo3d/tests/ducks.monkey2
  56. 1 1
      modules/mojo3d/tests/makequad.monkey2
  57. 1 1
      modules/mojo3d/tests/sprites.monkey2

+ 0 - 0
modules/mojo3d/graphics/shaders/copy.glsl → modules/mojo3d/assets/shaders/copy.glsl


+ 0 - 0
modules/mojo3d/graphics/shaders/effect-bloom.glsl → modules/mojo3d/assets/shaders/effect-bloom.glsl


+ 0 - 0
modules/mojo3d/graphics/shaders/effect-fog.glsl → modules/mojo3d/assets/shaders/effect-fog.glsl


+ 0 - 0
modules/mojo3d/graphics/shaders/effect-monochrome.glsl → modules/mojo3d/assets/shaders/effect-monochrome.glsl


+ 0 - 0
modules/mojo3d/graphics/shaders/lighting-deferred.glsl → modules/mojo3d/assets/shaders/lighting-deferred.glsl


+ 0 - 0
modules/mojo3d/graphics/shaders/material-particle.glsl → modules/mojo3d/assets/shaders/material-particle.glsl


+ 0 - 0
modules/mojo3d/graphics/shaders/material-pbr-deferred.glsl → modules/mojo3d/assets/shaders/material-pbr-deferred.glsl


+ 0 - 0
modules/mojo3d/graphics/shaders/material-pbr-forward.glsl → modules/mojo3d/assets/shaders/material-pbr-forward.glsl


+ 0 - 0
modules/mojo3d/graphics/shaders/material-sprite.glsl → modules/mojo3d/assets/shaders/material-sprite.glsl


+ 0 - 0
modules/mojo3d/graphics/shaders/material-water.glsl → modules/mojo3d/assets/shaders/material-water.glsl


+ 0 - 0
modules/mojo3d/graphics/shaders/skybox.glsl → modules/mojo3d/assets/shaders/skybox.glsl


+ 0 - 0
modules/mojo3d/graphics/textures/env_default.jpg → modules/mojo3d/assets/textures/env_default.jpg


+ 1 - 1
modules/mojo3d/graphics/animation.monkey2 → modules/mojo3d/components/animation.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc @hidden
 #end

+ 101 - 0
modules/mojo3d/components/animator.monkey2

@@ -0,0 +1,101 @@
+
+Namespace mojo3d
+
+#rem monkeydoc The Animator class.
+#end
+Class Animator Extends Component
+	
+	Const Type:=New ComponentType( "Animator",0,ComponentTypeFlags.Singleton )
+	
+	Method New( entity:Entity )
+		
+		Super.New( entity,Type )
+	End
+	
+	Property Animations:Animation[]()
+		
+		Return _animations
+		
+	Setter( animations:Animation[] )
+		
+		_animations=animations
+	End
+	
+	Property Entities:Entity[]()
+	
+		Return _entities
+	
+	Setter( entities:Entity[] )
+		
+		_entities=entities
+	End
+	
+	Property Paused:Bool()
+		
+		Return _paused
+	
+	Setter( paused:Bool )
+		
+		_paused=paused
+	End
+	
+	Property Speed:Float()
+		
+		Return _speed
+	
+	Setter( speed:Float )
+		
+		_speed=speed
+	End
+	
+	Property Time:Float()
+		
+		Return _time
+	
+	Setter( time:Float )
+		
+		_time=time
+	End
+	
+	Method Animate( animationId:Int,time:Float )
+		
+		Local animation:=_animations[animationId]
+
+		For Local i:=0 Until animation.Channels.Length
+			
+			Local channel:=animation.Channels[i]
+			If Not channel continue
+			
+			_entities[i].LocalPosition=channel.GetPosition( time )
+			_entities[i].LocalBasis=New Mat3f( channel.GetRotation( time ) )
+			_entities[i].LocalScale=channel.GetScale( time )
+		End
+		
+	End
+	
+	Method OnUpdate( elapsed:Float ) Override
+		
+		If _paused  or not _animations Return
+		
+		Local anim:=_animations[0]
+		
+		_time+=anim.Hertz*elapsed
+		
+		If _time>=anim.Duration _time-=anim.Duration Else If _time<0 _time+=anim.Duration
+			
+		Animate( 0,_time )
+	End
+	
+	Private
+
+	Field _animations:Animation[]
+
+	Field _entities:Entity[]
+	
+	Field _paused:Bool=True
+	
+	Field _speed:Float=1
+	
+	Field _time:Float=0
+	
+End

+ 13 - 0
modules/mojo3d/components/behaviour.monkey2

@@ -0,0 +1,13 @@
+
+Namespace mojo3d
+
+Class Behaviour Extends Component
+	
+	Const Type:=New ComponentType( "Behaviour",0,Null )
+	
+	Method New( entity:Entity )
+		
+		Super.New( entity,Type )
+	End
+	
+End

+ 68 - 0
modules/mojo3d/components/flycomponent.monkey2

@@ -0,0 +1,68 @@
+
+Namespace mojo3d
+
+Class FlyComponent Extends Component
+	
+	Const Type:=New ComponentType( "FlyController",0,ComponentTypeFlags.Singleton )
+	
+	Method New( entity:Entity )
+		
+		Super.New( entity,Type )
+	End
+	
+	Property Speed:Float()
+		
+		Return _speed
+	
+	Setter( speed:Float )
+		
+		_speed=speed
+	End
+	
+	Method OnUpdate( elapsed:Float ) Override
+		
+		Local c:=Entity.GetComponent<GameController>()
+		Assert( c,"Entity has no game controller" )
+		
+		Local rspeed:=_speed*(elapsed/(1.0/60.0))
+		
+		Local entity:=Entity
+		
+		Local view:=App.ActiveWindow
+	
+		If c.ButtonDown( Button.Up )
+			entity.RotateX( rspeed )
+		Else If c.ButtonDown( Button.Down )
+			entity.RotateX( -rspeed )
+		Endif
+		
+		If c.ButtonDown( Button.Left )
+			entity.RotateY( rspeed,True )
+		Else If c.ButtonDown( Button.Right )
+			entity.RotateY( -rspeed,True )
+		Endif
+	
+		If c.ButtonDown( Button.Forward )
+			entity.MoveZ( .1 )
+		Else If c.ButtonDown( Button.Backward )
+			entity.MoveZ( -.1 )
+		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
+		
+	End
+	
+	Private
+	
+	Field _speed:Float=3.0
+	
+End
+

+ 33 - 0
modules/mojo3d/components/gamecontroller.monkey2

@@ -0,0 +1,33 @@
+
+Namespace mojo3d
+
+Enum Button
+	Up
+	Down
+	Left
+	Right
+	Fire
+	Forward
+	Backward
+End
+
+Class GameController Extends Component
+	
+	Const Type:=New ComponentType( "GameController",-1,ComponentTypeFlags.Singleton )
+	
+	Method New( entity:Entity )
+		
+		Super.New( entity,Type )
+	End
+	
+	Method ButtonDown:Bool( button:Button ) Virtual
+	
+		Return False
+	End
+	
+	Method ButtonHit:Bool( button:Button ) Virtual
+		
+		Return False
+	End
+	
+End

+ 38 - 0
modules/mojo3d/components/keyboardcontroller.monkey2

@@ -0,0 +1,38 @@
+
+Namespace mojo3d
+
+Class KeyboardController Extends GameController
+	
+	Method New( entity:Entity )
+		
+		Super.New( entity )
+	End
+	
+	Method ButtonToKey:Key( button:Button )
+
+		Select button
+		Case Button.Up Return Key.Up
+		Case Button.Down Return Key.Down
+		Case Button.Left Return Key.Left
+		Case Button.Right Return Key.Right
+		Case Button.Fire Return Key.Space
+		Case Button.Forward Return Key.A
+		Case button.Backward Return Key.Z
+		End
+			
+		Return Null
+	End
+	
+	Method ButtonDown:Bool( button:Button ) Override
+		
+		Return Keyboard.KeyDown( ButtonToKey( button ) )
+	End
+	
+	Method ButtonHit:Bool( button:Button ) Override
+		
+		Return Keyboard.KeyHit( ButtonToKey( button ) )
+	End
+	
+End
+
+	

+ 1 - 1
modules/mojo3d/graphics/camera.monkey2 → modules/mojo3d/entities/camera.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The Camera class.
 #end

+ 1 - 1
modules/mojo3d/graphics/light.monkey2 → modules/mojo3d/entities/light.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The LightType enumeration.
 

+ 1 - 1
modules/mojo3d/graphics/model.monkey2 → modules/mojo3d/entities/model.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The Model class.
 #end

+ 10 - 26
modules/mojo3d/graphics/particlebuffer.monkey2 → modules/mojo3d/entities/particlebuffer.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 Class ParticleBuffer
 
@@ -148,9 +148,9 @@ Class ParticleBuffer
 				
 			Next
 			
-			_vbuffer.Unlock()
-			
 			_vbuffer.Invalidate()
+			
+			_vbuffer.Unlock()
 
 		Endif
 		
@@ -176,36 +176,20 @@ Class ParticleBuffer
 
 	Method AddParticle( vertices:Vertex3f Ptr,time:Float )
 	
-		Local r:=Rnd( -Pi,Pi )
-		Local d:=Rnd( 0,Tan( _coneAngle*.5*TwoPi/360.0 ) )
-		
-		Local velocity:=New Vec3f( Cos( r ) * d,Sin( r ) * d,1.0 ).Normalize() * Rnd( _minVelocity,_maxVelocity )
-
-		#rem	
-		Local rx:=Sin( Rnd( -_coneAngle*.5,_coneAngle*.5 )*TwoPi/360.0 )
-		Local ry:=Sin( Rnd( -_coneAngle*.5,_coneAngle*.5 )*TwoPi/360.0 )
-		
-		Local velocity:=Mat3f.Rotation( rx,ry,0 ) * New Vec3f( 0,0,Rnd( _minVelocity,_maxVelocity ) )
-		#end
-		
-		#rem
-		Local vx:=Sin( Rnd( -_coneAngle*.5,_coneAngle*.5 )*TwoPi/360.0 )
-		Local vy:=Sin( Rnd( -_coneAngle*.5,_coneAngle*.5 )*TwoPi/360.0 )
-		Local sp:=Float( Rnd( _minVelocity,_maxVelocity ) )
-		Local velocity:=New Vec3f( vx,vy,1.0 ) * sp '.Normalize() * sp
-		#end
-			
 		Local vertex:=vertices+_index
 		
-		_index+=1 
+		_index=(_index+1) Mod _length
+		
+		Local r:=Rnd( -Pi,Pi )
+		Local d:=Rnd( 0,Tan( _coneAngle*.5*TwoPi/360.0 ) )
 		
-		If _index=_length _index=0
+		Local dir:=New Vec3f( Cos( r ) * d,Sin( r ) * d,1.0 ).Normalize()
 		
+		Local velocity:=dir * Rnd( _minVelocity,_maxVelocity )
+
 		vertex->position=velocity											'velocity
 		vertex->texCoord0=New Vec2f( time,Rnd( _minSize,_maxSize ) )		'time, size
 		vertex->tangent=_colors[ Rnd( _colors.Length ) ]					'color
-		
-		_vbuffer.Invalidate()
 	End
 	
 End

+ 1 - 1
modules/mojo3d/graphics/particlematerial.monkey2 → modules/mojo3d/entities/particlematerial.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The ParticleMaterial class.
 #end

+ 1 - 1
modules/mojo3d/graphics/particlesystem.monkey2 → modules/mojo3d/entities/particlesystem.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 Class ParticleSystem Extends Renderable
 

+ 1 - 1
modules/mojo3d/graphics/renderable.monkey2 → modules/mojo3d/entities/renderable.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 Class Renderable Extends Entity Abstract
 

+ 1 - 1
modules/mojo3d/graphics/sprite.monkey2 → modules/mojo3d/entities/sprite.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc SpriteMode enumeration.
 

+ 1 - 1
modules/mojo3d/graphics/gltf2.monkey2 → modules/mojo3d/geometry/gltf2.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d.gltf2
 
 #rem monkeydoc @hidden
 #end

+ 1 - 1
modules/mojo3d/graphics/gltf2loader.monkey2 → modules/mojo3d/geometry/gltf2loader.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d.gltf2
 
 Private
 

+ 1 - 1
modules/mojo3d/graphics/loader.monkey2 → modules/mojo3d/geometry/loader.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc @hidden
 #end

+ 2 - 4
modules/mojo3d/graphics/mesh.monkey2 → modules/mojo3d/geometry/mesh.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The Mesh class.
 #end
@@ -15,12 +15,10 @@ Class Mesh Extends Resource
 	
 	#end
 	Method New()
-	
 		_dirty=Null
 		_bounds=Boxf.EmptyBounds
 		_vertices=New Stack<Vertex3f>
 		_materials=New Stack<MaterialID>
-'		AddMaterials( 1 )
 	End
 	
 	Method New( vertices:Vertex3f[],indices:UInt[] )
@@ -360,7 +358,7 @@ Class Mesh Extends Resource
 			
 			Local indices:=material.indices.Data
 		
-			For Local i:=0 Until material.indices.Length
+			For Local i:=0 Until material.indices.Length Step 3
 				
 				Local i1:=indices[i+0]
 				Local i2:=indices[i+1]

+ 8 - 8
modules/mojo3d/graphics/meshprims.monkey2 → modules/mojo3d/geometry/meshprims.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 Private
 
@@ -495,49 +495,49 @@ Class Model Extension
 	
 	Function CreateBox:Model( box:Boxf,xsegs:Int,ysegs:Int,zsegs:Int,material:Material,parent:Entity=Null )
 		
-		Local mesh:=mojo3d.graphics.Mesh.CreateBox( box,xsegs,ysegs,zsegs )
+		Local mesh:=mojo3d.Mesh.CreateBox( box,xsegs,ysegs,zsegs )
 		
 		Return New Model( mesh,material,parent )
 	End
 	
 	Function CreateSphere:Model( radius:Float,hsegs:Int,vsegs:Int,material:Material,parent:Entity=Null )
 		
-		Local mesh:=mojo3d.graphics.Mesh.CreateSphere( radius,hsegs,vsegs )
+		Local mesh:=mojo3d.Mesh.CreateSphere( radius,hsegs,vsegs )
 		
 		Return New Model( mesh,material,parent )
 	End
 	
 	Function CreateTorus:Model( outerRadius:Float,innerRadius:Float,outerSegs:Int,innerSegs:Int,material:Material,parent:Entity=Null )
 		
-		Local mesh:=mojo3d.graphics.Mesh.CreateTorus( outerRadius,innerRadius,outerSegs,innerSegs )
+		Local mesh:=mojo3d.Mesh.CreateTorus( outerRadius,innerRadius,outerSegs,innerSegs )
 		
 		Return New Model( mesh,material,parent )
 	End
 	
 	Function CreateCylinder:Model( radius:Float,length:Float,axis:Axis,segs:Int,material:Material,parent:Entity=null )
 		
-		Local mesh:=mojo3d.graphics.Mesh.CreateCylinder( radius,length,axis,segs )
+		Local mesh:=mojo3d.Mesh.CreateCylinder( radius,length,axis,segs )
 		
 		Return New Model( mesh,material,parent )
 	End
 	
 	Function CreateCapsule:Model( radius:Float,length:Float,axis:Axis,segs:Int,material:Material,parent:Entity=null )
 		
-		Local mesh:=mojo3d.graphics.Mesh.CreateCapsule( radius,length,axis,segs )
+		Local mesh:=mojo3d.Mesh.CreateCapsule( radius,length,axis,segs )
 		
 		Return New Model( mesh,material,parent )
 	End
 	
 	Function CreateCone:Model( radius:Float,length:Float,axis:Axis,segs:Int,material:Material,parent:Entity=null )
 		
-		Local mesh:=mojo3d.graphics.Mesh.CreateCone( radius,length,axis,segs )
+		Local mesh:=mojo3d.Mesh.CreateCone( radius,length,axis,segs )
 		
 		Return New Model( mesh,material,parent )
 	End
 	
 	Function CreateTerrain:Model( heightMap:Pixmap,bounds:Boxf,material:Material,parent:Entity=Null )
 		
-		Local mesh:=mojo3d.graphics.Mesh.CreateTerrain( heightMap,bounds )
+		Local mesh:=mojo3d.Mesh.CreateTerrain( heightMap,bounds )
 		
 		Return New Model( mesh,material,parent )
 	End

+ 1 - 1
modules/mojo3d/graphics/util3d.monkey2 → modules/mojo3d/geometry/util3d.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc @hidden
 #end

+ 0 - 55
modules/mojo3d/graphics/animator.monkey2

@@ -1,55 +0,0 @@
-
-Namespace mojo3d.graphics
-
-#rem monkeydoc The Animator class.
-#end
-Class Animator
-	
-	Method New( animations:Animation[],entities:Entity[] )
-
-#rem		
-		For Local i:=0 Until animations.Length
-			Print "anim["+i+"].Channels="+animations[i].Channels.Length
-			Print "anim["+i+"].Duration="+animations[i].Duration
-			Print "anim["+i+"].Hertz="+animations[i].Hertz
-		Next			
-		Print "entities="+entities.Length
-#end		
-		_animations=animations
-		
-		_entities=entities
-	End
-	
-	Property Animations:Animation[]()
-		
-		Return _animations
-	End
-	
-	Property Entities:Entity[]()
-		
-		Return _entities
-	End
-	
-	Method Animate( animationId:Int,time:Float )
-		
-		Local animation:=_animations[animationId]
-
-		For Local i:=0 Until animation.Channels.Length
-			
-			Local channel:=animation.Channels[i]
-			If Not channel continue
-			
-			_entities[i].LocalPosition=channel.GetPosition( time )
-			_entities[i].LocalBasis=New Mat3f( channel.GetRotation( time ) )
-			_entities[i].LocalScale=channel.GetScale( time )
-		End
-		
-	End
-	
-	Private
-
-	Field _animations:Animation[]
-
-	Field _entities:Entity[]
-	
-End

+ 47 - 50
modules/mojo3d/mojo3d.monkey2

@@ -4,57 +4,54 @@ Namespace mojo3d
 #Import "<std>"
 #Import "<mojo>"
 
-#Import "graphics/shaders/@/shaders"
-#Import "graphics/textures/@/textures"
+#Import "assets/"
+
+#Import "components/animation"
+#Import "components/animator"
+#Import "components/behaviour"
+#Import "components/flycomponent"
+#Import "components/gamecontroller"
+#Import "components/keyboardcontroller"
+
+#Import "entities/camera"
+#Import "entities/light"
+#Import "entities/model"
+#Import "entities/particlebuffer"
+#Import "entities/particlematerial"
+#Import "entities/particlesystem"
+#Import "entities/renderable"
+#Import "entities/sprite"
+
+#Import "render/deferredrenderer"
+#Import "render/forwardrenderer"
+#Import "render/material"
+#Import "render/renderer"
+#Import "render/renderqueue"
+#Import "render/spritebuffer"
+#Import "render/posteffect"
+
+#Import "render/materials/pbrmaterial"
+#Import "render/materials/spritematerial"
+#Import "render/materials/watermaterial"
+
+#Import "render/effects/fogeffect"
+#Import "render/effects/monochromeeffect"
+#Import "render/effects/bloomeffect"
+
+#Import "scene/component"
+#Import "scene/dynamicobject"
+#Import "scene/entity"
+#Import "scene/entityexts"
+#Import "scene/scene"
+
+#Import "geometry/loader"
+#Import "geometry/gltf2"
+#Import "geometry/gltf2loader"
+#Import "geometry/mesh"
+#Import "geometry/meshprims"
+#Import "geometry/util3d"
 
 Using std..
+Using gles20..
 Using mojo..
 Using mojo3d..
-Using gles20..
-
-#Import "graphics/dynamicobject"
-
-#Import "graphics/util3d"
-#Import "graphics/mesh"
-#Import "graphics/meshprims"
-
-#Import "graphics/entity"
-
-#Import "graphics/camera"
-
-#Import "graphics/light"
-
-#Import "graphics/model"
-
-#Import "graphics/sprite"
-#Import "graphics/spritebuffer"
-#Import "graphics/spritematerial"
-
-#Import "graphics/particlesystem"
-#Import "graphics/particlebuffer"
-#Import "graphics/particlematerial"
-
-#Import "graphics/scene"
-#Import "graphics/loader.monkey2"
-#Import "graphics/gltf2"
-#Import "graphics/gltf2loader"
-
-#Import "graphics/entityexts"
-
-#Import "graphics/renderqueue"
-#Import "graphics/renderable"
-#Import "graphics/renderer"
-#Import "graphics/deferredrenderer"
-#Import "graphics/forwardrenderer"
-
-#Import "graphics/animation"
-#Import "graphics/animator"
-
-#Import "graphics/posteffect"
-#Import "graphics/bloomeffect"
-#Import "graphics/fogeffect"
-#Import "graphics/monochromeeffect"
-
-#Import "graphics/material"
-#Import "graphics/pbrmaterial"
-#Import "graphics/watermaterial"

+ 22 - 0
modules/mojo3d/newdocs/manual.md

@@ -0,0 +1,22 @@
+
+@manpage The mojo3d module
+
+# The mojo3d module
+
+Mojo3d is a simple 3d rendering engine.
+
+@#### The mojo3d graphics system
+
+Mojo3d is a scene graph based rendering engine. Currently, only a singleton scene is supported. This can be retrieved using the [[Scene.GetCurrent]] function.
+
+The base class of all scene nodes is the [[Entity]] class. Subclasses of entity include [[Camera]], [[Light]], [[Model]] and [[Sprite]]. Entities can be arranged in hierarchies using the [[Entity.Parent]] property.
+
+A number of helper entity [[EntityEXT|extension]] properties and methods are also available for working with entities.
+
+@#### The mojo3d-loaders module
+
+Mojo3d includes a native gltf2 loader, which is used by default by the [[Mesh.Load]] and [[Model.Load]] methods.
+
+To load other 3d file formats, you can import the mojo3d-loaders module simply adding `#Import "<mojo3d-loaders>"` to your project. Note that this will increase the size of your final application somewhat.
+
+

+ 1 - 1
modules/mojo3d/graphics/deferredrenderer.monkey2 → modules/mojo3d/render/deferredrenderer.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem
 

+ 1 - 1
modules/mojo3d/graphics/bloomeffect.monkey2 → modules/mojo3d/render/effects/bloomeffect.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem The BloomEffect class.
 

+ 1 - 1
modules/mojo3d/graphics/fogeffect.monkey2 → modules/mojo3d/render/effects/fogeffect.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem The FogEffect class.
 

+ 1 - 1
modules/mojo3d/graphics/monochromeeffect.monkey2 → modules/mojo3d/render/effects/monochromeeffect.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The MonochromeEffect class.
 #end

+ 1 - 1
modules/mojo3d/graphics/forwardrenderer.monkey2 → modules/mojo3d/render/forwardrenderer.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem
 

+ 1 - 1
modules/mojo3d/graphics/material.monkey2 → modules/mojo3d/render/material.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The Material class.
 #end

+ 1 - 1
modules/mojo3d/graphics/pbrmaterial.monkey2 → modules/mojo3d/render/materials/pbrmaterial.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The PbrMaterial class.
 #end

+ 1 - 1
modules/mojo3d/graphics/spritematerial.monkey2 → modules/mojo3d/render/materials/spritematerial.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The SpriteMaterial class.
 #end

+ 1 - 1
modules/mojo3d/graphics/watermaterial.monkey2 → modules/mojo3d/render/materials/watermaterial.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The WaterMaterial class.
 #end

+ 1 - 1
modules/mojo3d/graphics/posteffect.monkey2 → modules/mojo3d/render/posteffect.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The PostEffect class.
 #end

+ 2 - 4
modules/mojo3d/graphics/renderer.monkey2 → modules/mojo3d/render/renderer.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The Renderer class.
 #end
@@ -139,11 +139,9 @@ Class Renderer
 		
 		_renderQueue.Time=time
 		
-		_renderQueue.AddShadowOps=False
-		
 		For Local r:=Eachin _renderScene.Renderables
 		
-			_renderQueue.AddShadowOps=r.CastsShadow
+			_renderQueue.CastsShadow=r.CastsShadow
 			
 			r.OnRender( _renderQueue )
 		Next

+ 25 - 27
modules/mojo3d/graphics/renderqueue.monkey2 → modules/mojo3d/render/renderqueue.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 Internal
 
@@ -29,11 +29,11 @@ Class RenderQueue
 	End
 	
 	Method Clear()
-	
-		_sprites.Clear()	
 		_opaqueOps.Clear()
-		_shadowOps.Clear()
 		_transparentOps.Clear()
+		_spriteOps.Clear()
+		_shadowOps.Clear()
+		_sprites.Clear()	
 	End
 	
 	Method AddRenderOp( material:Material,uniforms:UniformBlock,instance:Entity,vbuffer:VertexBuffer,ibuffer:IndexBuffer,order:Int,count:Int,first:Int )
@@ -86,29 +86,13 @@ Class RenderQueue
 	
 	Internal
 	
-	Method AddRenderOp( op:RenderOp )
+	Property CastsShadow:Bool()
 		
-		op.material.ValidateShader()
+		Return _castsShadow
 		
-		If op.material.BlendMode<>BlendMode.Opaque
-			_transparentOps.Push( op )
-		Else
-			_opaqueOps.Push( op )
-		Endif
-		
-		If _addShadowOps 
-			If (op.material.Shader.RenderPassMask & $10000) _shadowOps.Push( op )
-		Endif
+	Setter( castsShadow:Bool )
 		
-	End
-	
-	Property AddShadowOps:Bool()
-		
-		Return _addShadowOps
-		
-	Setter( addShadowOps:Bool )
-		
-		_addShadowOps=addShadowOps
+		_castsShadow=castsShadow
 	End
 	
 	Property OpaqueOps:Stack<RenderOp>()
@@ -137,6 +121,22 @@ Class RenderQueue
 		Return _sprites
 	End
 	
+	Method AddRenderOp( op:RenderOp )
+		
+		op.material.ValidateShader()
+		
+		If op.material.BlendMode<>BlendMode.Opaque
+			_transparentOps.Push( op )
+		Else
+			_opaqueOps.Push( op )
+		Endif
+		
+		If _castsShadow
+			If (op.material.Shader.RenderPassMask & $10000) _shadowOps.Push( op )
+		Endif
+		
+	End
+	
 	Method AddSpriteOp( material:Material,uniforms:UniformBlock,instance:Entity,vbuffer:VertexBuffer,ibuffer:IndexBuffer,order:Int,count:Int,first:Int )
 		Local op:=New RenderOp
 		op.material=material
@@ -162,10 +162,8 @@ Class RenderQueue
 	Field _transparentOps:=New Stack<RenderOp>
 	Field _spriteOps:=New Stack<RenderOp>
 	Field _shadowOps:=New Stack<RenderOp>
-	
 	Field _sprites:=New Stack<Sprite>
 	
-	Field _addShadowOps:Bool
-	
+	Field _castsShadow:Bool
 
 End

+ 1 - 1
modules/mojo3d/graphics/spritebuffer.monkey2 → modules/mojo3d/render/spritebuffer.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc @hidden
 #end

+ 95 - 0
modules/mojo3d/scene/component.monkey2

@@ -0,0 +1,95 @@
+
+Namespace mojo3d
+
+Enum ComponentTypeFlags
+	
+	Singleton=1
+End
+
+Class ComponentType
+	
+	Method New( name:String,priority:int,flags:ComponentTypeFlags )
+		
+		_name=name
+		
+		_priority=priority
+		
+		_flags=flags
+	End
+	
+	Property Name:String()
+		
+		Return _name
+	End
+	
+	Property Priority:Int()
+		
+		Return _priority
+	End
+	
+	Property Flags:ComponentTypeFlags()
+		
+		Return _flags
+	End
+	
+	Private
+	
+	Field _name:String
+	
+	Field _priority:Int
+	
+	Field _flags:ComponentTypeFlags
+End
+
+Class Component
+	
+	Method New( entity:Entity,type:ComponentType )
+		
+		_entity=entity
+		
+		_type=type
+		
+		_entity.AddComponent( Self )
+	End
+	
+	Property Entity:Entity()
+		
+		Return _entity
+	End
+	
+	Property Type:ComponentType()
+		
+		Return _type
+	End
+	
+	Method Copy:Component( entity:Entity )
+		
+		Return OnCopy( entity )
+	End
+		
+	Method OnCopy:Component( entity:Entity ) Virtual
+		Return Null
+	End
+	
+	Internal
+		
+	Method OnBeginUpdate() Virtual
+	End
+	
+	Method OnUpdate( elapsed:Float ) Virtual
+	End
+	
+	Method OnDestroy() Virtual
+	End
+	
+	Private
+	
+	Field _entity:Entity
+	
+	Field _priority:Int
+	
+	Field _type:ComponentType
+End
+
+
+

+ 0 - 0
modules/mojo3d/graphics/dynamicobject.monkey2 → modules/mojo3d/scene/dynamicobject.monkey2


+ 120 - 2
modules/mojo3d/graphics/entity.monkey2 → modules/mojo3d/scene/entity.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The Entity class.
 #end
@@ -325,6 +325,10 @@ Class Entity Extends DynamicObject
 			_visible=False
 			 OnHide()
 		Endif
+		
+		For Local c:=Eachin _components
+			c.OnDestroy()
+		Next
 
 		If _parent
 			_parent._children.Remove( Self )
@@ -338,6 +342,83 @@ Class Entity Extends DynamicObject
 		Destroyed()
 	End
 	
+	#rem monkeydoc @hidden
+	#end
+	Method NumComponents:Int( type:ComponentType )
+		
+		Local n:=0
+		For Local c:=Eachin _components
+			If c.Type=type n+=1
+		Next
+		Return n
+	End
+
+	Method NumComponents<T>:Int()
+		
+		Local n:=0
+		For Local c:=Eachin _components
+			If c.Type=T.Type n+=1
+		Next
+		Return n
+	End
+	
+	Internal
+	
+	Method AddComponent( c:Component )
+
+		If c.Type.Flags & ComponentTypeFlags.Singleton And NumComponents( c.Type ) RuntimeError( "Duplicate component" )
+			
+		For Local i:=0 Until _components.Length
+			
+			If c.Type.Priority>_components[i].Type.Priority
+				
+				_components.Insert( i,c )
+				
+				Return
+			Endif
+		Next
+
+		_components.Add( c )
+		
+		Return
+	End
+	
+	Public
+	
+	Method AddComponent<T>:T() Where T Extends Component
+		
+		Local c:=New T( Self )
+		
+		Return c
+	End
+	
+	Method GetComponent<T>:T( index:Int=0 ) Where T Extends Component
+	
+		For Local c:=Eachin _components
+			If c.Type<>T.Type Continue
+			
+			If index=0 Return Cast<T>( c )
+			index-=1
+		Next
+		Return Null
+	End
+	
+	Method DestroyComponent<T>( index:Int=0 ) Where T Extends Component
+		
+		For Local i:=0 Until _components.Length
+			
+			Local c:=_components[i]
+			If c.Type<>T.Type Continue
+			
+			If index=0
+				_components.Erase( i )
+				Return
+			Endif
+			index-=1
+		Next
+	End
+		
+	
 Protected
 
 	#rem monkeydoc @hidden
@@ -365,13 +446,48 @@ Protected
 	#rem monkeydoc @hidden
 	#end
 	Method CopyComplete( copy:Entity )
-	
+		
 		For Local child:=Eachin _children
 			child.Copy( copy )
 		Next
 
+		For Local c:=Eachin _components
+			c.Copy( copy )
+		Next
+
 		Copied( copy )
 	End
+	
+Internal
+
+	'bottom up
+	Method BeginUpdate()
+
+		For Local e:=Eachin _children
+			
+			e.BeginUpdate()
+		Next
+		
+		For Local c:=Eachin _components
+			
+			c.OnBeginUpdate()
+		Next
+		
+	End
+	
+	'top down
+	Method Update( elapsed:Float )
+		
+		For Local c:=Eachin _components
+			
+			c.OnUpdate( elapsed )
+		End
+		
+		For Local e:=Eachin _children
+			
+			e.Update( elapsed )
+		Next
+	End
 
 Private
 	
@@ -399,6 +515,8 @@ Private
 	Field _W:AffineMat4f
 	Field _IW:AffineMat4f
 	
+	Field _components:=New Stack<Component>
+	
 	Method InvalidateWorld()
 		
 		If _dirty & _dirty.W Return

+ 1 - 1
modules/mojo3d/graphics/entityexts.monkey2 → modules/mojo3d/scene/entityexts.monkey2

@@ -1,5 +1,5 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 Private
 

+ 34 - 1
modules/mojo3d/graphics/scene.monkey2 → modules/mojo3d/scene/scene.monkey2

@@ -1,9 +1,11 @@
 
-Namespace mojo3d.graphics
+Namespace mojo3d
 
 #rem monkeydoc The Scene class.
 #end
 Class Scene Extends DynamicObject
+	
+	Field Updating:Void( elapsed:Float )
 
 	#rem monkeydoc Creates a new scene.
 	#end
@@ -124,6 +126,37 @@ Class Scene Extends DynamicObject
 		Wend
 	End
 	
+	#rem monkeydoc Updates the scene.
+	#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()
+		
+		Global time:=0.0
+		
+		Local elapsed:=0.0
+		
+		If time
+			elapsed=Now()-time
+			time+=elapsed
+		Else
+			time=Now()
+		Endif
+		
+		Update( elapsed )
+	End
+	
 	#rem monkeydoc Renders the scene to	a canvas.
 	#end
 	Method Render( canvas:Canvas,camera:Camera )

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

@@ -39,7 +39,7 @@ Class MyWindow Extends Window
 		'
 		_light=New Light
 
-		_light.RotateX( 90 )
+		_light.Rotate( 30,60,0 )
 		
 		'Create donut - metallic silver...
 		'

+ 8 - 3
modules/mojo3d/tests/ducks.monkey2

@@ -57,8 +57,13 @@ Class MyWindow Extends Window
 		_camera.FOV=90
 		_camera.Move( 0,15,-20 )
 		
+		_camera.AddComponent<KeyboardController>()
+'		New KeyboardController( _camera )
+		
+		_camera.AddComponent<FlyComponent>()
+'		New FlyComponent( _camera )
+		
 		'create light
-		'
 		_light=New Light
 		_light.Type=LightType.Point
 		_light.Move( 0,20,0 )
@@ -121,13 +126,13 @@ Class MyWindow Extends Window
 		
 		'_ducks[0].RotateY( 1 )
 
-		util.Fly( _camera,Self )
+		_scene.Update()
 		
 		_scene.Render( canvas,_camera )
 
 		canvas.Scale( Width/640.0,Height/480.0 )
 		
-		'canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )
+		canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )
 	End
 	
 End

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

@@ -28,7 +28,7 @@ Class MyWindow Extends Window
 		_camera=New Camera
 		_camera.Near=.1
 		_camera.Far=100
-		_camera.Move( 0,0,-5 )
+		_camera.Move( 0,0,-2.5 )
 		
 		'create light
 		'

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

@@ -68,7 +68,7 @@ Class MyWindow Extends Window
 			_sprites.Push( sprite )
 		Next
 		
-		For Local i:=0 Until 10
+		For Local i:=0 Until 100
 			
 			Local box:=Model.CreateBox( New Boxf( -5,0,-5,5,Rnd(2,10),5 ),1,1,1,New PbrMaterial( New Color( Rnd(),Rnd(),Rnd() ) ) )