test-scene.monkey2 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. Namespace myapp3d
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojo3d>"
  5. #Reflect mojo3d
  6. Using std..
  7. Using mojo..
  8. Using mojo3d..
  9. Class MyWindow Extends Window
  10. Field _scene:Scene
  11. Field _camera:Camera
  12. Field _light:Light
  13. Field _ground:Model
  14. Field _donut:Model
  15. Method New( title:String="Simple mojo3d app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
  16. Super.New( title,width,height,flags )
  17. End
  18. Method OnCreateWindow() Override
  19. 'create editable scene
  20. _scene=New Scene( True )
  21. _scene.ClearColor = New Color( 0.2, 0.6, 1.0 )
  22. _scene.AmbientLight = _scene.ClearColor * 0.25
  23. _scene.FogColor = _scene.ClearColor
  24. _scene.FogFar = 1.0
  25. _scene.FogFar = 200.0
  26. 'create camera
  27. _camera=New Camera( Self )
  28. _camera.AddComponent<FlyBehaviour>()
  29. _camera.Move( 0,2.5,-5 )
  30. 'create light
  31. _light=New Light
  32. _light.CastsShadow=True
  33. _light.Rotate( 45, 45, 0 )
  34. 'create ground
  35. Local groundBox:=New Boxf( -100,-1,-100,100,0,100 )
  36. Local groundMaterial:=New PbrMaterial( Color.Lime )
  37. _ground=Model.CreateBox( groundBox,1,1,1,groundMaterial )
  38. _ground.CastsShadow=False
  39. 'create donut
  40. Local donutMaterial:=New PbrMaterial( Color.Red, 0.05, 0.2 )
  41. _donut=Model.CreateTorus( 2,.5,48,24,donutMaterial )
  42. _donut.Move( 0,2.5,0 )
  43. _donut.AddComponent<RotateBehaviour>().Speed=New Vec3f( .1,.2,.3 )
  44. _scene.Save( "test-scene.mojo3d","modules/mojo3d/tests/assets/" )
  45. _scene=Scene.Load( "test-scene.mojo3d" )
  46. End
  47. Method OnRender( canvas:Canvas ) Override
  48. RequestRender()
  49. _scene.Update()
  50. _scene.Render( canvas )
  51. canvas.DrawText( "FPS="+App.FPS,0,0 )
  52. End
  53. End
  54. Function Main()
  55. New AppInstance
  56. New MyWindow
  57. App.Run()
  58. End