On Thu, 2005-01-20 at 21:13 -0200, Flavio Coelho wrote:
> Hello,
>
> Is there a way to destroy objects (not just make them invisible)?
> removing them from a scene?
I'm not entirely sure what you are asking, but I'll give this one a
shot(gun;) anyway. Python's memory management is a reference-counted
system. When the reference count on an object drops to zero, it is
immediately deleted/destroyed/freed. Internally, every visible
primitive object's owning display owns one reference to the primitive.
Making the object invisible is implemented by removing the object from
its parent display, and removes the display's reference. This leaves
only the references that might exist in your program. In general, every
means of accessing the object counts as a reference. In the simplest
case, you only have a single local or global name that refers to the
object, and you just use the 'del' keyword to get rid of it, like this:
x = sphere()
x.visible = False
del x
# This step will raise an exception, since x does not exist:
x.pos = vector(1,0,0)
Or just assign a different object that name:
x = sphere()
x.q = 1.6e-19
x.visible = False
x = sphere()
print x.q # Error!, x.q does not exist, since this is a new object.
> another question is there a way to let a part of an object get out of
> sight? for example, suppose I have a curve object that keeps growing
> in a given direction. How do i allow for the older parts of the curve
> to move out of the frame to avoid auto rescaling?
For the curve object, you can write your own special append() function
that performs a shift+replace rather than a true append, like this:
def append_nogrow( curve_object, new_pos):
curve_object.pos[:-1] = curve_object.pos[1:]
curve_object.pos[-1] = new_pos
HTH,
-Jonathan Brandmeyer
|