mediaview.bb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ;Blitz media viewer.
  2. ;
  3. ;Create executable in 'bin'
  4. AppTitle CommandLine$()
  5. fil$=Lower$( CommandLine$() )
  6. index=Instr( fil$,"." )
  7. If index>0 ext$=Mid$( fil$,index+1 )
  8. Select ext$
  9. Case "x","3ds"
  10. ShowModel( fil$,False )
  11. Case "md2"
  12. ShowModel( fil$,True )
  13. Case "bmp","jpg","png","pcx","tga","iff"
  14. ShowImage( fil$ )
  15. Case "wav"
  16. ShowSound( fil$ )
  17. Case "mp3","mid","mod","x3m","xm","it"
  18. ShowMusic( fil$ )
  19. Default
  20. RuntimeError "Unknown File Extension"
  21. End Select
  22. End
  23. Function ShowModel( fil$,md2 )
  24. If Windowed3D()
  25. Graphics3D 400,300,0,2
  26. Else
  27. Graphics3D 640,480,0,1
  28. EndIf
  29. If md2
  30. model=LoadMD2( fil$ )
  31. If model ScaleEntity model,.025,.025,.025
  32. Else
  33. model=LoadMesh( fil$ )
  34. If model FitMesh model,-1,-1,-1,2,2,2,True
  35. EndIf
  36. If model=0 RuntimeError "Unable to load 3D mesh:"+fil$
  37. sc=CountSurfaces(model)
  38. For k=1 To sc
  39. vc=vc+CountVertices( GetSurface( model,k ) )
  40. tc=tc+CountTriangles( GetSurface( model,k ) )
  41. Next
  42. camera=CreateCamera()
  43. CameraClsColor camera,0,0,64
  44. CameraRange camera,.01,10
  45. xr#=0:yr#=0:z#=2.1
  46. light=CreateLight()
  47. TurnEntity light,45,45,0
  48. Repeat
  49. RotateEntity model,xr,yr,0
  50. PositionEntity model,0,0,z
  51. UpdateWorld
  52. RenderWorld
  53. Text 0,0,"Triangles:"+tc+" Vertices:"+vc+" Surfaces:"+sc
  54. Flip
  55. key=False
  56. Repeat
  57. If KeyHit(1) End
  58. If KeyDown(200) xr=xr-3:key=True
  59. If KeyDown(208) xr=xr+3:key=True
  60. If KeyDown(203) yr=yr+3:key=True
  61. If KeyDown(205) yr=yr-3:key=True
  62. If KeyDown( 30) z=z-.1:key=True
  63. If KeyDown( 44) z=z+.1:key=True
  64. If Not key WaitKey
  65. Until key
  66. Forever
  67. End Function
  68. Function ShowImage( fil$ )
  69. Graphics 400,300,0,2
  70. SetBuffer BackBuffer()
  71. image=LoadImage( fil$ )
  72. If image=0 RuntimeError "Unable to load image:"+fil$
  73. MidHandle image
  74. x=200:y=150:t=4
  75. Repeat
  76. Cls
  77. DrawImage image,x,y
  78. Flip
  79. key=False
  80. Repeat
  81. If KeyHit(1) End
  82. If KeyDown(200) y=y-t:key=True
  83. If KeyDown(208) y=y+t:key=True
  84. If KeyDown(203) x=x-t:key=True
  85. If KeyDown(205) x=x+t:key=True
  86. If Not key WaitKey
  87. Until key
  88. Forever
  89. End Function
  90. Function ShowSound( fil$ )
  91. sound=LoadSound( fil$ )
  92. If sound=0 RuntimeError "Unable to load sound:"+fil$
  93. Repeat
  94. PlaySound sound
  95. WaitKey
  96. If KeyHit(1) End
  97. Forever
  98. End Function
  99. Function ShowMusic( fil$ )
  100. music=PlayMusic( fil$ )
  101. If music=0 RuntimeError "Unable to play music: "+fil$
  102. WaitKey
  103. End Function