-
Notifications
You must be signed in to change notification settings - Fork 20
Geometry
The geometry is the basic component of 3D scenes, it defines all visual information. The data is composed of multiple vector and integer lists, which are rendered by the graphics card on screen using a Material. A geometry inherits from the Transform module a position and orientation in space, the geometric data is thus interpreted in the local coordinate system of the geometry.
Create a new scene and try out:
# Define a simple triangle
import VR
mat = VR.Material('myMaterial')
mat.setDiffuse([0,0,1])
mat.setLit(False)
geo = VR.Geometry('myTriangle')
geo.setPositions([[0,1,0], [-1,0,0], [1,0,0]])
geo.addTriangle()
geo.setMaterial(mat)
geo.setFrom([0,0,-2])
VR.find('light').addChild(geo)
The geometry data is as follows:
- Positions: a list of 3D points, the positions of the vertices of your geometry
- Normals: a list of 3D vectors used to define a surface normal, either one at each position, thus named vertex normals, or multiple normals to define a per facet normal. The first one produces a smooth look, the second variant a faceted look with hard edges.
- Colors: a list of RGB or RGBA colors. Can be used to colorize the model on a per vertex basis.
- Texture Coordinates: a list of 2D or 3D vectors, coordinates in a 2D or 3D texture image. Those are used to map image colors onto the geometry.
In addition to the vertex data the geometry defines the topology in integer lists
- Types: a list of OpenGL types (integer), a simple triangle mesh defines its Types list with a single value: GL_TRIANGLES
- Lengths: for each entry in Types it defines a length, the number of primitives of the corresponding type.
- Indices: a long list of integers that defines which vertices a primitive has.
There are two sets of colors and seven sets of texture coordinates.
It is important to make sure your geometry data is valid. A bad geometry can result in artifacts or even crashes the application.
- The only necessary data are the Positions. Normals, Colors and texture coordiantes are all optional.
- If not using separate indices the lengths of normals, colors or texture coordinates are the same as the length of the positions.
- The length of Types and Lengths is the same.
- The number of indices is equivalent to the sum of lengths times the number of vertices of the corresponding primitive. For example: for a mesh the Types and Lengths could be
[GL_TRIANGLE, GL_QUADS]
and[100, 50]
, the length of Indices has to be500 = 100*3 + 50*4
.
Usually one imports models, but for more complex applications, dynamic content generation may be necessary. First there are the basic functions to set the data directly:
geo.setPositions([...])
geo.setNormals([...])
geo.setColors([...])
geo.setTexCoords([...], channel)
geo.setTypes([...])
geo.setLengths([...])
geo.setIndices([...])
And here are utility functions to make the process easier and safer:
geo.addVertex( pos, norm, col, tc)
geo.addPoint( i )
geo.addLine( i, j )
geo.addTriangle( i, j, k )
geo.addQuad( i, j, k, l )
It may be necessary to manipulate normals:
geo.flipNormals()
geo.updateNormals( doFaceNormals )