Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directx

Status
Not open for further replies.

transparent

Programmer
Sep 15, 2001
333
GB
Does anybody know how to load a 3d object in any format (such as .x, .3ds .lwo etc) into the directx framework under vb?

I'm trying to get to grips with directx, with the aim to write a game. Any help will be greatly appreciated.

Cheers
 
Try messing around with this :)

Sub Load3DsMesh(Filename As String)
'##BD Load a 3DS file in the mesh. The materials and the texture will be loaded too.
'##PD filename 3Ds filename.
Dim LE As MaterialFactory8
Set LE = New MaterialFactory8

'SetPrimitiveType TV_TRIANGLELIST
'SetVertexType TV_VERTEX
On Error GoTo errs
Dim ErrString As String
ErrString = "3DS: Load3ds"
' AddLog "Load 3ds :" + filename
Dim VbCounter As Long
Dim ColorByte As udColorByte
Dim PercentInt As Integer
Dim cBlock As Byte ' Type of color currently being imported. See colorblock Enum
Dim Materials2() As aMaterial
Dim mCount As Integer ' Number of loaded material
'im MatTexture() As Texture8

Dim Info As tdsHeader ' Header of Chunk
Dim Index As Long ' Index in File -- filepos

Dim MeshName As String ' Current Mesh Name
Dim Done As Boolean
Dim CurrentMat As Integer
Dim NbGroupe As Integer
Dim vcount As Long ' redundant vertex counter
Dim vertices As Integer ' ""
Dim faces As Integer ' Numbder of faces
Dim VertexList() As D3DVECTOR ' #DS file Vertexlist
Dim Facelist() As aFace ' Facelist
Dim vbuf() As Long ' redunant vertexlist for vertex buffer
'Dim MeshVertices() As D3DVERTEX ' Actual constructor for vertex buffer

Dim UVCoords() As UVmap ' #DS file UV coordinates
Dim UVbuf() As UVmap ' Buffer for MeshVertices construction
Dim nBuf() As D3DVECTOR ' Buffer for the temp face Normals
Dim Normals() As D3DVECTOR ' Array to hold temporary face normals

Dim tVector As D3DVECTOR
Dim Char As Byte
Dim Strz As String ' All Generic definitions for reading
Dim Dword As Long ' types stored in #DS file via C typedefs
Dim word As Integer
Dim Real As Single
Dim i As Long
Dim TheScale As Long
Mesh(MeshIndex).Features.PrimType = D3DPT_TRIANGLELIST
TheScale = 1
Dim UVCoordsTrue As Boolean
UVCoordsTrue = False

Dim MinX, MinY, MinZ As Single
Dim MaxX, MaxY, maxZ As Single

Index = 1

TestPAKFile Filename
AddLog "Loading 3DS mesh : " + CStr(Filename) + "..."
Open Filename For Binary As #1


While Not EOF(1)
Get #1, Index, Info
Index = Index + 6
' Debug.Print Hex(Info.Header), Info.Length
Select Case Info.Header

Case &H2: ' 3DS Version Number
ErrString = "3DS Version"
Get #1, Index, Dword
Index = Index + Len(Dword)

Case &H3D3D: ' 3D Editor Header
ErrString = "3D Editor Chunk"

Case &H3D3E: ' Mesh Version
ErrString = "Mesh Version"
Get #1, Index, Dword
Index = Index + Len(Dword)

Case &H4000: ' Object Block -- Includes Name
ErrString = "Object Block"
Done = False
MeshName = ""
While Not Done
Get #1, Index, Char
If Char <> 0 Then
MeshName = MeshName + Chr(Char)
Else
Done = True
End If
Index = Index + Len(Char)
Wend
Debug.Print &quot;Name :&quot;; MeshName; &quot;&quot;

Case &H4100: ' Triangular Mesh
ErrString = &quot;Triangular Mesh&quot;
NbGroupe = NbGroupe + 1
SetGroupPointer NbGroupe
Debug.Print NbGroupe
Case &H4110: ' Verticies List
ErrString = &quot;Vertices&quot;
Get #1, Index, vertices
Index = Index + Len(vertices)
Debug.Print &quot;Vertex list &quot;; vertices
ReDim VertexList(vertices)
Get #1, Index, VertexList
Index = Index + Len(VertexList(0)) * CLng(vertices)

MinX = 500000: MinY = MinX: MinZ = MinY
MaxX = -500000: MaxY = MaxX: maxZ = MaxY

For i = 0 To vertices - 1
With VertexList(i)
VertexList(i).x = VertexList(i).x * TheScale
VertexList(i).y = VertexList(i).y * TheScale
VertexList(i).z = VertexList(i).z * TheScale
If .x < MinX Then MinX = .x
If .y < MinY Then MinY = .y
If .z < MinZ Then MinZ = .z

If .x > MaxX Then MaxX = .x
If .y > MaxY Then MaxY = .y
If .z > maxZ Then maxZ = .z
End With
Next i

Case &H4120: ' Face List
ErrString = &quot;Face List&quot;
Get #1, Index, faces
Index = Index + Len(faces)
Debug.Print &quot;Face list &quot;; faces

ReDim Facelist(faces)
Get #1, Index, Facelist
Index = Index + Len(Facelist(0)) * CLng(faces)

vcount = -1
ReDim vbuf(faces * 3)
ReDim UVbuf(faces * 3)
For i = 0 To faces - 1
vcount = vcount + 3
'debug.print vcount
If UVCoordsTrue Then
UVbuf(vcount - 2) = UVCoords(Facelist(i).a)
UVbuf(vcount - 1) = UVCoords(Facelist(i).b)
UVbuf(vcount) = UVCoords(Facelist(i).C)
End If
vbuf(vcount - 2) = Facelist(i).a
vbuf(vcount - 1) = Facelist(i).b
vbuf(vcount) = Facelist(i).C

' Make Face Normal
Dim a As D3DVECTOR, b As D3DVECTOR, C As D3DVECTOR
ReDim Preserve nBuf(vcount)
With DirectX
' Face Normal

D3DXVec3Subtract a, VertexList(vbuf(vcount - 2)), VertexList(vbuf(vcount - 1))
D3DXVec3Subtract b, VertexList(vbuf(vcount - 2)), VertexList(vbuf(vcount))
D3DXVec3Cross C, a, b
D3DXVec3Normalize C, C

nBuf(vcount) = C
nBuf(vcount - 1) = C
nBuf(vcount - 2) = C

End With
Next i
UVCoordsTrue = False


ErrString = &quot;Load3ds: Mesh Add&quot;
Debug.Print &quot;Mesh add &quot; + MeshName
With Mesh(MeshIndex)

For i = 0 To vcount
'AddLog &quot;Addvertex :&quot; + CStr(vbuf(I))
AddVertex VertexList(vbuf(i)).x, VertexList(vbuf(i)).y, VertexList(vbuf(i)).z, D3DColorMake(1, 1, 1, 1), UVbuf(i).U, 1 - UVbuf(i).V, nBuf(i).x, nBuf(i).y, nBuf(i).z
Next i
End With

Case &H4130: ' Face Material List
ErrString = &quot;Face Material&quot;
Done = False
Strz = &quot;&quot;
While Not Done
Get #1, Index, Char
If Char <> 0 Then
Strz = Strz + Chr(Char)
Else
Done = True
End If
Index = Index + Len(Char)
Wend

Dim Q As Integer
For Q = 1 To mCount
If Strz = Materials2(Q).MatName Then
' Store the Material Here
Debug.Print &quot;Selected :&quot;; Strz
Mesh(MeshIndex).Features.Groups(NbGroupe).TextureI = Materials2(Q).MapPercent
Materials(Materials2(Q).MaterialIndex).Mat.Ambient = Materials2(Q).Ambient
Materials(Materials2(Q).MaterialIndex).Mat.Diffuse = DXColor(1, 1, 1, 1)
Materials(Materials2(Q).MaterialIndex).Mat.Specular = Materials2(Q).Specular
Materials(Materials2(Q).MaterialIndex).Mat.emissive = DXColor(0, 0, 0, 0)
'Debug.Print Q, Materials2(Q).Ambient.r, , Materials2(Q).Ambient.g, Materials2(Q).Ambient.B
Mesh(MeshIndex).Features.Groups(NbGroupe).MaterialI = Materials2(Q).MaterialIndex
'SetTexture MatTexture(Q), NbGroupe
Exit For
End If
Next Q

Get #1, Index, word
Index = Index + Len(word)
For i = 1 To word
Get #1, Index, word
Index = Index + Len(word)
Next i

Case &H4140: ' Face Texture Coordinate
Debug.Print &quot;Add texture coordinates&quot;
ErrString = &quot;Face Texture Coordinates&quot;
Get #1, Index, word
Index = Index + Len(word)
ReDim UVCoords(word)
Get #1, Index, UVCoords
Index = Index + Len(UVCoords(0)) * CLng(word)
UVCoordsTrue = True

Case &H4160:
ErrString = &quot;Local Coordinate System&quot;
Get #1, Index, tVector
Index = Index + Len(tVector)
Get #1, Index, tVector
Index = Index + Len(tVector)
Get #1, Index, tVector
Index = Index + Len(tVector)
Get #1, Index, tVector
'DD.MeshParent(ObjName2).Mesh(MeshName).position
Index = Index + Len(tVector)

Case &HA000: ' Material Name
ErrString = &quot;Material Name&quot;
Done = False
Strz = &quot;&quot;
While Not Done
Get #1, Index, Char
If Char <> 0 Then
Strz = Strz + Chr(Char)
Else
Done = True
End If
Index = Index + Len(Char)
Wend
Materials2(mCount).MatName = Strz
Debug.Print &quot;Material Name :&quot;; Strz
Case &HAFFF: ' Material Editor Chunk
ErrString = &quot;Material Editor Chunk&quot;
mCount = mCount + 1
ReDim Preserve Materials2(mCount) ' Save stored materials
CurrentMat = LE.CreateMaterial
Materials2(mCount).MaterialIndex = CurrentMat
Case &H10: ' Single Color Chunk
ErrString = &quot;Single Color Chunk&quot;
Index = Index + Info.Length - 6

Case &H11: ' Byte Color Chunk
ErrString = &quot;Byte Color Chunk&quot;
Get #1, Index, ColorByte
Index = Index + Len(ColorByte)

Select Case cBlock
Case Ambient:
With Materials2(mCount).Ambient
.a = 1
.r = ColorByte.Red / 255
.g = ColorByte.Green / 255
.b = ColorByte.Blue / 255
Debug.Print &quot; Material Ambient :&quot;; .r; &quot; &quot;; .g; &quot; &quot;; .b
End With
Case Diffuse:
With Materials2(mCount).Diffuse
.a = 1
.r = ColorByte.Red / 255
.g = ColorByte.Green / 255
.b = ColorByte.Blue / 255
Debug.Print &quot; Material Diffuse :&quot;; .r; &quot; &quot;; .g; &quot; &quot;; .b

End With

Case Specular:
With Materials2(mCount).Specular
.a = 1
.r = ColorByte.Red / 255
.g = ColorByte.Green / 255
.b = ColorByte.Blue / 255
Debug.Print &quot; Material Specular :&quot;; .r; &quot; &quot;; .g; &quot; &quot;; .b

End With
End Select

Case &H30: ' Percent Chunk Int format
ErrString = &quot;Percent Chunk INT&quot;
Get #1, Index, PercentInt
Index = Index + Len(PercentInt)

Case &H31: ' Percent Chunk Float format
ErrString = &quot;Percent Chunk Float&quot;
Index = Index + Info.Length - 6

Case &HA010: ' Ambient color
ErrString = &quot;Ambient Color&quot;
cBlock = Ambient

Case &HA020: ' Diffuse Color
ErrString = &quot;Diffuse Color&quot;
cBlock = Diffuse

Case &HA030: ' Specular Color
ErrString = &quot;Specular Color&quot;
cBlock = Specular

Case &HA200: ' Map #1 -- diffuse?
cBlock = Diffuse

Case &HA300: ' Map FileName
ErrString = &quot;Map File Name&quot;
Done = False
Strz = &quot;&quot;
While Not Done
Get #1, Index, Char
If Char <> 0 Then
Strz = Strz + Chr(Char)
Else
Done = True
End If
Index = Index + Len(Char)
Wend
Select Case cBlock
Case Diffuse:
Materials2(mCount).MapName = Strz

End Select

Debug.Print &quot;Material Map Name: &quot; & Strz
'ReDim Preserve MatTexture(mCount)
'For i = 1 To 256
' If TextureName(i) = &quot;&quot; Then Exit For
'Next i
If Exist(Strz) = False Then
Strz = Left$(Filename, InStrRev(Filename, &quot;\&quot;)) + Strz
End If
i = LocTexFactory.LoadTexture(Strz, Strz, , , TV_COLORKEY_BLACK).GetTexIndex
'Set Texture(i) = LoadSimpleTexture(SearchExistPath(Strz, Left$(Filename, InStrRev(Filename, &quot;\&quot;))), 256, 256)
'TextureName(i) = &quot;3DS Texture &quot; + CStr(i)

