You don't need to convert it into obj, you can load all needed information out of it.
illstar posted this 3 years ago on a different forum. If you would put some afford into it you would've found this already. There are many hints in all those silkroad collision / navmesh threads here as well.
Code:
Imports System.IO
Public Class cBmsLoader
Public Structure sPoint
Public x As Single
Public y As Single
Public z As Single
Dim flag As Byte
End Structure
Public Structure sLine
Public PointA As UInt16
Public PointB As UInt16
Public NeighbourA As UInt16
Public NeighbourB As UInt16
Dim flag As Byte
End Structure
Public Structure sTriangle
Public PointA As UInt16
Public PointB As UInt16
Public PointC As UInt16
Dim unk As UInt16
End Structure
Dim vertex As Int32
Dim bone As Int32
Dim triangle As Int32
Dim unk1 As Int32
Dim unk2 As Int32
Dim stat As Int32
Dim unk3 As Int32
Dim HitBox As Int32
Public Points As New Collections.Generic.List(Of sPoint)
Public ObjectGround As New Collections.Generic.List(Of sTriangle)
Public Inlines As New Collections.Generic.List(Of sLine)
Public Outlines As New Collections.Generic.List(Of sLine)
Sub New(ByVal path As String) 'load the bms
path = "\" & path
Console.WriteLine(path)
Dim b() As Byte = PK2_Data.Get_file(path)
If b Is Nothing Then Exit Sub
Dim Reader As New BinaryReader(New IO.MemoryStream(b))
'### loding bms header ####
Reader.ReadChars(12) 'Header --> "JMXVRES 109 "
vertex = Reader.ReadInt32()
bone = Reader.ReadInt32()
triangle = Reader.ReadInt32()
unk1 = Reader.ReadInt32()
unk2 = Reader.ReadInt32()
stat = Reader.ReadInt32()
unk3 = Reader.ReadInt32()
HitBox = Reader.ReadInt32()
'#### Loading Points ####
Reader.BaseStream.Position = HitBox
Dim pCounter As Int32 = Reader.ReadInt32
For i As Int32 = 1 To pCounter
Dim point As New sPoint
point.x = Reader.ReadSingle 'point X position
point.z = Reader.ReadSingle 'point Z position
point.y = Reader.ReadSingle 'point Y position
Reader.ReadBytes(1) 'unk
Points.Add(point)
Next
'### Loading ObjectGround ###
pCounter = Reader.ReadInt32
For i As Int32 = 1 To pCounter
Dim Triangle As New sTriangle
Triangle.PointA = Reader.ReadUInt16 'point A index --> Points
Triangle.PointB = Reader.ReadUInt16 'point B index --> Points
Triangle.PointC = Reader.ReadUInt16 'point C index --> Points
Triangle.unk = Reader.ReadUInt16()
ObjectGround.Add(Triangle)
Next
'### Loading Outlines ###
pCounter = Reader.ReadInt32
For i As Int32 = 1 To pCounter
Dim Line As New sLine
Line.PointA = Reader.ReadUInt16 'point A index --> Points
Line.PointB = Reader.ReadUInt16 'point B index --> Points
Line.NeighbourA = Reader.ReadUInt16 'index of neighbour triangle A --> ObjectGround
Line.NeighbourB = Reader.ReadUInt16 'index of neighbour triangle B --> ObjectGround --> FFFF --> no Neighbour triangle
Line.flag = Reader.ReadByte 'seems to intcate if passable (3=not passable 0=passable else=unk)
Outlines.Add(Line)
Next
'### Loading Inlines ###
pCounter = Reader.ReadInt32
For i As Int32 = 1 To pCounter 'object inlines
Dim Line As New sLine
Line.PointA = Reader.ReadUInt16 'point A index --> Points
Line.PointB = Reader.ReadUInt16 'point B index --> Points
Line.NeighbourA = Reader.ReadUInt16 'index of neighbour triangle A --> objectground
Line.NeighbourB = Reader.ReadUInt16 'index of neighbour triangle B --> objectground
Line.flag = Reader.ReadByte 'seems to intcate if passable (7=not passable 3=passable else=unk)
Inlines.Add(Line)
Next
'... unk bytes ....
Reader.Close()
End Sub
End Class
How to draw it:
Code:
//Draw it line by line ... something like that:
foreach(Bms.sLine L in bms.Outlines) {
Pointf pA = new Pointf(bms.points(l.PointA).X,
bms.points(l.PointA).Y)
Pointf pB = new Pointf(bms.points(l.PointB).X,
bms.points(l.PointB).Y)
fx.DrawLine(new Pen(new SolidBrush(Color.Silver)),pA,pB)
}
Rotation Fix:
Code:
'You have to rotate before add the offset from the nvm
For Each Point As cBmsLoader.cPoint In Bms.Points
'aObject.Rotation --> rotation from the nvm
Dim newX As Single = Point.X * Math.Cos(-aObject.Rotation) - -Point.Y * Math.Sin(-aObject.Rotation)
Dim newY As Single = Point.X * Math.Sin(-aObject.Rotation) + -Point.Y * Math.Cos(-aObject.Rotation)
'aObject.Position.X/Y --> offset from the nvm
Point.X = newX + aObject.Position.X
Point.Y = newY + aObject.Position.Y
Next
You're still far ways from loading all bms files because there are some bugs in the code.