Adding a custom object type

I haven’t used Blender much in months and came back to see 2.6 stable. The amount of information on all the Python stuff available to do is overwhelming!

I’m trying to use Blender as a kind of level editor. The idea is I’d load up the level mesh and place my own particular entities and such around in it and manipulate them. I think I can see how I’d get the GUI components up from the snippets guides. Where I am puzzled is in how I could add a custom type to show in the UI.

I see it something like this. I’d like my entities to be represented basically like boxes, and I’d rather these raw boxes didn’t get saved with the level data itself. Instead, I want to save them off elsewhere. What is the most direct approach to take here?

Can you be a little more specific?

I don’t know whether to recommend appending to the Shift+a > Mesh menu, using Linking/proxies, putting each object in its own .blend so you can see thumbnails as you browse, a custom Addon subpanel, or what. Maybe the answer is to wait on Mango’s Asset Management improvements?


My level mesh would be in a .blend file and manipulated like a mesh generally. In the editor I would want to, say, place a monster. For that I wanted to place something representing my monster entity, with GUI components to manipulate its attributes. To physically represent the entity in space, I wanted to make it look like a cube. However, I don’t want Blender to treat it like any old mesh. It shouldn’t save it to the .blend file and the bulk of mesh manipulation operations shouldn’t work. Just about the only thing that should work is translating its position and perhaps rotating it.

So I was hoping there was a way to add a custom object type that was movable and rotatable, add my properties to it, and be able to get some hotkeys and menus set up for it. Generally it looks like all the GUI stuff is possible, but I don’t know how to approach the custom object itself.

Edit: Note that I’d prefer the new object to save with the .blend file, but when I wanted to export it, I hoped there wouldn’t be a bunch of cubes all over the place leftover from my entity representation.

The closet to a dummy starter object I could get was:

testobj = bpy.context.object

Which creates an empty object. I had hoped though I could see an object as basically a cube, select it by clicking on it, and be able to move it around using anything like normal Blender stuff. So from an interactivity viewpoint, just a movable cube. But when saving/exporting, it wouldn’t save as a mesh.

I’m wondering if this isn’t possible and I have to consider some things:

  1. Maybe just using mesh after all, but defaulting my objects to a special layer. I don’t know how exporters handle that.
  2. Just finding something in the game engine side of things I could override to represent my own entities.

I’m messing around with both.

I’ve looked up enough stuff to see some notes about how this can’t be done as comfortably in Blender as I had first hoped. My idea of entities is different from Quakes in a specific sense, but the same from a perspective of representing them in the editor. It looks like people just plop out specially-marked cubes and take some pains to make sure they don’t get included in the level mesh data. So I guess I’ll focus myself that way. I wonder if there are built-in ways to have any old exporter know to ignore certain meshes. Like, if I suppress a layer, can I expect an exporter not to export them? I assume not, and that I’ll probably have to toy with my exporters of choice myself.

Lamps are currently the only type of object that export correctly as entities. Whilst we can use an “Empty” or similar item to aid marking up a map, on export these types of objects and any resulting entity layouts are typically ignored or not properly converted. The only option then is to fall back on what we know can be exported, meshes. Here we can use a simple collection of objects in Blender, colour-coded and sized to represent the various entity types available - “info_”, “ammo_”, “target_” etc., as “placeholders” which can be swapped out at a later stage in the level editor. Generally speaking it’s highly recommended some form of entity layout is done in Blender whilst a level is being built as it’s often easier to get an immediate sense of placement and how doing so affects a levels construction as opposed to puzzling about it after-the-fact.

I figured I’d at least post that for anybody else pondering the same thing.