From 0d9cf2dc0be3b1703e5c66c4771596b8c6cf9c35 Mon Sep 17 00:00:00 2001 From: OmarEmaraDev Date: Sat, 27 Jan 2024 11:55:35 +0200 Subject: [PATCH] Fix #1941: Mesh nodes for python API changes Bevel weights and creases are now attributes. --- CHANGELOG.md | 4 ++++ animation_nodes/extend_bpy_types.py | 15 ++++++++++++--- .../nodes/mesh/set_bevel_edge_weight.py | 4 +++- .../nodes/mesh/set_bevel_vertex_weight.py | 4 +++- animation_nodes/nodes/mesh/set_edge_crease.py | 7 +++---- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4ede4f9f..23ac92710 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,10 @@ - Fixed symbol not found error on MacOS 10. - Fixed Custom Attributes for new API changes. - Fixed *Distribute Matrices* node causing superfluous executions. +- Fixed *Mesh Object Input* node for new API changes. +- Fixed *Set Vertex Weight* node for new API changes. +- Fixed *Set Edge Weight* node for new API changes. +- Fixed *Set Edge Crease* node for new API changes. ### Changed diff --git a/animation_nodes/extend_bpy_types.py b/animation_nodes/extend_bpy_types.py index 2761f057a..9c3a06116 100644 --- a/animation_nodes/extend_bpy_types.py +++ b/animation_nodes/extend_bpy_types.py @@ -95,18 +95,27 @@ def getVertexColorLayer(self, name): return vertexColors def getEdgeCreases(self): + attribute = self.mesh.attributes.get("crease_edge") + if not attribute or len(attribute.data) != len(self.mesh.edges): + return DoubleList.fromValue(0, length = len(self.mesh.edges)) edgeCreases = DoubleList(length = len(self.mesh.edges)) - self.mesh.edges.foreach_get("crease", edgeCreases.asNumpyArray()) + attribute.data.foreach_get("value", edgeCreases.asNumpyArray()) return edgeCreases def getBevelEdgeWeights(self): + attribute = self.mesh.attributes.get("bevel_weight_edge") + if not attribute or len(attribute.data) != len(self.mesh.edges): + return DoubleList.fromValue(0, length = len(self.mesh.edges)) bevelEdgeWeights = DoubleList(length = len(self.mesh.edges)) - self.mesh.edges.foreach_get("bevel_weight", bevelEdgeWeights.asNumpyArray()) + attribute.data.foreach_get("value", bevelEdgeWeights.asNumpyArray()) return bevelEdgeWeights def getBevelVertexWeights(self): + attribute = self.mesh.attributes.get("bevel_weight_vert") + if not attribute or len(attribute.data) != len(self.mesh.vertices): + return DoubleList.fromValue(0, length = len(self.mesh.vertices)) bevelVertexWeights = DoubleList(length = len(self.mesh.vertices)) - self.mesh.vertices.foreach_get("bevel_weight", bevelVertexWeights.asNumpyArray()) + attribute.data.foreach_get("value", bevelVertexWeights.asNumpyArray()) return bevelVertexWeights def getCustomAttribute(self, name): diff --git a/animation_nodes/nodes/mesh/set_bevel_edge_weight.py b/animation_nodes/nodes/mesh/set_bevel_edge_weight.py index 8236461c8..36cf3ca0d 100644 --- a/animation_nodes/nodes/mesh/set_bevel_edge_weight.py +++ b/animation_nodes/nodes/mesh/set_bevel_edge_weight.py @@ -25,7 +25,9 @@ def execute(self, object, weights): if object.mode != "OBJECT": self.raiseErrorMessage("Object is not in object mode.") + attribute = object.data.attributes.get("bevel_weight_edge") + if not attribute: attribute = object.data.attributes.new("bevel_weight_edge", "FLOAT", "EDGE") weights = VirtualDoubleList.create(weights, 0).materialize(len(object.data.edges)) - object.data.edges.foreach_set('bevel_weight', weights) + attribute.data.foreach_set('value', weights) object.data.update() return object diff --git a/animation_nodes/nodes/mesh/set_bevel_vertex_weight.py b/animation_nodes/nodes/mesh/set_bevel_vertex_weight.py index 599c4c090..f98803203 100644 --- a/animation_nodes/nodes/mesh/set_bevel_vertex_weight.py +++ b/animation_nodes/nodes/mesh/set_bevel_vertex_weight.py @@ -25,7 +25,9 @@ def execute(self, object, weights): if object.mode != "OBJECT": self.raiseErrorMessage("Object is not in object mode.") + attribute = object.data.attributes.get("bevel_weight_vert") + if not attribute: attribute = object.data.attributes.new("bevel_weight_vert", "FLOAT", "POINT") weights = VirtualDoubleList.create(weights, 0).materialize(len(object.data.vertices)) - object.data.vertices.foreach_set('bevel_weight', weights) + attribute.data.foreach_set('value', weights) object.data.update() return object diff --git a/animation_nodes/nodes/mesh/set_edge_crease.py b/animation_nodes/nodes/mesh/set_edge_crease.py index 792625024..c8fe5a2a1 100644 --- a/animation_nodes/nodes/mesh/set_edge_crease.py +++ b/animation_nodes/nodes/mesh/set_edge_crease.py @@ -24,10 +24,9 @@ def execute(self, object, creases): if object.mode != "OBJECT": self.raiseErrorMessage("Object is not in object mode.") - if not object.data.use_customdata_edge_crease: - object.data.use_customdata_edge_crease = True - + attribute = object.data.attributes.get("crease_edge") + if not attribute: attribute = object.data.attributes.new("crease_edge", "FLOAT", "EDGE") creases = VirtualDoubleList.create(creases, 0).materialize(len(object.data.edges)) - object.data.edges.foreach_set('crease', creases) + attribute.data.foreach_set('value', creases) object.data.update() return object