[Bf-python] Adding objects and scenes refactor
Campbell Barton
cbarton at metavr.com
Mon Aug 28 07:29:43 CEST 2006
Hey All, its generaly agreed that we need to change the way teh python
API creates new objects and adds them to a scene.
A few solutions have been suggested and its been discussed quite a bit
also but no conclusion has been made.
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
a lesser problem is that you can add objects without adding them to a
scene, this isnt so bad however it maye be good to make it that adding
an object also adds it to a scene.
There are all sorts of ways of doing this, but one thing I want to know
is weather we need to make this backwards compatible with old scripts.
The issue of objects not having any data could be fairly easerly solved
by adding the data at the same time the objects created. as well as
accepting obdata with the Object.New() function.
eg
ob= Object.New('Mesh') # would create obdata right away, so objects
would never have no data, would create orphan obdata tho.
ob= Object.New(Mesh.Get('MyMesg')) # add this as a new way to make an
object with linked data in 1 step, but still allow the line abouve to
work too.
This would be a fine short term solution IMHO but people are suggesting
we deprecate the old object system and add in new ways of dealing with
obdata
Requirements are...
1) Objects always have obdata
2) Must allow dealing with linked duplicates
3) Maybe enforce new objects to be added into a scene.
I started with my own solution but we will probably replace it after
discussing the best way to solve this.
added an iterator that allows you to acces scene objects like a list
that you can add and remove from.
Example code
scn= Scene.GetCurrent()
for ob in scn.objects: # replaces scn.getChildren() with a thin
wrapper.
print ob.name
print len(scn.objects)
scn.objects.remove(Object.Get('Cube')) # instead of scene.unlink()
scn.objects.add(someObject) # instead of scn.link()
# Adding an obejct from obdata in 1 step
ob= scn.objects.new(Mesh.New('Cube'))
# instead of
me= Mesh.New()
ob= Object.New('Mesh')
ob.link(me)
scn.link(ob)
... This may be acceptable but theres lots of ways it might be done
better
please reply with suggestions, or start a wiki and link to it.
--
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