Working with objects in Vue with Python


Get the size of an object


Getting the actual size of an object in Vue programmatically isn’t as easy as you’d think. You essentially have to get the BoundingBox of the object and work with that. So here we have a wind turbine object, and we have selected the pole and need to know (programmatically) how tall this pole really is.

wind turbine object in Vue

If you look at that z-value in the size properties, you see that it’s 76.045m tall. To get that height programmatically (result on line 21):

 


Multiple cameras



Turns out there is no Python method in the Vue API for creating a camera. In order to create cameras, you can duplicate the Main camera and then call your custom cameras by index, where the index is the ID number of the camera.

This results in two new cameras, Main camera0 and Main camera1. The names of the cameras in the layer list are pretty much meaningless since you access them via index.

And here is what they look like from the Top view:


Add an array of cylinders



We needed to test and make sure that, when using a planetary sphere in Vue, objects are indeed placed on the curvature of sphere (in our case, the Earth). The following script adds a cartesian-like array of cylinders into a Vue scene. First we need to create the cartesian array of points:

Which gives us a dictionary of key/value pairs where the key is an id number and the pairs are the X/Y cartesian coordinates, spaced 100 units apart in the X and Y:

Now let’s add z-values to the X and Y lists so we have a height for each cylinder:

Finally, here is the script to run on a 1km planetary terrain scene within Vue:

And the end result is this:

Now, granted this isn’t the most practical script, but it does show how a little bit of work with itertools, dictionaries, and the Vue API lets you place a massive amount of objects into a scene relatively painlessly and quickly.


wp-content/uploads/2012/10/Vue_Python.png
You are reading the series: Scripting Vue with Python

Comments are closed.