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:
Falk David 2024-10-21 14:10:32 +02:00 • committed by Falk David
parent d92ee66889
commit b05e9f7bd6
2 changed files with 42 additions and 15 deletions

View file

@ -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):
"""