Terrain Matcher

Have you ever wanted a plateau on your Vue terrain that a building can stand on? Maybe you want to cut a flat road through a scene? This python script, for Vue 6 Infinite and Vue 6 xStream, makes doing both of these tasks easier. How to match your terrain to an object in seven easy steps:

  1. Download this file onto your computer.
  2. Create a terrain. You can scale it but avoid rotating it.
  3. Place objects above the terrain that you want to affect the terrain. Don’t put them too close to the top of the terrain or it may be missed.
  4. Select the terrain to be modified.
  5. Then run script. To run it go to Python -> Run Python Script Then locate the file on your computer.
  6. Answer the questions that appear in the pop ups.
  7. Let it run till it pops up to say it’s finished.
  1. #******************************************************
  2. # Mold a terrain to objects placed above it
  3. #
  4. # - terrainmatcher.py
  5. # - By Mark Caldwell
  6. # - Version 0.1
  7. # - 10th April 2007
  8. # - Tested with Vue 6 Infinite
  9. #
  10. # How to use in 6 easy steps
  11. #
  12. # 1. Download this file onto your computer
  13. #
  14. # 2. Create a terrain (at this stage you can scale it
  15. # but avoid rotating it)
  16. #
  17. # 3. Place objects above the terrain that you want to
  18. # affect the terrain (don't put them too close to
  19. # the top of the terrain)
  20. #
  21. # 4. Select the terrain to be modified
  22. #
  23. # 5. Then run script
  24. # To run it go to Python -> Run Python Script
  25. # Then locate the file on your computer
  26. #
  27. # 6. Answer the questions that appear in the pop ups
  28. # then let it run till it pops up to say it's
  29. # finished
  30. #
  31. #******************************************************
  32.  
  33. import copy
  34.  
  35. #----------------------------------------------
  36. # Configuration
  37. #----------------------------------------------
  38.  
  39. spread=Prompt('How far should the match spread beyond the match to objects?','2',true,'Input Spread')
  40.  
  41. if int(spread)<0:
  42. spread=0
  43. else:
  44. spread=int(spread)
  45.  
  46. setheight=Prompt('What altitude should the top be set to on a scale of 1 to 100 with 100 at the top and 1 at the bottom of the terrain? (enter 0 to not affect matches altitude)',
  47. '100',true,'Input Top Altitude')
  48.  
  49. if float(setheight)==0:
  50. setheight=-1
  51. elif float(setheight)>100:
  52. setheight=0.99
  53. else:
  54. setheight=(float(setheight)-1)/100
  55.  
  56. setdepth=Prompt('What altitude should the areas not under the object be set to on a scale of 1 to 100 with 100 at the top and 1 at the bottom of the terrain? (enter 0 to not affect unmatched altitude)',
  57. '0',true,'Input Bottom Altitude')
  58.  
  59. if float(setdepth)==0:
  60. setdepth=-1
  61. elif float(setdepth)>100:
  62. setdepth=0.99
  63. else:
  64. setdepth=(float(setdepth)-1)/100
  65.  
  66. #setheight=0.2
  67. #setdepth=-1
  68.  
  69. #--------------------------------------------------------------------------
  70. # Test the user has a scene loaded
  71. #--------------------------------------------------------------------------
  72.  
  73. if TestLoaded():
  74.  
  75. #--------------------------------------------------------------------------
  76. # Test the user has 1 object and that it is a terrain
  77. #--------------------------------------------------------------------------
  78.  
  79. numselected=CountSelectedObjects()
  80.  
  81. if numselected>1:
  82. message="Please select only one object."
  83. elif numselected<1:
  84. message="Please select an object."
  85. else:
  86. bObject=GetSelectedObjectByIndex(0) # Get first selected object
  87.  
  88. if bObject.IsTerrain()==False:
  89. message="Please select a terrain."
  90. elif bObject.IsLocked(): # Check object isn't locked
  91. message="Please select an object that isn't locked."
  92. else:
  93.  
  94. #--------------------------------------------------------------------------
  95. # Apply terrain data to terrain
  96. #--------------------------------------------------------------------------
  97.  
  98. pos=bObject.Position()
  99. scal=bObject.GetScale()
  100.  
  101. altitudes=[]
  102.  
  103. TerrainObj=bObject.ToTerrain()
  104.  
  105. height= TerrainObj.Height() # Get Terrain Objects Height
  106. width= TerrainObj.Width() # Get Terrain Objects Width
  107.  
  108. factorheight=height
  109. factorwidth=width
  110.  
  111. stepdistancewidth=(factorheight*scal[0])/(width-1)
  112. stepdistanceheight=(factorwidth*scal[1])/(height-1)
  113.  
  114. altitudes=TerrainObj.TerrainAltitudes ()
  115. altitudes_new=[[0]*width for i in range(height)]
  116. xplus=pos[0]-((factorheight/2)*scal[0])
  117. yplus=pos[1]-((factorwidth/2)*scal[1])
  118.  
  119. altitudes=TerrainObj.TerrainAltitudes ()
  120.  
  121. for i in range (0,height):
  122. for j in range (0,width):
  123. x=(i*stepdistancewidth)+xplus
  124. y=(j*stepdistanceheight)+yplus
  125. z=pos[2]+(altitudes[j][i]*scal[2]*100)+(20*scal[2])
  126.  
  127. start=x,y,z
  128. vector=0,0,1
  129.  
  130. hitobj=GetFirstHitObject(start,vector)
  131. if hitobj:
  132. altitudes_new[j][i]=1
  133. else:
  134. altitudes_new[j][i]=0
  135.  
  136. if spread>0:
  137. altitudes_temp=[[0]*width for i in range(height)]
  138. for i in range (0,height):
  139. for j in range (0,width):
  140. if altitudes_new[j][i]==1:
  141. for k in range ((i-spread),(i+spread)):
  142. for l in range ((j-spread),(j+spread)):
  143. if k>=0 and k<height and l>=0 and l<width:
  144. altitudes_temp[l][k]=1
  145.  
  146. altitudes_new=copy.deepcopy(altitudes_temp)
  147.  
  148. altitudes_temp=[[0]*width for i in range(height)]
  149.  
  150. for i in range (0,height):
  151. for j in range (0,width):
  152. if setheight>=0 and altitudes_new[i][j]==1:
  153. altitudes_temp[i][j]=setheight
  154. elif setdepth>0 and altitudes_new[i][j]==0:
  155. altitudes_temp[i][j]=setdepth
  156. else:
  157. altitudes_temp[i][j]=altitudes[i][j]
  158.  
  159. TerrainObj.SetTerrainAltitudes (altitudes_temp) # Set terrain heights
  160.  
  161. message="Successfully Changed Terrain"
  162.  
  163. else:
  164. message="No Scene Loaded"
  165.  
  166. Refresh()
  167.  
  168. Message(message) # Display message
  169.  
  170. #--------------------------------------------------------------------------
  171. # End of Script
  172. #--------------------------------------------------------------------------

impworks © Copyright Mark Caldwell 1996 - 2017