Vue Python: GetFirstHitObject

The VUEInterface Class call GetFirstHitObject looks pretty straightforward in the documentation but I’ve had more emails about it than any other function in Vue’s Python. Hopefully this will help clarify its use.

You call GetFirstHitObject with two parameters. One says where to start trying to find an object from. The other says what direction to look in.

GetFirstHitObject ( vStart, vDirection )

vStart is a tuple of floats [x, y, z] that is the coordinates of the starting point. This uses Vue’s coordinates. It doesn’t use real world units if you’ve got those switched on for display.

vDirection is a tuple of floats [x, y, z] that is a vector of the direction to look for an object in.

So a call of GetFirstHitObject ((0,3.5,50),(0,0,-1)) starts at x=0 y=3.5 and z=50 it checks for an object that is somewhere below that point. If vDirection was (1,0,0) that would look along the x-axis. (1,1,0) would look along the diagonal of the x and y-axis.

Example Script

Get First Hit Object

Version: 0.1
Size: 17.5 KB
October 24, 2010

Python Code

  1. #******************************************************
  2. #
  3. # Demonstration of GetFirstHitObject()
  4. #
  5. # - getfirsthitobject.py
  6. # - By Mark Caldwell
  7. # - Version 0.1 24th October 2010
  8. # - Tested with Vue 8.5 Infinite
  9. #
  10. # How to use in 3 easy steps
  11. #
  12. # 1. Download this file and GetFirstHitObject.vue
  13. # onto your computer by downloading the zip file
  14. # and expanding it
  15. #
  16. # 2. Open GetFirstHitObject.vue in Vue 8.5 or later
  17. #
  18. # 3. Run this script
  19. #
  20. # To run it go to Python -> Run Python Script
  21. # Then locate the file on your computer
  22. #
  23. #******************************************************
  24.  
  25. DisplayPythonConsole()
  26. clear()
  27.  
  28. Obj=GetFirstHitObject ((0,3.5,50),(0,0,-1))
  29. print 'Object: '+str(Obj)
  30. if (Obj!=None):
  31. print 'Object Name: '+Obj.Name()
  32.  
  33. print
  34.  
  35. Obj=GetFirstHitObject ((0,3.5,50),(0,0,1))
  36. print 'Object: '+str(Obj)
  37. if (Obj!=None):
  38. print 'Object Name: '+Obj.Name()
  39.  
  40. print

Line by Line Example Explanation

Lines 1 to 24 are my standard brief header block so, other than including quick instructions on using the script, you can skip over them.

Line 25 calls DisplayPythonConsole() to open Vue’s Python console if you’ve not already opened it.

Line 26 calls clear() so there isn’t anything else shown in the console.

Line 28 is the first of two calls to GetFirstHitObject.  This one should hit a sphere in the scene called Hit.

Line 29 prints the Object information about the object hit.  It should be something like VUEBasicObject instance at >.

Line 30 tests to see if Obj is an actual hit object. If it is Line 31 prints its name. It should print Hit.

Line 32 to 34 are a bit of spacing in the script and a print to add a blank line to the console display.

Line 35 is a second call to GetFirstHitObject. This one is fired in the opposite direction from the first one and shouldn’t hit anything as it fires off into empty space.

Line 36 prints the Object information about the object hit. Since nothing should be hit None should be printed.

Line 37 tests, just like line 30. Since nothing was hit it shouldn’t print an objects name on the next line.

impworks © Copyright Mark Caldwell 1996 - 2017