room.monkey2 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. Namespace myapp
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojo3d>"
  5. #Import "assets/fish.glb"
  6. #Import "assets/monkey2-logo.png"
  7. Using std..
  8. Using mojo..
  9. Using mojo3d..
  10. Function Main()
  11. SetConfig( "MOJO_OPENGL_PROFILE","es" )
  12. New AppInstance
  13. New MyWindow
  14. App.Run()
  15. End
  16. Class MyWindow Extends Window
  17. Field _scene:Scene
  18. Field _camera:Camera
  19. Field _light:Light
  20. Field _room:Model
  21. Field _fish:Entity
  22. Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
  23. Super.New( title,width,height,flags )
  24. CreateScene()
  25. End
  26. Method CreateRoom()
  27. Local box:=New Boxf( -15,15 )
  28. Local material:=New PbrMaterial( Color.Orange )
  29. Local model:=Model.CreateBox( box,1,1,1,material )
  30. model.Mesh.FlipTriangles()
  31. model.Mesh.UpdateNormals()
  32. model.Mesh.UpdateTangents()
  33. model.CastsShadow=False
  34. End
  35. Method CreateFishes()
  36. Local model:=Model.Load( "asset::fish.glb" )
  37. model.Mesh.FitVertices( New Boxf( -1,1 ) )
  38. Local root:=New Pivot
  39. root.AddComponent<RotateBehaviour>().Speed=New Vec3f( 0,.1,0 )
  40. For Local an:=0 Until 360 Step 9
  41. Local copy:=model.Copy( root )
  42. copy.Rotate( 0,an,0 )
  43. copy.Move( 0,Sin( an )*3,Rnd( 2.5,9.5 ) )
  44. copy.Rotate( 0,-90,0 )
  45. Next
  46. model.Destroy()
  47. End
  48. Method CreateScene()
  49. 'Create scene
  50. _scene=New Scene
  51. _scene.ClearColor=Color.Black
  52. _scene.AmbientLight=Color.Black
  53. _scene.EnvColor=Color.Black
  54. _scene.ShadowAlpha=.7
  55. 'Create camera
  56. Local camera:=New Camera( Self )
  57. camera.Move( 0,1,-5 )
  58. camera.AddComponent<FlyBehaviour>()
  59. camera.Far=100
  60. 'Create light
  61. Local light:=New Light
  62. light.Type=LightType.Point
  63. light.Color=Color.White
  64. light.Texture=Texture.Load( "asset::monkey2-logo.png",TextureFlags.Filter|TextureFlags.Cubemap )
  65. light.CastsShadow=True
  66. light.Range=25
  67. light.AddComponent<RotateBehaviour>().Speed=New Vec3f( 0,-.05,0 )
  68. CreateRoom()
  69. CreateFishes()
  70. End
  71. Method OnRender( canvas:Canvas ) Override
  72. RequestRender()
  73. _scene.Update()
  74. _scene.Render( canvas )
  75. canvas.DrawText( "FPS "+App.FPS,Width,0,1,0 )
  76. End
  77. End