New Metaballs API in CVS

Cambo,

How exactly does that work? For example, the following produces no mesh for me:

import Blender

ObMball = Blender.Object.New("Mball","mib")
ObMesh = Blender.Object.New("Mesh","mie")

mb = Blender.Metaball.New()
lm = mb.elements.add()

me = Blender.Mesh.New()
me.getFromObject('mib')


ObMesh.link(me)
ObMball.link(mb)
sc = Blender.Scene.GetCurrent()
sc.link(ObMesh), sc.link(ObMball)

???
Am I doing something in the wrong order?

RS

[EDIT] Ok, I got it working - I’m still getting this Mesh->Object->Scene linking thing down.

From the docs, example #1

import Blender
ob =  Blender.Object.New("Mball","mb")
mb = Blender.Metaball.New()
for i in xrange(20):
  element= mb.elements.add()
  <b>element.loc=</b> Blender.Mathutils.Vector(i, 0, 0) 
ob.link(mb)
sc = Blender.Scene.GetCurrent()
sc.link(ob)

AttributeError: ‘Blender Metaelem’ object has no attribute ‘loc’

Tested with CVS 09-28-2006

EDIT

Looks like it should be

element.<b>co</b>= Blender.Mathutils.Vector(i, 0, 0)

(“co” ?? … co(ordinates) ? … why not “loc”)

Mike

Cambo,

I’ve run into a curious thing - I think converting metaballs to mesh is broken, but only when running it from background mode (change the save location to whatever you want first):

import Blender

scn = Blender.Scene.GetCurrent()

MetaObj = Blender.Object.New('Mball','Mball')
mb = Blender.Metaball.New('Meta')
mb.elements.add()
MetaObj.link(mb)
scn.link(MetaObj)
Blender.Redraw()

MeshObj = Blender.Object.New('Mesh','Mesh')
            
mesh = Blender.Mesh.New()
mesh.getFromObject('Mball')
MeshObj.link(mesh)
scn.link(MeshObj)

Blender.Save('/home/sclay/tmp/rocketship.blend')

RS

Its close to impossible to get some of blenders functions working iun BG mode. in general Id avoid BG mode for complex data manipulation and only use it for batch rendering.

Iv tried to get Object.join for eg working in background mode but its quite tricky and blender relies on having a screen, layers, etc to do some of these operations.

Cambo,

That’s about what I thought - is Nmesh.GetRawFromObject() any different?

I think it would be worth flagging things that don’t work(or might not work even) in background mode in the API…

RS

rocketship, the problem is that some datablocks are not initialized when running in BG mode. the ‘screen’ is not, therefor theres no active layers, therefor theres no user context - GetSelected fails.

instead of messing about with different workarounds perhaps its better just to initialize all that data and that should allow user context to exist even when running GUI’less

Cambo,

Its becoming clearer - I’m guessing the mesh conversion function for metaballs is getting the mesh as a byproduct of the screen renderer? I even looked into somehow redirecting X/OpenGL output to /dev/null (not running in backround mode), but that’s beyond my abilities…

RS

AFAIK Its not todo with openGL,

The datastructures for ‘screen’ are not initialized when in background mode.
I think they possibly could be and that might solve the problem.
Worth posting on bfcommiters about this

if you povide a script and/or blend that creahes blender, Ill see if I can make blender initialize the data in a way that makes it work.