Ooops
November 25, 2020, 07:26:14 AM

Author Topic: [bb] Jellyfish Animation by Mr Snidesmin [ 1+ years ago ]  (Read 541 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Jellyfish Animation by Mr Snidesmin [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Jellyfish Animation
Author : Mr Snidesmin
Posted : 1+ years ago

Description : My first ever 3d animation. . .  (just about sort of)

I would like to be able to display at least 20 of these at a time in a game with loads of other stuff going on, but I've no idea how to store the animation, replay etc quickly.

Someone help me please! :O)


Code :
Code: BlitzBasic
  1. Global JellyParam#
  2. Global WaveParam1#
  3. Global WaveParam2#
  4. Global WaveParam3#
  5.  
  6.  
  7. Local fps%
  8. Local fpscount%
  9. Local millistop%
  10. Local millis%
  11.  
  12.  
  13. Graphics3D 800, 600
  14.  
  15. ;create world:
  16. Global GlobalLight% = CreateLight()
  17. RotateEntity GlobalLight, 70, 45, 45
  18. Global GlobalCamera% = CreateCamera()
  19. LightColor GlobalLight, 255,255,255
  20. AmbientLight 100,120,255
  21. PositionEntity GlobalCamera, 4, 0, 0
  22. CameraClsColor GlobalCamera, 0,50,90
  23.  
  24. ;create jellyfish (mshJellyBase is just used to store original vert positions)
  25. Global mshJellyBase% = CreateMesh() ;LoadMesh("jelly.3ds")
  26. For n# = 0 To 1 Step 0.2
  27.         mshtmp = CreateSphere(8)
  28.         ScaleMesh mshtmp, 1/(1+10*n), 0.35, 1/(1+10*n)
  29.         PositionMesh mshtmp, 0, -n, 0
  30.         AddMesh mshtmp, mshJellyBase
  31.         FreeEntity mshtmp
  32. Next
  33. For a# = 0 To 350 Step 10
  34.         off# = -Rnd(0.3)
  35.         For n# = 0 To 0.5 Step 0.05
  36.                 mshtmp = CreateCylinder(2, False)
  37.                 ScaleMesh mshtmp, 0.003, 0.05, 0.003
  38.                 PositionMesh mshtmp, 0.8 * Cos(a), off-n, 0.8 * Sin(a)
  39.                 AddMesh mshtmp, mshJellyBase
  40.                 FreeEntity mshtmp
  41.         Next
  42. Next
  43. Global mshJelly% = CopyMesh(mshJellyBase)
  44. HideEntity mshJellyBase
  45. EntityAlpha mshJelly, 0.3
  46.  
  47. ;Begin main loop
  48. PointEntity GlobalCamera, mshJelly
  49. While Not KeyHit(1)
  50.         UpdateJelly
  51.         Navigate_World_With_MouseAndKeys(0.5, .1)
  52.        
  53.         UpdateWorld()
  54.        
  55.         SetBuffer BackBuffer()
  56.         RenderWorld()
  57.         Color 255, 0, 0
  58.         Text 1, 1, "FPS=" + fps
  59.         Text 1, 12, "TrisRendered=" + TrisRendered()
  60.         Flip
  61.        
  62.         fpscount = fpscount + 1
  63.         millis% = MilliSecs()
  64.         If millistop < millis - 1000 Then
  65.                 millistop = millis
  66.                 fps = fpscount
  67.                 fpscount = 0
  68.         End If
  69. Wend
  70. End
  71.  
  72.  
  73. ;deforms mesh:
  74. Function UpdateJelly()
  75.         spd# = 1.5 + 0.5 * Sin(JellyParam)
  76.         JellyParam = JellyParam + spd Mod 360
  77.         WaveParam1= WaveParam1+ 1.4 Mod 360
  78.         WaveParam2= WaveParam2+ 2.16 Mod 360
  79.         WaveParam3= WaveParam3+ 0.79 Mod 360
  80.        
  81.         s0% = GetSurface(mshJellyBase, 1)
  82.         s1% = GetSurface(mshJelly, 1)
  83.        
  84.         For iv% = 0 To CountVertices(s0)-1
  85.                 h1# = 590*(VertexY(s0, iv)+VertexX(s0, iv))
  86.                 h2# = 190*(VertexY(s0, iv)+VertexZ(s0, iv))
  87.                
  88.                 wz# = 0.08 * Cos(WaveParam1+h1) * Cos(WaveParam2+h1) * Cos(WaveParam3+h1) *VertexY(s0, iv)
  89.                 wx# = 0.08 * Sin(WaveParam1+h2) * Cos(WaveParam2+h2) * Cos(WaveParam3+h2) *VertexY(s0, iv)
  90.  
  91.  
  92.                 s# = Sqr(VertexX(s0, iv)^2 + VertexY(s0, iv)^2)
  93.                
  94.                 n# = 0.5 * Cos(JellyParam) / (Abs(VertexY(s0, iv))+0.3) + s
  95.                
  96.                 If VertexY(s0, iv) < 0 Then
  97.                         c# = 0.1 * Abs(VertexY(s0, iv)) ^ 2
  98.                 Else
  99.                         c = 0
  100.                 End If
  101.                
  102.                 n2# = 0.3 * (2.5+Sin(-JellyParam+140*VertexY(s0, iv))) / (Abs(VertexY(s0, iv))+1.3)
  103.                 VertexCoords s1, iv, VertexX(s0, iv) * (n2+c) + wx, VertexY(s0, iv) * (n+1.4)*0.4, VertexZ(s0, iv)* (n2+c) + wz
  104.         Next
  105.         UpdateNormals mshJelly
  106. End Function
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. Function Navigate_World_With_MouseAndKeys(turnSpeed#=1, moveSpeed#=1)
  114.         Local dY# = EntityPitch(GlobalCamera)+MouseYSpeed()/2*turnSpeed
  115.         If dY > 89 Then dY = 89
  116.         If dY < -89 Then dY = -89
  117.        
  118.         Local dz# = (KeyDown(200)-KeyDown(208)) * moveSpeed
  119.         Local dx# = (KeyDown(205)-KeyDown(203)) * moveSpeed
  120.         If dz <> 0 And dx <> 0 Then
  121.                 dx=dx * 0.707
  122.                 dz=dz * 0.707
  123.         End If
  124.         RotateEntity GlobalCamera, dY, EntityYaw(GlobalCamera)-(MouseXSpeed()/2)*turnSpeed, 0
  125.         MoveEntity GlobalCamera, dx, 0, dz
  126.         MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
  127.        
  128.         If KeyHit(4) Then
  129.                 CameraZoom GlobalCamera, 4.0
  130.         End If
  131.         If KeyHit(5) Then
  132.                 CameraZoom GlobalCamera, 1.0
  133.         End If
  134. End Function


Comments :


wizzlefish(Posted 1+ years ago)

 I get "illegal number of segments" error.


Gabriel(Posted 1+ years ago)

 So do I. It's this line
Code: [Select]
mshtmp = CreateCylinder(2, False)A cylinder can't possibly have 2 segments. 3 is the bare minimum.


BlitzSupport(Posted 1+ years ago)

 Once you correct that line (and move the mouse), it looks really good.


Mr Snidesmin(Posted 1+ years ago)

 That illegal number of segments error only appears in debug.With debug off, the error is not checked and you just get a flat 2 faced square, i.e. a 2 sided cylinder :O)I don't know why debug doesn't allow this cos there's nothing wrong with it. . .


Gabriel(Posted 1+ years ago)

 <div class="quote"> I don't know why debug doesn't allow this cos there's nothing wrong with it. . .  </div>Well there is. A cylinder is :<div class="quote"> The surface generated by a straight line intersecting and moving along a closed plane curve, the directrix, while remaining parallel to a fixed straight line that is not on or parallel to the plane of the directrix. </div>You have no closed plane curve, because your cylinder exists in only 2 dimensions. A cylinder is a 3 dimensional shape.But yeah, nice effect.As for your plea for help. Best thing I can suggest is to write ( or find ) an MD2 exporter. Export it from Blitz in code and then you can use quite a few of them without too much of a speed hit. Anything else is going to be slow because all B3D vertex operations are really slow.


wizzlefish(Posted 1+ years ago)

 I like the effect.


Blitzplotter(Posted 1+ years ago)

 Tried it, modified the cylinder and was quite impressed....


Mr. Bean(Posted 1+ years ago)

 I like the effect, too.


sonokong(Posted 1+ years ago)

 Huh...the jellyfish is quite fun. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal