EcoRotate

This script for Vue Infinite and xStream allows all the objects / instances in an EcoSystem to point in a direction. It also allows a a bit of variation to be included in the rotation.

  1. #***********************************************************************
  2. # Set all instances in an EcoSystem to point in a given direction
  3. # - EcoRotate.py
  4. # -
  5. # - By Mark Caldwell
  6. # - Version 0.2
  7. # - 25th August 2007
  8. # - Checked with Vue 6.5 Infinite
  9. #
  10. # How to use in 4 easy steps
  11. # 1. Select an object with a populated EcoSystem
  12. #
  13. # 2. Run this script
  14. #
  15. # 3. Enter the values requested by the script
  16. #
  17. # 4. Wait for the script to work
  18. #
  19. #***********************************************************************
  20.  
  21. #----------------------------------------------------
  22. # Get Input and Test Value for value 0-360 for Angles
  23. #----------------------------------------------------
  24.  
  25. def TestValAngle (messagetxt,titletxt,default):
  26. hit=-2
  27. val=-1
  28.  
  29. while hit<0:
  30. try:
  31. if int(val) in range (0,360):
  32. hit=1;
  33. elif hit==-2:
  34. val=Prompt (messagetxt,default,true,titletxt)
  35. hit=-1
  36. else:
  37. val=Prompt ("Error: Value must be an integer between 0 and 360\n\n"+messagetxt,val,true,titletxt)
  38. except:
  39. hit=-1
  40. val=Prompt ("Error: Value must be an integer between 0 and 360\n\n"+messagetxt,val,true,titletxt)
  41.  
  42. return float(val)
  43.  
  44. #--------------------------------------------
  45. # Get Input and Test Value for valuse 0 or 1
  46. #--------------------------------------------
  47.  
  48. def TestValZO (messagetxt,titletxt,default):
  49. hit=-2
  50. val=-1
  51.  
  52. while hit<0:
  53. try:
  54. if int(val) in range (0,2):
  55. hit=1;
  56. elif hit==-2:
  57. val=Prompt (messagetxt,default,true,titletxt)
  58. hit=-1
  59. else:
  60. val=Prompt ("Error: Value must be either 0 or 1\n\n"+messagetxt,val,true,titletxt)
  61. except:
  62. hit=-1
  63. val=-3
  64.  
  65. return val
  66.  
  67. #--------------------------------------------
  68. # Start of Main Code
  69. #--------------------------------------------
  70.  
  71. import random
  72.  
  73. #--------------------------------------------------------------------------
  74. # Test the user has a scene loaded
  75. #--------------------------------------------------------------------------
  76.  
  77. if TestLoaded():
  78.  
  79. #--------------------------------------------------------------------------
  80. # Test the user has 1 object selected with an Eco System on it
  81. #--------------------------------------------------------------------------
  82.  
  83. numselected=CountSelectedObjects()
  84.  
  85. if numselected>1:
  86. message="Please select only one object."
  87. elif numselected<1:
  88. message="Please select an object."
  89. else:
  90.  
  91. #--------------------------------------------------------------------------
  92. # Get User values for rotation required, which to rotate and randomness
  93. #--------------------------------------------------------------------------
  94.  
  95. xon=TestValZO ('Rotate on X axis? (Enter 0 for yes and 1 for no)','Rotate on X?','0')
  96.  
  97. if xon=="1":
  98. rx=TestValAngle ('Rotate to X (0 to 360 degrees)','X Rotation','0')
  99. rxv=TestValAngle ('Variation of Rotation to X (0 to 360 degrees)','X Rotation Variation','0')
  100.  
  101. yon=TestValZO ('Rotate on Y axis? (Enter 0 for yes and 1 for no)','Rotate on Y?','0') # Rotate y (set to 1 to change 0 to leave alone)
  102.  
  103. if yon=="1":
  104. ry=TestValAngle ('Rotate to Y (0 to 360 degrees)','Y Rotation','0')
  105. ryv=TestValAngle ('Variation of Rotation to Y (0 to 360 degrees)','Y Rotation Variation','0')
  106.  
  107. zon=TestValZO ('Rotate on Z axis? (Enter 0 for yes and 1 for no)','Rotate on Z?','0') # Rotate z (set to 1 to change 0 to leave alone)
  108.  
  109. if zon=="1":
  110. rz=TestValAngle ('Rotate to Z (0 to 360 degrees)','Z Rotation','0')
  111. rzv=TestValAngle ('Variation of Rotation to Z (0 to 360 degrees)','Z Rotation Variation','0')
  112.  
  113. #--------------------------------------------------------------------------
  114. #Set Up a Few Variables
  115. #--------------------------------------------------------------------------
  116.  
  117. bObject=GetSelectedObjectByIndex(0) # Get first selected object
  118. Eco = GetEcosystemOnObject(bObject) # Get EcoSystem on first selected
  119.  
  120. objlist=[bObject]
  121.  
  122. if Eco==None:
  123. message="Please select an object with an EcoSystem material applied to it."
  124. elif bObject.IsLocked(): # Check object isn't locked
  125. message="Please select an object that isn't locked."
  126. else:
  127. ecocount=Eco.GetInstanceCount () # Count number of instances in EcoSystem
  128.  
  129. if ecocount==0:
  130. message="Please select an EcoSystem that has been populated."
  131. else:
  132.  
  133. #--------------------------------------------------------------------------
  134. # Rotate EcoObjects
  135. #--------------------------------------------------------------------------
  136.  
  137. for i in range(0,ecocount):
  138. currentrotation=Eco.GetInstanceRotation (i)
  139.  
  140. if xon!="1":
  141. rix=currentrotation[0]
  142. else:
  143. rix=rx+random.uniform(-rxv,rxv)
  144.  
  145. if yon!="1":
  146. riy=currentrotation[1]
  147. else:
  148. riy=ry+random.uniform(-ryv,ryv)
  149.  
  150. if zon!="1":
  151. riz=currentrotation[2]
  152. else:
  153. riz=rz+random.uniform(-rzv,rzv)
  154.  
  155. Eco.SetInstanceRotation(i,rix,riy,riz)
  156.  
  157. message="Eco Rotation Success"
  158. else:
  159. message="No Scene Loaded"
  160.  
  161. Message(message) # Display message
  162.  
  163. #--------------------------------------------------------------------------
  164. # End of Script
  165. #------------------------------------------------------------------------

impworks © Copyright Mark Caldwell 1996 - 2017