Materials2(mCount).MapPercent = i
'Set MatTexture(mCount) = LocalScene.LoadTexture(&quot;d:\&quot; + Strz, 256, 256)
Case &HA33A: ' Map #2 -- Ambient?
cBlock = Ambient

Case &HA354
ErrString = &quot;V scaling for Map&quot;
Index = Index + Info.Length - 6

Case &HA356
ErrString = &quot;U scaling for Map&quot;
Index = Index + Info.Length - 6

Case &HA358
ErrString = &quot;U offset for Map&quot;
Index = Index + Info.Length - 6

Case &HA35A
ErrString = &quot;V offset for Map&quot;
Index = Index + Info.Length - 6

Case &HA35C
ErrString = &quot;Rotation Angle for Map&quot;
Index = Index + Info.Length - 6

Case &H100: ' One Unit
ErrString = &quot;One Unit&quot;
Get #1, Index, Real
Index = Index + Len(Real)
Case &H4D4D ' OK the object begins

Case Else ' Unknown Chunk
ErrString = &quot;Unknown Chunk&quot;
Index = Index + Info.Length - 6
End Select
Debug.Print &quot; ## &quot;; Hex$(Info.Header); &quot;(&quot;; ErrString; &quot;)&quot;
AddLog &quot; ## &quot; + Hex$(Info.Header) + &quot; (&quot; + CStr(ErrString) + &quot;)&quot;
Wend
Close #1
DeletePAKTemp Filename
AddLog &quot;End of 3DS Loading.&quot;
Exit Sub
errs:
Debug.Print &quot;Error :&quot;; ErrString, Err.Number, Err.Description
AddLog &quot;Error in 3Ds loader :&quot; + CStr(Err.Number) + &quot; &quot; + Err.Description + &quot; &quot; + ErrString
Resume Next
End Sub
 
Here is some code from an engine to load 3DS meshes.
Lol and to think this doesn't even cover texturing and rendering. Your best bet is to probably get a book that tells you how to load 3ds models, or to use an engine. If you use an engine, may I suggest TrueVision 3D for VB, check it out at


Sub Load3DsMesh(Filename As String)
'##BD Load a 3DS file in the mesh. The materials and the texture will be loaded too.
'##PD filename 3Ds filename.
Dim LE As MaterialFactory8
Set LE = New MaterialFactory8

'SetPrimitiveType TV_TRIANGLELIST
'SetVertexType TV_VERTEX
On Error GoTo errs
Dim ErrString As String
ErrString = &quot;3DS: Load3ds&quot;
' AddLog &quot;Load 3ds :&quot; + filename
Dim VbCounter As Long
Dim ColorByte As udColorByte
Dim PercentInt As Integer
Dim cBlock As Byte ' Type of color currently being imported. See colorblock Enum
Dim Materials2() As aMaterial
Dim mCount As Integer ' Number of loaded material
'im MatTexture() As Texture8

Dim Info As tdsHeader ' Header of Chunk
Dim Index As Long ' Index in File -- filepos

Dim MeshName As String ' Current Mesh Name
Dim Done As Boolean
Dim CurrentMat As Integer
Dim NbGroupe As Integer
Dim vcount As Long ' redundant vertex counter
Dim vertices As Integer ' &quot;&quot;
Dim faces As Integer ' Numbder of faces
Dim VertexList() As D3DVECTOR ' #DS file Vertexlist
Dim Facelist() As aFace ' Facelist
Dim vbuf() As Long ' redunant vertexlist for vertex buffer
'Dim MeshVertices() As D3DVERTEX ' Actual constructor for vertex buffer

Dim UVCoords() As UVmap ' #DS file UV coordinates
Dim UVbuf() As UVmap ' Buffer for MeshVertices construction
Dim nBuf() As D3DVECTOR ' Buffer for the temp face Normals
Dim Normals() As D3DVECTOR ' Array to hold temporary face normals

