Tutorial on Creating Geometric Content#

First Step#

To complete these exercises, launch ipython with the following option:

ipython --gui=qt

Warning If you don’t use this option, you’ll likely have problems displaying your results with the viewer.

Import all plantgl modules:

from openalea.plantgl.all import *

Exercises#

Hello World#

  1. Use the help on the Box primitive. What are the possible constructor arguments?

  2. Consult the plantgl documentation on the web.

  3. Create a Sphere with radius 5.

  4. Display it in the Viewer.

Your result should look like:

Sphere with radius 5{ width=”40%”, align=”center” }

Note In the viewer, you can change the camera angle by dragging, change the light direction by holding ctrl and dragging, and zoom in/out with the scroll wheel.

Solution for Hello World


Material#

Create a shape with the previous sphere and associate a red material to it.

Red sphere{ width=”40%”, align=”center” }

Hint: Use Shape and Material.

Solution for Material


Transformation#

Create a Sphere centered at point (-2,0,0).

Translated sphere{ width=”40%”, align=”center” }

Hint: Use the help on Translated.

Solution for Transformation


Scene#

Display a scene with two spheres, one red and one yellow, positioned respectively at (-5,0,0) and (-2,0,1).

Scene with two spheres{ width=”40%”, align=”center” }

Hint: Use the help on Scene.

Solution for Scene


Instantiation#

In the previous scene, use the same sphere primitive for the translations. Change the radius of the sphere and observe the effect on the scene.

Instantiated scene{ width=”40%”, align=”center” }

Solution for Instantiation


Mesh#

  1. Create a square with QuadSet.

  2. Add different colors to the vertices of the square.

  3. Create a cube with QuadSet and different colors for each face.

  4. Create a cube with QuadSet and a different color for each point of each face.

Square{ width=”40%” } Colored square{ width=”40%” } Cube 1{ width=”40%” } Cube 2{ width=”40%” }

Solution for Mesh


Texture and Billboard#

  1. Add texture coordinates to the vertices of the square to display an image:

    Wood texture{ width=”20%”, align=”center” }

    Hint: Create a Shape with your square as geometry and ImageTexture as material.

  2. Use transparency to display a leaf on a square:

    Leaf texture{ width=”20%”, align=”center” }

  3. Display the wood texture on the square but only part of the image (half width/height starting from 1/4,1/4).

  4. Always display the same image on the 6 faces of a cube.

  5. Create a cross with 5 squares and display a part of the texture on each square.

Results:

Tex1{ width=”40%” } Tex2{ width=”40%” } Tex3{ width=”40%” } Tex4{ width=”40%” } Tex5{ width=”40%” }

Solution for Texture and Billboard


Discretization#

  1. Create a QuadSet corresponding to a cylinder.

  2. Create a TriangleSet corresponding to a cylinder.

  3. (Difficult) Create a Sphere as a truncated icosahedron.

Results:

Cylinder quads{ width=”40%” } Cylinder tris{ width=”40%” }

Solution for Discretization


Hulls#

  1. Create a python function to display a growing AsymmetricHull.

    Asym hull 1{ width=”40%” } Asym hull 2{ width=”40%” } Asym hull 3{ width=”40%” } Asym hull 4{ width=”40%” }

  2. Create profiles with positive x coordinates using Polyline2D, BezierCurve2D, NurbsCurve2D.

    Polyline{ width=”40%” } Bezier{ width=”40%” } Nurbs{ width=”40%” }

  3. Create a Swung hull with the previous profiles at different angles between [0;2*pi].

    Profile hulls{ width=”40%”, align=”center” }

  4. Create a circle with Polyline2D.Circle and a closed profile representing the silhouette of a tree.

    Hulls circle{ width=”40%”, align=”center” }

  5. With these two profiles, create an ExtrudedHull to obtain:

    Extruded hulls{ width=”40%”, align=”center” }

Solution for Hulls


Generalized Cylinder#

With a circle and a 3D line, create a branch with an Extrusion. Expected result:

Branches{ width=”40%”, align=”center” }

Solution for Generalized Cylinder


Positioning Objects#

  1. Create a 2-meter trunk with a cylinder and pairs of lateral leaves every 50 cm. Hint: Use Translated, AxisRotated, EulerRotated, etc.

  2. Same thing with decreasing leaf sizes. Hint: Use Scaled.

  3. Same thing with a trunk bent 30° in the middle.

Tree 1{ width=”30%” } Tree 2{ width=”30%” } Tree 3{ width=”30%” }

Hint: Pay attention to the order of transformations!

Solution for Positioning Objects


Solutions#

Solution for Hello World#

Python script to get help on Box:

# solutions_python/box.py

The arguments for initializing a Box are the x, y and z scales. To create a sphere with radius 5:

# solutions_python/sphere_5.py

Box{ width=”40%”, align=”center” } Sphere 5{ width=”40%”, align=”center” }


Solution for Material#

To associate a red material to a sphere:

# solutions_python/material.py

Red sphere{ width=”40%”, align=”center” }


Solution for Transformation#

To translate a sphere:

# solutions_python/transformation.py

Translated sphere{ width=”40%”, align=”center” }


Solution for Scene#

To create a scene with two different spheres:

# solutions_python/scene.py

Scene{ width=”40%”, align=”center” }


Solution for Instantiation#

To use the same sphere primitive in the scene:

# solutions_python/scene2.py

Instantiated scene{ width=”40%”, align=”center” }


Solution for Mesh#

Colored square:

# solutions_python/carre.py

QuadSet{ width=”40%”, align=”center” }

Cube with color per face:

# solutions_python/cube.py

Cube 1{ width=”40%”, align=”center” }

Cube with color per vertex:

# solutions_python/cube2.py

Cube 2{ width=”40%”, align=”center” }


Solution for Texture and Billboard#

Textured square:

# solutions_python/square_tex.py

Tex1{ width=”40%”, align=”center” }

Textured square with alpha:

# solutions_python/square_tex2.py

Tex2{ width=”40%”, align=”center” }

Partially textured square:

# solutions_python/square_tex3.py

Tex3{ width=”40%”, align=”center” }

Textured cube:

# solutions_python/cube_tex.py

Tex4{ width=”40%”, align=”center” }

Textured cross:

# solutions_python/cross_tex.py

Tex5{ width=”40%”, align=”center” }


Solution for Discretization#

Cylinder with QuadSet:

# solutions_python/cyl_quadset.py

Cylinder quads{ width=”40%”, align=”center” }

Cylinder with TriangleSet:

# solutions_python/cyl_triangleset.py

Cylinder tris{ width=”40%”, align=”center” }


Solution for Hulls#

Growing hulls:

# solutions_python/asymmetric_hulls.py

Asym hulls{ width=”40%”, align=”center” }

Swung hulls:

# solutions_python/hull_profil.py

Profile hulls{ width=”40%”, align=”center” }

Extruded hulls:

# solutions_python/hull_extruded.py

Extruded hulls{ width=”40%”, align=”center” }


Solution for Generalized Cylinder#

Extruded branches:

# solutions_python/branches.py

Branches{ width=”40%”, align=”center” }


Solution for Positioning Objects#

Tree with same-sized leaves:

# solutions_python/tree1.py

Tree 1{ width=”40%”, align=”center” }

Tree with decreasing leaf sizes:

# solutions_python/tree2.py

Tree 2{ width=”40%”, align=”center” }

Tree with bent trunk:

# solutions_python/tree3.py

Tree 3{ width=”40%”, align=”center” }