/[cvs]/rabit/RaBit's Rapid Racers/Module_GeoParser.bas
ViewVC logotype

Annotation of /rabit/RaBit's Rapid Racers/Module_GeoParser.bas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Mar 12 21:23:07 2002 UTC (22 years, 9 months ago) by cvsrabit
Branch point for: NFO, MAIN
Initial revision

1 cvsrabit 1.1 Attribute VB_Name = "Module_GeoParser"
2     Public Sub OpenGeometryFromGEO()
3    
4     Dim iBlockType As Integer
5     Dim iFileNo As Integer
6     Dim iSegsCount As Integer
7     Dim iSubBlockType As Integer
8    
9     Dim lCount As Long
10     Dim lDataSize As Long
11    
12     Dim strFileLine As String
13     Dim lpStrLineSegs() As String
14    
15     Dim lpLvVerticesListEmpty() As LITVERTEX
16     Dim lpLvVerticesList() As LITVERTEX
17    
18     Dim lpIIndicesList() As Integer
19     Dim lpIIndicesListEmpty() As Integer
20    
21     Dim IbIndexBuffer As Direct3DIndexBuffer8
22    
23     Dim VbVertexBuffer As Direct3DVertexBuffer8
24    
25     iFileNo = FreeFile
26    
27     Open App.Path + "\Scenes\geo1.geo" For Input As #iFileNo
28    
29     While Not EOF(iFileNo)
30    
31     Line Input #iFileNo, strFileLine
32    
33     strFileLine = Trim(strFileLine)
34    
35     If strFileLine <> "" Then
36    
37     lpStrLineSegs = Split(strFileLine, ",")
38    
39     iSegsCount = UBound(lpStrLineSegs) + 1
40    
41     If iSegsCount > 0 Then
42    
43     Select Case LCase(Trim(lpStrLineSegs(0)))
44    
45     Case ":cols" ' Start of a colour list
46    
47     iBlockType = 1
48     iSubBlockType = 0
49    
50     Case ":ip" ' Start of an indexed primitive object
51    
52     iBlockType = 2
53     iSubBlockType = 0
54    
55     Case "vd" ' after ":ip" - Vertex data following
56    
57     If iBlockType = 2 Then
58    
59     iSubBlockType = 1
60    
61     End If
62    
63     Case "id" ' after ":ip" - Index data following
64    
65     If iBlockType = 2 Then
66    
67     iSubBlockType = 2
68    
69     End If
70    
71     Case "/vd" ' after ":ip" - End of vertex data
72    
73     If iBlockType = 2 And iSubBlockType = 1 Then
74    
75     On Error Resume Next
76    
77     lCount = 0
78     lCount = UBound(lpLvVerticesList) + 1
79    
80     On Error GoTo 0
81    
82     lDataSize = Len(lpLvVerticesList(0)) * lCount
83    
84     Set VbVertexBuffer = D3DDevice.CreateVertexBuffer(lDataSize, 0, FVF_LVERTEX, D3DPOOL_MANAGED)
85    
86     If VbVertexBuffer Is Nothing Then
87    
88     Debug.Print "Could not create vertex buffer! Maybe no adapter memory left."
89    
90     Else
91    
92     D3DVertexBuffer8SetData VbVertexBuffer, 0, lDataSize, 0, lpLvVerticesList(0)
93     gCol_Geo_VbVertexBuffers.Add VbVertexBuffer
94    
95     End If
96    
97     iSubBlockType = 0
98     lpLvVerticesList = lpLvVerticesListEmpty
99    
100     End If
101    
102     Case "/id" ' after ":ip" - End of index data
103    
104     If iBlockType = 2 And iSubBlockType = 2 Then
105    
106     On Error Resume Next
107    
108     lCount = 0
109     lCount = UBound(lpIIndicesList) + 1
110    
111     On Error GoTo 0
112    
113     lDataSize = Len(lpIIndicesList(0)) * lCount
114    
115     Set IbIndexBuffer = D3DDevice.CreateIndexBuffer(lDataSize, 0, D3DFMT_INDEX16, D3DPOOL_MANAGED)
116    
117     If IbIndexBuffer Is Nothing Then
118    
119     Debug.Print "Could not create index buffer! Maybe no adapter memory left."
120    
121     Else
122    
123     D3DIndexBuffer8SetData IbIndexBuffer, 0, lDataSize, 0, lpIIndicesList(0)
124     gCol_Geo_IbIndexBuffers.Add IbIndexBuffer
125    
126     End If
127    
128     iSubBlockType = 0
129     lpIIndicesList = lpIIndicesListEmpty
130    
131     End If
132    
133     Case Else
134    
135     Select Case iBlockType
136    
137     Case 1
138    
139     If iSegsCount = 1 Then
140    
141     gCol_Geo_lColours.Add lpStrLineSegs(0)
142    
143     End If
144    
145     Case 2
146    
147     Select Case iSubBlockType
148    
149     Case 1
150    
151     If iSegsCount = 7 Then
152    
153     On Error Resume Next
154    
155     lCount = 0
156     lCount = UBound(lpLvVerticesList) + 1
157    
158     On Error GoTo 0
159    
160     ReDim Preserve lpLvVerticesList(lCount) As LITVERTEX
161    
162     lpLvVerticesList(lCount) = CreateLitVertex(Val(lpStrLineSegs(0)), Val(lpStrLineSegs(1)), Val(lpStrLineSegs(2)), gCol_Geo_lColours(Val(lpStrLineSegs(3)) + 1), CLng(lpStrLineSegs(4)), Val(lpStrLineSegs(5)), Val(lpStrLineSegs(6)))
163    
164     End If
165    
166     Case 2
167    
168     If iSegsCount = 3 Then
169    
170     On Error Resume Next
171    
172     lCount = 0
173     lCount = UBound(lpIIndicesList) + 1
174    
175     On Error GoTo 0
176    
177     ReDim Preserve lpIIndicesList(lCount + 2) As Integer
178    
179     lpIIndicesList(lCount) = CInt(lpStrLineSegs(0))
180     lpIIndicesList(lCount + 1) = CInt(lpStrLineSegs(1))
181     lpIIndicesList(lCount + 2) = CInt(lpStrLineSegs(2))
182    
183     End If
184    
185     End Select
186    
187     End Select
188    
189     End Select
190    
191     End If
192    
193     End If
194    
195     Wend
196    
197     Close #iFileNo
198     Dim txTempTexture As Direct3DTexture8
199    
200     Set txTempTexture = D3DX.CreateTextureFromFileEx(D3DDevice, App.Path & "\Scenes\tex1.jpg", 256, 256, 1, 0, DispMode.Format, D3DPOOL_MANAGED, D3DX_FILTER_LINEAR, D3DX_FILTER_LINEAR, 0, ByVal 0, ByVal 0)
201    
202     gCol_Geo_TexDiffuseTextures.Add txTempTexture
203    
204     Set txTempTexture = Nothing
205    
206    
207     ' Dim x As Dir
208     '
209     ' With x
210     '
211     ' .MatD3D.
212     '
213     ' End With
214    
215     ' D3DX.CreateMesh
216    
217     End Sub
218    
219     Public Sub OpenGeometryFromGEO2()
220    
221     Dim iBlockType As Integer
222     Dim iFileNo As Integer
223     Dim iSegsCount As Integer
224     Dim iSubBlockType As Integer
225    
226     Dim lCount As Long
227     Dim lDataSize As Long
228    
229     Dim strFileLine As String
230     Dim lpStrLineSegs() As String
231    
232     Dim lpLvVerticesListEmpty() As VERTEX
233     Dim lpLvVerticesList() As VERTEX
234    
235     Dim lpIIndicesList() As Integer
236     Dim lpIIndicesListEmpty() As Integer
237    
238     Dim IbIndexBuffer As Direct3DIndexBuffer8
239    
240     Dim VbVertexBuffer As Direct3DVertexBuffer8
241    
242     iFileNo = FreeFile
243    
244     Open App.Path + "\Scenes\geo1.geo" For Input As #iFileNo
245    
246     While Not EOF(iFileNo)
247    
248     Line Input #iFileNo, strFileLine
249    
250     strFileLine = Trim(strFileLine)
251    
252     If strFileLine <> "" Then
253    
254     lpStrLineSegs = Split(strFileLine, ",")
255    
256     iSegsCount = UBound(lpStrLineSegs) + 1
257    
258     If iSegsCount > 0 Then
259    
260     Select Case LCase(Trim(lpStrLineSegs(0)))
261    
262     Case ":cols" ' Start of a colour list
263    
264     iBlockType = 1
265     iSubBlockType = 0
266    
267     Case ":ip" ' Start of an indexed primitive object
268    
269     iBlockType = 2
270     iSubBlockType = 0
271    
272     Case "vd" ' after ":ip" - Vertex data following
273    
274     If iBlockType = 2 Then
275    
276     iSubBlockType = 1
277    
278     End If
279    
280     Case "id" ' after ":ip" - Index data following
281    
282     If iBlockType = 2 Then
283    
284     iSubBlockType = 2
285    
286     End If
287    
288     Case "/vd" ' after ":ip" - End of vertex data
289    
290     If iBlockType = 2 And iSubBlockType = 1 Then
291    
292     On Error Resume Next
293    
294     lCount = 0
295     lCount = UBound(lpLvVerticesList) + 1
296    
297     On Error GoTo 0
298    
299     lDataSize = Len(lpLvVerticesList(0)) * lCount
300    
301     Set VbVertexBuffer = D3DDevice.CreateVertexBuffer(lDataSize, 0, FVF_VERTEX, D3DPOOL_MANAGED)
302    
303     If VbVertexBuffer Is Nothing Then
304    
305     Debug.Print "Could not create vertex buffer! Maybe no adapter memory left."
306    
307     Else
308    
309     D3DVertexBuffer8SetData VbVertexBuffer, 0, lDataSize, 0, lpLvVerticesList(0)
310     gCol_Geo_VbVertexBuffers.Add VbVertexBuffer
311    
312     End If
313    
314     iSubBlockType = 0
315     lpLvVerticesList = lpLvVerticesListEmpty
316    
317     End If
318    
319     Case "/id" ' after ":ip" - End of index data
320    
321     If iBlockType = 2 And iSubBlockType = 2 Then
322    
323     On Error Resume Next
324    
325     lCount = 0
326     lCount = UBound(lpIIndicesList) + 1
327    
328     On Error GoTo 0
329    
330     lDataSize = Len(lpIIndicesList(0)) * lCount
331    
332     Set IbIndexBuffer = D3DDevice.CreateIndexBuffer(lDataSize, 0, D3DFMT_INDEX16, D3DPOOL_MANAGED)
333    
334     If IbIndexBuffer Is Nothing Then
335    
336     Debug.Print "Could not create index buffer! Maybe no adapter memory left."
337    
338     Else
339    
340     D3DIndexBuffer8SetData IbIndexBuffer, 0, lDataSize, 0, lpIIndicesList(0)
341     gCol_Geo_IbIndexBuffers.Add IbIndexBuffer
342    
343     End If
344    
345     iSubBlockType = 0
346     lpIIndicesList = lpIIndicesListEmpty
347    
348     End If
349    
350     Case Else
351    
352     Select Case iBlockType
353    
354     Case 1
355    
356     If iSegsCount = 1 Then
357    
358     gCol_Geo_lColours.Add lpStrLineSegs(0)
359    
360     End If
361    
362     Case 2
363    
364     Select Case iSubBlockType
365    
366     Case 1
367    
368     If iSegsCount = 7 Then
369    
370     On Error Resume Next
371    
372     lCount = 0
373     lCount = UBound(lpLvVerticesList) + 1
374    
375     On Error GoTo 0
376    
377     ReDim Preserve lpLvVerticesList(lCount) As VERTEX
378    
379     ' lpLvVerticesList(lCount) = CreateLitVertex(Val(lpStrLineSegs(0)), Val(lpStrLineSegs(1)), Val(lpStrLineSegs(2)), gCol_Geo_lColours(Val(lpStrLineSegs(3)) + 1), CLng(lpStrLineSegs(4)), Val(lpStrLineSegs(5)), Val(lpStrLineSegs(6)))
380     With lpLvVerticesList(lCount)
381    
382     .nx = 0
383     .ny = 1
384     .nz = 0
385     .x = Val(lpStrLineSegs(0))
386     .Y = Val(lpStrLineSegs(1))
387     .Z = Val(lpStrLineSegs(2))
388     .tU = Val(lpStrLineSegs(5))
389     .tV = Val(lpStrLineSegs(6))
390    
391     End With
392     '= CreateLitVertex(, gCol_Geo_lColours(Val(lpStrLineSegs(3)) + 1), CLng(lpStrLineSegs(4)), Val(lpStrLineSegs(5)), Val(lpStrLineSegs(6)))
393    
394     End If
395    
396     Case 2
397    
398     If iSegsCount = 3 Then
399    
400     On Error Resume Next
401    
402     lCount = 0
403     lCount = UBound(lpIIndicesList) + 1
404    
405     On Error GoTo 0
406    
407     ReDim Preserve lpIIndicesList(lCount + 2) As Integer
408    
409     lpIIndicesList(lCount) = CInt(lpStrLineSegs(0))
410     lpIIndicesList(lCount + 1) = CInt(lpStrLineSegs(1))
411     lpIIndicesList(lCount + 2) = CInt(lpStrLineSegs(2))
412    
413     End If
414    
415     End Select
416    
417     End Select
418    
419     End Select
420    
421     End If
422    
423     End If
424    
425     Wend
426    
427     Close #iFileNo
428     Dim txTempTexture As Direct3DTexture8
429    
430     Set txTempTexture = D3DX.CreateTextureFromFileEx(D3DDevice, App.Path & "\Scenes\tex1.jpg", 256, 256, 1, 0, DispMode.Format, D3DPOOL_MANAGED, D3DX_FILTER_LINEAR, D3DX_FILTER_LINEAR, 0, ByVal 0, ByVal 0)
431    
432     gCol_Geo_TexDiffuseTextures.Add txTempTexture
433    
434     Set txTempTexture = Nothing
435    
436     ' Dim x As Dir
437     '
438     ' With x
439     '
440     ' .MatD3D.
441     '
442     ' End With
443    
444     ' D3DX.CreateMesh
445    
446     End Sub
447    

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed