• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

N3xtD - Free 3D engine

Started by Brice Manuel, August 25, 2011, 06:40:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brice Manuel

A few topics down is an old thread about 3Impact.  Since there was some interest in it, I am posting some info about a 3D engine that I just stumbled on that looks pretty nice.  It is called N3xtD.  It is free and is being used for a 3D modeling program I am trying out.  There are not any PowerB wrappers at this point, but there are wrappers included for several other languages.  It should be easy enough for somebody skilled with PowerB to convert the FreeBasic wrappers to PowerB.

http://n3xt-d.org

It could be something fun for somebody to play with.

Peter Weis

#1
Hello Manuel,
I've made ​​the effort and adapted to the Includes PowerBASIC! But there are still errors. But for a try, it already reached

regards Peter ;D

Include Attention new today 11.10.2011

Peter Weis

Hello,
here is the next example

regards Peter

Peter Weis

Hello,
resist a few mistakes in "N3xtD.bi" eliminated

regards Peter

Peter Weis

And here is the next example


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  006   as   Load a simple 3D Object And set multiple mesh
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

' Dimes
FUNCTION PBMAIN()
    DIM app AS DWORD
    DIM Quit AS LONG

    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app=%NULL THEN
        END
    END IF



    ' Load an 3D Object
    DIM obj AS Mesh
    obj = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)



    ' Create several mesh
    DIM i AS INTEGER
    DIM sphere AS EntityNode
    FOR  i = 0 TO 3
        '; Create a mesh with one of the 3D Object loaded
        sphere = CreateEntityNode(obj, 0,  0,  0, %NULL)
        ' set position
        PositionNode(sphere, 3*i,0,0)
    NEXT




    ' create a camera
    DIM cam AS CameraNode
    cam = CreateCamera(%NULL)
    PositionNode(cam, 6,0,-10)


    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        ' just turn our sphere
        TurnNode(sphere, 0,0.5,0, 0)



        ' ---------------
        '      Render
        ' ---------------
        BeginScene(0, 0, 0, 255, 1, 1)
        DrawScene()
        EndScene()

    WEND
    ' end
    FreeEngine()
END FUNCTION
                                         



Peter Weis

Next example


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  007   as   just create a single mesh
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD 'any Ptr
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)

    IF app=%NULL THEN
        EXIT FUNCTION
    END IF






    '---------------------------
    ' define a ManualContruct Mesh
    DIM mesh_ AS Mesh

    ' Create the mesh
    mesh_ = CreateEmptyMesh(%VERTEX_TYPE.EVT_STANDART)


    ' add one buffer For vertices And faces
    ' define 3 vertices
    DIM v1 AS LONG
    v1 = AddVertexMesh(mesh_, 0, 0,0,0, 0,0,0,  &h0ffff, 0, 0, 0, 0)
    DIM v2 AS LONG
    v2 = AddVertexMesh(mesh_, 0, 2,2,0, 0,0,0,  &h0ffff, 0, 0, 0, 0)
    DIM v3 AS LONG
    v3 = AddVertexMesh(mesh_, 0, 2,0,0, 0,0,0,  &h0ffff, 0, 0, 0, 0)

    ' add one face
    AddFaceMesh(mesh_, 0, v1, v2, v3)

    ' add second buffer For vertices And faces
    AddEmptyMeshBuffer(mesh_, %VERTEX_TYPE.EVT_STANDART)
    ' define 3 vertices
    v1 = AddVertexMesh(mesh_, 1, 0,2,0, 0,0,0,  &h0ffff, 0, 0, 0, 0)
    v2 = AddVertexMesh(mesh_, 1, 2,2,0, 0,0,0,  &h0ffff, 0, 0, 0, 0)
    v3 = AddVertexMesh(mesh_, 1, 0,0,0, 0,0,0,  &h0ffff, 0, 0, 0, 0)
    ' add one face

    AddFaceMesh(mesh_, 1, v1,v2,v3)



    ' Create a mesh with one of the 3D Object loaded
    DIM element AS EntityNode
    element = CreateEntityNode(mesh_, 0, 0, 0, %NULL)



    '---------------------------
    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCamera(%NULL)
    PositionNode(cam, 1,0,-10)



    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


    ' If Escape Key, Exit
    IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
        Quit=1
    END IF


    ' just turn our sphere
    TurnNode(element, 0,0.5,0, 0)



    ' ---------------
    '      Render
    ' ---------------
    BeginScene(0, 0, 0, 255, 1, 1)
    DrawScene()
    EndScene()

    WEND
    ' end
    FreeEngine()
