rootFrame = Mesh.LoadHierarchyFromFile(error)

Started by
11 comments, last by FeanorLobelia 16 years, 1 month ago
Hi, I'm using vb.net 2003 with the dec 2004 sdk. I'm having a problem with .x file animation. I already have the code from Zman and robydx so sending me there won't be of any value. I have the code below which should work. I'm having a problem with rootFrame = Mesh.LoadHierarchyFromFile I've tried everyway I can to fix this problem but I can't find out what it is. You will notice message boxes in the code,that is because stepping through the code isn't telling me anything. After the messagebox("ErrorHere") I get an error in the 3d3x dll. I don't know where to go from here.


Imports System
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms

Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D



Public Class Form2
    Inherits System.Windows.Forms.Form
    Private components As System.ComponentModel.Container = Nothing

    Private timer As Timer ' use timer to refresh the display
    Private device As Device ' the device for DX
    Private radius As Single ' the radius and center of the mesh
    Private center As Vector3
    Private rootFrame As AnimationRootFrame
    ' the root frame object 
    Public Sub New()
        InitializeComponent()

        ' we'll do  all our drawing
        SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)

        timer = New Timer
        ' we'll update the display 20 times a sec
        timer.Interval = 50
        AddHandler timer.Tick, AddressOf tickHandler

    End Sub 'New


    Protected Overloads Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)

    End Sub 'Dispose

#Region "Windows Form Designer generated code"

    '/ <summary>
    '/ Required method for Designer support - do not modify
    '/ the contents of this method with the code editor.
    '/ </summary>
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.Size = New System.Drawing.Size(640, 480)
        Me.Text = "Form1"

    End Sub 'InitializeComponent
#End Region


    <STAThread()> _
    Shared Sub Main()
        Dim frm As New Form2
        Try
            frm.Show()
            frm.InitializeGraphics()
            Application.Run(frm)
        Finally
            frm.Dispose()
        End Try

    End Sub 'Main


    Sub InitializeGraphics()
        Dim presentParams As New PresentParameters

        presentParams.Windowed = True
        presentParams.SwapEffect = SwapEffect.Discard
        presentParams.AutoDepthStencilFormat = DepthFormat.D16
        presentParams.EnableAutoDepthStencil = True
        device = New Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, presentParams)

        ' avoid weird resource management issues
        device.IsUsingEventHandlers = False
        Dim tinyfile As String
        tinyfile = "tiny.x"
        ' load our x file
        LoadAnim(MediaUtilities.FindFile(tinyfile))
        MessageBox.Show(tinyfile)
        AddHandler device.DeviceReset, AddressOf OnDeviceReset
        OnDeviceReset(device, Nothing)

    End Sub 'InitializeGraphics


    Sub LoadAnim(ByVal fileName As String)
        device = device
        Dim alloc As New MyAllocateHierarchy
        MessageBox.Show(fileName)
        ' build the hierarchy of frames from the x file using our alloc object
        rootFrame = Mesh.LoadHierarchyFromFile(MessageBox.Show(fileName) & fileName, MessageBox.Show("aaa") & MeshFlags.Managed & MessageBox.Show("ErrorHere"), device, alloc, Nothing)
        radius = Frame.CalculateBoundingSphere(rootFrame.FrameHierarchy, center)

        ' connect the bones the frames in the mesh
        AttachBones(CType(rootFrame.FrameHierarchy, MyFrame))

    End Sub 'LoadAnim


    Sub OnDeviceReset(ByVal sender As Object, ByVal e As EventArgs)
        Dim dev As Device = CType(sender, Device)
        dev.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, -2.0F * radius), center, New Vector3(0, 1, 0))

        dev.Transform.Projection = Matrix.PerspectiveFovLH(System.Convert.ToSingle(Math.PI) / 4, 1.3F, 0.1F, 10.0F * radius)

        dev.Lights(0).Type = LightType.Directional
        dev.Lights(0).Direction = New Vector3(0.0F, 0.0F, 1.0F)
        dev.Lights(0).Diffuse = Color.White
        dev.Lights(0).Update()
        dev.Lights(0).Enabled = True

        timer.Start()

    End Sub 'OnDeviceReset


    Sub tickHandler(ByVal o As Object, ByVal e As EventArgs)
        Me.Invalidate()

    End Sub 'tickHandler


    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        ' move our animation ahead (the constant 0.05 was obtained by trial and error)
        If Not (rootFrame.AnimationController Is Nothing) Then
            rootFrame.AnimationController.AdvanceTime(0.05F, Nothing)
        End If
        ' update all the hierarchy of frames with the new transform values
        If Not (rootFrame.FrameHierarchy Is Nothing) Then
            UpdateFrameMatrices(CType(rootFrame.FrameHierarchy, MyFrame), Matrix.Identity)
        End If
        device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Blue, 1.0F, 0)
        device.BeginScene()

        ' draw the animation
        If Not (rootFrame.FrameHierarchy Is Nothing) Then
            DrawFrame(CType(rootFrame.FrameHierarchy, MyFrame))
        End If
        device.EndScene()
        device.Present()

    End Sub 'OnPaint


    '
    ' walk the tree of frames and draw each one
    '
    Sub DrawFrame(ByVal frame As MyFrame)
        Dim mesh As MyMeshContainer = CType(frame.MeshContainer, MyMeshContainer)
        While Not (mesh Is Nothing)
            DrawMeshContainer(mesh)
            mesh = CType(mesh.NextContainer, MyMeshContainer)
        End While

        If Not (frame.FrameSibling Is Nothing) Then
            DrawFrame(CType(frame.FrameSibling, MyFrame))
        End If

        If Not (frame.FrameFirstChild Is Nothing) Then
            DrawFrame(CType(frame.FrameFirstChild, MyFrame))
        End If

    End Sub 'DrawFrame


    '
    ' when we have a mesh container with skin info, we set the proper
    ' blending information
    '
    Sub DrawMeshContainer(ByVal mesh As MyMeshContainer)
        If Not (mesh.SkinInformation Is Nothing) Then
            Dim offsetMatrices As Matrix() = mesh.OffsetMatrices
            Dim frameMatrices As MyFrame() = mesh.FrameMatrices

            ' for each subset with similar attrib, draw it
            Dim iattrib As Integer
            For iattrib = 0 To mesh.NumberAttributes
                ' set the proper world matrix for blending
                Dim boneCombo As BoneCombination = mesh.BoneTable(iattrib)
                Dim i As Integer
                For i = 0 To mesh.NumberInfluences
                    Dim matrixIndex As Integer = boneCombo.BoneId(i)
                    ' it seems when the BoneId is not -1, the matrix index is valid
                    ' where is the doc for this???
                    If matrixIndex <> -1 Then
                        Dim tempMatrix As Matrix = Matrix.Multiply(offsetMatrices(matrixIndex), frameMatrices(matrixIndex).Combined)
                        device.Transform.SetWorldMatrixByIndex(i, tempMatrix)
                    End If
                Next i

                ' set the render state, material and texture
                device.RenderState.VertexBlend = CType(boneCombo.BoneId.Length, VertexBlend) - 1
                device.Material = mesh.GetMaterials()(boneCombo.AttributeId).Material3D
                device.SetTexture(0, mesh.Textures(boneCombo.AttributeId))

                ' draw the subset
                mesh.MeshData.Mesh.DrawSubset(iattrib)
            Next iattrib
        End If

    End Sub 'DrawMeshContainer


    '
    ' walk the tree and attach each bone
    '
    Overloads Sub AttachBones(ByVal frame As MyFrame)
        If Not (frame.MeshContainer Is Nothing) Then
            AttachBones(CType(frame.MeshContainer, MyMeshContainer))
        End If

        If Not (frame.FrameSibling Is Nothing) Then
            AttachBones(CType(frame.FrameSibling, MyFrame))
        End If

        If Not (frame.FrameFirstChild Is Nothing) Then
            AttachBones(CType(frame.FrameFirstChild, MyFrame))
        End If

    End Sub 'AttachBones


    '
    ' when we have a mesh container, we set its frameMatrices accordingly
    '
    Overloads Sub AttachBones(ByVal mesh As MyMeshContainer)
        If Not (mesh.SkinInformation Is Nothing) Then
            Dim numBones As Integer = mesh.SkinInformation.NumberBones

            ' for each bone, find the frame of the same name
            Dim frameMatrices(numBones) As MyFrame
            Dim i As Integer
            For i = 0 To numBones
                Dim frame As MyFrame = CType(frame.Find(rootFrame.FrameHierarchy, mesh.SkinInformation.GetBoneName(i)), MyFrame)

                If frame Is Nothing Then
                    Throw New ArgumentException
                End If
                ' asssign the found frame into the MeshContaienr frameMatrices
                frameMatrices(i) = frame
            Next i
            mesh.FrameMatrices = frameMatrices
        End If

    End Sub 'AttachBones


    '
    ' walk the tree and update the hierarchy
    '
    Sub UpdateFrameMatrices(ByVal frame As MyFrame, ByVal parentMatrix As Matrix)
        ' first transform with the parent
        frame.Combined = Matrix.Multiply(frame.TransformationMatrix, parentMatrix)

        ' if sibling, use transform with parent
        If Not (frame.FrameSibling Is Nothing) Then
            UpdateFrameMatrices(CType(frame.FrameSibling, MyFrame), parentMatrix)
        End If

        ' if child, transform with new combined matrix
        If Not (frame.FrameFirstChild Is Nothing) Then
            UpdateFrameMatrices(CType(frame.FrameFirstChild, MyFrame), frame.Combined)
        End If

    End Sub 'UpdateFrameMatrices
End Class 'Form1


Public Class MyFrame
    Inherits Frame
    Public Combined As Matrix = Matrix.Identity
End Class 'MyFrame


Public Class MyMeshContainer
    Inherits MeshContainer
    ' I'm not a big fan of properties 
    Public Textures As Texture() = Nothing
    Public NumberAttributes As Integer = 0
    Public NumberInfluences As Integer = 0
    Public BoneTable() As BoneCombination
    Public FrameMatrices() As MyFrame
    Public OffsetMatrices() As Matrix
End Class 'MyMeshContainer


Public Class MyAllocateHierarchy
    Inherits Microsoft.DirectX.Direct3D.AllocateHierarchy
    Public Sub New()
        MessageBox.Show("hello")
    End Sub

    Public Overrides Function CreateFrame(ByVal name As String) As Frame
        MessageBox.Show("CreateFrame")
        Dim frame As New MyFrame
        frame.Name = name
        frame.TransformationMatrix = Matrix.Identity

        Return frame

    End Function 'CreateFrame


    Public Overrides Function CreateMeshContainer(ByVal name As String, ByVal meshData As MeshData, ByVal materials() As ExtendedMaterial, ByVal effectInstances() As EffectInstance, ByVal adjacency As GraphicsStream, ByVal skinInfo As SkinInformation) As MeshContainer
        MessageBox.Show("CreateMeshContainer")
        ' create the container object and set some of its properties
        Dim mesh As New MyMeshContainer

        mesh.Name = name
        Dim numFaces As Integer = meshData.Mesh.NumberFaces
        Dim dev As Device = meshData.Mesh.Device

        mesh.SetMaterials(materials)
        mesh.SetAdjacency(adjacency)

        ' fill in the texture info
        Dim meshTextures(materials.Length) As Texture
        Dim i As Integer
        For i = 0 To materials.Length
            If Not (materials(i).TextureFilename Is Nothing) Then
                'meshTextures(i) = TextureLoader.FromFile(dev, MediaUtilities.FindFile(materials(i).TextureFilename))
            End If
        Next i
        mesh.Textures = meshTextures

        ' if needed, fill in the skin info
        If Not (skinInfo Is Nothing) Then
            mesh.SkinInformation = skinInfo

            ' stores the bone offset matrix away
            Dim numBones As Integer = skinInfo.NumberBones
            Dim offsetMatrices(numBones) As Matrix
            'Dim i As Integer
            For i = 0 To numBones
                offsetMatrices(i) = skinInfo.GetBoneOffsetMatrix(i)
            Next i
            mesh.OffsetMatrices = offsetMatrices

            ' Fill the skin info by calling ConvertToBlendedMesh, this generates the BoneTable
            meshData.Mesh = skinInfo.ConvertToBlendedMesh(meshData.Mesh, MeshFlags.Managed Or MeshFlags.OptimizeVertexCache, mesh.GetAdjacencyStream(), mesh.NumberInfluences, mesh.BoneTable)

            mesh.NumberAttributes = mesh.BoneTable.Length
        End If
        ' use new mesh for our drawing
        mesh.MeshData = meshData
        Return mesh

    End Function 'CreateMeshContainer
End Class 'MyAllocateHierarchy



[Edited by - Steve5050 on March 13, 2008 11:14:40 AM]
Advertisement
bump
I am having no luck at all with this,all kinds of different
ways yet still the same error.

geeeez
Any ideas anybody.
Just stuck.
Have you checked the return value of MediaUtilities.FindFile(tinyfile)?
Yes that is good,no problem with my static models,
they load in fine,I can load tiny with that loader
just no anim.

