January 26, 2021, 05:22:43 AM

Author Topic: [bb] Model Viewer by bytecode77 [ 1+ years ago ]  (Read 439 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Model Viewer by bytecode77 [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : Model Viewer
Author : bytecode77
Posted : 1+ years ago

Description : This is my own model viewer to see models i downloaded or made.
compile it. make a link on the desctop and push models into it!

keys:
  - Ise mouse buttons and mouse axis to move
  - Use 'W' for wireframe look
  - Use Space to toggle freelook/view. To freelook use cursorkeys+mouse.


Code :
Code: BlitzBasic
  1. file$ = CommandLine()
  2. file$ = Replace(file$, Chr(34), "")
  3. file$ = Trim(file$)
  4. If file$ = "" RuntimeError "Failed to load Model " + Chr(34) + file$ + Chr(34) + "."
  5.  
  6. Graphics3D 1024, 768, 32, 2
  7. SetBuffer BackBuffer()
  8. AppTitle "Model View"
  9.  
  10. ;Camera
  11. Global Cam = CreateCamera()
  12. CameraRange Cam, .01, 1000
  13.  
  14. ;Light
  15. RotateEntity CreateLight(), 45, 45, 0
  16.  
  17. ;Model
  18. ms = MilliSecs()
  19. If Right(file$, 4) = ".md2" Then
  20.         Model = LoadMD2(file$)
  21.         ScaleEntity Model, .1, .1, .1
  22. Else
  23.         Model = LoadMesh(file$)
  24.         FitMesh Model, -1, -1, -1, 2, 2, 2, True
  25. EndIf
  26. PositionEntity Model, 0, 0, 3
  27. If Model = 0 RuntimeError "Failed to load Model " + Chr(34) + file$ + Chr(34) + "."
  28. ModelLoadTime = MilliSecs() - ms
  29.  
  30. cnt_surf = CountSurfaces(Model)
  31. For i = 1 To cnt_surf
  32.         cnt_vert = cnt_vert + CountVertices(GetSurface(Model, i))
  33.         cnt_tris = cnt_tris + CountTriangles(GetSurface(Model, i))
  34. Next
  35.  
  36. wire = False
  37. freelook = False
  38. While Not KeyHit(1)
  39.         If MouseDown(1) Then
  40.                 mys# = mys# - MouseYSpeed()
  41.                 mxs# = mxs# + MouseXSpeed()
  42.         EndIf
  43.         If MouseDown(2) Then mzs# = mzs# + MouseYSpeed() * .03
  44.         TurnEntity Model, mys#, mxs#, 0, True
  45.         TranslateEntity Model, 0, 0, mzs#
  46.         mxs# = mxs# * .65
  47.         mys# = mys# * .65
  48.         mzs# = mzs# * .65
  49.         If KeyHit(17) Then
  50.                 wire = 1 - wire
  51.                 WireFrame wire
  52.         EndIf
  53.         If KeyHit(57) Then
  54.                 freelook = 1 - freelook
  55.         EndIf
  56.         If freelook Then
  57.                 PositionEntity Model, 0, 0, 3
  58.                 RotateEntity Model, 0, 0, 0
  59.                 FreeLook(.003)
  60.         Else
  61.                 PositionEntity Cam, 0, 0, 0
  62.                 RotateEntity Cam, 0, 0, 0
  63.                 MouseXSpeed()
  64.                 MouseYSpeed()
  65.         EndIf
  66.         RenderWorld
  67.         xp = GraphicsWidth() / 2
  68.         Text 0, 0, "Surfaces: " + cnt_surf
  69.         Text 0, 20, "Vertices: " + cnt_vert
  70.         Text 0, 40, "Triangles: " + cnt_tris
  71.         Text 0, 60, "Load time: " + ModelLoadTime
  72.         Text xp, 0, "Press 'W' for wireframe mode.", True
  73.         Text xp, 20, "Press 'SPACE' for freelook mode.", True
  74.         Flip
  75. Wend
  76. End
  77.  
  78. Global CamXS#, CamZS#, CamRotXS#, CamRotYS#
  79. Function FreeLook(sp# = .1)
  80. If sp# > 0 Then
  81.         CamXS# = (CamXS# + ((KeyDown(32) Or KeyDown(205)) - (KeyDown(30) Or KeyDown(203))) * sp# * 2) * .75
  82.         CamZS# = (CamZS# + ((KeyDown(17) Or KeyDown(200)) - (KeyDown(31) Or KeyDown(208))) * sp# * 2) * .75
  83.         MoveEntity Cam, CamXS#, 0, CamZS#
  84. EndIf
  85. CamRotXS# = ((MouseXSpeed() - CamRotXS#) * .35 + CamRotXS#) * .75
  86. CamRotYS# = ((MouseYSpeed() - CamRotYS#) * .35 + CamRotYS#) * .75
  87. If EntityPitch(Cam) + CamRotYS# < -85 pitch# = -85 ElseIf EntityPitch(Cam) + CamRotYS# > 85 pitch# = 85 Else pitch# = EntityPitch(Cam) + CamRotYS#
  88. yaw# = -CamRotXS# + EntityYaw(Cam)
  89. RotateEntity Cam, pitch#, yaw#, 0
  90. MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2
  91. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal