I'm building a Blender (2.75) plugin for our 3D engine (https://github.com/aerys/minko). So far so good.
One of the things I'd like to do is to mimic Unity's feature that scripts can be directly added to scene nodes in the editor. Such scripts properties can then be edited directly through a dynamic property inspector built by parsing the script public members.
I've already done what I think is the worst part: using libclang and the python bindings to parse my C++ headers and retrieve a list of the public properties (each property being a public getter/setter pair). I can use this list to generate a list of Blender properties like so:
def get_properties(self):
if not self._props:
c = self._get_minko_script_classes(self._clangSource.cursor)
setters = self._get_class_setters(c[0])
self._props = {}
for name, set_type in setters.items():
if set_type == 'bool':
self._props[name] = bpy.props.BoolProperty(name=name)
elif set_type == 'int':
self._props[name] = bpy.props.IntProperty(name=name)
elif set_type == 'minko::math::ivec2':
self._props[name] = bpy.props.IntVectorProperty(name=name, size=2)
elif set_type == 'minko::math::ivec3':
self._props[name] = bpy.props.IntVectorProperty(name=name, size=3)
elif set_type == 'minko::math::ivec4':
self._props[name] = bpy.props.IntVectorProperty(name=name, size=4)
elif set_type == 'float':
self._props[name] = bpy.props.FloatProperty(name=name)
elif set_type == 'minko::math::vec2':
self._props[name] = bpy.props.FloatVectorProperty(name=name, size=2)
elif set_type == 'minko::math::vec3':
self._props[name] = bpy.props.FloatVectorProperty(name=name, size=3)
elif set_type == 'minko::math::vec4':
self._props[name] = bpy.props.FloatVectorProperty(name=name, size=4)
elif set_type == 'std::string':
self._props[name] = bpy.props.StringProperty(name=name)
return self._props
Now I want to display those properties (self._props) in a panel. But Blender examples are all about "static" property definition, declaring properties as class members... I guess Python would let me create dynamic classes definitions. But it sounds hacky.
So my question is: how to pass this list of Blender *Property to the UI to display it properly in a Blender friendly way?
Thank you,
set_type
) repeatable? Are they globals, or may individual objects use any and any amount of these properties?bpy.props
properties need to registered globally, e.g. onbpy.types.Scene
, and will be available on every instance. For individual properties, ID props should be used instead, but there's not as much control UI-wise over them compared tobpy.props
. $\endgroup$minko::math::ivec4
for instance per object (which would translate tobpy.props.CollectionProperty
). It seems like you would need one property group class for every object, because they are all different. I would actually try to use ID properties instead, as they are much more suitable. $\endgroup$