Fix #127523: Missing update when updating positions with Python
The issue was that the strokes were not using the `POLY` type and needed to be tagged. This adds a function `tag_positions_changed` on the `GreasePencilDrawing` so that the high-level python API can tag the positions if the `point.position` attibute is written to. Pull Request: https://projects.blender.org/blender/blender/pulls/129292
This commit is contained in:
@@ -123,8 +123,6 @@ def DefAttributeGetterSetters(attributes_list):
|
||||
# Define the list of attributes that should be exposed as read/write properties on the class.
|
||||
@DefAttributeGetterSetters([
|
||||
# Property Name, Attribute Name, Type, Default Value, Doc-string.
|
||||
("position", "position", 'FLOAT_VECTOR', (0.0, 0.0, 0.0),
|
||||
"The position of the point (in local space)."),
|
||||
("radius", "radius", 'FLOAT', 0.01, "The radius of the point."),
|
||||
("opacity", "opacity", 'FLOAT', 0.0, "The opacity of the point."),
|
||||
("vertex_color", "vertex_color", 'FLOAT_COLOR', (0.0, 0.0, 0.0, 0.0),
|
||||
@@ -138,13 +136,32 @@ class GreasePencilStrokePoint(AttributeGetterSetter):
|
||||
"""
|
||||
A helper class to get access to stroke point data.
|
||||
"""
|
||||
__slots__ = ("_curve_index", "_point_index")
|
||||
__slots__ = ("_drawing", "_curve_index", "_point_index")
|
||||
|
||||
def __init__(self, drawing, curve_index, point_index):
|
||||
super().__init__(drawing.attributes, point_index, 'POINT')
|
||||
self._drawing = drawing
|
||||
self._curve_index = curve_index
|
||||
self._point_index = point_index
|
||||
|
||||
@property
|
||||
def position(self):
|
||||
"""
|
||||
The position of the point (in local space).
|
||||
"""
|
||||
if attribute := self._attributes.get("position"):
|
||||
return attribute.data[self._point_index].vector
|
||||
# Position attribute should always exist, but return default just in case.
|
||||
return (0.0, 0.0, 0.0)
|
||||
|
||||
@position.setter
|
||||
def position(self, value):
|
||||
# Position attribute should always exist
|
||||
if attribute := self._attributes.get("position"):
|
||||
attribute.data[self._point_index].vector = value
|
||||
# Tag the positions of the drawing.
|
||||
self._drawing.tag_positions_changed()
|
||||
|
||||
@property
|
||||
def select(self):
|
||||
"""
|
||||
|
||||
@@ -107,6 +107,11 @@ static void rna_GreasePencilDrawing_resize_curves(ID *grease_pencil_id,
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_GreasePencilDrawing_tag_positions_changed(GreasePencilDrawing *drawing_ptr)
|
||||
{
|
||||
drawing_ptr->wrap().tag_positions_changed();
|
||||
}
|
||||
|
||||
static GreasePencilFrame *rna_Frames_frame_new(ID *id,
|
||||
GreasePencilLayer *layer_in,
|
||||
ReportList *reports,
|
||||
@@ -484,6 +489,11 @@ void RNA_api_grease_pencil_drawing(StructRNA *srna)
|
||||
0,
|
||||
10000);
|
||||
RNA_def_parameter_flags(parm, PROP_DYNAMIC, ParameterFlag(0));
|
||||
|
||||
func = RNA_def_function(
|
||||
srna, "tag_positions_changed", "rna_GreasePencilDrawing_tag_positions_changed");
|
||||
RNA_def_function_ui_description(
|
||||
func, "Indicate that the positions of points in the drawing have changed");
|
||||
}
|
||||
|
||||
void RNA_api_grease_pencil_frames(StructRNA *srna)
|
||||
@@ -677,12 +687,12 @@ void RNA_api_grease_pencil_layer_groups(StructRNA *srna)
|
||||
parm = RNA_def_string(
|
||||
func, "name", "GreasePencilLayerGroup", MAX_NAME, "Name", "Name of the layer group");
|
||||
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
|
||||
parm = RNA_def_pointer(
|
||||
func,
|
||||
"parent_group",
|
||||
"GreasePencilLayerGroup",
|
||||
"",
|
||||
"The parent layer group the new group will be created in (use None for the main stack)");
|
||||
parm = RNA_def_pointer(func,
|
||||
"parent_group",
|
||||
"GreasePencilLayerGroup",
|
||||
"",
|
||||
"The parent layer group the new group will be created in (use None "
|
||||
"for the main stack)");
|
||||
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_RNAPTR);
|
||||
parm = RNA_def_pointer(
|
||||
func, "layer_group", "GreasePencilLayerGroup", "", "The newly created layer group");
|
||||
@@ -735,12 +745,12 @@ void RNA_api_grease_pencil_layer_groups(StructRNA *srna)
|
||||
func, "layer_group", "GreasePencilLayerGroup", "", "The layer group to move");
|
||||
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
|
||||
RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, ParameterFlag(0));
|
||||
parm = RNA_def_pointer(
|
||||
func,
|
||||
"parent_group",
|
||||
"GreasePencilLayerGroup",
|
||||
"",
|
||||
"The parent layer group the layer group will be moved into (use None for the main stack)");
|
||||
parm = RNA_def_pointer(func,
|
||||
"parent_group",
|
||||
"GreasePencilLayerGroup",
|
||||
"",
|
||||
"The parent layer group the layer group will be moved into (use "
|
||||
"None for the main stack)");
|
||||
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED | PARM_RNAPTR);
|
||||
RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, ParameterFlag(0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user