Can you create new classes of objects?

I’ve been looking over the Python API for Blender, and I see how you can manipulate all of Blender’s existing object types, which is pretty good.

I have an idea that I’m studying the feasibility of, and it would require using new object models that are stored outside of Blender. In this concept, my program (plugin/script/etc) would provide the objects, control their state, etc. But ideally, I’d be able to capture messages to the objects (e.g. “I’m being re-sized”). Going into “edit” mode would have special behavior too, probably, since I’d want that to bring up my object properties in a script window.

The 3D visualization of the object could be done with existing Blender functionality – I could just return a NMesh representing the object, or some such thing, but the model would internally “know” that it wasn’t just a mesh, and attempting to edit it as a mesh should fail (or maybe, bring up my script window instead).

I think I would need something like this capability in order to implement CAD features in Blender, which is what I’m contemplating. The idea is to use Blender as “View” and “Controller” in a “Model-View-Controller” application model, and have something like a STEP object schema in an external data store as the model.

Naturally, there’d be some kind of import/export capability so you don’t really get stuck, but I’m not trying to write an import/export script. The ideas is that CAD objects stay CAD objects, but have a Blender viewable visualization and capture Blender actions that would affect the object, so my script can “do the right thing” to the original STEP model. That would allow you to edit the STEP model using Blender, rather than merely being able to import it to blend format (which would lose data, since STEP has a lot of concepts beyond just 3D modelling that don’t make sense to Blender (yet)).

So, am I just out of my mind, or does this have a chance of working?

I suspect the Python scripting API won’t be quite strong enough for this —but maybe it can be implemented at the C level as a handle of somekind, and the Python API could then be extended to make use of it?

I think this would be worth a fair amount of effort, since there’s really no decent free 3D CAD solution in existence, and it’s a monumental task to do from scratch. Using Blender would take advantage of an already thought-out and well-designed interface (not to mention, one that many people already know how to use). But as I say, I’m still trying to figure out just how much effort it would take.

there is no python only way to create a new datatype

doing so in blender’s source would probably be a lot of work, a new datatype hasn’t been introduced for… a long time

though there have been major changes, only like one since open sourcing [armatures instead of ika-s in 2.20 iirc, and after open sourcing new meta types were added, but no new object types have been added while I’ve been using blender]

you’d probably want to start looking at blender’s source [and the documentation of it on blender3d.org], subscribe to the mailing lists, watch the developer forum on blender.org, watch the blender development irc channels [at the moment I forget what they are]… and stuff

Thanks!

sigh

Yeah, I was afraid of that. Well, I think all that would be required is a hook of some kind, so maybe it wouldn’t be so difficult. Or maybe it will be shear unmitigated hell. :smiley: Who knows? I suppose I’ll be downloading the source now. :slight_smile:

This should be interesting …

there is no python only way to create a new datatype

Huh?


class myObject(object):
    __init__(self):
        #look me, I am a class constructor..
        None

Ok, it might not be what you want, but python not only can create new datatypes as extensions of object, but can even overload operators (tho I haven’t studied their syntax), so that i can write
a=myObject()
b=myObject()

c=a + b
and still have a meaningful result out of that. I suppose you could link blender meshes to an object that is persistent in the python script, and every time either of them is modified resyncronize their state. The problem is that the script would have to run continuously, and I don’t know if Blender can do that.

No, no, no. I know you can make a new class in Python, but I was talking about classes of Blender model objects (current classes are “Meshes”, “Metaballs”, etc).

Not knowing the source, it’s hard to say whether these things are actually “objects” or “classes” in the OOP sense, but they certainly are conceptually. Reading the intro to the sources leads me to believe that they are actually “structs” in C. That would mean that operations working on them are probably done by functions, rather than methods, so a new datatype will probably mean adding bits of code in many different places.

If so, my addition will be sort of painful, but also very useful, since it would create the notion of an actual OOP object representing the model object, and that object would be extensible in Python. Which would be a beautiful thing.

Of course, it may exist already — I only just downloaded the source last night.

The point is, in order to do what I want, I need to have a callback from the object so that when the user tries to edit it, my script will be called instead. This would allow the visual object to be only a representation of the “real” (STEP CAD) object which is stored externally.

(This is required because there will not in general be a 1:1 correspondence between what Blender can do with the representation object and what STEP can represent in the original. Otherwise, this would be an import/export problem. As it is, I could write an importer for STEP to Blender, but data would be lost — afterwards, if I edited anything and then tried to export back to STEP, data would be lost again).

Of course, I’m also realizing that I’m probably in the wrong place to discuss technical detail like this — would’ve been appropriate if the Python API already provided a means to do this, which I wasn’t sure about.

Thanks.

there is no python only way to create a new datatype

doing so in blender’s source would probably be a lot of work, a new datatype hasn’t been introduced for… a long time[/quote]
What about the Half-Edge mesh datatype?

Martin

there is no python only way to create a new datatype

doing so in blender’s source would probably be a lot of work, a new datatype hasn’t been introduced for… a long time[/quote]
What about the Half-Edge mesh datatype?

Martin[/quote]
excelent point, I had completely forgotten about it [probably because I was considering only blender releases]

Yeah, joeedh wrote a tutorial about adding a new object type too. No idea how complete it is, but it’s got to be a start:

http://wiki.blender.org/bin/view.pl/Blenderdev/ObjectType

[quote=“broken”]

Yeah, joeedh wrote a tutorial about adding a new object type too. No idea how complete it is, but it’s got to be a start:

http://wiki.blender.org/bin/view.pl/Blenderdev/ObjectType[/quote]

Wow. That is extraordinarily helpful, thank you for posting that link. :smiley:

I guess that makes it pretty easy, having blow-by-blow instructions and all.

The only bad part is that it removes any excuse I might have for not doing
the work. :wink:

One question, what does “DNA” stand for? (other than “deoxyribonucleic acid”, I mean :wink: ).

It’s Blender’s internal database system of keeping track of the info in memory and files. Here’s another link :slight_smile:

http://www.blender3d.org/cms/Notes_on_SDNA.436.0.html