meshfx.bb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ;========================
  2. ;Mesh deformation effects
  3. ;========================
  4. ;by Joshua 'H A L O' Klint
  5. ;[email protected]
  6. Include "../start.bb"
  7. Global offset#
  8. camera=CreateCamera()
  9. CameraRange camera,1,1000
  10. PositionEntity camera,0,0,-20
  11. mesh=LoadMesh("test.3ds")
  12. mesh2=LoadMesh("test.3ds")
  13. t=LoadTexture("skin.bmp")
  14. EntityTexture mesh,t
  15. FreeTexture t
  16. ScaleEntity mesh,0.1,0.1,0.1
  17. HideEntity mesh2
  18. RotateEntity mesh2,0,90,45
  19. l=CreateLight()
  20. PositionEntity l,5,5,-5
  21. depth#=3
  22. speed#=0.1
  23. effect=3
  24. While Not KeyDown(1)
  25. If KeyDown(203) TurnEntity mesh,0,4,0
  26. If KeyDown(205) TurnEntity mesh,0,-4,0
  27. If KeyDown(200) TurnEntity mesh,4,0,0
  28. If KeyDown(208) TurnEntity mesh,-4,0,0
  29. If KeyDown(2) Then effect=2
  30. If KeyDown(3) Then effect=3
  31. If effect=2 Then Breath(mesh,mesh2,(Sin(MilliSecs()*speed)*depth)+(depth))
  32. If effect=3 Then ripple(mesh,mesh2,depth,speed)
  33. UpdateWorld
  34. RenderWorld
  35. Text 0,0,"Press 1 for 'breathe' effect."
  36. Text 0,20,"Press 2 for 'egg tube' effect."
  37. Flip
  38. Wend
  39. End
  40. ;============================
  41. Function Breath(mesh,omesh,am#)
  42. For k=1 To CountSurfaces(mesh)
  43. surf=GetSurface(mesh,k)
  44. surf2=GetSurface(omesh,k)
  45. For index=0 To CountVertices(surf)-1
  46. newx#=VertexX(surf2,index)+VertexNX(surf2,index)*am
  47. newy#=VertexY(surf2,index)+VertexNY(surf2,index)*am
  48. newz#=VertexZ(surf2,index)+VertexNZ(surf2,index)*am
  49. VertexCoords surf,index,newx,newy,newz
  50. Next
  51. Next
  52. End Function
  53. ;==========================
  54. Function ripple(mesh,omesh,depth#,speed#)
  55. For k=1 To CountSurfaces(mesh)
  56. surf=GetSurface(mesh,k)
  57. surf2=GetSurface(omesh,k)
  58. For index=0 To CountVertices(surf)-1
  59. i=i+1
  60. add#=0
  61. If wrapvalue#((MilliSecs()*speed)+i,0,720)>630 Or wrapvalue#((MilliSecs()*speed)+i,0,720)<270
  62. add#=(Sin(MilliSecs()*speed+(i))*depth)
  63. newx#=add*VertexNX(surf,index)+VertexX(surf2,index)
  64. newy#=add*VertexNY(surf,index)+VertexY(surf2,index)
  65. newz#=add*VertexNZ(surf,index)+VertexZ(surf2,index)
  66. Else
  67. add=depth/-1
  68. newx#=add*VertexNX(surf,index)+VertexX(surf2,index)
  69. newy#=add*VertexNY(surf,index)+VertexY(surf2,index)
  70. newz#=add*VertexNZ(surf,index)+VertexZ(surf2,index)
  71. EndIf
  72. VertexCoords surf,index,newx,newy,newz
  73. Next
  74. Next
  75. End Function
  76. ;====================
  77. Function wrapvalue#(value#,lo#,hi#)
  78. i=Floor(value/(hi-lo))
  79. r#=i*(hi-lo)
  80. Return (value-r)+lo
  81. End Function
  82. ;====================
  83. Function curvevalue#( newvalue#,oldvalue#,increments# )
  84. If increments>1 Then oldvalue#=oldvalue#-(oldvalue#-newvalue#)/increments
  85. If increments<=1 Then oldvalue=newvalue
  86. Return oldvalue#
  87. End Function