Results 1 to 3 of 3

Thread: Mesh creation in irrlicht

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Mesh creation in irrlicht

    trying to mimic example 15 of IrrlichtWrapper for freebasic , look the wrapper here http://www.frankdodd.screaming.net/I...pperPortal.htm
    my problem is : can't connect all the pyramid vertices with lines, i am aware that arrays in thinbasic begins with 1, i have changed all the vertices and indices to begin with 1.
    to try the example download the wrapper for thinbasic from here http://www.thinbasic.com/community/s...ll=1#post83724 look example irrlicht-tb-largo3a-all.zip and save the code below in it. attached also the freebasic code
    note that in freebasic there is:
    DIM indices(0 to 17) as ushort
    i have tried in TB UInt16, long, dword, word
    to let it display only the vertices (as big smooth points) uncomment:
    IrrSetNodeMaterialFlag( PyramidNode, %IRR_EMF_POINTCLOUD, 1 )
    and comment:
    IrrSetNodeMaterialFlag( PyramidNode, %IRR_EMF_WIREFRAME, 1 )

    #Include "%app_includepath%\thinbasic_gl.inc"
    #Include "%app_includepath%\thinbasic_glu.inc"
    #Include "Irrlicht_lw1c.inc" 
    Uses "console"
    '' global variables
    Dim xx,yy,zz As Long
    ' irrlicht objects
    Dim PyramidNode As irr_node 
    
    Dim Pyramid As irr_mesh
    Dim OurCamera As irr_camera
    
    ' -----------------------------------------------------------------------------
    ' start the irrlicht interface 
    IrrStart( %IRR_EDT_OPENGL, 800, 600, %IRR_BITS_PER_PIXEL_32, %IRR_WINDOWED, _ '200
              %IRR_SHADOWS, %IRR_IGNORE_EVENTS, %IRR_VERTICAL_SYNC_ON )
    
    ' send the window caption
    IrrSetWindowCaption(  Ucode$("Example 15: Create a custom mesh"))
    
    Dim verts(5) As IRR_VERT
    Dim indices(18) As DWord 'UInt16
    
    ' -----------------------------------------------------------------------------
    ' set up five vertices to define the points of a pyramid. the vertices have
    ' many properties that need to be set up to properly define the structure
    verts(1).x = -10 : verts(1).y = 0 : verts(1).z = -10
    verts(2).x = -10 : verts(2).y = 0 : verts(2).z = 10
    verts(3).x = 10 :  verts(3).y = 0 : verts(3).z = 10
    verts(4).x = 10 :  verts(4).y = 0 : verts(4).z = -10
    verts(5).x = 0 :   verts(5).y = 20:verts(5).z = 0
    
    ' each of the vertices can be assigned a colour to tint the texture, in this
    ' case we use white
    verts(1).vcolor = &H000000FF 
    verts(2).vcolor = &H000000FF
    verts(3).vcolor = &H00FF0000
    verts(4).vcolor = &H00007D00
    verts(5).vcolor = &H00007D00
    
    ' -----------------------------------------------------------------------------
    ' create the faces, this is an array of indices referencing the vectors they
    ' are collected into groups of three each defining a triangle in the mesh
    indices(1) = 1 : indices(2) = 2 : indices(3) = 5
    indices(4) = 2 : indices(5) = 3 : indices(6) = 5
    indices(7) = 3 : indices(8) = 4 : indices(9) = 5
    indices(10) = 4 : indices(11) = 1 : indices(12) = 5
    indices(13) = 3 : indices(14) = 2 : indices(15) = 1
    indices(16) = 1 : indices(17) = 4 : indices(18) = 3
    
    ' create the mesh from the array of vertices and indices
    Pyramid = IrrCreateMesh( "TestMesh", 5, verts(1), 18, indices(1))
    PyramidNode = IrrAddMeshToScene( Pyramid )
    ' switch off lighting effects on this node
    IrrSetNodeMaterialFlag( PyramidNode, %IRR_EMF_LIGHTING, %IRR_OFF )
    IrrSetNodeMaterialFlag( PyramidNode, %IRR_EMF_WIREFRAME, 1 )
    'IrrSetNodeMaterialFlag( PyramidNode, %IRR_EMF_POINTCLOUD, 1 )
    IrrSetNodeMaterialFlag( PyramidNode, %IRR_EMF_BACK_FACE_CULLING, 0 )
    
    IrrSetNodeScale( PyramidNode, 0.5, 0.5, 0.5 )
    IrrSetNodePosition( PyramidNode, -8,-3,0)
    
    ' add a camera into the scene 
    OurCamera = IrrAddCamera( 0,25,-29, 0,0,0 )
    'IrrSetNodePosition( OurCamera, 30,20,25)
    IrrSetCameraTarget(OurCamera, 0,0,0)
    'IrrHideMouse
    
    
    IrrAddFlyCircleAnimator(PyramidNode,0,8,0,11.5,-0.001)
    
    ' -----------------------------------------------------------------------------
    ' while the irrlicht environment is still running
       
    While IrrRunning
        glEnable(%GL_POINT_SMOOTH)
        glPointSize(10)
        glLineWidth(5) 
        yy=yy+1:xx=xx+0:zz=zz+0
        
        'IrrSetNodeRotation( PyramidNode, xx, yy, zz )
        
        ' begin the scene, erasing the canvas with sky-blue before rendering
        IrrBeginScene( 240, 255, 255 )
        ' draw the scene
        IrrDrawScene
    
        ' end drawing the scene and render it
        IrrEndScene
    Wend
    ' -----------------------------------------------------------------------------
    ' Stop the irrlicht engine and release resources
    IrrStop
    
    the freebasic code:
    '' ----------------------------------------------------------------------------
    '' Irrlicht Wrapper for Imperative Languages - Freebasic Examples
    '' Frank Dodd (2006)
    '' ----------------------------------------------------------------------------
    '' Example 15 : Custom Mesh
    '' This example creates a pyramid mesh that is set up ready to be textured
    '' it then adds the mesh as a new node and applies a material to it
    '' ----------------------------------------------------------------------------
    
    '' ////////////////////////////////////////////////////////////////////////////
    '' Includes for extension libraries
    #include "IrrlichtWrapper.bi"
    
    '' ////////////////////////////////////////////////////////////////////////////
    '' global variables
    
    ' irrlicht objects
    DIM Mesh as irr_mesh
    DIM MeshTexture as irr_texture
    DIM SceneNode as irr_node
    DIM OurCamera as irr_camera
    
    
    '' ////////////////////////////////////////////////////////////////////////////
    '' GDB debugger main() function
    
    ' -----------------------------------------------------------------------------
    ' start the irrlicht interface
    IrrStart( IRR_EDT_OPENGL, 400, 400, IRR_BITS_PER_PIXEL_32, _
            IRR_WINDOWED, IRR_SHADOWS, IRR_IGNORE_EVENTS, IRR_VERTICAL_SYNC_ON )
    
    ' set the window caption
    IrrSetWindowCaption( "Example 15: Create a custom mesh" )
    
    ' a mesh is created from an array of types called vertices that define a point
    ' in space. and an array of indices to these vertices that are grouped into
    ' threes to create triangles that form the mesh
    DIM verts(0 to 4) as IRR_VERT
    DIM indices(0 to 17) as ushort
    
    ' -----------------------------------------------------------------------------
    ' set up five vertices to define the points of a pyramid. the vertices have
    ' many properties that need to be set up to properly define the structure
    verts(0).x = -10 : verts(0).y = 0 : verts(0).z = -10
    verts(1).x = -10 : verts(1).y = 0 : verts(1).z = 10
    verts(2).x = 10 : verts(2).y = 0 : verts(2).z = 10
    verts(3).x = 10 : verts(3).y = 0 : verts(3).z = -10
    verts(4).x = 0 : verts(4).y = 20 : verts(4).z = 0
    
    ' the co-ordinates across a texture run from 0 to 1 so we place each of the
    ' vertices on this texture plane to appear as if the pyramid was painted from
    ' its bottom up
    verts(0).texture_x = 0 : verts(0).texture_y = 0
    verts(1).texture_x = 0 : verts(1).texture_y = 1
    verts(2).texture_x = 1 : verts(2).texture_y = 1
    verts(3).texture_x = 1 : verts(3).texture_y = 0
    verts(4).texture_x = 0.5 : verts(4).texture_y = 0.5
    
    ' each of the vertices can be assigned a colour to tint the texture, in this
    ' case we use white
    verts(0).vcolor = &h00FFFFFF
    verts(1).vcolor = &h00FFFFFF
    verts(2).vcolor = &h00FFFFFF
    verts(3).vcolor = &h00FFFFFF
    verts(4).vcolor = &h00FFFFFF
    
    ' -----------------------------------------------------------------------------
    ' create the faces, this is an array of indices referencing the vectors they
    ' are collected into groups of three each defining a triangle in the mesh
    indices(0) = 0 : indices(1) = 1 : indices(2) = 4
    indices(3) = 1 : indices(4) = 2 : indices(5) = 4
    indices(6) = 2 : indices(7) = 3 : indices(8) = 4
    indices(9) = 3 : indices(10) = 0 : indices(11) = 4
    indices(12) = 2 : indices(13) = 1 : indices(14) = 0
    indices(15) = 0 : indices(16) = 3 : indices(17) = 2
    
    ' create the mesh from the array of vertices and indices
    Mesh = IrrCreateMesh( "TestMesh", 5, verts(0), 18, indices(0))
    
    ' load texture resource for texturing the nodes
    MeshTexture = IrrGetTexture( "./media/texture.jpg" )
    
    ' add the mesh to the scene a couple of times
    SceneNode = IrrAddMeshToScene( Mesh )
    
    ' apply a material to the node
    IrrSetNodeMaterialTexture( SceneNode, MeshTexture, 0 )
    
    ' switch off lighting effects on this node
    IrrSetNodeMaterialFlag( SceneNode, IRR_EMF_LIGHTING, IRR_OFF )
    
    ' add a camera into the scene and resposition it to look at the pyramid
    OurCamera = IrrAddFPSCamera( IRR_NO_OBJECT, 100.0f, 0.1f )
    IrrSetNodePosition( OurCamera, 30,50,25)
    IrrSetCameraTarget(OurCamera, 0,0,0)
    IrrHideMouse
    
    
    ' -----------------------------------------------------------------------------
    ' while the irrlicht environment is still running
    WHILE IrrRunning
        ' begin the scene, erasing the canvas with sky-blue before rendering
        IrrBeginScene( 64, 96, 96 )
    
        ' draw the scene
        IrrDrawScene
        
        ' end drawing the scene and render it
        IrrEndScene
    WEND
    
    ' -----------------------------------------------------------------------------
    ' Stop the irrlicht engine and release resources
    IrrStop
    
    Last edited by primo; 30-10-2017 at 10:56.

Similar Threads

  1. Cloud and mesh processing software ....
    By RobbeK in forum TBGL module by Petr Schreiber
    Replies: 3
    Last Post: 23-03-2014, 14:43
  2. Multiple BIFF File Creation
    By fgasoi in forum BIFF
    Replies: 7
    Last Post: 22-01-2010, 16:56
  3. Early black box preview of ray-mesh collisions
    By Petr Schreiber in forum TBGL General
    Replies: 8
    Last Post: 19-10-2008, 11:29
  4. thinBundle module new features to complete exe creation
    By ErosOlmi in forum thinBundle suggest new features
    Replies: 7
    Last Post: 27-03-2007, 21:01

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •