Post by Danilo on Sept 5, 2019 18:51:49 GMT
Basic 3D Test
Run this example ONLINE
Run this example ONLINE
#Import "<std>"
#Import "<mojo>"
#Import "<mojo3d>"
Using std..
Using mojo..
Using mojo3d..
Const NUM_BOXES:Int = 150 '
Const SHADOWS:Bool = True ' <<-- SHADOWS = False allows more Boxes
Class MyWindow Extends Window
Field scene:Scene
Field camera:Camera
Field model:mojo3d.Model
Field boxes:mojo3d.Model[]
Method New()
Super.New( "In Town",App.DesktopSize.X*0.8,App.DesktopSize.Y*0.5,WindowFlags.Resizable )
CreateScene()
End
Method CreateGroundPlane:Model()
Local box:=New Boxf( -256,0,-256,256,1,256 )
Local material:=New PbrMaterial( Color.FromRGBA($008000ff),1,1 )
Local ground:=Model.CreateBox(box,1,1,1,material)
ground.CastsShadow = SHADOWS
Return ground
End
Method CreateBoxes()
Local material:=New PbrMaterial( Color.White*0.9,1,0.9 )
Local box:=New Boxf( -.5,.5 )
model=Model.CreateBox( box,1,1,1,material )
model.CastsShadow = SHADOWS
model.Visible = False
For Local i:=0 Until NUM_BOXES
boxes[i] = CopyModel()
Next
End
Method CopyModel:Model()
Local copy:=model.Copy()
Local h:=2+Rnd(10)
Local s:= New std.geom.Vec3f(Rnd(2,8),h,Rnd(1,5))
copy.Scale = s
copy.Move( -40+Rnd(80),0.9+h*.5,Rnd( 50,110 ) )
copy.Visible = True
Return copy
End
Method CreateScene()
SeedRnd( Millisecs() )
boxes=New mojo3d.Model[NUM_BOXES]
scene=New Scene
scene.FogColor=Color.Black'*0.995
scene.FogNear=30
scene.FogFar=50
scene.EnvColor=Color.White
scene.AmbientLight=Color.White
scene.ClearColor=Color.Blue*0.1
camera=New Camera( Self )
camera.Near=.1
camera.Far=1000
camera.Move( 0,12.5,-5 )
camera.FOV=100
Local light:=New Light
light.CastsShadow=SHADOWS
light.RotateX( 60 )
light.RotateY( 15 )
CreateGroundPlane()
CreateBoxes()
End
Method OnUpdate()
For Local i:=0 Until NUM_BOXES
boxes[i].Move(0,0,-.15)
If boxes[i].Z <= -10
boxes[i].Destroy()
boxes[i] = CopyModel()
Endif
Next
End
Method OnRender( canvas:Canvas ) Override
OnUpdate()
scene.Update()
scene.Render( canvas )
canvas.DrawText( "FPS="+App.FPS,5,5,0,0 )
RequestRender()
End
End
Function Main()
New AppInstance
New MyWindow
App.Run()
End