plane.monkey2 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. Namespace plane
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojo3d>"
  5. #Import "source/PlaneControl"
  6. #Import "textures/"
  7. #Import "models/"
  8. Using std..
  9. Using mojo..
  10. Using mojo3d..
  11. Class MyWindow Extends Window
  12. Field _res :Vec2i
  13. Field _scene:Scene
  14. Field _camera:Camera
  15. Field _light:Light
  16. ' Field _fog:FogEffect
  17. Field _water:Model
  18. Field _plane:Model
  19. Field _pivot:Model 'Needs to be a Model instead of Entity otherwise the plane isn't rendered!
  20. Field _camTarget:Entity
  21. Field test:Model
  22. Method New()
  23. Super.New( "Toy Plane", 1280, 720, WindowFlags.Resizable )' | WindowFlags.HighDPI )
  24. _res = New Vec2i( Width, Height )
  25. Print _res
  26. Layout = "fill"
  27. _scene=New Scene
  28. _scene.SkyTexture=Texture.Load( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap )
  29. _scene.EnvTexture = _scene.SkyTexture
  30. _scene.FogColor = New Color(0.69, 0.78, 0.82, 0.3 )
  31. _scene.FogFar = 5000
  32. _scene.FogNear = 1
  33. 'create light
  34. _light=New Light
  35. _light.Rotate( 45, 45, 0 )
  36. _light.CastsShadow = True
  37. 'create water material
  38. Local waterMaterial:=New WaterMaterial
  39. waterMaterial.ScaleTextureMatrix( 300,300 )
  40. waterMaterial.ColorFactor=New Color( 0.025, 0.125, 0.15 )
  41. waterMaterial.Roughness=0
  42. waterMaterial.NormalTextures=New Texture[](
  43. Texture.Load( "asset::water_normal0.png",TextureFlags.WrapST | TextureFlags.FilterMipmap ),
  44. Texture.Load( "asset::water_normal1.png",TextureFlags.WrapST | TextureFlags.FilterMipmap ) )
  45. waterMaterial.Velocities=New Vec2f[](
  46. New Vec2f( .01,.03 ),
  47. New Vec2f( .02,.05 ) )
  48. 'create water
  49. _water=Model.CreateBox( New Boxf( -10000,-1,-10000,10000,0,10000 ),1,1,1,waterMaterial )
  50. 'create bloom
  51. Local _bloom := New BloomEffect( 2 )
  52. _scene.AddPostEffect( _bloom )
  53. 'create main pivot
  54. _pivot = New Model
  55. 'create airplane
  56. _plane = Model.LoadBoned( "asset::plane/plane.gltf" )
  57. _plane.Animator.Animate( 0 )
  58. _plane.Parent = _pivot
  59. _plane.Position = New Vec3f
  60. ' Local matrix := New AffineMat4<Float>
  61. ' _plane.Rotate( 0, 180, 0)
  62. ' _plane.Mesh.TransformVertices( matrix )
  63. ' Local mat := Cast<PbrMaterial>( _plane.Material )
  64. ' Local mat := New PbrMaterial( Color.LightGrey, 0.1, 0.1, True )
  65. ' Local tex := Texture.Load( "asset::plane_Oc.png", TextureFlags.FilterMipmap )
  66. ' mat.OcclusionTexture = tex
  67. Print _plane.Materials.Length
  68. Print ( _plane.Material? "true" Else "False" )
  69. ' _plane.Material = mat
  70. 'create camera target
  71. _camTarget = New Pivot( _pivot )
  72. ' _camTarget = Model.CreateSphere( 0.25, 12, 12, New PbrMaterial( Color.Red ) )
  73. ' _camTarget.Parent = _plane
  74. _camTarget.Position = New Vec3f( 0, 0, -10 )
  75. 'create camera
  76. _camera=New Camera( _pivot )
  77. _camera.View = Self
  78. _camera.Near=.1
  79. _camera.Far=10000
  80. _camera.FOV = 75
  81. _camera.Move( 0,3,8 )
  82. 'Control component
  83. Local control := _pivot.AddComponent<PlaneControl>()
  84. control.plane = _plane
  85. control.camera = _camera
  86. control.target = _camTarget
  87. _pivot.Position = New Vec3f( 0, 6, 0 )
  88. ' Local ball := Model.CreateSphere( 2, 24, 24, New PbrMaterial( Color.Red, 0.1, 0.25 ) )
  89. ' ball.Move( 0, 4, 0)
  90. End
  91. Method OnRender( canvas:Canvas ) Override
  92. RequestRender()
  93. _water.Position=New Vec3f( Round(_camera.Position.x/2000)*2000,0,Round(_camera.Position.z/2000)*2000 )
  94. _camera.PointAt( _camTarget.Position )
  95. _scene.Update()
  96. _camera.Render( canvas )
  97. canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS + " Aspect=" + _camera.Aspect,0,0 )
  98. End
  99. Method OnMeasure:Vec2i() Override
  100. Return _res
  101. End
  102. End
  103. Function Main()
  104. New AppInstance
  105. New MyWindow
  106. App.Run()
  107. End