[Bf-python] Re: wishes about colorbands

Joseph Gilbert models at paposo.com
Wed Mar 31 15:18:39 CEST 2004


>and the actual Blender ColorBand's data is changed
>between runs, the object won't get automatically updated
It's like the 'verts' member of NMesh. They just are temp structures for
adding verts to a mesh. The colorband would not be a persistant structure.
It could just be used to get/set colorbands.

>have get/set routines to copy the data from/to individual textures
Yes I think this is better. Although also having a list that contains the
original colorband python object may be useful. That way if someone one
comes back in the same script and tries to work with the colorband in the
texture (using colorband internal methods for instance) you aren't
recreating python objects.

>it might
>be possible to have the python object store a pointer to the texture,
>and check the texture's COLORBAND flag before trying to access the
>colorband memory
I think that's a great idea

>But then it would be impossible [or hacky] to create
>ColorBands who weren't associated with textures
Creating a colorband not associated with a texture is fine because it will
be dealloc'ed when the script exits. It can't be persistant, unless it is
associated with a texture. (There really is no point to floating
Colorbands - you have to do something with them - either import/export or
associated them).


-----Original Message-----
From: bf-python-admin at blender.org [mailto:bf-python-admin at blender.org]On
Behalf Of alex mole
Sent: Wednesday, March 31, 2004 3:48 AM
To: bf-python at blender.org
Subject: Re: [Bf-python] Re: wishes about colorbands


Hi Joseph

Are you talking about using PyMem_Malloc to create the CBData that will
be stored within Blender, or just copies whose data gets copied to the
Blender-allocated objects?

Either way, I can see problems [there are always problems :)]

With the first, if the user creates a ColorBand through the UI, it will
have been allocated with MEM_callocN, so won't be allocated compatibly.

With the second, the problem is much smaller: it only becomes an issue
of persistance and synchronisation. If the BPY object is stored in
Blender.Registry, and the actual Blender ColorBand's data is changed
between runs, the object won't get automatically updated. I guess that
could be solved by making the API:

- create new python ColorBand objects and create the associated CBData
simultaneously [this would probably mean that PyMem_Malloc isn't even
needed, as the destructor could simply free the data]

- have get/set routines to copy the data from/to individual textures
[not to "assign" the python ColorBand object with the Texture- changing
the ColorBand after would not change the Texture's CB data]


Such an implementation would make Nicolas' ColorBand dictionary easy to
write :)


Obviously this isn't a 100% ideal solution though. If we really wanted
to represent the underlying Blender code with two-way updating, it might
be possible to have the python object store a pointer to the texture,
and check the texture's COLORBAND flag before trying to access the
colorband memory... But then it would be impossible [or hacky] to create
ColorBands who weren't associated with textures :(


Alex


Joseph Gilbert wrote:
> I believe that when colorbands are added internally, memory is allocated
for
> them (CBData objects) with MEM_callocN which will increment the totblock
> count in blender. However, you can also use PyMem_Malloc as well and in
this
> case python will take care of the memory management. All pointers
allocated
> with PyMem_Malloc will be cleaned up through python's GC.
> The best way to do this it seems would be to create a 1 element list that
> contains a colorband python object -> [PyColorband] or [].  You could
create
> a function to append Python colorbands to a texture eg.
> text->attachColorband(myBand) - which would append the colorband to the
> texture's list.
> This way your not passing pointer references around to data objects that
> could disappear. The allocated pointers would be in the PyColorband object
> and managed by python (rather then through blender).
> The allocated data would be PyMem_Malloc created for the colorband, the
> PyColorband attached inside a PyList to the PyTexture. This will keep the
> PyColorband associated with the texture until you remove the PyColorband
> from the PyList.
> Anyway that's my thoughts.
>
> Joseph
>
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://www.blender.org/mailman/listinfo/bf-python





More information about the Bf-python mailing list