Dim tVector As D3DVECTOR
Dim Char As Byte
Dim Strz As String ' All Generic definitions for reading
Dim Dword As Long ' types stored in #DS file via C typedefs
Dim word As Integer
Dim Real As Single
Dim i As Long
Dim TheScale As Long
Mesh(MeshIndex).Features.PrimType = D3DPT_TRIANGLELIST
TheScale = 1
Dim UVCoordsTrue As Boolean
UVCoordsTrue = False

Dim MinX, MinY, MinZ As Single
Dim MaxX, MaxY, maxZ As Single

Index = 1

TestPAKFile Filename
AddLog &quot;Loading 3DS mesh : &quot; + CStr(Filename) + &quot;...&quot;
Open Filename For Binary As #1


While Not EOF(1)
Get #1, Index, Info
Index = Index + 6
' Debug.Print Hex(Info.Header), Info.Length
Select Case Info.Header

Case &H2: ' 3DS Version Number
ErrString = &quot;3DS Version&quot;
Get #1, Index, Dword
Index = Index + Len(Dword)

Case &H3D3D: ' 3D Editor Header
ErrString = &quot;3D Editor Chunk&quot;

Case &H3D3E: ' Mesh Version
ErrString = &quot;Mesh Version&quot;
Get #1, Index, Dword
Index = Index + Len(Dword)

Case &H4000: ' Object Block -- Includes Name
ErrString = &quot;Object Block&quot;
Done = False
MeshName = &quot;&quot;
While Not Done
Get #1, Index, Char
If Char <> 0 Then
MeshName = MeshName + Chr(Char)
Else
Done = True
End If
Index = Index + Len(Char)
Wend
Debug.Print &quot;Name :&quot;; MeshName; &quot;&quot;

Case &H4100: ' Triangular Mesh
ErrString = &quot;Triangular Mesh&quot;
NbGroupe = NbGroupe + 1
SetGroupPointer NbGroupe
Debug.Print NbGroupe
Case &H4110: ' Verticies List
ErrString = &quot;Vertices&quot;
Get #1, Index, vertices
Index = Index + Len(vertices)
Debug.Print &quot;Vertex list &quot;; vertices
ReDim VertexList(vertices)
Get #1, Index, VertexList
Index = Index + Len(VertexList(0)) * CLng(vertices)

MinX = 500000: MinY = MinX: MinZ = MinY
MaxX = -500000: MaxY = MaxX: maxZ = MaxY

For i = 0 To vertices - 1
With VertexList(i)
VertexList(i).x = VertexList(i).x * TheScale
VertexList(i).y = VertexList(i).y * TheScale
VertexList(i).z = VertexList(i).z * TheScale
If .x < MinX Then MinX = .x
If .y < MinY Then MinY = .y
If .z < MinZ Then MinZ = .z

If .x > MaxX Then MaxX = .x
If .y > MaxY Then MaxY = .y
If .z > maxZ Then maxZ = .z
End With
Next i

Case &H4120: ' Face List
ErrString = &quot;Face List&quot;
Get #1, Index, faces
Index = Index + Len(faces)
Debug.Print &quot;Face list &quot;; faces

ReDim Facelist(faces)
Get #1, Index, Facelist
Index = Index + Len(Facelist(0)) * CLng(faces)

vcount = -1
ReDim vbuf(faces * 3)
ReDim UVbuf(faces * 3)
For i = 0 To faces - 1
vcount = vcount + 3
'debug.print vcount
If UVCoordsTrue Then
UVbuf(vcount - 2) = UVCoords(Facelist(i).a)
UVbuf(vcount - 1) = UVCoords(Facelist(i).b)
UVbuf(vcount) = UVCoords(Facelist(i).C)
End If
vbuf(vcount - 2) = Facelist(i).a
vbuf(vcount - 1) = Facelist(i).b
vbuf(vcount) = Facelist(i).C

' Make Face Normal
Dim a As D3DVECTOR, b As D3DVECTOR, C As D3DVECTOR
ReDim Preserve nBuf(vcount)
With DirectX
' Face Normal

D3DXVec3Subtract a, VertexList(vbuf(vcount - 2)), VertexList(vbuf(vcount - 1))
D3DXVec3Subtract b, VertexList(vbuf(vcount - 2)), VertexList(vbuf(vcount))
D3DXVec3Cross C, a, b
D3DXVec3Normalize C, C

nBuf(vcount) = C
nBuf(vcount - 1) = C
nBuf(vcount - 2) = C

End With
Next i
UVCoordsTrue = False


ErrString = &quot;Load3ds: Mesh Add&quot;
Debug.Print &quot;Mesh add &quot; + MeshName
With Mesh(MeshIndex)

For i = 0 To vcount
'AddLog &quot;Addvertex :&quot; + CStr(vbuf(I))
AddVertex VertexList(vbuf(i)).x, VertexList(vbuf(i)).y, VertexList(vbuf(i)).z, D3DColorMake(1, 1, 1, 1), UVbuf(i).U, 1 - UVbuf(i).V, nBuf(i).x, nBuf(i).y, nBuf(i).z
Next i
End With

Case &H4130: ' Face Material List
ErrString = &quot;Face Material&quot;
Done = False
Strz = &quot;&quot;
While Not Done
Get #1, Index, Char
If Char <> 0 Then
Strz = Strz + Chr(Char)
Else
Done = True
End If
Index = Index + Len(Char)
Wend

Dim Q As Integer
For Q = 1 To mCount
If Strz = Materials2(Q).MatName Then
' Store the Material Here
Debug.Print &quot;Selected :&quot;; Strz
Mesh(MeshIndex).Features.Groups(NbGroupe).TextureI = Materials2(Q).MapPercent
Materials(Materials2(Q).MaterialIndex).Mat.Ambient = Materials2(Q).Ambient
Materials(Materials2(Q).MaterialIndex).Mat.Diffuse = DXColor(1, 1, 1, 1)
Materials(Materials2(Q).MaterialIndex).Mat.Specular = Materials2(Q).Specular
Materials(Materials2(Q).MaterialIndex).Mat.emissive = DXColor(0, 0, 0, 0)
'Debug.Print Q, Materials2(Q).Ambient.r, , Materials2(Q).Ambient.g, Materials2(Q).Ambient.B
Mesh(MeshIndex).Features.Groups(NbGroupe).MaterialI = Materials2(Q).MaterialIndex
'SetTexture MatTexture(Q), NbGroupe
Exit For
End If
Next Q

Get #1, Index, word
Index = Index + Len(word)
For i = 1 To word
Get #1, Index, word
Index = Index + Len(word)
Next i

Case &H4140: ' Face Texture Coordinate
Debug.Print &quot;Add texture coordinates&quot;
ErrString = &quot;Face Texture Coordinates&quot;
Get #1, Index, word
Index = Index + Len(word)
ReDim UVCoords(word)
Get #1, Index, UVCoords
Index = Index + Len(UVCoords(0)) * CLng(word)
UVCoordsTrue = True

Case &H4160:
ErrString = &quot;Local Coordinate System&quot;
Get #1, Index, tVector
Index = Index + Len(tVector)
Get #1, Index, tVector
Index = Index + Len(tVector)
Get #1, Index, tVector
Index = Index + Len(tVector)
Get #1, Index, tVector
'DD.MeshParent(ObjName2).Mesh(MeshName).position
Index = Index + Len(tVector)

Case &HA000: ' Material Name
ErrString = &quot;Material Name&quot;
Done = False
Strz = &quot;&quot;
While Not Done
Get #1, Index, Char
If Char <> 0 Then
Strz = Strz + Chr(Char)
Else
Done = True
End If
Index = Index + Len(Char)
Wend
Materials2(mCount).MatName = Strz
Debug.Print &quot;Material Name :&quot;; Strz
Case &HAFFF: ' Material Editor Chunk
ErrString = &quot;Material Editor Chunk&quot;
mCount = mCount + 1
ReDim Preserve Materials2(mCount) ' Save stored materials
CurrentMat = LE.CreateMaterial
Materials2(mCount).MaterialIndex = CurrentMat
Case &H10: ' Single Color Chunk
ErrString = &quot;Single Color Chunk&quot;
Index = Index + Info.Length - 6

Case &H11: ' Byte Color Chunk
ErrString = &quot;Byte Color Chunk&quot;
Get #1, Index, ColorByte
Index = Index + Len(ColorByte)

Select Case cBlock
Case Ambient:
With Materials2(mCount).Ambient
.a = 1
.r = ColorByte.Red / 255
.g = ColorByte.Green / 255
.b = ColorByte.Blue / 255
Debug.Print &quot; Material Ambient :&quot;; .r; &quot; &quot;; .g; &quot; &quot;; .b
End With
Case Diffuse:
With Materials2(mCount).Diffuse
.a = 1
.r = ColorByte.Red / 255
.g = ColorByte.Green / 255
.b = ColorByte.Blue / 255
Debug.Print &quot; Material Diffuse :&quot;; .r; &quot; &quot;; .g; &quot; &quot;; .b

