Well, the first thing I'd do is check how many vertices there are.
rem open the file
open to read 1 , "vertices.txt"
rem count the vertices
vertCount = 0
repeat
rem read in the data but don't store
read string 1 , string$
read string 1 , string$
read string 1 , string$
read string 1 , string$
inc vertCount
until file end(1)
close file 1
Next check that the number of vertices is valid:
if vertCount%3 > 0
print "Incorrect number of vertices, we need 3 per face, but you have ";vertCount%3;" too many!"
print "Press any key to continue"
wait
endif
Now before we continue to create the mesh, we need to look at how we're going to structure the memblock. First thing to do is look at the FVF format:
#constant FVF_XYZ 0x002
#constant FVF_XYZRHW 0x004
#constant FVF_XYZB1 0x006
#constant FVF_XYZB2 0x008
#constant FVF_XYZB3 0x00a
#constant FVF_XYZB4 0x00c
#constant FVF_XYZB5 0x00e
#constant FVF_NORMAL 0x010
#constant FVF_PSIZE 0x020
#constant FVF_DIFFUSE 0x040
#constant FVF_SPECULAR 0x080
#constant FVF_TEX0 0x000
#constant FVF_TEX1 0x100
#constant FVF_TEX2 0x200
#constant FVF_TEX3 0x300
#constant FVF_TEX4 0x400
#constant FVF_TEX5 0x500
#constant FVF_TEX6 0x600
#constant FVF_TEX7 0x700
#constant FVF_TEX8 0x800
MyFVF as dword
MyFVF = FVF_XYZ || FVF_NORMAL || FVF_DIFFUSE || FVF_TEX1
We'll be using XYZ, normals, diffuse (because you have a colour value there), and texture. That should give you a value of 338. This will make each vertex use 36 bytes of data.
Great! Let's read in the data and create the mesh now.
rem determine some header data
FVF = 338
vertSize = 36
pos = 12
rem create the memblock
make memblock 1 , vertCount * vertSize + pos
rem write header data
write memblock dword 1 , 0 , FVF
write memblock dword 1 , 4 , vertSize
write memblock dword 1 , 8 , vertCount
rem open the file
open to read 1 , "vertices.txt"
rem read in data and convert
repeat
read string 1 , string$
x# = val( right$(string$,len(string$)-2) )
read string 1 , string$
y# = val( right$(string$,len(string$)-2) )
read string 1 , string$
z# = val( right$(string$,len(string$)-2) )
read string 1 , string$
color = val( right$(string$,len(string$)-2) )
rem write to memblock
write memblock float 1 , pos + 0 , x#
write memblock float 1 , pos + 4 , y#
write memblock float 1 , pos + 8 , z#
write memblock float 1 , pos + 12, 0
write memblock float 1 , pos + 16, 0
write memblock float 1 , pos + 20, 0
write memblock dword 1 , pos + 24, color
write memblock float 1 , pos + 28, 0
write memblock float 1 , pos + 32, 0
inc pos , vertSize
until file end(1)
close file 1
rem convert to object
make mesh from memblock 1 , 1
make object 1 , 1 , 0
delete mesh 1
delete memblock 1
rem recalculate normals
set object normals 1
wait key
end
TheComet