Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] Diff of /trunk/sml3d/examples/md3-viewer/load-md3.sml
ViewVC logotype

Diff of /trunk/sml3d/examples/md3-viewer/load-md3.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 392, Wed Jan 14 04:33:48 2009 UTC revision 394, Wed Jan 14 05:25:18 2009 UTC
# Line 96  Line 96 
96              ({x=x, y=y, z=z}, pos)              ({x=x, y=y, z=z}, pos)
97            end            end
98    
99  (*+DEBUG*)  (*+DEBUG
100  val t2s = SML3dTypeUtil.fmt3 Float.toString  val t2s = SML3dTypeUtil.fmt3 Float.toString
101  val v2s = SML3dTypeUtil.fmtv3 Float.toString  val v2s = SML3dTypeUtil.fmtv3 Float.toString
102  (*-DEBUG*)  -DEBUG*)
103    
104    (* read the MD3 header *)    (* read the MD3 header *)
105      fun readHdr inS = let      fun readHdr inS = let
# Line 137  Line 137 
137            val (localOrigin, pos) = getVec3 (data, pos)            val (localOrigin, pos) = getVec3 (data, pos)
138            val (radius, pos) = getF32 (data, pos)            val (radius, pos) = getF32 (data, pos)
139            val (name, pos) = getString (data, pos, 16)            val (name, pos) = getString (data, pos, 16)
140    (*+DEBUG
141  val _ = print(concat[  val _ = print(concat[
142          "frame: name = \"", name, "\"; bbox = (", v2s minBounds, ", ", v2s maxBounds, ")\n",          "frame: name = \"", name, "\"; bbox = (", v2s minBounds, ", ", v2s maxBounds, ")\n",
143          "       origin = ", v2s localOrigin, "\n"          "       origin = ", v2s localOrigin, "\n"
144        ])        ])
145    -DEBUG*)
146            in MD3.FRAME{            in MD3.FRAME{
147              name = name,              name = name,
148              minBounds = minBounds,              minBounds = minBounds,
# Line 156  Line 158 
158            val (xAxis, pos) = getVec3 (data, pos)            val (xAxis, pos) = getVec3 (data, pos)
159            val (yAxis, pos) = getVec3 (data, pos)            val (yAxis, pos) = getVec3 (data, pos)
160            val (zAxis, pos) = getVec3 (data, pos)            val (zAxis, pos) = getVec3 (data, pos)
161  val _ = print(concat["tag: name = \"", name, "\"\n"])  (*+DEBUG
162    val _ = print(concat["tag: name = \"", name, "\" at ", v2s origin, "\n"])
163    -DEBUG*)
164            in MD3.TAG{            in MD3.TAG{
165              name = name,              name = name,
166              frame = {              frame = {
# Line 201  Line 205 
205            val data = readData (inS, 68)            val data = readData (inS, 68)
206            val (name, pos) = getString (data, 0, 64)            val (name, pos) = getString (data, 0, 64)
207            val (shader, pos) = getS32 (data, pos)            val (shader, pos) = getS32 (data, pos)
208    (*+DEBUG
209  val _ = print(concat["shader: name = \"", name, "\"\n"])  val _ = print(concat["shader: name = \"", name, "\"\n"])
210            in            in
211              MD3.SHADER{name = name, index = shader}              MD3.SHADER{name = name, index = shader}
212            end            end
213    -DEBUG*)
214    
215    (* read the vertex indices of a triangle *)    (* read the vertex indices of a triangle *)
216      fun readTriangle inS = let      fun readTriangle inS = let
# Line 262  Line 268 
268            val {name = name, numFrames, numShaders, numVerts, numTris,            val {name = name, numFrames, numShaders, numVerts, numTris,
269                    trisOffset, shadersOffset, stsOffset, vertsOffset, endOffset                    trisOffset, shadersOffset, stsOffset, vertsOffset, endOffset
270                  } = readSurfaceHdr inS                  } = readSurfaceHdr inS
271    (*+DEBUG
272  val _ = print(concat["surface: name = \"", name, "\", #frames = ",  val _ = print(concat["surface: name = \"", name, "\", #frames = ",
273  Int.toString numFrames, ", #shaders = ", Int.toString numShaders,  Int.toString numFrames, ", #shaders = ", Int.toString numShaders,
274  ", numVerts = ", Int.toString numVerts, ", #numTris = ", Int.toString numTris, "\n"  ", numVerts = ", Int.toString numVerts, ", #numTris = ", Int.toString numTris, "\n"
275  ])  ])
276    -DEBUG*)
277            val () = seek (inS, start + shadersOffset)            val () = seek (inS, start + shadersOffset)
278            val shaders = readN readShader (inS, numShaders)            val shaders = readN readShader (inS, numShaders)
279            val () = seek (inS, start + trisOffset)            val () = seek (inS, start + trisOffset)
# Line 275  Line 283 
283                        val (v1, v2, v3) = readTriangle inS                        val (v1, v2, v3) = readTriangle inS
284                        val i = 3*i                        val i = 3*i
285                        in                        in
286  (*  (*+DEBUG
287  print(concat["T[", StringCvt.padLeft #" " 3 (Int.toString i), "] = (",  print(concat["T[", StringCvt.padLeft #" " 3 (Int.toString i), "] = (",
288  Word.fmt StringCvt.DEC v1, ", ",  Word.fmt StringCvt.DEC v1, ", ",
289  Word.fmt StringCvt.DEC v2, ", ",  Word.fmt StringCvt.DEC v2, ", ",
290  Word.fmt StringCvt.DEC v3, ")\n"]);  Word.fmt StringCvt.DEC v3, ")\n"]);
291  *)  -DEBUG*)
292                          DB.setui(buf, i, v1);                          DB.setui(buf, i, v1);
293                          DB.setui(buf, i+1, v2);                          DB.setui(buf, i+1, v2);
294                          DB.setui(buf, i+2, v3)                          DB.setui(buf, i+2, v3)
# Line 306  Line 314 
314                        fun read i = let                        fun read i = let
315                              val (v, n) = readVertex inS                              val (v, n) = readVertex inS
316                              in                              in
317  (*  (*+DEBUG
318  print(concat["V[", StringCvt.padLeft #" " 3 (Int.toString i), "] v = ",  print(concat["V[", StringCvt.padLeft #" " 3 (Int.toString i), "] v = ",
319  t2s v, ", n = ", t2s n, "\n"]);  t2s v, ", n = ", t2s n, "\n"]);
320  *)  *)
# Line 336  Line 344 
344            val {name, numFrames, numTags, numSurfaces,            val {name, numFrames, numTags, numSurfaces,
345                    framesOffset, tagsOffset, surfsOffset                    framesOffset, tagsOffset, surfsOffset
346                  } = readHdr inS                  } = readHdr inS
347    (*+DEBUG
348  val () = print(concat["HDR: name = \"", name, "\", #frames = ",  val () = print(concat["HDR: name = \"", name, "\", #frames = ",
349  Int.toString numFrames, ", #tags = ", Int.toString numTags,  Int.toString numFrames, ", #tags = ", Int.toString numTags,
350  ", #surfaces = ", Int.toString numSurfaces, "\n"  ", #surfaces = ", Int.toString numSurfaces, "\n"
351  ])  ])
352    -DEBUG*)
353            val () = seek (inS, framesOffset)            val () = seek (inS, framesOffset)
354            val frames = readN readFrame (inS, numFrames)            val frames = readN readFrame (inS, numFrames)
355            val () = seek (inS, tagsOffset)            val () = seek (inS, tagsOffset)
356            val tags = readN readTag (inS, numTags)            val tags = readN (fn inS => readN readTag (inS, numTags)) (inS, numFrames)
357            val () = seek (inS, surfsOffset)            val () = seek (inS, surfsOffset)
358            val surfs = readN readSurface (inS, numSurfaces)            val surfs = readN readSurface (inS, numSurfaces)
359            in            in

Legend:
Removed from v.392  
changed lines
  Added in v.394

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0