Random Walk

Select some objects, run this script and they wander around randomly in your scene.

  1. #******************************************************
  2. # Add a random walk animation to selected objects
  3. # - random_walk.py
  4. # - Give Selected Objects a simple random
  5. # animation
  6. # - By Mark Caldwell
  7. # - Version 0.1
  8. # - 30th April 2006
  9. # - Tested with Vue 5 Infinite 5.10 and Vue 6 Infinite Pre Release
  10. #
  11. # How to use in 4 easy steps
  12. #
  13. # 1. Download this file onto your computer
  14. #
  15. # 2. Edit the configuration variables below
  16. #
  17. # 3. Select Objects to be Replace in Vue Infinite
  18. #
  19. # 4. Then run script and wait for it to work
  20. # To run it go to Python -> Run Python Script
  21. # Then locate the file on your computer
  22. #
  23. #******************************************************
  24.  
  25. def RandomWalk (objprop,i,accxmin,accxmax,accymin,accymax,acczmin,acczmax):
  26. vx=random.uniform(accxmin,accxmax)
  27. vy=random.uniform(accymin,accymax)
  28. vz=random.uniform(acczmin,acczmax)
  29. vel=[vx,vy,vz]
  30. objprop=UpdateObj (objprop,i,vel)
  31. return objprop
  32.  
  33. def UpdateObj (objprop,i,vel):
  34. objprop[i][0]=objprop[i][0]+vel[0]
  35. objprop[i][1]=objprop[i][1]+vel[1]
  36. objprop[i][2]=objprop[i][2]+vel[2]
  37. return objprop
  38.  
  39. import random
  40.  
  41. #----------------------------------------------
  42. # Configuration: Set these to alter end result
  43. #----------------------------------------------
  44.  
  45. # Frames to generate
  46. start=0 # First frame of animation
  47. stop=101 # Last frame of animation if step divides into stop add 1 to get a frame on last step
  48. step=10 # Number of frames between key frames
  49.  
  50. # Starting Velocity of objects
  51. velsxmin=-1 # Starting Minimum Velocity in the x direction
  52. velsxmax=1 # Starting Maximum Velocity in the x direction
  53. velsymin=-1 # Starting Maximum Velocity in the y direction
  54. velsymax=1 # Starting Maximum Velocity in the y direction
  55. velszmin=-1 # Starting Maximum Velocity in the z direction
  56. velszmax=1 # Starting Maximum Velocity in the z direction
  57.  
  58. # Random Walk accelerations applied at a key frame
  59. accxmin=-20 # Minimum Acceleration the x direction
  60. accxmax=20 # Maximum Acceleration the x direction
  61. accymin=-20 # Minimum Acceleration the y direction
  62. accymax=20 # Maximum Acceleration the y direction
  63. acczmin=-20 # Minimum Acceleration the z direction
  64. acczmax=20 # Maximum Acceleration the z direction
  65.  
  66. #----------------------------------------------
  67. # Internal Variables Set Up: Don't alter these
  68. #----------------------------------------------
  69.  
  70. obj=[]
  71. objprop=[]
  72. ran = random.Random()
  73. countobj=CountSelectedObjects()
  74.  
  75. #----------------------------------------------
  76. # Find Selected Objects
  77. #----------------------------------------------
  78.  
  79. for i in range(0,countobj):
  80. object=GetSelectedObjectByIndex(i)
  81. obj.append(object)
  82. vx=random.uniform(velsxmin,velsxmax)
  83. vy=random.uniform(velsymin,velsymax)
  84. vz=random.uniform(velszmin,velszmax)
  85. v=[vx,vy,vz]
  86. objprop.append(v)
  87.  
  88. #----------------------------------------------
  89. # Add Plants
  90. #----------------------------------------------
  91.  
  92. for j in range(start+step,stop,step):
  93. SetCurrentFrame (j)
  94. for i in range(0,countobj):
  95. object=obj[i]
  96. objprop=RandomWalk (objprop,i,accxmin,accxmax,accymin,accymax,acczmin,acczmax)
  97. object.Move(objprop[i][0],objprop[i][1],objprop[i][2])

impworks © Copyright Mark Caldwell 1996 - 2017