I was stepping through some different code that I
have now and I'm coming up with a frame problem.
I'm still trying to figure that out.
the problem may be lies inside your MyAllocateHierarchy class code.
I'm at the point where I need an animation
class that will work.I found that there is
a problem with the CreateMeshContainer materials.
I tried making my own animation class and I
haven't got it to work.Very frustrated.
I'll put up the animation class i'm attempting:
Imports Microsoft.DirectXImports Microsoft.DirectX.Direct3DPublic Class AnimPositionedMesh    Private Device As Device = Nothing    Private meshTextures As Texture() = Nothing    Private numAttr As Integer = 0    Private numInfl As Integer = 0    Private bones() As BoneCombination    Private frameMatrices() As Frame    Private offsetMatrices() As Matrix    Private combined As Matrix = Matrix.Identity    Private rootFrame As AnimationRootFrame    Private objectCenter As Vector3    Private objectRadius As Single    Private elapsedTime As Single    Public Sub New()    End Sub    Public Function CreateFrame(ByVal name As String) As Frame        Dim frame As Frame        frame.Name = name        frame.TransformationMatrix = Matrix.Identity        CombinedTransformationMatrix = Matrix.Identity        Return frame    End Function 'CreateFrame    Private Sub DrawFrame(ByVal frame As Frame)        Dim mesh As MeshContainer = CType(frame.MeshContainer, MeshContainer)        While Not (mesh Is Nothing)            DrawMeshContainer(mesh, frame)            mesh = CType(mesh.NextContainer, MeshContainer)        End While        If Not (frame.FrameSibling Is Nothing) Then            DrawFrame(CType(frame.FrameSibling, Frame))        End If        If Not (frame.FrameFirstChild Is Nothing) Then            DrawFrame(CType(frame.FrameFirstChild, Frame))        End If    End Sub 'DrawFrame    Private Sub DrawMeshContainer(ByVal mesh As MeshContainer, ByVal frame As Frame)        ' Is there skin information?        If Not (mesh.SkinInformation Is Nothing) Then            If NumberInfluences = 1 Then                Device.RenderState.VertexBlend = VertexBlend.ZeroWeights            Else                Device.RenderState.VertexBlend = CType(NumberInfluences - 1, VertexBlend)            End If            If NumberInfluences > 0 Then                Device.RenderState.IndexedVertexBlendEnable = True            End If            Dim bones As BoneCombination() = GetBones()            Dim iAttrib As Integer            For iAttrib = 0 To NumberAttributes                ' first, get world matrices                Dim iPaletteEntry As Integer                While iPaletteEntry < NumberPaletteEntries                    Dim iMatrixIndex As Integer = bones(iAttrib).BoneId(iPaletteEntry)                    If iMatrixIndex <> -1 Then                        '''''Device.Transform.SetWorldMatrixByIndex(iPaletteEntry, Matrix.Multiply(GetOffsetMatrices()(iMatrixIndex), GetFrames())                    End If                    iPaletteEntry += 1                End While                               'device.Material = mesh.GetMaterials()[bones[iAttrib].AttribId].Material3D;                'device.SetTexture(0, mesh.GetTextures()[bones[iAttrib].AttribId]);                Device.Material = mesh.GetMaterials()(bones(iAttrib).AttributeId).Material3D                Device.SetTexture(0, GetTextures()(bones(iAttrib).AttributeId))                ' Finally draw the subset                mesh.MeshData.Mesh.DrawSubset(iAttrib)            Next iAttrib            ' standard mesh, just draw it after setting material properties        Else            Device.Transform.World = CombinedTransformationMatrix            Dim mtrl As ExtendedMaterial() = mesh.GetMaterials()            Dim iMaterial As Integer            For iMaterial = 0 To mtrl.Length                Device.Material = mtrl(iMaterial).Material3D                Device.SetTexture(0, GetTextures()(iMaterial))                mesh.MeshData.Mesh.DrawSubset(iMaterial)            Next iMaterial        End If    End Sub 'DrawMeshContainer    Public Sub GenerateSkinnedMesh(ByVal mesh As MeshContainer)        If mesh.SkinInformation Is Nothing Then            Throw New ArgumentException        End If        Dim numMaxFaceInfl As Integer        Dim flags As MeshFlags = MeshFlags.OptimizeVertexCache        Dim m As MeshData = mesh.MeshData        Dim ib As IndexBuffer = m.Mesh.IndexBuffer        Try            numMaxFaceInfl = mesh.SkinInformation.GetMaxFaceInfluences(ib, m.Mesh.NumberFaces)        Finally            ib.Dispose()        End Try        ' 12 entry palette guarantees that any triangle (4 independent         ' influences per vertex of a tri) can be handled        numMaxFaceInfl = Fix(Math.Min(numMaxFaceInfl, 12))        If Device.DeviceCaps.MaxVertexBlendMatrixIndex + 1 >= numMaxFaceInfl Then            NumberPaletteEntries = Fix(Math.Min((Device.DeviceCaps.MaxVertexBlendMatrixIndex + 1) / 2, mesh.SkinInformation.NumberBones))            flags = flags Or MeshFlags.Managed        End If        Dim bones() As BoneCombination        Dim numInfl As Integer        m.Mesh = mesh.SkinInformation.ConvertToIndexedBlendedMesh(m.Mesh, flags, mesh.GetAdjacencyStream(), NumberPaletteEntries, numInfl, bones)        SetBones(bones)        NumberInfluences = numInfl        NumberAttributes = bones.Length        mesh.MeshData = m    End Sub 'GenerateSkinnedMesh    Public Sub ProcessNextFrame()        ' Get the current elapsed time        elapsedTime = DXUtil.Timer(DirectXTimer.GetElapsedTime)        ' Set the world matrix        Dim worldMatrix As Matrix = Matrix.Translation(objectCenter)        Device.Transform.World = worldMatrix        If Not (rootFrame.AnimationController Is Nothing) Then            rootFrame.AnimationController.AdvanceTime(elapsedTime, Nothing)        End If        UpdateFrameMatrices(CType(rootFrame.FrameHierarchy, Frame), worldMatrix)    End Sub 'ProcessNextFrame    Private Overloads Sub SetupBoneMatrices(ByVal frame As Frame)        If Not (frame.MeshContainer Is Nothing) Then            SetupBoneMatrices(CType(frame.MeshContainer, MeshContainer))        End If        If Not (frame.FrameSibling Is Nothing) Then            SetupBoneMatrices(CType(frame.FrameSibling, Frame))        End If        If Not (frame.FrameFirstChild Is Nothing) Then            SetupBoneMatrices(CType(frame.FrameFirstChild, Frame))        End If    End Sub 'SetupBoneMatrices    Private Overloads Sub SetupBoneMatrices(ByVal mesh As MeshContainer)        ' Is there skin information?  If so, setup the matrices        If Not (mesh.SkinInformation Is Nothing) Then            Dim numBones As Integer = mesh.SkinInformation.NumberBones            Dim frameMatrices(numBones) As Frame            Dim i As Integer            For i = 0 To numBones                Dim frame As Frame = CType(frame.Find(rootFrame.FrameHierarchy, mesh.SkinInformation.GetBoneName(i)), Frame)                If frame Is Nothing Then                    Throw New ArgumentException                End If                frameMatrices(i) = frame            Next i            SetFrames(frameMatrices)        End If    End Sub 'SetupBoneMatrices    Private Sub UpdateFrameMatrices(ByVal frame As Frame, ByVal parentMatrix As Matrix)        CombinedTransformationMatrix = Matrix.Multiply(frame.TransformationMatrix, parentMatrix)        If Not (frame.FrameSibling Is Nothing) Then            UpdateFrameMatrices(CType(frame.FrameSibling, Frame), parentMatrix)        End If        If Not (frame.FrameFirstChild Is Nothing) Then            UpdateFrameMatrices(CType(frame.FrameFirstChild, Frame), CombinedTransformationMatrix)        End If    End Sub 'UpdateFrameMatrices    ' Public properties    Public Function GetTextures() As Texture()        Return meshTextures    End Function 'GetTextures    Public Sub SetTextures(ByVal textures() As Texture)        meshTextures = textures    End Sub 'SetTextures    Public Function GetBones() As BoneCombination()        Return bones    End Function 'GetBones    Public Sub SetBones(ByVal b() As BoneCombination)        bones = b    End Sub 'SetBones    Public Function GetFrames() As Frame()        Return frameMatrices    End Function 'GetFrames    Public Sub SetFrames(ByVal frames() As Frame)        frameMatrices = frames    End Sub 'SetFrames    Public Function GetOffsetMatrices() As Matrix()        Return offsetMatrices    End Function 'GetOffsetMatrices    Public Sub SetOffsetMatrices(ByVal matrices() As Matrix)        offsetMatrices = matrices    End Sub 'SetOffsetMatrices     Public Property CombinedTransformationMatrix() As Matrix        Get            Return combined        End Get        Set(ByVal Value As Matrix)            combined = Value        End Set    End Property    Public Property NumberAttributes() As Integer        Get            Return numAttr        End Get        Set(ByVal Value As Integer)            numAttr = Value        End Set    End Property    Public Property NumberInfluences() As Integer        Get            Return numInfl        End Get        Set(ByVal Value As Integer)            numInfl = Value        End Set    End Property    Private numPal As Integer = 0    Public Property NumberPaletteEntries() As Integer        Get            Return numPal        End Get        Set(ByVal Value As Integer)            numPal = Value        End Set    End Property    Public Overloads Function CreateMeshContainer(ByVal name As String, ByVal meshData As MeshData, ByVal materials() As ExtendedMaterial, ByVal effectInstances As EffectInstance, ByVal adjacency As GraphicsStream, ByVal skinInfo As SkinInformation) As MeshContainer        If meshData.Mesh Is Nothing Then            Throw New ArgumentException        End If        ' We must have a vertex format mesh        If meshData.Mesh.VertexFormat = VertexFormats.None Then            Throw New ArgumentException        End If        Dim mesh As MeshContainer        mesh.Name = name        Dim numFaces As Integer = meshData.Mesh.NumberFaces        Dim dev As Device = meshData.Mesh.Device        ' Make sure there are normals        If (meshData.Mesh.VertexFormat And VertexFormats.Normal) = 0 Then            ' Clone the mesh            Dim tempMesh As Mesh = meshData.Mesh.Clone(meshData.Mesh.Options.Value, meshData.Mesh.VertexFormat Or VertexFormats.Normal, dev)            meshData.Mesh = tempMesh            meshData.Mesh.ComputeNormals()        End If        ' Store the materials        mesh.SetMaterials(materials)        mesh.SetAdjacency(adjacency)        ''Dim meshTextures(materials.Length) As Texture        'Dim meshTextures As Texture() = New Texture(materials.Length - 1) {}        '''Dim meshMaterials As Material() = New Material(materials.Length - 1) {}        '''Dim textureNames As String() = New String(materials.Length - 1) {}        '''Dim xFilePath As String = Path.GetDirectoryName(app.MeshPath)        ''''''''''''''''''''''        meshTextures = New Texture(materials.Length - 1) {}        ' Create any textures        Dim i As Integer        For i = 0 To materials.Length            If Not (materials(i).TextureFilename Is Nothing) Then                meshTextures(i) = TextureLoader.FromFile(dev, MediaUtilities.FindFile(materials(i).TextureFilename))            End If        Next i        SetTextures(meshTextures)        mesh.MeshData = meshData        ''Dim i As Integer        ' If there is skinning info, save any required data        If Not (skinInfo Is Nothing) Then            mesh.SkinInformation = skinInfo            Dim numBones As Integer = skinInfo.NumberBones            Dim offsetMatrices(numBones) As Matrix            For i = 0 To numBones                offsetMatrices(i) = skinInfo.GetBoneOffsetMatrix(i)            Next i            SetOffsetMatrices(offsetMatrices)            Me.GenerateSkinnedMesh(mesh)        End If        Return mesh    End Function 'CreateMeshContainer    Public Sub CreateAnimation(ByVal file As String)        ' Create our allocate hierarchy derived class        Dim alloc As AllocateHierarchy        ' Load our file        rootFrame = Mesh.LoadHierarchyFromFile(file, MeshFlags.Managed, Device, alloc, Nothing)        ' Calculate the center and radius of a bounding sphere        objectRadius = Frame.CalculateBoundingSphere(rootFrame.FrameHierarchy, objectCenter)        ' Setup the matrices for animation        SetupBoneMatrices(CType(rootFrame.FrameHierarchy, Frame))        ' Start the timer        DXUtil.Timer(DirectXTimer.Start)    End Sub 'CreateAnimation    Public Sub Render()        DrawFrame(CType(rootFrame.FrameHierarchy, Frame))    End SubEnd Class


I can see two errors in the CreateAnimation(ByVal file As String) function.

1. alloc has not been initialized before using it.

2. AllocateHierarchy class can not be used directly. You should use a class derived from it, and the derived class should have the contents the the application needs. I have seen one in your code in the starting of this thread.

einstone

This topic is closed to new replies.

Advertisement