[Bf-python] Adding objects and scenes refactor

Campbell Barton cbarton at metavr.com
Mon Aug 28 17:21:44 CEST 2006


Hi Willian

Object.New() never adds data,
see Object.c line 862
*object->data = NULL;

*The data is created when linking to a scene - if its not alredy there, 
or when getting the data as you show.

But objects can exist- and be in Blenders database - with 1 python user 
and have no obdata,
this should not happen. (think we all agree on that)
*
*Removing object data creation directly worries me a bit- I like to be 
able to manage Blenders library of data- objects and object data - 
without being limited  too much.
Blender supports obdata with no object users (Fake Users) - so I dont 
see  why python should enforce this.
Also- it would be possible to make zero user obdata anyway by baking an 
object+data then unlinking from the scene,

Once use for being able to add new obdata (without a new object) is so 
you can make new data for an existing object
Im trying to think of examples where adding obdata without an object is 
usefull and can think of a few but they are fairly obscure, so I might 
just be too used to the old API ;)

Examples of cases adding obdata without an object could be usefull.
* if you want to make a mesh thats only used as a texmesh, needs no 
object.- The texture bakingscript I wrote does this.
* Say you wanted to import  a flickbook of meshes- 1 for each frame that 
cycled through frames, Blender cant do this but a scruiptlink could.   
Youd wantto be able to make all the meshes and give them fake users so 
they would be accessable.
* In some cases it makes sense to use new object data for storing new 
data to export- me= Mesh.New();  me.getFromObject(ob.name) - is used for 
exporters that export with modifiers applied.

- Cam






Willian Padovani Germano wrote:
> Hi Campbell,
>
> We do need a wiki page for this topic, I'll just reply here to a small 
> issue.
>
> Campbell Barton wrote:
>> Once of the biggest problems is that Python API allows you to create 
>> an object with no obdata...
>> Ton was requested this be made not possible
>
> No, that was never possible. Object.New() *always creates obdata*, 
> unless you're creating an Empty, of course. The issue is with obdata, 
> since NMesh.New(), Camera.New(), etc. create *obdata that is not 
> linked to any object*. For this reason, the docs advise people to use:
>
> ob = Object.New('Lamp')
> obdata = ob.data
>
> #instead of:
>
> obdata = Lamp.New()
> ob = Object.New('Lamp') # is created with obdata already
> ob.link(obdata) # unlinks the original obdata
>
> One possibility is to simply remove these obdata creation functions, 
> but since there are situations where they are useful (and for 
> backwards compatibility), we may just ad a new better way to create an 
> ob+obdata already linked to a scene and keep this older way for those 
> who need it.
>
> To all: we agreed that the API for creating data (ob, obdata, scenes, 
> texts, images) deserves a wiki page for discussions, once it is 
> created (anyone is free to start it) and announced here, let's 
> continue the discussion there.
>


-- 
Campbell J Barton

133 Hope Street
Geelong West, Victoria 3218 Australia

URL:    http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241



More information about the Bf-python mailing list