3DTrue - 3D Tools & Software
3DTrue - 3D Tools & Software
 
3D
3D
3D Tutorials Home Previous Page - Getting Started in 3D Next Page - 3D Hardware Primer 8 Items 12345678

Poser Python Hello World

3D Tutorials Poser allows Python, a programming language, to interact with the scene. This can be achieved through the Python Scripts menu window, or by opening a python script under the File > Run Python Script option. Either way, this is how i got a box to appear on the stage as a new prop. First, start with a text file in your favorite text editor. Python is veeery specific about tabs so choose your tool wisely.

To make things easy, let's use the simplest shape we can, a tetrahedron, or a pyramid on a triangular base if you will. To top it off we are going to create this figure with only ten lines of code. This is done so you can learn from it, don't expect the world from this shape. To build our tetra hedron we will only need four points (vertices) in 3D space. the top of the tetrahedron is one point, the other three will all sit on the floor at the corners. From these four points, we can also create four faces. Each face will have three sides. The following python script does exactly that. It creates a tetrahedron on your main stage by running the python script. Better test it now before you edit it. Make sure it works in your installation of Poser before modification.

Here's the code:

The first two lines of the scene we initialize the Poser scene for a new mesh creation. Lines 3,4, and 5 actually define our shape. Everything else is just code. The command "CreatePropFromGeom" takes our data and creates the prop, Python doesn't actually do this, Poser does. Python just sent the request in. Keep in mind that there is a special library which Poser has called the Poser library. This library is written in Python. It is automatically initialized when Poser is open. Officially, you are supposed to have a line at the very top that says "import Poser".

Copy the code exactly as written, do not put any tabs in the file or fool with it in any way till you see it work once. After we create our new prop on the stage we select it with the SelectActor command. This is not necessary but i use it to save time having to click the object in Poser. The final call DrawAll() updates the Poser window should it need it.

So how are the three geometry lines above used? The first set we called meshVerts are the actual points in space. There are three values (x,y,z) for each point, there are a total of four points. If you move one of the points by changing it's value, the triangle's shape will change as well. The next line, meshSets, are the faces of our shape. Each number represents a vertex point (0-3 for all four points we made). If you trace out these points in your mind, you will see that they trace a path along each point. The path must go counterclockwise and everything to the path's left is considered filled. In our shape, each face has only three points, the minimum for any face. The "meshPolys" i have always taken to mean the order for the points to faces. This is a vague area to me still but my best guess is this. To create this value, take your first face and start with 0, count the number of points and place that value after your zero. Next starting number would be the first value plus the second value. So, our first value [0,3] means at position zero begin a face for the next three points. Our second value [3,3] would be again, the current position in our index, and the number of points in that face. Hope this makes sense. A shape whose faces were made up of four points each would like so ([0,4],[4,4],[8,4]). A shape with 5 points to each face would look like so ([0,5],[5,5],[10,5]). And just so you will really understand it, a shape with complex faces (some five points, some, four, some three) would look like this [0,3],[3,4],[7,3],[10,5],[15,4],[19,3],[22,4]. This pattern continues till you are out of faces.

Finally, the big confession, at the time of this writing i do not know why the Numeric.Int value is at the end of each line (3-5). I thought it was the length of each array, but i do not see how it was filled in the first place.

I learned enough to write this Python script as well as this tutorial by reading the Poser 5 PDF document on Poser Python and from looking around the web.

Want more? Check out our PoserPython Scripts Collection.





Renderosity
All Site Content © 2006 3dtrue.com / Hits / Web Hosting by Gigfoot