About Monkey 2 › Forums › Monkey 2 Programming Help › Mojo3d – Light not doing anything with custom meshes.
This topic contains 2 replies, has 2 voices, and was last updated by
Ethernaut
1 year ago.
-
AuthorPosts
-
March 21, 2018 at 5:48 am #14074
I can not seem to get the lighting working. I tried placing it on different positions(even rnd in loop) and pointing it but the scene does not seem affected. I am building my own meshes.
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"Using std..Using mojo..Using mojo3d..Class MyWindow Extends WindowField _scene:SceneField _camera:CameraField _light:LightField _model:ModelField _material:MaterialField worldmap:Int[,]' The camera positionField mapx:Int=40,mapy:Int=40Method New()' Create our world map and give it' random valuesworldmap = New Int[100,100]For Local y:Int=0 Until 100For Local x:Int=0 Until 100worldmap[x,y] = Rnd(0,4)NextNext'get scene'_scene=Scene.GetCurrent()'create camera'_camera=New Camera_camera.Near=.1_camera.Far=100_camera.Move( 0,-8,8 )_camera.PointAt(New Vec3f(0,0,0))'create light'_light=New Light_light.Color = Color.Red_light.Move(0,20,20)_light.PointAt(New Vec3f(0,0,0))createmap()EndMethod OnRender( canvas:Canvas ) OverrideRequestRender()scrollmap()_scene.Render( canvas,_camera )canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )If Keyboard.KeyReleased(Key.Escape) Then App.Terminate()End Method' Here we move the mapMethod scrollmap()Local tx:Int=mapxLocal ty:Int=mapyIf Keyboard.KeyDown(Key.Right) Then tx -= 1If Keyboard.KeyDown(Key.Left) Then tx += 1If Keyboard.KeyDown(Key.Up) Then ty += 1If Keyboard.KeyDown(Key.Down) Then ty -= 1If tx<0 Then tx = 0If tx+10>=worldmap.GetSize(0) Then tx = worldmap.GetSize(0)-10If ty<0 Then ty = 0If ty+10>=worldmap.GetSize(1) Then ty = worldmap.GetSize(1)-10Local redr:Bool=TrueIf mapy <> ty Or mapx <> tx Then redr = Truemapx = txmapy = tyIf redr Thencreatemap()End IfEnd MethodMethod createmap()'Destroy all models_scene.DestroyAllEntities()' Draw the mapFor Local y:Int=0 Until 10For Local x:Int=0 Until 10Local mesh:MeshSelect worldmap[x+mapx,y+mapy]Case 0mesh = createpyramid()Defaultmesh = createquad()End Select'create model for the mesh'_model=New Model_model.Mesh=mesh'Color based on worldmap valueSelect worldmap[x+mapx,y+mapy]Case 0_model.Material=New PbrMaterial( Color.Red)Case 1_model.Material=New PbrMaterial( Color.Green)Case 2_model.Material=New PbrMaterial( Color.Blue)Case 3_model.Material=New PbrMaterial( Color.Black)End Select_model.Material.CullMode=CullMode.None_model.Move(x-5,y-5,0)NextNextEnd Method' Create a squareMethod createquad:Mesh()'create quad mesh'Local vertices:=New Vertex3f[4]vertices[0].position=New Vec3f( -1, 1,0 )vertices[1].position=New Vec3f( 1, 1,0 )vertices[2].position=New Vec3f( 1,-1,0 )vertices[3].position=New Vec3f( -1,-1,0 )Local indices:=New UInt[6]indices[0]=0indices[1]=1indices[2]=2indices[3]=0indices[4]=2indices[5]=3Local mesh:=New Mesh( vertices,indices )Return meshEnd Method' create a pyramidMethod createpyramid:Mesh()'create quad mesh'Local vertices:=New Vertex3f[5]vertices[0].position=New Vec3f( -1, -1,0 )'left topvertices[1].position=New Vec3f( 1, -1,0 )'right topvertices[2].position=New Vec3f( -1,1,0 )'bottom leftvertices[3].position=New Vec3f( 1,1,0 ) 'bottom rightvertices[4].position=New Vec3f( 0,0,1 )'centerLocal indices:=New UInt[12]indices[0]=0indices[1]=1indices[2]=4indices[3]=4indices[4]=1indices[5]=3indices[6]=2indices[7]=4indices[8]=3indices[9]=0indices[10]=4indices[11]=2Local mesh:=New Mesh( vertices,indices )Return meshEnd MethodEnd ClassFunction Main()New AppInstanceNew MyWindowApp.Run()EndMarch 21, 2018 at 6:19 am #14075I got it doing something. I think that DestroyAllEntities also kills the lights and that needs to be recreated,
The shadows look a little bit broken though if I add the command : CastsShadow = True
March 21, 2018 at 6:46 am #14076I think you may be missing information in the vertices. Try adding texture coordinates ( (0,0) for bottom left, (1,1) for top right ) and call UpdateNormals() to recalculate the normals on all vertices.
Some good examples here:
https://github.com/blitz-research/monkey2/blob/develop/modules/mojo3d/geometry/meshprims.monkey2 -
AuthorPosts
You must be logged in to reply to this topic.