Python Script Engine  1.0
GL Studio Editor Python Script API
BasicGLPolygon.py

Example on how to create a simple GLPolygon.

1 # import all referenced modules
2 import Editor
3 import GLPolygon
4 import VertexArray
5 import Vertex
6 
7 # Get the currently open and in focus document
8 currentDoc = Editor.GetCurrentDocument()
9 
10 # Create some vertices to use as the bounds of the GLPolygon
12 verts.Insert(Vertex.Vertex(10, 10, 0, 100, 0, 0, 185))
13 verts.Insert(Vertex.Vertex(210, 10, 0, 100, 0, 0, 185))
14 verts.Insert(Vertex.Vertex(210, 110, 0, 100, 0, 0, 185))
15 verts.Insert(Vertex.Vertex(10, 110, 0, 100, 0, 0, 185))
16 
17 # Create the GLPolygon, passing in the vertices we just created
18 polygon = GLPolygon.GLPolygon(verts)
19 polygon.SetPolygonMode( polygon.POLY_MODE_FILLED )
20 
21 # Add the new GLPolygon to our current Document
22 currentDoc.InsertObject( polygon )
23 
24 # New in GL Studio 6.0.1.
25 # How to create a Yellow GLPolygon from a Python list of Vertices.
26 vertsList = [
27  Vertex.Vertex(50, 50, 0, 200, 220, 0, 255),
28  Vertex.Vertex(120, 50, 0, 200, 220, 0, 255),
29  Vertex.Vertex(120, 120, 0, 200, 220, 0, 255),
30  Vertex.Vertex(50, 120, 0, 200, 220, 0, 255),
31 ]
32 
33 # Create a polygon and set its fill mode to filled.
34 yellowPolygon = GLPolygon.GLPolygon( vertsList )
35 yellowPolygon.SetPolygonMode( yellowPolygon.POLY_MODE_FILLED )
36 
37 currentDoc.InsertObject( yellowPolygon )
38 
39 # Make a larger polygon and set a location.
40 multiPolygon = GLPolygon.GLPolygon([
41  Vertex.Vertex(80, 65, 0, 0, 40, 0, 0),
42  Vertex.Vertex(95, 35, 0, 0, 40, 0, 0),
43  Vertex.Vertex(180, 35, 0, 0, 40, 150, 100),
44  Vertex.Vertex(195, 65, 0, 0, 255, 150, 100),
45  Vertex.Vertex(180, 100, 0, 255, 40, 150, 255),
46  Vertex.Vertex(95, 100, 0, 0, 40, 0, 0),
47  ],
48  Vertex.Vertex(-130,0,0)
49 )
50 # Fill and outline mode, and turn on Gouraud shading
51 multiPolygon.SetPolygonMode( multiPolygon.POLY_MODE_FILL_AND_OUTLINE )
52 multiPolygon.SetShadingMode( multiPolygon.SHADING_GOURAUD )
53 
54 currentDoc.InsertObject( multiPolygon )