heres a 3ds model ripper ive coded up quickly for my own purposes i thought it might be usefull to you guys so im posting it.
Dim Shared As String ModelPath
ModelPath = "Sphere.3ds"
Const OutPutPath = "Sphere.Bi"
Type Vertices
X As Double
Y As Double
Z As Double
U As Double
V As Double
End Type
Type Faces
A As Integer
B As Integer
C As Integer
End Type
Type Entity3ds
ModelName As STRING
NoVertices As INTEGER
NoFaces As INTEGER
Vertex As Vertices PTR
Face As Faces PTR
End Type
Declare Function Load3ds ( BYVAL FileName As STRING ) As Entity3ds PTR
Declare Sub ConvertToDataFile ( Entity As Entity3ds PTR , BYVAL OutPath As STRING )
Declare Sub Delete ( Entity As Entity3ds PTR )
Dim Shared As Entity3ds PTR TestEntity
TestEntity = Load3ds( ModelPath )
ConvertToDataFile( TestEntity , OutPutPath )
Delete( TestEntity )
Function Load3ds( BYVAL FileName As STRING ) As Entity3ds PTR
dim Entity As Entity3ds ptr
Entity = Callocate(Len(Entity3ds))
dim vertex_x as single
dim vertex_y as single
dim vertex_z as single
dim face_p1 as ushort
dim face_p2 as ushort
dim face_p3 as ushort
dim vertex_u as single
dim vertex_v as single
dim chunk_id as ushort
dim chunk_len as integer
dim char as byte
dim qty as ushort
dim face_flags as ushort
dim filepointer as ubyte
dim as integer file = freefile
open filename for binary as #file
While (1)
if eof(1) then
close #file
return Entity
endif
get #file, , chunk_id
get #file, , chunk_len
Select case chunk_id
Case &h4D4D
Case &h3D3D
Case &h4000
do
get #file, ,char
If Char<>0 Then Entity->ModelName = Entity->ModelName+Chr(Char)
loop Until(char=0)
Case &h4100
Case &h4110
get #file, ,qty
entity->NoVertices = qty
entity->vertex = callocate( Entity->NoVertices * len(vertices) )
For i=0 To qty-1
get #file, ,vertex_x
get #file, ,vertex_y
get #file, ,vertex_z
Entity->vertex[i]->x = vertex_x
Entity->vertex[i]->y = vertex_y
Entity->vertex[i]->z = vertex_z
Next
Case &h4120
get #file, ,qty
Entity->NoFaces = qty
Entity->face = callocate( Entity->NoFaces * len(faces) )
For i=0 To qty-1
get #file, ,face_p1
get #file, ,face_p2
get #file, ,face_p3
Entity->face[i]->a = face_p1
Entity->face[i]->b = face_p2
Entity->face[i]->c = face_p3
get #file, ,face_flags
Next
Case &h4140
get #file, ,qty
For i=0 To qty-1
get #file, ,vertex_u
get #file, ,vertex_v
Entity->vertex[i]->u = vertex_u
Entity->vertex[i]->v = vertex_v
Next
case else
for x = 1 to chunk_len - 6
get #file, ,filepointer
next
End Select
Wend
return 0
End Function
Sub ConvertToDataFile( Entity As Entity3ds PTR , BYVAL OutPath As STRING )
File = FreeFile
Open OutPutPath For Binary As #File
Put #File , , Entity->ModelName+":"+Chr$(13)+Chr$(10)
Put #File , , Chr$(13)+Chr$(10)+"'REM NoVerttices , NoFaces"+Chr$(13)+Chr$(10)
Put #File , , "Data "+Str(Entity->NoVertices)+" , "+Str(Entity->NoFaces)+Chr$(13)+Chr$(10)
Put #File , , Chr$(13)+Chr$(10)+"'REM Vertices"+Chr$(13)+Chr$(10)
For x = 0 To Entity->NoVertices-1
Put #File , , "Data "+Str(Entity->Vertex[ X ]->X)+" , "+Str(Entity->Vertex[ X ]->Y)+" , "+Str(Entity->Vertex[ X ]->Z)+Chr$(13)+Chr$(10)
Next
Put #File , , Chr$(13)+Chr$(10)+"'REM UV`s"+Chr$(13)+Chr$(10)
For x = 0 To Entity->NoVertices-1
Put #File , , "Data "+Str(Entity->Vertex[ X ]->U)+" , "+Str(Entity->Vertex[ X ]->V)+Chr$(13)+Chr$(10)
Next
Put #File , , Chr$(13)+Chr$(10)+"'Face Connections "+Chr$(13)+Chr$(10)
For x = 0 To Entity->NoFaces-1
Put #File , , "Data "+Str(Entity->Face[ X ]->A)+" , "+Str(Entity->Face[ X ]->B)+" , "+Str(Entity->Face[ X ]->C)+Chr$(13)+Chr$(10)
Next
Close
End Sub
Sub Delete( Entity As Entity3ds PTR )
If (Entity) Then
If (Entity->Vertex) Then
Deallocate(Entity->Vertex)
EndIf
If (Entity->Face) Then
Deallocate(Entity->Face)
EndIf
Deallocate(Entity)
Endif
End Sub
all it does is rip the vertex face and uv data out of a 3ds file and put it in a .bi file in data statments itll be good for bulding complex models into the exe
heres the exe and a test model.