END FUNCTION


                                 

Peter Weis

Did the declaration of Sendlog N3xtD.bi changed in that is better


DECLARE SUB SendLog CDECL LIB "N3XTD.DLL" ALIAS "_SendLog"(logtext AS ASCIZ)                                                                       


instead of


DECLARE SUB SendLog CDECL LIB "N3XTD.DLL" ALIAS "_SendLog"(byval logtext AS ASCIZ ptr)
                                                                                                                                                 



This facilitates the transfer

And a new example


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  009   as   modifiy mesh loaded geometry

'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD 'any Ptr
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app=%NULL THEN
        EXIT FUNCTION
    END IF



    ' Load an 3D Object
    DIM obj AS Mesh
    obj  = LoadMesh("media/earth.x", 0)
    ' dim obj as Mesh = _CreateSphereMesh(1)


    ' Create several mesh
    DIM sphere AS EntityNode
    DIM i AS INTEGER
    FOR  i  = 0 TO 3
        ' Create a mesh with one of the 3D Object loaded
        sphere = CreateEntityNode(obj, 0,  0, 0, %NULL)
        ' set position
        PositionNode(sphere, 3*i,0,0)
    NEXT



    ' send inside the console some mesh buffer information
    SendLog("Number of MeshBuffer as  " + STR$(MeshBufferCount(obj)))
    SendLog("Type of Vertex Buffer as  " + STR$(MeshTypeVertex(obj,  0)))
    '_SendLog("adr of mesh buffer 0 as  "+ str$(_MeshBuffer(obj, 0)))
    SendLog("number of vertices inside the meshbuffer as  "+ STR$(MeshVertexCount(obj,0) ))



    'apply the scale transformation For all the vertices
    DIM vec(4) AS SINGLE
    FOR i = 0 TO MeshVertexCount(obj, 0)-1
        ' get vertex
        MeshVertex(obj, 0, i, BYVAL VARPTR (vec(0)))
        ' multiply vertices position values
        vec(0)=vec(0)*3
        vec(1)=vec(1)*3
        vec(2)=vec(2)*3
        ' set vertex
        VertexPositionMesh(obj,0, i, vec(0), vec(1), vec(2))
    NEXT
    ' because all spheres mesh is based on the same Object geometrie,
    ' If you transform this mesh geometrie, all the mesh will be
    ' affected by this transformation




    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCamera(%NULL)
    PositionNode(cam, 6,0,-10)


    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        TurnNode(sphere, 0,0.5,0, 0)


        ' ---------------
        '      Render
        ' ---------------
        BeginScene(128,128,128, 255, 1, 1)
        DrawScene()
        EndScene()


    WEND
    ' end
    FreeEngine()

END FUNCTION
                           

Peter Weis

#7
Next example


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  010   as   first texturing

'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app=%NULL THEN
        EXIT FUNCTION
    END IF


    'Create mesh
    DIM cubemesh AS Mesh
    cubemesh = CreateCubeMesh(1.0)
    DIM spheremesh AS Mesh
    spheremesh = CreateSphereMesh(1.0, 16)
    DIM cylindermesh AS Mesh
    cylindermesh = CreateCylinderMesh(1.0, 3.0, &h0ffffffff, 8, %True, 0)


    ' Create all entity with mesh
    DIM cube AS EntityNode
    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    PositionNode(cube, -6,0,0)
    ' first Method To texturing
    DIM material AS NMaterial
    material = NodeMaterial(cube, 0)
    ' Load texture
    DIM tex AS NTexture
    tex = LoadTexture( "media/wall.jpg")
    ' set texture in material
    TextureMaterial(material,  0, tex)



    ' Create a sphere And set position
    DIM sphere AS EntityNode
    sphere = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
    PositionNode(sphere, -2,0,0)
    ' second Method
    LoadTextureNode(sphere, "media/body.bmp", 0, 0)


    ' Create a cylinder And set position
    DIM cylinder AS EntityNode
    cylinder = CreateEntityNode(cylindermesh, 0, 0, 0, %NULL)
    PositionNode(cylinder, 2,0,0)
    ' Load texture
    LoadTextureNode(cylinder, "media/five.bmp", 0, 0)




    ' Create a camera
    DIM cam AS CameraNode
    cam  = CreateCamera(%NULL)
    PositionNode(cam, 0,0,-10)


    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        ' ---------------
        '      Render
        ' ---------------
        BeginScene(12,12,12, 255, 1, 1)
        DrawScene()
        EndScene()


    WEND
    ' end
    FreeEngine()
END FUNCTION
                                     



N3xtD.bi was also changed again


regards

Peter Weis

example 011


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  011   as   render on texture.


'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN

    ' Dimes
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app=%NULL THEN
        EXIT FUNCTION
    END IF


    ' set ambient light
    AmbientLight(&h0ffaaaaaa)


    ' Create mesh
    DIM cubemesh AS Mesh
    cubemesh = CreateCubeMesh(1.0)


    '-----------------------------------------
    ' Create a cube And set position
    DIM cube AS EntityNode
    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    PositionNode(cube, 0,0,0)
    ' first Method To texturing
    DIM  material AS NMaterial
    material = NodeMaterial(cube, 0)
    ' Load texture
    DIM  tex AS NTexture
    tex = LoadTexture( "media/glass.bmp")
    ' set texture in material
    TextureMaterial(material,  0, tex)



    '-----------------------------------------
    ' Create cube For receive texturerendered
    DIM target AS EntityNode
    target = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    ScaleNode(target, 3,3,3)
    PositionNode(target, -6,0,0)
    MaterialFlagNode(target, %EMF_LIGHTING, %False)

    ' assign target texture on the *target cube
    DIM textureTarget AS NTexture
    textureTarget = CreateRenderTargetTexture( 256, 256, %ECF_UNKNOWN)
    MaterialTextureNode(target, textureTarget, 0 )



    ' Create first  camera
    DIM cam AS CameraNode
    cam = CreateCamera(%NULL)
    PositionNode(cam, -5,3,-10)

    ' Create second  camera For render target
    DIM cam2 AS CameraNode
    cam2 = CreateCamera(%NULL)
    PositionNode(cam2, 0,0,-3)


    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF

        TurnNode(cube, 0,1,0, 0)

        ' ---------------
        '      Render
        ' ---------------
        BeginScene(0,0,0, 255, 1, 1)

        ' render traget texture with camera 2
        ActiveCamera(cam2)
        RenderTarget(textureTarget , %True,  %True,  &hff666600)
        ' this Method
        RenderNode(cam2)
        RenderNode(cube)
        ' <<Or>>
        '_VisibleNode(*target, #False)
        '_DrawScene()


        ' render with Main camera
        ActiveCamera(cam)
        RenderTarget(%Null , %True,  %True,  0)
        VisibleNode(target, %True)
        DrawScene()

        EndScene()


    WEND
    ' end
    FreeEngine()
END FUNCTION
                               

Peter Weis

example 013


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  013   as  primitives with a light.
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD
    DIM Quit AS DWORD


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app=%NULL THEN
        EXIT FUNCTION
    END IF



    ' Create light And set position
    DIM light AS LightNode
    light = CreateLight( &h0ffffffff, 12, %ELT_POINT , %NULL                                                                                                   )
    PositionNode(light, 0,5,5)
    ' change light diffuse color
    DiffuseColorLight( light, &h0ffffff00)
    AmbientLight( &h0ff22222)


    ' Create mesh
    DIM cubemesh AS Mesh
    cubemesh = CreateCubeMesh(1.0)
    DIM spheremesh AS Mesh
    spheremesh = CreateSphereMesh(1.0, 16)
    DIM cylindermesh AS Mesh
    cylindermesh = CreateCylinderMesh(1.0, 3.0, &H0ffffffff, 8, %True, 0)

    ' Create all entity with mesh
    DIM cube AS EntityNode
    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    PositionNode(cube, -6,0,0)

    ' Create a sphere And set position
    DIM sphere AS EntityNode
    sphere = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
    PositionNode(sphere, -2,0,0)

    ' Create a cylinder And set position
    DIM cylinder AS EntityNode
    cylinder = CreateEntityNode(cylindermesh, 0, 0, 0, %NULL)
    PositionNode(cylinder, 2,0,0)
    RotateNode(cylinder, 0,0,90)


    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCamera(%NULL)
    PositionNode(cam, 0,0,-10)


    DIM lightpos(4) AS SINGLE
    DIM angle AS SINGLE

    '; ---------------------------------------
    ';           Main loop
    '; ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        angle = angle + 0.05
        lightpos(0) = 10*COS( angle)
        lightpos(2) = 10*SIN( angle)
        XNode( light, lightpos(0))
        ZNode( light, lightpos(2))

        '---------------
        '      Render
        ' ---------------
        BeginScene(128,128,128, 255, 1, 1)
        DrawScene()
        EndScene()


    WEND
    ' end
    FreeEngine()
END FUNCTION
                           

Peter Weis

The last example for today


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  014   as  primitives with a light And material.

'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD '
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app = %NULL THEN
        EXIT FUNCTION
    END IF



    ' Create light And set position
    DIM light AS LightNode
    light = CreateLight( &h0ffffffff, 10, %ELT_POINT , %NULL)
    PositionNode(light, 0,5,0)


    ' Create mesh
    DIM cubemesh AS Mesh
    cubemesh = CreateCubeMesh(1.0)
    DIM spheremesh AS Mesh
    spheremesh = CreateSphereMesh(1.0, 16)
    DIM cylindermesh AS Mesh
    cylindermesh = CreateCylinderMesh(1.0, 3.0, &H0ffffffff, 8, %True, 0)


    ' Create a cube And set position
    DIM cube AS EntityNode
    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    PositionNode(cube, -6,0,0)
    ' first Method set
    DIM mat_ AS NMaterial
    mat_= NodeMaterial(cube, 0)
    ColorMaterial(mat_,  %ECM_NONE)
    DiffuseColorMaterial(mat_,  &h0ffff0000)



    ' Create a sphere And set position
    DIM sphere AS EntityNode
    sphere = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
    PositionNode(sphere, -2,0,0)
    ' second metohd set
    MaterialColorNode(sphere, %ECM_NONE)
    DiffuseColorNode(sphere, &h0ff00ff00)



    ' Create a cylinder And set position
    DIM cylinder AS EntityNode
    cylinder = CreateEntityNode(cylindermesh, 0, 0, 0, %NULL)
    PositionNode(cylinder, 2,2,0)
    RotateNode(cylinder, 0,0,90)
    ' second metohd set
    MaterialColorNode(cylinder, %ECM_NONE)
    DiffuseColorNode(cylinder, &h0ff0000ff)



    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCamera(%NULL)
    PositionNode(cam, 0,0,-10)



    DIM lightpos(4) AS SINGLE
    DIM angle AS SINGLE
    angle = 3.0

    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        angle = angle + 0.02
        lightpos(0) = 10*COS( angle)
        lightpos(2) = 10*SIN( angle)
        XNode( light, lightpos(0))
        ZNode( light, lightpos(2))

        ' ---------------
        '      Render
        ' ---------------
        BeginScene(128,128,128, 255, 1, 1)
        DrawScene()
        EndScene()


    WEND
    ' end
    FreeEngine()

END FUNCTION
                 

Peter Weis

Next example


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  015  : primitives with a spot light and material.
'   Historique  :
'     29/03/09  19:16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN

    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app=%NULL THEN
        EXIT FUNCTION
    END IF



    '----------------------------------------
    ' Create light And set position
    DIM light AS LightNode
    light = CreateLight(&h0ffffffff, 10, %ELT_POINT , %NULL)
    PositionNode(light, 0,15,-8)
    ' change light Type -> SPOTLIGHT
    TypeLight( light, %ELT_SPOT) ' Or  iTypeLight( light, ELT_DIRECTIONAL)
    ' redefine internal parameters
    RadiusLight( light,  30)
    RotateNode( light, 60,0,0)
    OuterConeLight( light, 30)
    InnerConeLight( light,  25 )
    ' color light set element
    '_AmbientColorLight( light, &hff999999)
    '_DiffuseColorLight( light, &hff555555)



    '----------------------------------------
    ' Create mesh
    DIM cubemesh AS Mesh
    cubemesh = CreateCubeMesh(1.0)

    DIM spheremesh AS Mesh
    spheremesh = CreateSphereMesh(1.0, 16)

    DIM cylindermesh AS Mesh
    cylindermesh = CreateCylinderMesh(1.0, 3.0, &H0ffffffff, 8, %True, 0)


    ' Create a cube And set position
    DIM cube AS EntityNode
    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    PositionNode(cube, -6,0,0)
    ' first Method set
    DIM mat_ AS NMaterial
    mat_ = NodeMaterial(cube, 0)
    ColorMaterial(mat_, %ECM_NONE)
    DiffuseColorMaterial(mat_, &h0ff000044)
    ShadowVolumeEntity(cube, %True, 10000.0 )


    ' Create a sphere And set position
    DIM sphere AS EntityNode
    sphere = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
    PositionNode(sphere, -2,0,0)
    ' second metohd set
    MaterialColorNode(sphere, %ECM_NONE)
    DiffuseColorNode(sphere, &h0ff004400)
    ShadowVolumeEntity(sphere, %True, 10000.0)

    ' Create a cylinder And set position
    DIM cylinder AS EntityNode
    cylinder = CreateEntityNode(cylindermesh, 0, 0, 0, %NULL)
    PositionNode(cylinder, 2,2,0)
    RotateNode(cylinder, 0,0,90)
    ' second metohd set
    MaterialColorNode(cylinder, %ECM_NONE)
    DiffuseColorNode(cylinder, &hff440000)
    ShadowVolumeEntity(cylinder, %True, 10000.0)




    '----------------------------------------
    ' quick ground For light spot test
    DIM hillplanemesh AS Mesh
    hillplanemesh = CreateHillPlaneMesh(50.0,50.0, 80,80, %NULL, 0, 0, 0, 1, 1)

    DIM hillplane AS EntityNode
    hillplane = CreateEntityNode(hillplanemesh, 0, 0, 0, %NULL)
    PositionNode(hillplane, 0,-2,0)
    ScaleMesh(hillplanemesh, 0.01, 0.01, 0.01)
    ' second metohd set
    AmbientColorNode(hillplane, &h0ff444444)
    DiffuseColorNode(hillplane, &hff888888)



    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCamera(%NULL)
    PositionNode(cam, 0,10,-13)
    RotateNode(cam, 20,0,0)


    '-----------------------------------
    ' Load font png
    LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
    DIM font_ AS IGUIFont
    font_ = GetFont()



    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        ' move light with dir key And mouse (Left click)
        IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN MoveNode(light, 0.5,0,0, %COLLIDE_RESPONSE.RESP_NONE)
        IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT) THEN MoveNode(light, -0.5,0,0, %COLLIDE_RESPONSE.RESP_NONE)
        IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN MoveNode(light, 0,0,0.5, %COLLIDE_RESPONSE.RESP_NONE)
        IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN MoveNode(light, 0,0,-0.5, %COLLIDE_RESPONSE.RESP_NONE)
        IF GetMouseEvent(%MOUSE_EVENT.MOUSE_BUTTON_LEFT) THEN
            DIM angley AS SINGLE
            angley =  GetDeltaMouseX(0) / 4.0
            DIM anglex AS SINGLE
            anglex =  GetDeltaMouseY(0) / 4.0
            TurnNode(light, anglex, angley,0, 0)
        END IF




        '; ---------------
        ';      Render
        '; ---------------
        BeginScene(0, 0, 0, 255, 1, 1)
        DrawScene()
        DrawText(font_, "for move spot light: dir key / mouse with leftclick",  10,10,0,0, &h0ffff99ff)
        EndScene()


    WEND
    ' end
    FreeEngine()
END FUNCTION
                   

Peter Weis

Example 016 and other errors by eliminating N3xtD.bi


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  016  as   Test transparent cubemesh
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD
    DIM Quit AS LONG


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app=%NULL THEN
        EXIT FUNCTION
    END IF





    DIM cubemesh AS Mesh
    cubemesh = CreateCubeMesh(5.0)
    DIM hillmesh AS Mesh
    hillmesh = CreateHillPlaneMesh(10.0, 10.0, 10, 10, %NULL, 0, 0, 0, 1, 1)


    '----------------------------------------
    ' Create a first cube And set position
    DIM cube AS EntityNode
    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    PositionNode(cube, 5,5,6)
    LoadTextureNode(cube, "media/sp1.png", 0, 0)

    MaterialTypeNode(cube,  %EMT_TRANSPARENT_ALPHA_CHANNEL )



    ' Create a second cube And set position
    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    PositionNode(cube, 0,5,0)
    LoadTextureNode(cube, "media/sp1.png", 0, 0)
    MaterialTypeNode(cube,  %EMT_TRANSPARENT_ALPHA_CHANNEL )


    '----------------------------------------
    ' quick ground
    DIM hillplane AS EntityNode
    hillplane = CreateEntityNode(hillmesh, 0, 0, 0, %NULL)
    LoadTextureNode(hillplane, "media/wall.jpg", 0, 0)



    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(80.0,  0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
    PositionNode(cam, 0,10,-30)


    '---------------------------------------
    '           Main loop
    '---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF



        ' just turn our sphere
        TurnNode(cube, 0,0.5,0, 0)




        ' ---------------
        '      Render
        ' ---------------
        BeginScene(0, 0, 0, 255, 1, 1)
        DrawScene()
        EndScene()

    WEND
    ' end
    FreeEngine()

END FUNCTION
                           

Peter Weis

Even a supplement for today 8)

' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  017   as   alpha blending test mesh
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD
    DIM Quit AS LONG


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app=%NULL THEN
        END
    END IF



    '----------------------------------------
    ' Create light And set position
    DIM light AS LightNode
    light = CreateLight(&h0ffffffff, 100, %ELT_POINT , %NULL)
    PositionNode(light, 0,15,-8)



    DIM cubemesh AS Mesh
    cubemesh = CreateCubeMesh(5.0)
    DIM hillmesh AS Mesh
    hillmesh = CreateHillPlaneMesh(10.0, 10.0, 10, 10, %NULL, 0, 0, 0, 1, 1)


    '----------------------------------------
    ' Create a first cube And set position
    DIM cube AS EntityNode
    cube = CreateEntityNode(cubemesh, 0,  0, 0, %NULL)
    PositionNode(cube, 5,5,6)
    LoadTextureNode(cube, "media/glass.bmp", 0, 0)
    DIM material AS NMaterial
    material = NodeMaterial(cube, 0)
    TypeMaterial(material,  %EMT_TRANSPARENT_ADD_COLOR )



    '----------------------------------------
    ' Create a second cube And set position
    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    PositionNode(cube, 0,5,0)
    LoadTextureNode(cube, "media/glass.bmp", 0, 0)
    ' work on material now
    material  = NodeMaterial(cube, 0)
    ColorMaterial(material, %ECM_NONE)
    TypeMaterial(material,  %EMT_ONETEXTURE_BLEND )
    TypeBlendMaterial(material, %EBF_SRC_ALPHA, %EBF_ONE_MINUS_SRC_ALPHA,    %EMFN_MODULATE_1X,  %EAS_TEXTURE OR %EAS_VERTEX_COLOR)




    '----------------------------------------
    ' quick ground
    DIM hillplane AS EntityNode
    hillplane  = CreateEntityNode(hillmesh, 0, 0, 0, %NULL)
    LoadTextureNode(hillplane, "media/wall.jpg", 0, 0)



    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(80.0,  0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
    PositionNode(cam, 0,10,-18)


    '-----------------------------------
    ' Load font png
    LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
    DIM font_ AS IGUIFont
    font_ = GetFont()

    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    DIM alpha AS LONG
    DIM src AS LONG
    src =  6
    DIM dest AS LONG
    dest = 7
    DIM cColor AS LONG
    WHILE Quit = 0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        TurnNode(cube, 0,0.5,0, 0)


        IF GetKeyUp(%KEY_CODE.KEY_KEY_Y) THEN
            src = src +1
            TypeBlendMaterial(material, src, dest,   %EMFN_MODULATE_1X, %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
        END IF
        IF GetKeyUp(%KEY_CODE.KEY_KEY_H) THEN
            src = src -1
            TypeBlendMaterial(material, src, dest,   %EMFN_MODULATE_1X,  %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
        END IF
        IF GetKeyUp(%KEY_CODE.KEY_KEY_U) THEN
            dest = dest +1
            TypeBlendMaterial(material, src, dest,   %EMFN_MODULATE_1X,  %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
        END IF
        IF GetKeyUp(%KEY_CODE.KEY_KEY_J) THEN
            dest = dest -1
            TypeBlendMaterial(material, src, dest,   %EMFN_MODULATE_1X,  %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
        END IF




        IF GetKeyDown(%KEY_CODE.KEY_KEY_T) THEN
            alpha = alpha + 1
            IF(alpha>254) THEN alpha = 0
            cColor = &h01000000 * alpha + &h010000*alpha + &h0100 * alpha + alpha
            DiffuseColorNode(cube,  ccolor)
        END IF
        IF GetKeyDown(%KEY_CODE.KEY_KEY_G) THEN
            alpha = alpha - 1
            IF(alpha<1) THEN alpha = 255
            cColor  = &h01000000 * alpha + &h010000*alpha + &h0100 * alpha + alpha
            DiffuseColorNode(cube,  ccolor)
        END IF




        ' ---------------
        '      Render
        ' ---------------
        BeginScene(0, 0, 0, 255, 1, 1)
        DrawScene()
        DrawText(font_, "Key T/G to change alpha as "+ STR$(alpha),  10,10,0,0, &h0ffff3333)
        DrawText(font_, "Key Y/H to change src  as "+ STR$(src),  10,30,0,0, &h0ffff3333)
        DrawText(font_, "Key U/J to changedest as "+ STR$(dest),  10,45,0,0, &h0ffff3333)
        EndScene()


    WEND
    ' end
    FreeEngine()
END FUNCTION
                                             

Peter Weis

Small charge for even today  :-[

' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  019  : Parallax mapping scene with bumpmap earth
'   Historique  :
'     29/03/09  19:16    TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app = %NULL THEN
        EXIT FUNCTION
    END IF


    '----------------------------------------
    ' fog definition
    Fog(&h00908050, %FOG_TYPE.EFT_FOG_LINEAR,  250.0, 1000.0,  0.003,  %True,  %FALSE )


    '----------------------------------------
    ' Load 3D objects
    DIM obj AS Mesh
    obj = LoadMesh("media/room.3ds", %HARDMAPPING.EHM_STATIC)
    ' change planar texture mapping on the mesh
    MakePlanarTextureMappingMesh(obj, 0.003)
    DIM obj2 AS Mesh
    obj2 = CreateMeshWithTangents(obj, %False, %False, %False, %True)
    FreeLoadedMesh(obj)



    '----------------------------------------
    ' Create room
    DIM room AS EntityNode
    room =  CreateEntityNode(obj2, 0, 0, 0, %NULL)
    ' Load two textures
    DIM colormap AS NTexture
    colormap = LoadTexture( "media/rockwall.bmp")

    DIM normalmap AS NTexture
    normalmap = LoadTexture( "media/rockwall_height.bmp")
    ' Creates a normal map from a height map texture.
    NormalMapTexture(normalmap, 10.0)

    ' set texture in the New room (room2)
    MaterialTextureNode(room, colormap , 0)
    MaterialTextureNode(room, normalmap , 1)

    ' set material For room parallax mapping
    DIM material AS NMaterial
    material = NodeMaterial(room, 0)
    SpecularColorMaterial(material, 0)
    MaterialTypeNode(room,  %EMT_PARALLAX_MAP_SOLID )
    MaterialFlagNode(room,  %EMF_FOG_ENABLE,  %True)
    TypeParamMaterial(material, 1.0/64.0)
    '----------------------------------------






    '----------------------------------------
    DIM obj1 AS Mesh
    obj1 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)

    DIM obj0 AS Mesh
    obj0 = CreateMeshWithTangents(obj1, %False, %False, %False, %True)
    FreeLoadedMesh(obj1)
    ' set the alpha value of all vertices To 200
    VertexColorAlphaMesh(obj0,  190)
    ' scale And position mesh
    ScaleMesh(obj0, 65,65,65)


    '----------------------------------------
    ' Create EARTH
    DIM sphere AS EntityNode
    sphere = CreateEntityNode(obj0, 0, 0, 0, %NULL)
    ' Create New sphere with tangent composants
    PositionNode(sphere, -70,130,45)
    ' Load heightmap, Create normal map from it And set it
    DIM earthNormalMap AS NTexture
    earthNormalMap = LoadTexture( "media/earthbump.bmp")
    ' Creates a normal map from a height map texture.
    NormalMapTexture(earthNormalMap, 9.0)
    MaterialTextureNode(sphere, earthNormalMap , 1)
    ' adjust material settings
    MaterialTypeNode(sphere,  %EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA )
    MaterialFlagNode(sphere,  %EMF_FOG_ENABLE,  %True)


    '----------------------------------------
    ' Create light And set position
    DIM light AS LightNode
    light = CreateLight(&h5588ff, 400, %ELT_POINT , %NULL)
    PositionNode(light, 0,0,0)
    CreateFlyCircleAnimator(light, 0,150,0, 200.0, 0.001)

    '----------------------------------------
    ' create light and set position
    DIM light1 AS LightNode
    light1 = CreateLight(&hff8800, 400, %ELT_POINT , %NULL)
    CreateFlyCircleAnimator(light1, 50,300,0, 190.0, -0.003)


    '----------------------------------------
    '----------------------------------------
    ' Create PARTICLE SYSTEM
    DIM part AS ParticleSystemNode
    part = CreateParticleSystem(%FALSE, light)
    ' Create a box particle emitter
    DIM aabbox(6) AS SINGLE
    aabbox(0)=-3 : aabbox(1)=0 : aabbox(2)=-3 : aabbox(3)=3 : aabbox(4)=1 : aabbox(5)=3
    DIM box_emitter AS ParticleEmitter
    box_emitter = CreateParticleBoxEmitter(part, 0, 0.03, 0, 80, 100, &h0Affffff, &h0Affffff, 400, 1000,0,5,5,5,5, BYVAL VARPTR( aabbox(0)))

    ' change SizeOf each particle inside the particle emitter
    MinStartSizeParticle(box_emitter,  30.0, 40.0  )
    MaxStartSizeParticle(box_emitter,  30.0, 40.0  )
    ' add New emitter inside the particlesystem
    AddEmitterParticleSystem(part, box_emitter )
    ' fadeout element
    FadeOutParticleSystem( part, 0, 1000)

    ' adjust some material settings
    LoadTextureNode(part, "media/fireball.bmp", 0, 0)

    DIM mat_ AS NMaterial
    mat_ = NodeMaterial(part, 0)
    TypeMaterial(mat_,  %EMT_TRANSPARENT_ADD_COLOR)
    '----------------------------------------





    '----------------------------------------
    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(80.0,  0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
    PositionNode(cam, -145,215,-263)
    TargetCamera(cam, -70,130,45)

    ' simple text inside the scene area
    LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
    DIM font_ AS IGUIFont
    font_ = GetFont()


    '---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF

        TurnNode(sphere, 0,0.5,0, 0)



        ' ---------------
        '      Render
        ' ---------------
        BeginScene(128,128,128, 255, 1, 1)
        DrawScene()
        EndScene()

    WEND
    ' end
    FreeEngine()
END FUNCTION