Skip to content

Python_CreateGeometricObjects

Daniel Stoeckel edited this page Feb 20, 2015 · 2 revisions

How can I create a simple geometric object in BALLView?

The following example creates a simple box with given color:

{{{ #!python

specify dimensions of the new box

size = 3 v1 = Vector3(0.) v2 = Vector3(size, 0, 0) v3 = Vector3(0, size, 0) v4 = Vector3(0, 0, size)

create a red box

colored_box = Box(v1, v2, v3, v4) colored_box.setColor(ColorRGBA(1, 0, 0, 0.8))

create a representation for the box

r = Representation() r.insert(colored_box)

add the representation to the main control

getMainControl().insert(r)

update the representation

getMainControl().update(r) }}}

Here a sphere is created:

{{{ #!python

specify radius and position (center) of the sphere

r = 4 pos = Vector3(0.)

create a sphere with given radius and center

s = Sphere() s.setRadius(r) s.setPosition(pos)

color = ColorRGBA(1, 0, 0, 0.8) s.setColor(color)

create/update the representation for the box

r = Representation() r.insert(s) getMainControl().insert(r) getMainControl().update(r) }}}

NOTE:

The examples are intended for usage within BALLView.

Clone this wiki locally