How to create property rnas?


#1

I want to add a bool property for the brushes and expose it in python but I have no idea of how to make it.

seems like every boolean property follow the same pattern of setters and getters but there some misterious binary stuff that I dont quite understand.

void Brush_use_frontface_set(PointerRNA *ptr, bool value)
{
	Brush *data = (Brush *)(ptr->data);
	if (value) data->flag |= 134217728;
	else data->flag &= ~134217728;
}

Is 134217728 a binary mask or something, how to I calculate this number from the flag?


#2

That is auto-generated code, you can look at rna_brush.c and DNA_brush_types.h.

Some documentation on that is here:
https://en.blender.org/index.php/Dev:2.5/Source/Architecture/RNA


#3

I’ve tried to add a float property but it prints an error about pointer alignment, I have no idea of what I did wrong.

on rna_brush.c ive added the property definition with a copy paste, edit.

 ...
RNA_def_property_ui_text(prop, "Autosmooth", "Amount of smoothing to automatically apply to each stroke");
RNA_def_property_update(prop, 0, "rna_Brush_update");

prop = RNA_def_property(srna, "toporake_factor", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "toporake_factor");
RNA_def_property_float_default(prop, 0);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.001, 3);
RNA_def_property_ui_text(prop, "Toporake", "Automatically align dyntopo to the brush movement direction");
RNA_def_property_update(prop, 0, "rna_Brush_update");

prop = RNA_def_property(srna, "stencil_pos", PROP_FLOAT, PROP_XYZ);
RNA_def_property_float_sdna(prop, NULL, "stencil_pos");
...
...

and on DNA_brush_types.c I added float definition.

float autosmooth_factor;

float toporake_factor;

float crease_pinch_factor;

but during compile it prints this error message:

4>Align pointer error in struct (len_native 8): Brush *gpencil_settings
4>Align pointer error in struct (len_64 8): Brush *gpencil_settings
4>Sizeerror 8 in struct: Brush (add 4 bytes)

#4

See:
https://en.blender.org/index.php/Dev:Source/Architecture/SDNA_Notes


#5

Ah, thanx, I would never guess what those padding variables mean alone :slight_smile: