VB.NET (2010) 09-Mesh Viewer Code (99%)

A forum to store posts deemed exceptionally wise and useful

VB.NET (2010) 09-Mesh Viewer Code (99%)

Postby WaxyChicken » Wed Jul 27, 2011 1:35 am

I thought i'd post this up to help out any other VB people out there.
Irrlicht Lime wrapper of the IrrLicht Engine example 09- MeshViewer

Code can be compiled and run, but the coding for the slider bars does not work. (thus the 99%)
Still very educational.

vb Code: Select all
 
 
Option Explicit On
 
Imports System.Threading
Imports System.Collections.Generic
Imports System
 
Imports Microsoft.VisualBasic.Strings
Imports System.Net
Imports Microsoft.VisualBasic
Imports IrrlichtLime
Imports IrrlichtLime.Core
Imports IrrlichtLime.Video
Imports IrrlichtLime.IO
Imports IrrlichtLime.GUI
Imports IrrlichtLime.Scene
Imports IrrlichtLime.IrrlichtDevice
Imports System.Text
Imports System.IO
Imports System.ComponentModel
Imports System.Xml
 
Public Module Module1
    Public device As IrrlichtDevice = Nothing
    Public startUpModelFile As String
    Public messageText As String
    Public caption As String
    Public model As SceneNode = Nothing
    Public skybox As SceneNode = Nothing
    Public octree As Boolean = False
    Public useLight As Boolean = False
 
    Public camera(1) As CameraSceneNode
 
 
    ' Values used to identify individual GUI elements
   Public Enum guiID
        DialogRootWindow = &H10000
 
        XScale
        YScale
        ZScale
 
        OpenModel
        SetModelArchive
        LoadAsOctree
 
        SkyBoxVisible
        ToggleDebugInfo
 
        DebugOff
        DebugBoundingBox
        DebugNormals
        DebugSkeleton
        DebugWireOverlay
        DebugHalfTransparent
        DebugBuffersBoundingBoxes
        DebugAll
 
        ModelMaterialSolid
        ModelMaterialTransparent
        ModelMaterialReflection
 
        CameraMaya
        CameraFirstPerson
 
        PositionText
 
        About
        Quit
 
        TextureFilter
        SkinTransparency
        SkinAnimationFPS
 
        ButtonSetScale
        ButtonScaleMul10
        ButtonScaleDiv10
        ButtonOpenModel
        ButtonShowAbout
        ButtonShowToolbox
        ButtonSelectArchive
 
        Logo
    End Enum
 
    ' And some magic numbers
   Private Const MaxFramerate As Integer = 1000
    Private Const DefaultFramerate As Integer = 30
 
    Public Sub Main(ByVal args() As String)
        Dim driverType As New DriverType
        driverType = AskUserForDriver(driverType)
       
        device = IrrlichtDevice.CreateDevice(driverType, New Dimension2Di(800, 600), 16)
        If device Is Nothing Then
            Return
        End If
 
        AddHandler device.OnEvent, AddressOf device_OnEvent
        device.SetWindowResizable(True)
        device.SetWindowCaption("Irrlicht Engine - Loading...")
 
        Dim driver As VideoDriver = device.VideoDriver
        Dim env As GUIEnvironment = device.GUIEnvironment
        Dim smgr As SceneManager = device.SceneManager
 
        ' "COLLADA_CreateSceneInstances" is a value of scene::COLLADA_CREATE_SCENE_INSTANCES, Irrlicht' constant.
       ' It is not ported yet, so for Lime it is a "magic" value.
       ' All "magic" values that can be used with SceneManager's Attributes,
       ' described in "Variables" section at http://irrlicht.sourceforge.net/docu/na ... scene.html.
       smgr.Attributes.SetValue("COLLADA_CreateSceneInstances", True)
 
        driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, True)
 
        smgr.AddLightSceneNode(Nothing, New Vector3Df(200), New Colorf(1.0F, 1.0F, 1.0F), 2000)
        smgr.AmbientLight = New Colorf(0.3F, 0.3F, 0.3F)
 
        ' add our media directory as "search path"
       device.FileSystem.AddFileArchive("../../media/")
 
        ' read configuration from xml file
       ' (we use .NET way to do this, since Lime doesn't support native Irrlicht' xml reader)
       Dim xml As New XmlDocument()
        xml.Load("../../media/config.xml")
        startUpModelFile = xml.DocumentElement("startUpModel").Attributes("file").Value
        caption = xml.DocumentElement("messageText").Attributes("caption").Value
        messageText = xml.DocumentElement("messageText").InnerText
 
        If args.Length > 0 Then
            startUpModelFile = args(0)
        End If
 
        ' set a nicer font
       Dim font As GUIFont = env.GetFont("fonthaettenschweiler.bmp")
        If font IsNot Nothing Then
            env.Skin.SetFont(font)
        End If
 
        ' load the irrlicht engine logo
       Dim img As GUIImage = env.AddImage(driver.GetTexture("irrlichtlogoalpha2.tga"), New Vector2Di(10, CInt(driver.ScreenSize.Height) - 128))
        img.ID = CInt(Fix(guiID.Logo))
 
        ' lock the logo's edges to the bottom left corner of the screen
       img.SetAlignment(GUIAlignment.UpperLeft, GUIAlignment.UpperLeft, GUIAlignment.LowerRight, GUIAlignment.LowerRight)
 
        ' create menu
       Dim menu As GUIContextMenu = env.AddMenu()
        menu.AddItem("File", -1, True, True)
        menu.AddItem("View", -1, True, True)
        menu.AddItem("Camera", -1, True, True)
        menu.AddItem("Help", -1, True, True)
 
        Dim submenu As GUIContextMenu
        submenu = menu.GetSubMenu(0)
        submenu.AddItem("Open Model File & Texture...", CInt(Fix(guiID.OpenModel)))
        submenu.AddItem("Set Model Archive...", CInt(Fix(guiID.SetModelArchive)))
        submenu.AddItem("Load as Octree", CInt(Fix(guiID.LoadAsOctree)))
        submenu.AddSeparator()
        submenu.AddItem("Quit", CInt(Fix(guiID.Quit)))
 
        submenu = menu.GetSubMenu(1)
        submenu.AddItem("sky box visible", CInt(Fix(guiID.SkyBoxVisible)), True, False, True)
        submenu.AddItem("toggle model debug information", CInt(Fix(guiID.ToggleDebugInfo)), True, True)
        submenu.AddItem("model material", -1, True, True)
 
        submenu = submenu.GetSubMenu(1)
        submenu.AddItem("Off", CInt(Fix(guiID.DebugOff)))
        submenu.AddItem("Bounding Box", CInt(Fix(guiID.DebugBoundingBox)))
        submenu.AddItem("Normals", CInt(Fix(guiID.DebugNormals)))
        submenu.AddItem("Skeleton", CInt(Fix(guiID.DebugSkeleton)))
        submenu.AddItem("Wire overlay", CInt(Fix(guiID.DebugWireOverlay)))
        submenu.AddItem("Half-Transparent", CInt(Fix(guiID.DebugHalfTransparent)))
        submenu.AddItem("Buffers bounding boxes", CInt(Fix(guiID.DebugBuffersBoundingBoxes)))
        submenu.AddItem("All", CInt(Fix(guiID.DebugAll)))
 
        submenu = menu.GetSubMenu(1).GetSubMenu(2)
        submenu.AddItem("Solid", CInt(Fix(guiID.ModelMaterialSolid)))
        submenu.AddItem("Transparent", CInt(Fix(guiID.ModelMaterialTransparent)))
        submenu.AddItem("Reflection", CInt(Fix(guiID.ModelMaterialReflection)))
 
        submenu = menu.GetSubMenu(2)
        submenu.AddItem("Maya Style", CInt(Fix(guiID.CameraMaya)))
        submenu.AddItem("First Person", CInt(Fix(guiID.CameraFirstPerson)))
 
 
 
        submenu = menu.GetSubMenu(3)
        submenu.AddItem("About", CInt(Fix(guiID.About)))
 
        ' create toolbar

        Dim bar As GUIToolBar = env.AddToolBar()
 
        Dim image As Texture = driver.GetTexture("open.png")
        bar.AddButton(CInt(Fix(guiID.ButtonOpenModel)), Nothing, "Open a model", image, Nothing, False, True)
 
        image = driver.GetTexture("tools.png")
        bar.AddButton(CInt(Fix(guiID.ButtonShowToolbox)), Nothing, "Open Toolset", image, Nothing, False, True)
 
        image = driver.GetTexture("zip.png")
        bar.AddButton(CInt(Fix(guiID.ButtonSelectArchive)), Nothing, "Set Model Archive", image, Nothing, False, True)
 
        image = driver.GetTexture("help.png")
        bar.AddButton(CInt(Fix(guiID.ButtonShowAbout)), Nothing, "Open Help", image, Nothing, False, True)
 
        ' create a combobox with some senseless texts

        Dim box As GUIComboBox = env.AddComboBox(New Recti(250, 4, 350, 23), bar, CInt(Fix(guiID.TextureFilter)))
        box.AddItem("No filtering")
        box.AddItem("Bilinear")
        box.AddItem("Trilinear")
        box.AddItem("Anisotropic")
        box.AddItem("Isotropic")
 
        ' disable alpha
       setSkinTransparency(255, env.Skin)
 
        ' add a tabcontrol
       createToolBox()
 
        ' create fps text
       Dim fpstext As GUIStaticText = env.AddStaticText("", New Recti(400, 4, 570, 23), True, False, bar)
        Dim postext As GUIStaticText = env.AddStaticText("", New Recti(10, 50, 470, 80), False, False, Nothing, CInt(Fix(guiID.PositionText)))
        postext.Visible = False
 
        ' show about message box and load default model
       If args.Length = 0 Then
            showAboutText()
        End If
 
        loadModel(startUpModelFile)
 
        ' add skybox

        skybox = smgr.AddSkyBoxSceneNode("irrlicht2_up.jpg", "irrlicht2_dn.jpg", "irrlicht2_lf.jpg", "irrlicht2_rt.jpg", "irrlicht2_ft.jpg", "irrlicht2_bk.jpg")
 
        ' add a camera scene node

        camera(0) = smgr.AddCameraSceneNodeMaya()
        camera(0).FarValue = 20000
        ' Maya cameras reposition themselves relative to their target,
       ' so target the location where the mesh scene node is placed.
       camera(0).Target = New Vector3Df(0, 30, 0)
 
        camera(1) = smgr.AddCameraSceneNodeFPS()
        camera(1).FarValue = 20000
        camera(1).Position = New Vector3Df(0, 0, -70)
        camera(1).Target = New Vector3Df(0, 30, 0)
 
        setActiveCamera(camera(0))
 
        ' set window caption
       caption = String.Format("{0} - [{1}]", caption, driver.Name)
        device.SetWindowCaption(caption)
 
        ' draw everything
       Do While device.Run() AndAlso driver IsNot Nothing
            If device.WindowActive Then
                driver.BeginScene(True, True, New Color(50, 50, 50))
                smgr.DrawAll()
                env.DrawAll()
                driver.EndScene()
 
                Dim str As String = String.Format("FPS: {0} Tris: {1}", driver.FPS, driver.PrimitiveCountDrawn)
                fpstext.Text = str
 
                Dim cam As CameraSceneNode = device.SceneManager.ActiveCamera
                str = String.Format("Pos: {0} Tgt: {1}", cam.Position, cam.Target)
                postext.Text = str
            Else
                device.Yield()
            End If
        Loop
 
        device.Drop()
    End Sub
 
    Public Function device_OnEvent(ByVal e As [Event]) As Boolean
        ' Escape swaps Camera Input
       If e.Type = EventType.Key AndAlso (Not e.Key.PressedDown) AndAlso OnKeyUp(e.Key.Key) Then
            Return True
        End If
 
        If e.Type = EventType.GUI Then
            Dim id As guiID = CType(e.GUI.Caller.ID, guiID)
            Dim env As GUIEnvironment = device.GUIEnvironment
 
            Select Case e.GUI.Type
                Case GUIEventType.MenuItemSelected
                    ' a menu item was clicked
                   OnMenuItemSelected(e.GUI.Caller)
 
                Case GUIEventType.FileDialogFileSelected
                    ' load the model file, selected in the file open dialog
                   loadModel(e.ToString)
 
                Case GUIEventType.ScrollBarChanged
                    If id = guiID.SkinTransparency Then
                        ' Can't figure this part out. transparancey control
                       '
                       ' control skin transparency
                       'Dim p As Integer = e.GUI.Element. 'Element  ' Integer = 0 ' e.GUI.Element.
                       'setSkinTransparency(p, env.Skin)
                       '    setSkinTransparency(p, env.Skin)
                   ElseIf id = guiID.SkinAnimationFPS Then
                        'control animation speed
                       Dim p As GUI.GUIScrollBar = e.GUI.Element 'As Integer = 0 'e.GUI.Caller.Position
                       If model.Type = SceneNodeType.AnimatedMesh Then
                            ' Can't figure this part out. Animation speed control
                           '
                           ' AnimatedMeshSceneNode.AnimationSpeed
                           ' model.
                           ' model = AnimatedMeshSceneNode '
                           ' model. = p.Position
                       End If
                    End If
 
 
                Case GUIEventType.ComboBoxChanged
                    If id = guiID.TextureFilter Then
                        ' control anti-aliasing/filtering
                       OnTextureFilterSelected(e.GUI.Caller)
 
                    End If
 
 
                Case GUIEventType.ButtonClicked
                    Select Case id
                        Case guiID.ButtonSetScale
                            ' set scale
                           Dim r As GUIElement = env.RootElement
                            Dim s As New Vector3Df(Convert.ToSingle(r.GetElementFromID(CInt(Fix(guiID.XScale)), True).Text), Convert.ToSingle(r.GetElementFromID(CInt(Fix(guiID.YScale)), True).Text), Convert.ToSingle(r.GetElementFromID(CInt(Fix(guiID.ZScale)), True).Text))
 
                            If model IsNot Nothing Then
                                model.Scale = s
                            End If
 
                            updateScaleInfo(model)
 
                        Case guiID.ButtonScaleMul10
                            If model IsNot Nothing Then
                                model.Scale *= 10
                            End If
 
                            updateScaleInfo(model)
 
                        Case guiID.ButtonScaleDiv10
                            If model IsNot Nothing Then
                                model.Scale *= 0.1F
                            End If
 
                            updateScaleInfo(model)
 
                        Case guiID.ButtonOpenModel
                            env.AddFileOpenDialog("Please select a model file to open")
 
                        Case guiID.ButtonSelectArchive
                            env.AddFileOpenDialog("Please select your game archive/directory")
 
                        Case guiID.ButtonShowAbout
                            showAboutText()
 
                        Case guiID.ButtonShowToolbox
                            createToolBox()
                    End Select
 
            End Select
        End If
 
        Return False
    End Function
 
    Public Function OnKeyUp(ByVal keyCode As KeyCode) As Boolean
        If device Is Nothing Then
            Return False
        End If
 
        Select Case keyCode
            Case keyCode.Esc
                Dim c As CameraSceneNode = device.SceneManager.ActiveCamera
                If c IsNot Nothing Then
                    c.InputReceiverEnabled = Not c.InputReceiverEnabled
                End If
 
                Return True
 
            Case keyCode.F1
                Dim e As GUIElement = device.GUIEnvironment.RootElement.GetElementFromID(CInt(Fix(guiID.PositionText)))
                If e IsNot Nothing Then
                    e.Visible = Not e.Visible
                End If
 
 
            Case keyCode.KeyM
                device.MinimizeWindow()
 
            Case keyCode.KeyL
                useLight = Not useLight
                If model IsNot Nothing Then
                    model.SetMaterialFlag(MaterialFlag.Lighting, useLight)
                    model.SetMaterialFlag(MaterialFlag.NormalizeNormals, useLight)
                End If
 
        End Select
 
        Return False
    End Function
    Public Sub OnMenuItemSelected(ByVal menu As GUIContextMenu)
        Dim id As guiID = CType(menu.SelectedCommandID, guiID)
        Dim env As GUIEnvironment = device.GUIEnvironment
 
        Select Case id
            Case guiID.OpenModel ' FilOnButtonSetScalinge -> Open Model
               env.AddFileOpenDialog("Please select a model file to open")
 
            Case guiID.SetModelArchive ' File -> Set Model Archive
               env.AddFileOpenDialog("Please select your game archive/directory")
 
            Case guiID.LoadAsOctree ' File -> LoadAsOctree
               octree = Not octree
                menu.SetItemChecked(menu.SelectedIndex, octree)
 
            Case guiID.Quit ' File -> Quit
               device.Close()
 
            Case guiID.SkyBoxVisible ' View -> Skybox
               menu.SetItemChecked(menu.SelectedIndex, (Not menu.GetItemChecked(menu.SelectedIndex)))
                skybox.Visible = Not skybox.Visible
 
            Case guiID.DebugOff ' View -> Debug Information -> Off
               For i As Integer = 1 To 6
                    menu.SetItemChecked(menu.SelectedIndex + i, False)
                Next i
 
                If model IsNot Nothing Then
                    model.DebugDataVisible = DebugSceneType.Off
                End If
 
 
            Case guiID.DebugBoundingBox ' View -> Debug Information -> Bounding Box
               menu.SetItemChecked(menu.SelectedIndex, (Not menu.GetItemChecked(menu.SelectedIndex)))
 
                If model IsNot Nothing Then
                    model.DebugDataVisible = model.DebugDataVisible Xor DebugSceneType.BBox
                End If
 
 
            Case guiID.DebugNormals ' View -> Debug Information -> Normals
               menu.SetItemChecked(menu.SelectedIndex, (Not menu.GetItemChecked(menu.SelectedIndex)))
 
                If model IsNot Nothing Then
                    model.DebugDataVisible = model.DebugDataVisible Xor DebugSceneType.Normals
                End If
 
 
            Case guiID.DebugSkeleton ' View -> Debug Information -> Skeleton
               menu.SetItemChecked(menu.SelectedIndex, (Not menu.GetItemChecked(menu.SelectedIndex)))
 
                If model IsNot Nothing Then
                    model.DebugDataVisible = model.DebugDataVisible Xor DebugSceneType.Skeleton
                End If
 
 
            Case guiID.DebugWireOverlay ' View -> Debug Information -> Wire overlay
               menu.SetItemChecked(menu.SelectedIndex, (Not menu.GetItemChecked(menu.SelectedIndex)))
 
                If model IsNot Nothing Then
                    model.DebugDataVisible = model.DebugDataVisible Xor DebugSceneType.MeshWireOverlay
                End If
 
 
            Case guiID.DebugHalfTransparent ' View -> Debug Information -> Half-Transparent
               menu.SetItemChecked(menu.SelectedIndex, (Not menu.GetItemChecked(menu.SelectedIndex)))
 
                If model IsNot Nothing Then
                    model.DebugDataVisible = model.DebugDataVisible Xor DebugSceneType.HalfTransparency
                End If
 
 
            Case guiID.DebugBuffersBoundingBoxes ' View -> Debug Information -> Buffers bounding boxes
               menu.SetItemChecked(menu.SelectedIndex, (Not menu.GetItemChecked(menu.SelectedIndex)))
 
                If model IsNot Nothing Then
                    model.DebugDataVisible = model.DebugDataVisible Xor DebugSceneType.BBoxBuffers
                End If
 
 
            Case guiID.DebugAll ' View -> Debug Information -> All
               For i As Integer = 1 To 6
                    menu.SetItemChecked(menu.SelectedIndex - i, True)
                Next i
 
                If model IsNot Nothing Then
                    model.DebugDataVisible = DebugSceneType.Full
                End If
 
 
            Case guiID.About ' Help->About
               showAboutText()
 
            Case guiID.ModelMaterialSolid ' View -> Material -> Solid
               If model IsNot Nothing Then
                    model.SetMaterialType(MaterialType.Solid)
                End If
 
 
            Case guiID.ModelMaterialTransparent ' View -> Material -> Transparent
               If model IsNot Nothing Then
                    model.SetMaterialType(MaterialType.TransparentAddColor)
                End If
 
 
            Case guiID.ModelMaterialReflection ' View -> Material -> Reflection
               If model IsNot Nothing Then
                    model.SetMaterialType(MaterialType.SphereMap)
                End If
 
 
            Case guiID.CameraMaya
                setActiveCamera(camera(0))
 
            Case guiID.CameraFirstPerson
                setActiveCamera(camera(1))
        End Select
    End Sub
 
    Public Sub OnTextureFilterSelected(ByVal combo As GUIComboBox)
        If model Is Nothing Then
            Return
        End If
 
        Dim p As Integer = combo.SelectedIndex
        Select Case p
            Case 0 ' No filtering
               model.SetMaterialFlag(MaterialFlag.BilinearFilter, False)
                model.SetMaterialFlag(MaterialFlag.TrilinearFilter, False)
                model.SetMaterialFlag(MaterialFlag.AnisotropicFilter, False)
 
            Case 1 ' Bilinear
               model.SetMaterialFlag(MaterialFlag.BilinearFilter, True)
                model.SetMaterialFlag(MaterialFlag.TrilinearFilter, False)
 
            Case 2 ' Trilinear
               model.SetMaterialFlag(MaterialFlag.BilinearFilter, False)
                model.SetMaterialFlag(MaterialFlag.TrilinearFilter, True)
 
            Case 3 ' Anisotropic
               model.SetMaterialFlag(MaterialFlag.AnisotropicFilter, True)
 
            Case 4 ' Isotropic
               model.SetMaterialFlag(MaterialFlag.AnisotropicFilter, False)
        End Select
    End Sub
 
    Public Sub setActiveCamera(ByVal newActive As CameraSceneNode)
        If device Is Nothing Then
            Return
        End If
 
        Dim c As CameraSceneNode = device.SceneManager.ActiveCamera
        c.InputReceiverEnabled = False
 
        newActive.InputReceiverEnabled = True
        device.SceneManager.ActiveCamera = newActive
    End Sub
 
    Public Sub setSkinTransparency(ByVal alpha As Integer, ByVal skin As GUISkin)
        Dim I As Integer
        For I = 0 To 24 ' (0 to 24 is the enums of GUIDefaultColor)
           'System.Enum.GetValues '(typeof(GUIDefaultColor))
           Dim c As Color = skin.GetColor(I)
            c.Alpha = alpha
            skin.SetColor(c, I)
        Next
 
    End Sub
 
    Public Sub updateScaleInfo(ByVal model As SceneNode)
        Dim t As GUIElement = device.GUIEnvironment.RootElement.GetElementFromID(CInt(Fix(guiID.DialogRootWindow)), True)
        If t Is Nothing Then
            Return
        End If
 
        If model Is Nothing Then
            t.GetElementFromID(CInt(Fix(guiID.XScale)), True).Text = "-"
            t.GetElementFromID(CInt(Fix(guiID.YScale)), True).Text = "-"
            t.GetElementFromID(CInt(Fix(guiID.ZScale)), True).Text = "-"
        Else
            Dim s As Vector3Df = model.Scale
            t.GetElementFromID(CInt(Fix(guiID.XScale)), True).Text = s.X.ToString()
            t.GetElementFromID(CInt(Fix(guiID.YScale)), True).Text = s.Y.ToString()
            t.GetElementFromID(CInt(Fix(guiID.ZScale)), True).Text = s.Z.ToString()
        End If
    End Sub
    Public Sub showAboutText()
        device.GUIEnvironment.AddMessageBox(caption, messageText)
    End Sub
 
    Public Sub loadModel(ByVal f As String)
        Dim e As String = Path.GetExtension(f)
 
        Select Case e
            ' if a texture is loaded apply it to the current model
           Case ".jpg", ".pcx", ".png", ".ppm", ".pgm", ".pbm", ".psd", ".tga", ".bmp", ".wal", ".rgb", ".rgba"
                Dim t As Texture = device.VideoDriver.GetTexture(f)
                If t IsNot Nothing AndAlso model IsNot Nothing Then
                    ' always reload texture
                   device.VideoDriver.RemoveTexture(t)
                    t = device.VideoDriver.GetTexture(f)
                    model.SetMaterialTexture(0, t)
                End If
                Return
 
                ' if a archive is loaded add it to the FileArchive
           Case ".pk3", ".zip", ".pak", ".npk"
                device.FileSystem.AddFileArchive(f)
                Return
        End Select
 
        ' load a model into the engine

        If model IsNot Nothing Then
            model.Remove()
        End If
 
        model = Nothing
 
        If e = ".irr" Then
            device.SceneManager.LoadScene(f)
            model = device.SceneManager.GetSceneNodeFromType(SceneNodeType.AnimatedMesh)
            Return
        End If
 
        Dim m As AnimatedMesh = device.SceneManager.GetMesh(f)
        If m Is Nothing Then
            ' model could not be loaded
           If startUpModelFile <> f Then
                device.GUIEnvironment.AddMessageBox(caption, "The model could not be loaded. Maybe it is not a supported file format.")
            End If
 
            Return
        End If
 
        ' set default material properties

        If octree Then
            model = device.SceneManager.AddOctreeSceneNode(m.GetMesh(0))
        Else
            Dim n As AnimatedMeshSceneNode = device.SceneManager.AddAnimatedMeshSceneNode(m)
            n.AnimationSpeed = 30
            model = n
        End If
 
        model.SetMaterialFlag(MaterialFlag.Lighting, useLight)
        model.SetMaterialFlag(MaterialFlag.NormalizeNormals, useLight)
        model.DebugDataVisible = DebugSceneType.Off
 
        ' we need to uncheck the menu entries. would be cool to fake a menu event, but
       ' that's not so simple. so we do it brute force
       Dim u As GUIContextMenu = device.GUIEnvironment.RootElement.GetElementFromID(CInt(Fix(guiID.ToggleDebugInfo)), True)
        If u IsNot Nothing Then
            For i As Integer = 0 To 5
                u.SetItemChecked(i, False)
            Next i
        End If
 
        updateScaleInfo(model)
    End Sub
    Public Sub createToolBox()
        Dim env As GUIEnvironment = device.GUIEnvironment
        Dim root As GUIElement = env.RootElement
 
        ' remove tool box if already there
       Dim e As GUIElement = root.GetElementFromID(CInt(Fix(guiID.DialogRootWindow)), True)
        If e IsNot Nothing Then
            e.Remove()
        End If
 
        ' create the toolbox window
       Dim w As GUIWindow = env.AddWindow(New Recti(600, 45, 800, 480), False, "Toolset", Nothing, CInt(Fix(guiID.DialogRootWindow)))
 
        ' create tab control and tabs
       Dim tab As GUITabControl = env.AddTabControl(New Recti(2, 20, 800 - 602, 480 - 7), w, True, True)
 
        Dim t1 As GUITab = tab.AddTab("Config")
 
        ' add some edit boxes and a button to tab one
       env.AddStaticText("Scale:", New Recti(10, 20, 60, 45), False, False, t1)
        env.AddStaticText("X:", New Recti(22, 48, 40, 66), False, False, t1)
        env.AddEditBox("1.0", New Recti(40, 46, 130, 66), True, t1, CInt(Fix(guiID.XScale)))
        env.AddStaticText("Y:", New Recti(22, 78, 40, 96), False, False, t1)
        env.AddEditBox("1.0", New Recti(40, 76, 130, 96), True, t1, CInt(Fix(guiID.YScale)))
        env.AddStaticText("Z:", New Recti(22, 108, 40, 126), False, False, t1)
        env.AddEditBox("1.0", New Recti(40, 106, 130, 126), True, t1, CInt(Fix(guiID.ZScale)))
 
        env.AddButton(New Recti(10, 134, 85, 165), t1, CInt(Fix(guiID.ButtonSetScale)), "Set")
 
        ' quick scale buttons
       env.AddButton(New Recti(65, 20, 95, 40), t1, CInt(Fix(guiID.ButtonScaleMul10)), "* 10")
        env.AddButton(New Recti(100, 20, 130, 40), t1, CInt(Fix(guiID.ButtonScaleDiv10)), "* 0.1")
 
        updateScaleInfo(model)
 
        ' add transparency control
       env.AddStaticText("GUI Transparency Control:", New Recti(10, 200, 150, 225), True, False, t1)
        Dim b As GUIScrollBar = env.AddScrollBar(True, New Recti(10, 225, 150, 240), t1, CInt(Fix(guiID.SkinTransparency)))
        b.MaxValue = 255
        b.Position = 255
 
        ' add framerate control
       env.AddStaticText("Framerate:", New Recti(10, 240, 150, 265), True, False, t1)
        b = env.AddScrollBar(True, New Recti(10, 265, 150, 280), t1, CInt(Fix(guiID.SkinAnimationFPS)))
        b.MaxValue = MaxFramerate
        b.MinValue = -MaxFramerate
        b.Position = DefaultFramerate
 
        ' bring irrlicht engine logo to front, because it now may be below the newly created toolbox
       root.BringToFront(root.GetElementFromID(CInt(Fix(guiID.Logo)), True))
    End Sub
 
    Public Function AskUserForDriver(ByVal OutdriverType As Integer) As Integer
        OutdriverType = DriverType.Null
 
        Console.Write("Please select the driver you want for this example:" & vbLf & " (a) OpenGL" & vbLf & " (b) Direct3D 9.0c" & vbLf & " (c) Direct3D 8.1" & vbLf & " (d) Burning's Software Renderer" & vbLf & " (e) Software Renderer" & vbLf & " (f) NullDevice" & vbLf & " (otherKey) exit" & vbLf & vbLf)
 
        Dim i As ConsoleKeyInfo = Console.ReadKey()
 
        Select Case i.Key
            Case ConsoleKey.A
                OutdriverType = DriverType.OpenGL
            Case ConsoleKey.B
                OutdriverType = DriverType.Direct3D9
            Case ConsoleKey.C
                OutdriverType = DriverType.Direct3D8
            Case ConsoleKey.D
                OutdriverType = DriverType.BurningsVideo
            Case ConsoleKey.E
                OutdriverType = DriverType.Software
            Case ConsoleKey.F
                OutdriverType = DriverType.Null
            Case Else
                Return 0
        End Select
        Return OutdriverType
 
        Return True
    End Function
End Module
 


Special thanks to the people that want to educate instead of get into debates that "My .NET 2010 Language is more powerful than your .NET 2010 Language" even though they compile the same.
_______________________________________________________
You could argue with me all day long about which language is best.
But what it comes down to is:
which language is best for YOU and which language is best for ME.
WaxyChicken
 
Posts: 95
Joined: Sat Jun 25, 2011 6:15 am

Re: VB.NET (2010) 09-Mesh Viewer Code (99%)

Postby greenya » Tue Nov 08, 2011 4:51 pm

You can use translator from C# to VB.NET.
For example i used http://www.developerfusion.com/tools/co ... arp-to-vb/ and it worked for me, the only thing it translates wrong for event subscription and it should be translated manually.

For example, next C# code:
cpp Code: Select all
this.OnRegisterSceneNode += new RegisterSceneNodeEventHandler(CSampleSceneNode_OnRegisterSceneNode);

will look in VB.NET next way:
cpp Code: Select all
AddHandler Me.OnRegisterSceneNode, AddressOf CSampleSceneNode_OnRegisterSceneNode


P.S.: AFAIK all .NET languages compiles into MSIL and that is why anything written on any .NET language can be simple translated to another one.
User avatar
greenya
 
Posts: 951
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine

Re: VB.NET (2010) 09-Mesh Viewer Code (99%)

Postby Johnathan » Sat Jan 21, 2012 8:44 pm

WaxyChicken, ( lol ok creative I suppose :) )

Thank you for this, I hope you still pay attention to this thread.

I am taking VB classes and I can see this will be a lot help for me to let me use Irricht to practice my vb coding.

Only, could you please go more in depth into how to get this going in VB.Net (I am using Visual Studio 2010 Professional)
If you could help me get this completely running in vb, I would be able to adapt it for what I want on my own.

All i really need is the viewport where in:
The variables for the mesh, textures, and shaders are left open and I could create my own controls to load them, but I am afraid I need more help to get me to that point.
Johnathan
 
Posts: 1
Joined: Sat Jan 21, 2012 8:08 pm


Return to FAQs, Tutorials, Howtos, and external tool lists

Who is online

Users browsing this forum: No registered users and 1 guest