|
@@ -1,4 +1,3 @@
|
|
-
|
|
|
|
Namespace plane
|
|
Namespace plane
|
|
|
|
|
|
#Import "<std>"
|
|
#Import "<std>"
|
|
@@ -8,8 +7,7 @@ Namespace plane
|
|
#Import "source/PlaneControl"
|
|
#Import "source/PlaneControl"
|
|
|
|
|
|
#Import "textures/"
|
|
#Import "textures/"
|
|
-
|
|
|
|
-#Import "models/plane/"
|
|
|
|
|
|
+#Import "models/"
|
|
|
|
|
|
Using std..
|
|
Using std..
|
|
Using mojo..
|
|
Using mojo..
|
|
@@ -17,42 +15,44 @@ Using mojo3d..
|
|
|
|
|
|
Class MyWindow Extends Window
|
|
Class MyWindow Extends Window
|
|
|
|
|
|
- Global _res :Vec2i
|
|
|
|
|
|
+ Field _res :Vec2i
|
|
|
|
|
|
Field _scene:Scene
|
|
Field _scene:Scene
|
|
Field _camera:Camera
|
|
Field _camera:Camera
|
|
Field _light:Light
|
|
Field _light:Light
|
|
|
|
+' Field _fog:FogEffect
|
|
|
|
|
|
Field _water:Model
|
|
Field _water:Model
|
|
Field _plane:Model
|
|
Field _plane:Model
|
|
Field _pivot:Model 'Needs to be a Model instead of Entity otherwise the plane isn't rendered!
|
|
Field _pivot:Model 'Needs to be a Model instead of Entity otherwise the plane isn't rendered!
|
|
|
|
|
|
Field _camTarget:Entity
|
|
Field _camTarget:Entity
|
|
-
|
|
|
|
Field test:Model
|
|
Field test:Model
|
|
|
|
|
|
|
|
+
|
|
Method New()
|
|
Method New()
|
|
Super.New( "Toy Plane", 1280, 720, WindowFlags.Resizable )' | WindowFlags.HighDPI )
|
|
Super.New( "Toy Plane", 1280, 720, WindowFlags.Resizable )' | WindowFlags.HighDPI )
|
|
_res = New Vec2i( Width, Height )
|
|
_res = New Vec2i( Width, Height )
|
|
- Layout = "letterbox"
|
|
|
|
|
|
+ Print _res
|
|
|
|
+ Layout = "fill"
|
|
|
|
|
|
_scene=New Scene
|
|
_scene=New Scene
|
|
_scene.SkyTexture=Texture.Load( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap )
|
|
_scene.SkyTexture=Texture.Load( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap )
|
|
_scene.EnvTexture = _scene.SkyTexture
|
|
_scene.EnvTexture = _scene.SkyTexture
|
|
- _scene.FogColor=New Color(0.69, 0.78, 0.82, 0.75 )
|
|
|
|
- _scene.FogNear=1
|
|
|
|
- _scene.FogFar=1000
|
|
|
|
|
|
+ _scene.FogColor = New Color(0.69, 0.78, 0.82, 0.3 )
|
|
|
|
+ _scene.FogFar = 5000
|
|
|
|
+ _scene.FogNear = 1
|
|
|
|
|
|
'create light
|
|
'create light
|
|
_light=New Light
|
|
_light=New Light
|
|
- _light.Rotate( 54,144,0 ) 'calibrated to match sky texture!
|
|
|
|
|
|
+ _light.Rotate( 45, 45, 0 )
|
|
_light.CastsShadow = True
|
|
_light.CastsShadow = True
|
|
|
|
|
|
'create water material
|
|
'create water material
|
|
Local waterMaterial:=New WaterMaterial
|
|
Local waterMaterial:=New WaterMaterial
|
|
|
|
|
|
- waterMaterial.ScaleTextureMatrix( 100,100 )
|
|
|
|
- waterMaterial.ColorFactor=New Color( 0.05, 0.25, 0.3 )
|
|
|
|
|
|
+ waterMaterial.ScaleTextureMatrix( 300,300 )
|
|
|
|
+ waterMaterial.ColorFactor=New Color( 0.025, 0.125, 0.15 )
|
|
waterMaterial.Roughness=0
|
|
waterMaterial.Roughness=0
|
|
|
|
|
|
waterMaterial.NormalTextures=New Texture[](
|
|
waterMaterial.NormalTextures=New Texture[](
|
|
@@ -64,8 +64,7 @@ Class MyWindow Extends Window
|
|
New Vec2f( .02,.05 ) )
|
|
New Vec2f( .02,.05 ) )
|
|
|
|
|
|
'create water
|
|
'create water
|
|
- _water=Model.CreateBox( New Boxf( -2000,-1,-2000,2000,0,2000 ),1,1,1,waterMaterial )
|
|
|
|
- _water.CastsShadow=False
|
|
|
|
|
|
+ _water=Model.CreateBox( New Boxf( -10000,-1,-10000,10000,0,10000 ),1,1,1,waterMaterial )
|
|
|
|
|
|
'create bloom
|
|
'create bloom
|
|
Local _bloom := New BloomEffect( 2 )
|
|
Local _bloom := New BloomEffect( 2 )
|
|
@@ -75,24 +74,37 @@ Class MyWindow Extends Window
|
|
_pivot = New Model
|
|
_pivot = New Model
|
|
|
|
|
|
'create airplane
|
|
'create airplane
|
|
- _plane = Model.LoadBoned( "asset::plane.gltf" )
|
|
|
|
-' _plane.Animator.Animate( 0 )
|
|
|
|
|
|
+ _plane = Model.LoadBoned( "asset::plane/plane.gltf" )
|
|
|
|
+ _plane.Animator.Animate( 0 )
|
|
_plane.Parent = _pivot
|
|
_plane.Parent = _pivot
|
|
_plane.Position = New Vec3f
|
|
_plane.Position = New Vec3f
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+' Local matrix := New AffineMat4<Float>
|
|
|
|
+' _plane.Rotate( 0, 180, 0)
|
|
|
|
+' _plane.Mesh.TransformVertices( matrix )
|
|
|
|
+
|
|
|
|
+' Local mat := Cast<PbrMaterial>( _plane.Material )
|
|
|
|
+' Local mat := New PbrMaterial( Color.LightGrey, 0.1, 0.1, True )
|
|
|
|
+' Local tex := Texture.Load( "asset::plane_Oc.png", TextureFlags.FilterMipmap )
|
|
|
|
+' mat.OcclusionTexture = tex
|
|
|
|
+
|
|
|
|
+ Print _plane.Materials.Length
|
|
|
|
+ Print ( _plane.Material? "true" Else "False" )
|
|
|
|
+' _plane.Material = mat
|
|
|
|
+
|
|
'create camera target
|
|
'create camera target
|
|
- _camTarget = New Entity( _plane )
|
|
|
|
|
|
+ _camTarget = New Entity( _pivot )
|
|
' _camTarget = Model.CreateSphere( 0.25, 12, 12, New PbrMaterial( Color.Red ) )
|
|
' _camTarget = Model.CreateSphere( 0.25, 12, 12, New PbrMaterial( Color.Red ) )
|
|
- _camTarget.Parent = _plane
|
|
|
|
- _camTarget.Position = New Vec3f( 0, 0, 10 )
|
|
|
|
|
|
+' _camTarget.Parent = _plane
|
|
|
|
+ _camTarget.Position = New Vec3f( 0, 0, -10 )
|
|
|
|
|
|
'create camera
|
|
'create camera
|
|
_camera=New Camera( _pivot )
|
|
_camera=New Camera( _pivot )
|
|
- _camera.Viewport=Rect
|
|
|
|
|
|
+ _camera.View = Self
|
|
_camera.Near=.1
|
|
_camera.Near=.1
|
|
- _camera.Far=1000
|
|
|
|
- _camera.FOV = 60
|
|
|
|
- _camera.Move( 0,3,-12 )
|
|
|
|
|
|
+ _camera.Far=10000
|
|
|
|
+ _camera.FOV = 75
|
|
|
|
+ _camera.Move( 0,3,8 )
|
|
|
|
|
|
'Control component
|
|
'Control component
|
|
Local control := _pivot.AddComponent<PlaneControl>()
|
|
Local control := _pivot.AddComponent<PlaneControl>()
|
|
@@ -101,51 +113,30 @@ Class MyWindow Extends Window
|
|
control.target = _camTarget
|
|
control.target = _camTarget
|
|
|
|
|
|
_pivot.Position = New Vec3f( 0, 6, 0 )
|
|
_pivot.Position = New Vec3f( 0, 6, 0 )
|
|
|
|
+
|
|
|
|
+' Local ball := Model.CreateSphere( 2, 24, 24, New PbrMaterial( Color.Red, 0.1, 0.25 ) )
|
|
|
|
+' ball.Move( 0, 4, 0)
|
|
End
|
|
End
|
|
|
|
|
|
|
|
|
|
Method OnRender( canvas:Canvas ) Override
|
|
Method OnRender( canvas:Canvas ) Override
|
|
RequestRender()
|
|
RequestRender()
|
|
-
|
|
|
|
- _camera.Viewport=Rect
|
|
|
|
-
|
|
|
|
_water.Position=New Vec3f( Round(_camera.Position.x/2000)*2000,0,Round(_camera.Position.z/2000)*2000 )
|
|
_water.Position=New Vec3f( Round(_camera.Position.x/2000)*2000,0,Round(_camera.Position.z/2000)*2000 )
|
|
-
|
|
|
|
- _camera.WorldPointAt( _camTarget.Position )
|
|
|
|
-
|
|
|
|
|
|
+ _camera.PointAt( _camTarget.Position )
|
|
_scene.Update()
|
|
_scene.Update()
|
|
- _scene.Render( canvas )
|
|
|
|
-
|
|
|
|
- canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )
|
|
|
|
-' canvas.DrawText( _plane.Rotation,0,15 )
|
|
|
|
-' canvas.DrawText( _plane.LocalRotation,0,30 )
|
|
|
|
|
|
+ _camera.Render( canvas )
|
|
|
|
+ canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS + " Aspect=" + _camera.Aspect,0,0 )
|
|
End
|
|
End
|
|
|
|
|
|
-'
|
|
|
|
|
|
+
|
|
Method OnMeasure:Vec2i() Override
|
|
Method OnMeasure:Vec2i() Override
|
|
Return _res
|
|
Return _res
|
|
End
|
|
End
|
|
|
|
|
|
End
|
|
End
|
|
|
|
|
|
-
|
|
|
|
-Class Entity Extension
|
|
|
|
-
|
|
|
|
- Method WorldPointAt( target:Vec3f,up:Vec3f=New Vec3f( 0,1,0 ) )
|
|
|
|
- Local k:=(target-Position).Normalize()
|
|
|
|
- Local i:=up.Cross( k ).Normalize()
|
|
|
|
- Local j:=k.Cross( i )
|
|
|
|
- Basis=New Mat3f( i,j,k )
|
|
|
|
- End
|
|
|
|
-
|
|
|
|
-End
|
|
|
|
-
|
|
|
|
Function Main()
|
|
Function Main()
|
|
-
|
|
|
|
New AppInstance
|
|
New AppInstance
|
|
-
|
|
|
|
New MyWindow
|
|
New MyWindow
|
|
-
|
|
|
|
App.Run()
|
|
App.Run()
|
|
End
|
|
End
|
|
-
|
|
|