About Monkey 2 › Forums › Monkey 2 Programming Help › Request – Mojo3d – Addtriangle example
This topic contains 1 reply, has 2 voices, and was last updated by
Mark Sibly
1 year, 9 months ago.
-
AuthorPosts
-
July 10, 2017 at 12:57 am #9216
I have been trying but failing into understanding on how to create a simple triangle. I want to start building things with meshes( I think that is what i need)
With blitz3d there was an example where it showed how to make a ramp. I was always able to go back to that to study how to make walls ect myself.
Would anyone who understands this already place some barebones code on how to make a wall or triangle?
July 10, 2017 at 1:39 am #9218Just added this to tests!
The easiest way to go is to create an array of vertices and an array of indices and just use New Mesh( vertices,triangles ).
Also, have a look at the source code for Mesh.CreateBox, Mesh.CreateSphere etc in modules/mojo3d/graphics/meshprims.monkey2
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"Using std..Using mojo..Using mojo3d..Class MyWindow Extends WindowField _scene:SceneField _camera:CameraField _light:LightField _model:ModelMethod New()'get scene'_scene=Scene.GetCurrent()'create camera'_camera=New Camera_camera.Near=.1_camera.Far=100_camera.Move( 0,0,-5 )'create light'_light=New Light_light.RotateX( Pi/2 ) 'aim directional light downwards - Pi/2=90 degrees.'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 )'create model for the mesh'_model=New Model_model.Mesh=mesh_model.Material=New PbrMaterial( Color.Red )_model.Material.CullMode=CullMode.NoneEndMethod OnRender( canvas:Canvas ) OverrideRequestRender()_model.RotateY( .1 )_scene.Render( canvas,_camera )canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()End -
AuthorPosts
You must be logged in to reply to this topic.