Skip to content

Commit

Permalink
Fix #1941: Mesh nodes for python API changes
Browse files Browse the repository at this point in the history
Bevel weights and creases are now attributes.
OmarEmaraDev committed Jan 27, 2024
1 parent ea4e10b commit 0d9cf2d
Showing 5 changed files with 25 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

15 changes: 12 additions & 3 deletions animation_nodes/extend_bpy_types.py
Original file line number Diff line number Diff line change
@@ -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):
4 changes: 3 additions & 1 deletion animation_nodes/nodes/mesh/set_bevel_edge_weight.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion animation_nodes/nodes/mesh/set_bevel_vertex_weight.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions animation_nodes/nodes/mesh/set_edge_crease.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0d9cf2d

Please sign in to comment.