md2 size

Blitz3D Forums/Blitz3D Programming/md2 size

D4NM4N(Posted 2006) [#1]
is there a way of obtaining the W,D,H of a md2


b32(Posted 2006) [#2]
In Blitz3D, AFAIK there is no way. However, maybe you could try and use a 3d modeller to find out the width/height/depth of the model.


Dreamora(Posted 2006) [#3]
Yes I would do either this and then save it into a file and do a "MD2Type" or something where you save this information.

Or you do what others did with BSP for example: hack the information out of the file (because somewhere it must be otherwise the cull wouldn't work)


Doggie(Posted 2006) [#4]
Just specify it in the first place....with scaleentity.
Scale it with variables then track those variables.
Maybe that's oversimplifying things. What do I know?


Dreamora(Posted 2006) [#5]
That makes no sense unless the original model has a size of 1,1,1 when loading


Rroff(Posted 2006) [#6]
Can you not just loop through all the vertices in the loaded model and get the max value for each axis from the model origin?


Doggie(Posted 2006) [#7]
No. It makes perfect sense if you know what effect the scaling has on your model. Simple trial and error. But I don't know what the OP is trying to accomplish so I'll leave it at that.


jfk EO-11110(Posted 2006) [#8]
Rrof : you cannot access the vertices of an md2. Doggie is right, you need to multiply the scaleentity size * the original size.

Since MD2 supports collision, (if I recall right), there is a third, quick'n'dirty way to determine it's absolute size in space:

use a simple cube that moves towards the md2 and checks for collision. do this from all 6 directions, this will tell you the true size. Practically you'd pack this into a handy function that will create and remove the cube mesh etc.

For extra high accuracy you may use a binary search of the points of collision. This will take you only 32 steps to get the point with about 0.0005 units accuracy.


BIG BUG(Posted 2006) [#9]
Here is a coding for loading MD2.
I used it to test my exporter for C4D, so it's quick and dirty.


Const c_model$ = "gargoyle.md2"
Const C_DIV# = 1.0


Dim mesh(255)
Dim surface(255)
Dim texU#(4047)
Dim texV#(4047)

Dim CheckTriangle(1023)


Graphics3D 640,480,32,2
SetBuffer BackBuffer()
camera=CreateCamera()
CameraClsColor camera, 128,128,128

light=CreateLight()
PositionEntity camera,0,30,-80



brush=CreateBrush(255,255,255)


CameraRange camera, 1, 1000




datei = ReadFile(c_model$)
If Not datei RuntimeError "Datei nicht gefunden" 


       Print int2text$(ReadInt(datei))  ;identifier
       Print ReadInt(datei)             ;version
skinwidth  = ReadInt(datei)            ;SkinWidth
skinheight = ReadInt(datei)            ;SkinHeight
 FrameSize = ReadInt(datei)            ;FrameSize
 numSkins  = ReadInt(datei)            ;numSkins 
 numVertex = ReadInt(datei)            ;numVertices
 numTexCoords = ReadInt(datei)            ;numTexCoords
 numTriangle = ReadInt(datei)            ;numTriangles
 numGl       = ReadInt(datei)            ;numGlCommands
 numFrames = ReadInt(datei)            ;numFrames 
 offSkins  = ReadInt(datei)            ;offsetSkins
 offTexCoords = ReadInt(datei)            ;offsetTexCoords
 offTriangle = ReadInt(datei)            ;offsetTriangles
 offFrames = ReadInt(datei)            ;offsetFrames
 offGl     = ReadInt(datei)            ;offsetGlCommands
       Print ReadInt(datei)            ;offsetEnd    

 Print offFrames

 Print numTexCoords
 Print numVertex


;  read frames 

   SeekFile(datei, offFrames)

   For Frame = 1 To numFrames

      mesh(Frame)=CreateMesh()
      surface(Frame)=CreateSurface(mesh(Frame),brush)

      scalez# = ReadFloat#(datei)            ;scalez 
      scalex# = ReadFloat#(datei)            ;scalex    
      scaley# = ReadFloat#(datei)            ;scaley  
 
      posz# = ReadFloat#(datei)            ;posz 
      posx# = ReadFloat#(datei)            ;posx  
      posy# = ReadFloat#(datei)            ;poxy 


      Print int2text$(ReadInt(datei))   ;tex1
      Print int2text$(ReadInt(datei))   ;tex2
      Print int2text$(ReadInt(datei))   ;tex3
      Print int2text$(ReadInt(datei))   ;tex4

;     read vertices
      For Vertex = 1 To numVertex
         z# = (ReadByte(datei) * scalez# + posz#) / C_DIV#  ;z
         x# = (ReadByte(datei) * scalex# + posx#) / C_DIV#  ;x
         y# = (ReadByte(datei) * scaley# + posy#) / C_DIV#  ;y

         light = ReadByte(datei)
         v0 = AddVertex(surface(Frame),x#,y#,z#)

      Next


   Next


;  read UV
   SeekFile(datei, offTexCoords)

   For uv_coord = 0 To numTexCoords-1
       
       texU#(uv_coord) = ReadShort(datei) / Float(skinwidth)    ;U     
       texV#(uv_coord) = ReadShort(datei) / Float(skinheight)   ;V

   Next 
   
;  read triangles and build surface
   SeekFile(datei, offTriangle)

   For tri = 1 To numTriangle

       v0 = ReadShort(datei) ;vertex-index 1
       v1 = ReadShort(datei) ;vertex-index 2
       v2 = ReadShort(datei) ;vertex-index 3

       t0 = ReadShort(datei) ;UV-Index 1
       t1 = ReadShort(datei) ;UV-Index 2
       t2 = ReadShort(datei) ;UV-Index 3

       For Frame = 1 To numFrames

           AddTriangle(surface(Frame),v1,v0,v2)

           VertexTexCoords surface(Frame), v0, texU#(t0), texV#(t0)
           VertexTexCoords surface(Frame), v1, texU#(t1), texV#(t1)
           VertexTexCoords surface(Frame), v2, texU#(t2), texV#(t2)

       Next


   Next


;  GL lesen
   SeekFile(datei, offGl)

   For gl_group = 1 To numGl

       num_UV = Abs(ReadInt(Datei))


       For gl_uv = 1 To num_UV

          coord_U#  = ReadFloat(Datei)
          coord_V#  = ReadFloat(Datei)
          index_tri = ReadInt(Datei)

          For Frame = 1 To numFrames
 
;              VertexTexCoords surface(Frame), index_tri, coord_U#, coord_V# 
   
          Next    
 
       Next

   Next 

;  Skins lesen
   SeekFile datei, offSkins
   Print "------"
   For skin = 1 To numSkins

       For i = 1 To 16
          Print int2text$(ReadInt(datei))   ;tex1
       Next
       Print "------"
   Next

   Print SkinWidth

   CloseFile(datei)

Print "FrameSize:" + FrameSize
Print "NumFrames:" + numFrames

   For Frame = 1 To numFrames
        UpdateNormals mesh(Frame)
   Next

;  load model with b3d-loader for easy comparison
   mesh(0) = LoadMD2(c_model)
   If tex <> 0 Then EntityTexture mesh(0), tex

Print "Hit Enter to continue"

WaitKey()

WireFrame 0

auswahl = 1

AnimateMD2 mesh(0),2,2;,1,0,10


While Not KeyHit(1)


   For Frame = 0 To numFrames
       HideEntity mesh(Frame)
   Next

   ShowEntity mesh(auswahl)
   RotateEntity mesh(auswahl),hpitch#,hyaw#,hroll#

   TurnEntity mesh(auswahl),KeyDown(203)-KeyDown(205),KeyDown(200)-KeyDown(208),KeyDown(44)-KeyDown(45)

   hpitch# = EntityPitch(mesh(auswahl)) 
   hyaw#   = EntityYaw(mesh(auswahl))
   hroll#  = EntityRoll(mesh(auswahl)) 

   If KeyHit(201) Then auswahl = auswahl - 1
   If KeyHit(209) Then auswahl = auswahl + 1

   If auswahl < 0         Then auswahl = numFrames
   If auswahl > numFrames Then auswahl = 0

   MoveEntity camera, 0,0,KeyDown(78)-KeyDown(74)


UpdateWorld
RenderWorld

Text 5, 5, "Use Page Up/Down to switch between animation frames"
Text 5, 20, auswahl
Flip 1
Wend
End



Function int2text$(I)

   Local txt$
   Local l

   For l = 0 To 3

      txt$ = txt$ + Chr$((i Shr l*8) And $FF) 

   Next
   Return txt$
 
End Function



D4NM4N(Posted 2006) [#10]
Hmm,

Ill find a way, thanks for the code ill take a look at that later. And for everones help & ideas.

Unfortunately the package idea is not an option as its a package im writing.