8.1. GeomObject — Geometry base class

The GeomObject class is the base class for all geometries. Instances of this class are stored in the geom attribute of the world objects and can be shared among them.

class GeomObject

...params?...

GeomObject.boundingBox()

Return the local axis aligned bounding box. The bounding box is given with respect to the local transformation L (which is not what you get from the transform slot of the world object).

GeomObject.drawGL()

Draw the geometry using OpenGL commands.

GeomObject.uniformCount()

Return the multiplicity of UNIFORM variables.

GeomObject.varyingCount()

Return the multiplicity of VARYING variables.

GeomObject.vertexCount()

Return the multiplicity of VERTEX variables.

GeomObject.faceVaryingCount()

Return the multiplicity of FACEVARYING variables.

GeomObject.faceVertexCount()

Return the multiplicity of FACEVERTEX variables.

GeomObject.slotSizeConstraint(storage)

Return a constraint object for primitive variable slots or None if the size of the slot should be unconstrained. This method is called when a new primitive variable is created. The returned constraint object is used for the array slot that holds the values of the variable. storage is the storage class of the new variable which will be one of UNIFORM, VARYING, VERTEX, FACEVARYING or FACEVERTEX. The method will never be called when CONSTANT or USER variables are created.

GeomObject.newVariable(name, storage, type, multiplicity=1, user_n=0)

Attaches a new primitive variable to the geometry.

storage specifies the storage class, i.e. how many values are actually stored. It must be one of CONSTANT, UNIFORM, VARYING, VERTEX, FACEVARYING, FACEVERTEX or USER. The exact number of values depends on the actual geometry. However, CONSTANT is always exactly one value for the entire geometry and USER is a user defined number specified in user_n.

type is the type of the variable and must be one of INT, FLOAT, STRING, COLOR, POINT, VECTOR, NORMAL, MATRIX and HPOINT. If multiplicity is greater than 1, then an array with that size is created.

Creating a new variable will always create a new slot of that name as well. The slot is always an ArraySlot (even for CONSTANT variables). After you have created a variable you can use the corresponding slot to manipulate the values of the variable.

Here is an example of a “varying int [3]” variable that’s created on a sphere geometry. This means, the variable will consist of four 3-tuples of integers (one for each parametric corner).

>>> from cgkit.all import *
>>> sg=SphereGeom()
>>> sg.newVariable("foo", VARYING, INT, multiplicity=3)
>>> for v in sg.iterVariables(): print v
...
('foo', cgkit._core.VarStorage.VARYING, cgkit._core.VarType.INT, 3)
>>> s=sg.slot("foo")
>>> s[1]=(1,2,3)
>>> for f in s: print f
...
(0, 0, 0)
(1, 2, 3)
(0, 0, 0)
(0, 0, 0)
GeomObject.deleteVariable(name)

Delete the primitive variable with the specified name.

GeomObject.deleteAllVariables()

Delete all primitive variables.

GeomObject.findVariable(name)

Search for a particular primitive variable and return its descriptor. None is returned if a variable called name cannot be found. The return value is a 4-tuple (name, storage class, type, multiplicity) describing the variable. See the newVariable() method for a description of the individual elements.

GeomObject.iterVariables()

Return an iterator that iterates over all existing primitive variables. The iterator will return the same 4-tuple as returned by findVariable().

GeomObject.convert(targetgeom)

Convert the geometry into another type of geometry. targetgeom is another GeomObject that will receive the result of the conversion. If the conversion is not possible, a NotImplementedError exception is thrown.

In the following example, a box geometry is converted into a triangle mesh:

>>> bg=BoxGeom(segmentsx=3, segmentsy=3, segmentsz=3)
>>> tm=TriMeshGeom()
>>> bg.convert(tm)
>>> print len(tm.verts)
56
>>> print len(tm.faces)
108

Previous topic

8. GeomObjects

Next topic

8.2. BoxGeom — Box geometry

This Page