End With

Case Specular:
With Materials2(mCount).Specular
.a = 1
.r = ColorByte.Red / 255
.g = ColorByte.Green / 255
.b = ColorByte.Blue / 255
Debug.Print &quot; Material Specular :&quot;; .r; &quot; &quot;; .g; &quot; &quot;; .b

End With
End Select

Case &H30: ' Percent Chunk Int format
ErrString = &quot;Percent Chunk INT&quot;
Get #1, Index, PercentInt
Index = Index + Len(PercentInt)

Case &H31: ' Percent Chunk Float format
ErrString = &quot;Percent Chunk Float&quot;
Index = Index + Info.Length - 6

Case &HA010: ' Ambient color
ErrString = &quot;Ambient Color&quot;
cBlock = Ambient

Case &HA020: ' Diffuse Color
ErrString = &quot;Diffuse Color&quot;
cBlock = Diffuse

Case &HA030: ' Specular Color
ErrString = &quot;Specular Color&quot;
cBlock = Specular

Case &HA200: ' Map #1 -- diffuse?
cBlock = Diffuse

Case &HA300: ' Map FileName
ErrString = &quot;Map File Name&quot;
Done = False
Strz = &quot;&quot;
While Not Done
Get #1, Index, Char
If Char <> 0 Then
Strz = Strz + Chr(Char)
Else
Done = True
End If
Index = Index + Len(Char)
Wend
Select Case cBlock
Case Diffuse:
Materials2(mCount).MapName = Strz

End Select

Debug.Print &quot;Material Map Name: &quot; & Strz
'ReDim Preserve MatTexture(mCount)
'For i = 1 To 256
' If TextureName(i) = &quot;&quot; Then Exit For
'Next i
If Exist(Strz) = False Then
Strz = Left$(Filename, InStrRev(Filename, &quot;\&quot;)) + Strz
End If
i = LocTexFactory.LoadTexture(Strz, Strz, , , TV_COLORKEY_BLACK).GetTexIndex
'Set Texture(i) = LoadSimpleTexture(SearchExistPath(Strz, Left$(Filename, InStrRev(Filename, &quot;\&quot;))), 256, 256)
'TextureName(i) = &quot;3DS Texture &quot; + CStr(i)

Materials2(mCount).MapPercent = i
'Set MatTexture(mCount) = LocalScene.LoadTexture(&quot;d:\&quot; + Strz, 256, 256)
Case &HA33A: ' Map #2 -- Ambient?
cBlock = Ambient

Case &HA354
ErrString = &quot;V scaling for Map&quot;
Index = Index + Info.Length - 6

Case &HA356
ErrString = &quot;U scaling for Map&quot;
Index = Index + Info.Length - 6

Case &HA358
ErrString = &quot;U offset for Map&quot;
Index = Index + Info.Length - 6

Case &HA35A
ErrString = &quot;V offset for Map&quot;
Index = Index + Info.Length - 6

Case &HA35C
ErrString = &quot;Rotation Angle for Map&quot;
Index = Index + Info.Length - 6

Case &H100: ' One Unit
ErrString = &quot;One Unit&quot;
Get #1, Index, Real
Index = Index + Len(Real)
Case &H4D4D ' OK the object begins

Case Else ' Unknown Chunk
ErrString = &quot;Unknown Chunk&quot;
Index = Index + Info.Length - 6
End Select
Debug.Print &quot; ## &quot;; Hex$(Info.Header); &quot;(&quot;; ErrString; &quot;)&quot;
AddLog &quot; ## &quot; + Hex$(Info.Header) + &quot; (&quot; + CStr(ErrString) + &quot;)&quot;
Wend
Close #1
DeletePAKTemp Filename
AddLog &quot;End of 3DS Loading.&quot;
Exit Sub
errs:
Debug.Print &quot;Error :&quot;; ErrString, Err.Number, Err.Description
AddLog &quot;Error in 3Ds loader :&quot; + CStr(Err.Number) + &quot; &quot; + Err.Description + &quot; &quot; + ErrString
Resume Next
End Sub
 
Cheers for the replies.... Does anybnody suggest ang decfent books on this stuff?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top