From 19984757a7a2f19be33d9ddb12d8f2aa5211b6ed Mon Sep 17 00:00:00 2001 From: 3DSinghVFX Date: Mon, 6 Nov 2023 18:29:36 +0530 Subject: [PATCH 01/13] Fix custom attributes nodes. --- .../data_structures/attributes/attribute.pxd | 1 + .../data_structures/attributes/attribute.pyx | 3 +++ animation_nodes/extend_bpy_types.py | 4 +++- .../nodes/mesh/get_custom_attribute.py | 5 ++++- .../nodes/mesh/insert_custom_attribute.py | 19 +++++++++++++++- .../nodes/mesh/mesh_object_output.py | 2 +- .../nodes/mesh/set_custom_attribute.py | 22 +++++++++++++++++-- 7 files changed, 50 insertions(+), 6 deletions(-) diff --git a/animation_nodes/data_structures/attributes/attribute.pxd b/animation_nodes/data_structures/attributes/attribute.pxd index a9779b7af..13ccfd47f 100644 --- a/animation_nodes/data_structures/attributes/attribute.pxd +++ b/animation_nodes/data_structures/attributes/attribute.pxd @@ -18,6 +18,7 @@ cpdef enum AttributeDomain: cpdef enum AttributeDataType: INT, + INT32_2D, FLOAT, FLOAT2, FLOAT_VECTOR, diff --git a/animation_nodes/data_structures/attributes/attribute.pyx b/animation_nodes/data_structures/attributes/attribute.pyx index 090b6e433..6a3054d56 100644 --- a/animation_nodes/data_structures/attributes/attribute.pyx +++ b/animation_nodes/data_structures/attributes/attribute.pyx @@ -6,10 +6,12 @@ from .. lists.base_lists cimport ( BooleanList, Vector2DList, Vector3DList, + EdgeIndicesList, ) cListFromDataType = { INT: LongList, + INT32_2D: EdgeIndicesList, FLOAT: FloatList, FLOAT2: Vector2DList, FLOAT_VECTOR: Vector3DList, @@ -38,6 +40,7 @@ stringFromDomain = { stringFromDataType = { INT: "INT", + INT32_2D: "INT32_2D", FLOAT: "FLOAT", FLOAT2: "FLOAT2", FLOAT_VECTOR: "FLOAT_VECTOR", diff --git a/animation_nodes/extend_bpy_types.py b/animation_nodes/extend_bpy_types.py index 566da47c2..9fdbbc506 100644 --- a/animation_nodes/extend_bpy_types.py +++ b/animation_nodes/extend_bpy_types.py @@ -125,6 +125,8 @@ def getCustomAttribute(self, name): data = DoubleList(length = amount) elif attribute.data_type == "INT": data = LongList(length = amount) + elif attribute.data_type == "INT32_2D": + data = EdgeIndicesList(length = amount) elif attribute.data_type == "FLOAT2": data = Vector2DList(length = amount) elif attribute.data_type == "FLOAT_VECTOR": @@ -134,7 +136,7 @@ def getCustomAttribute(self, name): else: data = BooleanList(length = amount) - if attribute.data_type in ("FLOAT", "INT", "BOOLEAN"): + if attribute.data_type in ("FLOAT", "INT", "INT32_2D", "BOOLEAN"): attribute.data.foreach_get("value", data.asNumpyArray()) elif attribute.data_type in ("FLOAT2", "FLOAT_VECTOR"): attribute.data.foreach_get("vector", data.asNumpyArray()) diff --git a/animation_nodes/nodes/mesh/get_custom_attribute.py b/animation_nodes/nodes/mesh/get_custom_attribute.py index 3fd88b7f1..244e59fcd 100644 --- a/animation_nodes/nodes/mesh/get_custom_attribute.py +++ b/animation_nodes/nodes/mesh/get_custom_attribute.py @@ -11,6 +11,7 @@ ("FLOAT_COLOR", "Color", "", "NONE", 4), ("BYTE_COLOR", "Byte Color", "", "NONE", 5), ("BOOLEAN", "Boolean", "", "NONE", 6), + ("INT32_2D", "Int32_2d", "", "NONE", 7), ] class GetCustomAttributeNode(AnimationNode, bpy.types.Node): @@ -35,8 +36,10 @@ def create(self): self.newOutput("Vector List", "Vectors", "data") elif self.dataType in ("FLOAT_COLOR", "BYTE_COLOR"): self.newOutput("Color List", "Colors", "data") - else: + elif self.dataType == "BOOLEAN": self.newOutput("Boolean List", "Values", "data") + else: + self.newOutput("Edge Indices List", "Values", "data") self.newOutput("Text", "Type", "type", hide = True) self.newOutput("Text", "Domain ", "domain", hide = True) self.newOutput("Text", "Data Type ", "dataType", hide = True) diff --git a/animation_nodes/nodes/mesh/insert_custom_attribute.py b/animation_nodes/nodes/mesh/insert_custom_attribute.py index 1057bc981..780b45610 100644 --- a/animation_nodes/nodes/mesh/insert_custom_attribute.py +++ b/animation_nodes/nodes/mesh/insert_custom_attribute.py @@ -1,9 +1,11 @@ import bpy from bpy.props import * from ... math import Vector +from . c_utils import createEdgeIndices from ... base_types import AnimationNode, VectorizedSocket from ... data_structures import ( Color, + LongList, FloatList, Attribute, AttributeType, @@ -32,6 +34,7 @@ ("FLOAT_COLOR", "Color", "", "NONE", 4), ("BYTE_COLOR", "Byte Color", "", "NONE", 5), ("BOOLEAN", "Boolean", "", "NONE", 6), + ("INT32_2D", "Int32_2d", "", "NONE", 7), ] class InsertCustomAttributeNode(AnimationNode, bpy.types.Node): @@ -65,9 +68,13 @@ def create(self): elif self.dataType in ("FLOAT_COLOR", "BYTE_COLOR"): self.newInput(VectorizedSocket("Color", "useDataList", ("Color", "data"), ("Colors", "data"))) - else: + elif self.dataType == "BOOLEAN": self.newInput(VectorizedSocket("Boolean", "useDataList", ("Value", "data"), ("Values", "data"))) + else: + self.newInput(VectorizedSocket("Edge Indices", "useDataList", + ("Value", "data"), ("Values", "data"))) + self.newOutput("Mesh", "Mesh", "mesh") @@ -89,6 +96,16 @@ def execute(self, mesh, customAttributeName, data): if self.dataType == "INT": _data = VirtualLongList.create(data, 0).materialize(amount) + elif self.dataType == "INT32_2D": + if self.useDataList: + indices1 = LongList.fromValues(data.asNumpyArray()[::2]) + indices2 = LongList.fromValues(data.asNumpyArray()[1::2]) + else: + indices1 = LongList.fromValues([data[0]]) + indices2 = LongList.fromValues([data[1]]) + _indices1 = VirtualLongList.create(indices1, 0) + _indices2 = VirtualLongList.create(indices2, 0) + _data = createEdgeIndices(amount, _indices1, _indices2) elif self.dataType == "FLOAT": _data = FloatList.fromValues(VirtualDoubleList.create(data, 0).materialize(amount)) elif self.dataType == "FLOAT2": diff --git a/animation_nodes/nodes/mesh/mesh_object_output.py b/animation_nodes/nodes/mesh/mesh_object_output.py index f31cb3d2c..a09926e78 100644 --- a/animation_nodes/nodes/mesh/mesh_object_output.py +++ b/animation_nodes/nodes/mesh/mesh_object_output.py @@ -171,7 +171,7 @@ def setMesh(self, outMesh, mesh, object): attributeOut = outMesh.attributes.new(attribute.name, dataType, domain) - if dataType in ("FLOAT", "INT", "BOOLEAN"): + if dataType in ("FLOAT", "INT", "INT32_2D", "BOOLEAN"): attributeOut.data.foreach_set("value", data.asMemoryView()) elif dataType in ("FLOAT2", "FLOAT_VECTOR"): attributeOut.data.foreach_set("vector", data.asMemoryView()) diff --git a/animation_nodes/nodes/mesh/set_custom_attribute.py b/animation_nodes/nodes/mesh/set_custom_attribute.py index f419ff4a1..181c49638 100644 --- a/animation_nodes/nodes/mesh/set_custom_attribute.py +++ b/animation_nodes/nodes/mesh/set_custom_attribute.py @@ -1,10 +1,13 @@ import bpy from bpy.props import * from ... math import Vector +from . c_utils import createEdgeIndices from ... base_types import AnimationNode, VectorizedSocket from ... data_structures import ( Color, + LongList, FloatList, + VirtualPyList, VirtualLongList, VirtualColorList, VirtualDoubleList, @@ -28,6 +31,7 @@ ("FLOAT_COLOR", "Color", "", "NONE", 4), ("BYTE_COLOR", "Byte Color", "", "NONE", 5), ("BOOLEAN", "Boolean", "", "NONE", 6), + ("INT32_2D", "Int32_2d", "", "NONE", 7), ] class SetCustomAttributeNode(AnimationNode, bpy.types.Node): @@ -61,9 +65,12 @@ def create(self): elif self.dataType in ("FLOAT_COLOR", "BYTE_COLOR"): self.newInput(VectorizedSocket("Color", "useDataList", ("Color", "data"), ("Colors", "data"))) - else: + elif self.dataType == "BOLEAN": self.newInput(VectorizedSocket("Boolean", "useDataList", ("Value", "data"), ("Values", "data"))) + else: + self.newInput(VectorizedSocket("Edge Indices", "useDataList", + ("Value", "data"), ("Values", "data"))) self.newOutput("Object", "Object", "object") @@ -94,6 +101,17 @@ def execute(self, object, customAttributeName, data): if self.dataType == "INT": _data = VirtualLongList.create(data, 0).materialize(amount) + elif self.dataType == "INT32_2D": + if self.useDataList: + indices1 = LongList.fromValues(data.asNumpyArray()[::2]) + indices2 = LongList.fromValues(data.asNumpyArray()[1::2]) + else: + indices1 = LongList.fromValues([data[0]]) + indices2 = LongList.fromValues([data[1]]) + _indices1 = VirtualLongList.create(indices1, 0) + _indices2 = VirtualLongList.create(indices2, 0) + _data = createEdgeIndices(amount, _indices1, _indices2) + _data = createEdgeIndices(amount, _indices1, _indices2) elif self.dataType == "FLOAT": _data = FloatList.fromValues(VirtualDoubleList.create(data, 0).materialize(amount)) elif attribute.data_type == "FLOAT2": @@ -105,7 +123,7 @@ def execute(self, object, customAttributeName, data): else: _data = VirtualBooleanList.create(data, False).materialize(amount) - if self.dataType in ("FLOAT", "INT", "BOOLEAN"): + if self.dataType in ("FLOAT", "INT", "INT32_2D", "BOOLEAN"): attribute.data.foreach_set("value", _data.asMemoryView()) elif self.dataType in ("FLOAT2", "FLOAT_VECTOR"): attribute.data.foreach_set("vector", _data.asMemoryView()) From b7a952ec2a1fa05b1766401d191424851291614f Mon Sep 17 00:00:00 2001 From: 3DSinghVFX Date: Mon, 6 Nov 2023 18:59:17 +0530 Subject: [PATCH 02/13] Fix the typo. --- animation_nodes/nodes/mesh/set_custom_attribute.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/animation_nodes/nodes/mesh/set_custom_attribute.py b/animation_nodes/nodes/mesh/set_custom_attribute.py index 181c49638..5b3191565 100644 --- a/animation_nodes/nodes/mesh/set_custom_attribute.py +++ b/animation_nodes/nodes/mesh/set_custom_attribute.py @@ -65,7 +65,7 @@ def create(self): elif self.dataType in ("FLOAT_COLOR", "BYTE_COLOR"): self.newInput(VectorizedSocket("Color", "useDataList", ("Color", "data"), ("Colors", "data"))) - elif self.dataType == "BOLEAN": + elif self.dataType == "BOOLEAN": self.newInput(VectorizedSocket("Boolean", "useDataList", ("Value", "data"), ("Values", "data"))) else: From d132077f0bfe07018fc1fc1e6c91c8c5d0254a24 Mon Sep 17 00:00:00 2001 From: 3DSinghVFX Date: Thu, 30 Nov 2023 16:03:16 +0530 Subject: [PATCH 03/13] Added Int2 List and socket type. --- CHANGELOG.md | 2 + animation_nodes/data_structures/__init__.py | 2 +- .../data_structures/attributes/attribute.pyx | 4 +- .../lists/special_list_types.json | 11 +++++ animation_nodes/extend_bpy_types.py | 4 +- animation_nodes/nodes/mesh/c_utils.pyx | 22 +++++++++- .../nodes/mesh/get_custom_attribute.py | 2 +- .../nodes/mesh/insert_custom_attribute.py | 2 +- .../nodes/mesh/set_custom_attribute.py | 2 +- animation_nodes/sockets/int2.py | 44 +++++++++++++++++++ 10 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 animation_nodes/sockets/int2.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 87db19502..eceb29a9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Added Container Type advanced option to object instancer node. - Added Evaluate FCurves Transforms node. - Added *Lamp Input* and *Lamp Output* nodes. +- Added *Int2* list and socket type. ### Fixed @@ -32,6 +33,7 @@ - Fixed *Set Bevel Vertex Weight* and *Set Bevel Edge Weight* nodes for API changes. - Fixed *Set Keyframe* node failing when path contains a subscript. - Fixed symbol not found error on MacOS 10. +- Fixed Custom Attributes for new API changes. ### Changed diff --git a/animation_nodes/data_structures/__init__.py b/animation_nodes/data_structures/__init__.py index 1d5587652..3b89d0b14 100644 --- a/animation_nodes/data_structures/__init__.py +++ b/animation_nodes/data_structures/__init__.py @@ -11,7 +11,7 @@ def importDataStructures(): from . lists.base_lists import ( Vector3DList, Vector2DList, Matrix4x4List, EdgeIndicesList, EulerList, ColorList, BooleanList, FloatList, DoubleList, LongList, IntegerList, UShortList, CharList, - QuaternionList, UIntegerList, ShortList, UShortList + QuaternionList, UIntegerList, ShortList, UShortList, Int2List ) from . virtual_list.virtual_list import VirtualList, VirtualPyList diff --git a/animation_nodes/data_structures/attributes/attribute.pyx b/animation_nodes/data_structures/attributes/attribute.pyx index 6a3054d56..0c5de447e 100644 --- a/animation_nodes/data_structures/attributes/attribute.pyx +++ b/animation_nodes/data_structures/attributes/attribute.pyx @@ -6,12 +6,12 @@ from .. lists.base_lists cimport ( BooleanList, Vector2DList, Vector3DList, - EdgeIndicesList, + Int2List, ) cListFromDataType = { INT: LongList, - INT32_2D: EdgeIndicesList, + INT32_2D: Int2List, FLOAT: FloatList, FLOAT2: Vector2DList, FLOAT_VECTOR: Vector3DList, diff --git a/animation_nodes/data_structures/lists/special_list_types.json b/animation_nodes/data_structures/lists/special_list_types.json index 4a3470dc9..28adebeb1 100644 --- a/animation_nodes/data_structures/lists/special_list_types.json +++ b/animation_nodes/data_structures/lists/special_list_types.json @@ -91,5 +91,16 @@ "from ... math.color cimport Color", "from ... math.conversion cimport setColor, toPyColor, toColor" ] + }, + "Int2List" : { + "Type" : "Int2", + "Buffer Type" : "unsigned int", + "Equals" : "not memcmp(&(\\1), &(\\2), sizeof(Int2))", + "Try Conversion" : "if len(value) == 2: target.v1, target.v2 = value[0], value[1]\nelse: raise TypeError(\"length has to be 2\")", + "To PyObject" : "(value.v1, value.v2)", + "Additional Methods" : "__indices_list_functions.src", + "Declarations" : [ + "cdef struct Int2:\n unsigned int v1, v2" + ] } } diff --git a/animation_nodes/extend_bpy_types.py b/animation_nodes/extend_bpy_types.py index 9fdbbc506..2761f057a 100644 --- a/animation_nodes/extend_bpy_types.py +++ b/animation_nodes/extend_bpy_types.py @@ -5,7 +5,7 @@ from . utils.depsgraph import getActiveDepsgraph from . data_structures import (Vector3DList, EdgeIndicesList, PolygonIndicesList, FloatList, UShortList, UIntegerList, Vector2DList, - ColorList, DoubleList, LongList, BooleanList) + ColorList, DoubleList, LongList, BooleanList, Int2List) def register(): bpy.types.Context.getActiveAnimationNodeTree = getActiveAnimationNodeTree @@ -126,7 +126,7 @@ def getCustomAttribute(self, name): elif attribute.data_type == "INT": data = LongList(length = amount) elif attribute.data_type == "INT32_2D": - data = EdgeIndicesList(length = amount) + data = Int2List(length = amount) elif attribute.data_type == "FLOAT2": data = Vector2DList(length = amount) elif attribute.data_type == "FLOAT_VECTOR": diff --git a/animation_nodes/nodes/mesh/c_utils.pyx b/animation_nodes/nodes/mesh/c_utils.pyx index 00f1ac3ab..c249b509d 100644 --- a/animation_nodes/nodes/mesh/c_utils.pyx +++ b/animation_nodes/nodes/mesh/c_utils.pyx @@ -17,7 +17,8 @@ from ... data_structures cimport ( Mesh, VirtualLongList, VirtualDoubleList, - EdgeIndices + EdgeIndices, + Int2List ) from ... math cimport ( @@ -707,3 +708,22 @@ def getReplicatedLoopEdges(UIntegerList loopEdges, Py_ssize_t amount, Py_ssize_t _newLoopEdges[index] = _loopEdges[j] + offset index += 1 return newLoopEdges + +# Conversion +################################### + +def convert_EdgeIndicesList_to_Int2List(EdgeIndicesList values): + cdef Py_ssize_t i + cdef Int2List int2D = Int2List(length = len(values)) + for i in range(len(values)): + int2D.data[i].v1 = values.data[i].v1 + int2D.data[i].v2 = values.data[i].v2 + return int2D + +def convert_Int2List_to_EdgeIndicesList(Int2List values): + cdef Py_ssize_t i + cdef EdgeIndicesList edges = EdgeIndicesList(length = len(values)) + for i in range(len(values)): + edges.data[i].v1 = values.data[i].v1 + edges.data[i].v2 = values.data[i].v2 + return edges diff --git a/animation_nodes/nodes/mesh/get_custom_attribute.py b/animation_nodes/nodes/mesh/get_custom_attribute.py index 244e59fcd..7fb60325f 100644 --- a/animation_nodes/nodes/mesh/get_custom_attribute.py +++ b/animation_nodes/nodes/mesh/get_custom_attribute.py @@ -39,7 +39,7 @@ def create(self): elif self.dataType == "BOOLEAN": self.newOutput("Boolean List", "Values", "data") else: - self.newOutput("Edge Indices List", "Values", "data") + self.newOutput("Int2 List", "Values", "data") self.newOutput("Text", "Type", "type", hide = True) self.newOutput("Text", "Domain ", "domain", hide = True) self.newOutput("Text", "Data Type ", "dataType", hide = True) diff --git a/animation_nodes/nodes/mesh/insert_custom_attribute.py b/animation_nodes/nodes/mesh/insert_custom_attribute.py index 780b45610..bb125c287 100644 --- a/animation_nodes/nodes/mesh/insert_custom_attribute.py +++ b/animation_nodes/nodes/mesh/insert_custom_attribute.py @@ -72,7 +72,7 @@ def create(self): self.newInput(VectorizedSocket("Boolean", "useDataList", ("Value", "data"), ("Values", "data"))) else: - self.newInput(VectorizedSocket("Edge Indices", "useDataList", + self.newInput(VectorizedSocket("Int2", "useDataList", ("Value", "data"), ("Values", "data"))) diff --git a/animation_nodes/nodes/mesh/set_custom_attribute.py b/animation_nodes/nodes/mesh/set_custom_attribute.py index 5b3191565..2d3f87e7b 100644 --- a/animation_nodes/nodes/mesh/set_custom_attribute.py +++ b/animation_nodes/nodes/mesh/set_custom_attribute.py @@ -69,7 +69,7 @@ def create(self): self.newInput(VectorizedSocket("Boolean", "useDataList", ("Value", "data"), ("Values", "data"))) else: - self.newInput(VectorizedSocket("Edge Indices", "useDataList", + self.newInput(VectorizedSocket("Int2", "useDataList", ("Value", "data"), ("Values", "data"))) self.newOutput("Object", "Object", "object") diff --git a/animation_nodes/sockets/int2.py b/animation_nodes/sockets/int2.py new file mode 100644 index 000000000..6480e1f41 --- /dev/null +++ b/animation_nodes/sockets/int2.py @@ -0,0 +1,44 @@ +import bpy +from .. data_structures import Int2List +from .. base_types import AnimationNodeSocket, CListSocket +from . implicit_conversion import registerImplicitConversion + + +class Int2Socket(bpy.types.NodeSocket, AnimationNodeSocket): + bl_idname = "an_Int2Socket" + bl_label = "Int2 Socket" + dataType = "Int2" + drawColor = (0.625, 0.7, 1.0, 1) + comparable = True + storable = True + + @classmethod + def getDefaultValue(cls): + return (0, 1) + + @classmethod + def getDefaultValueCode(cls): + return "(0, 1)" + + @classmethod + def correctValue(cls, value): + if isinstance(value, tuple) and len(value) == 2: return value, 0 + elif isinstance(value, (list, set)) and len(value) == 2: return tuple(value), 1 + else: return cls.getDefaultValue(), 2 + +registerImplicitConversion("Edge Indices", "Int2", "(value.x, value.y)") +registerImplicitConversion("Int2", "Edge Indices", "(value.x, value.y)") + +class Int2ListSocket(bpy.types.NodeSocket, CListSocket): + bl_idname = "an_Int2ListSocket" + bl_label = "Int2 List Socket" + dataType = "Int2 List" + baseType = Int2Socket + drawColor = (0.625, 0.7, 1.0, 0.5) + storable = True + comparable = False + listClass = Int2List + +from .. nodes.mesh.c_utils import convert_EdgeIndicesList_to_Int2List, convert_Int2List_to_EdgeIndicesList +registerImplicitConversion("Edge Indices List", "Int2 List", convert_EdgeIndicesList_to_Int2List) +registerImplicitConversion("Int2 List", "Edge Indices List", convert_Int2List_to_EdgeIndicesList) From 2336073ad42b7d8f889d3260cdbac0aa493f7e3c Mon Sep 17 00:00:00 2001 From: 3DSinghVFX Date: Mon, 11 Dec 2023 15:40:08 +0530 Subject: [PATCH 04/13] Add Int2 Virtual List. --- .../data_structures/lists/special_list_types.json | 6 +++--- .../data_structures/virtual_list/virtual_clist_types.json | 5 +++++ animation_nodes/math/vector.pxd | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/animation_nodes/data_structures/lists/special_list_types.json b/animation_nodes/data_structures/lists/special_list_types.json index 28adebeb1..c1327f186 100644 --- a/animation_nodes/data_structures/lists/special_list_types.json +++ b/animation_nodes/data_structures/lists/special_list_types.json @@ -94,13 +94,13 @@ }, "Int2List" : { "Type" : "Int2", - "Buffer Type" : "unsigned int", + "Buffer Type" : "int", "Equals" : "not memcmp(&(\\1), &(\\2), sizeof(Int2))", "Try Conversion" : "if len(value) == 2: target.v1, target.v2 = value[0], value[1]\nelse: raise TypeError(\"length has to be 2\")", "To PyObject" : "(value.v1, value.v2)", - "Additional Methods" : "__indices_list_functions.src", + "Additional Methods" : "", "Declarations" : [ - "cdef struct Int2:\n unsigned int v1, v2" + "cdef struct Int2:\n int v1, v2" ] } } diff --git a/animation_nodes/data_structures/virtual_list/virtual_clist_types.json b/animation_nodes/data_structures/virtual_list/virtual_clist_types.json index d88f27599..31bc8d33e 100644 --- a/animation_nodes/data_structures/virtual_list/virtual_clist_types.json +++ b/animation_nodes/data_structures/virtual_list/virtual_clist_types.json @@ -9,6 +9,11 @@ "Import" : "from ... math.vector cimport Vector2", "Return" : "Pointer" }, + "Int2List" : { + "Type" : "Int2", + "Import" : "from ... math.vector cimport Int2", + "Return" : "Pointer" + }, "Matrix4x4List" : { "Type" : "Matrix4", "Import" : "from ... math.matrix cimport Matrix4", diff --git a/animation_nodes/math/vector.pxd b/animation_nodes/math/vector.pxd index 4263ad423..32e373c0b 100644 --- a/animation_nodes/math/vector.pxd +++ b/animation_nodes/math/vector.pxd @@ -1,3 +1,6 @@ +cdef struct Int2: + int x, y + cdef struct Vector2: float x, y From cf0c095ca5eeca11476a5001ac47f3900ee7a7e9 Mon Sep 17 00:00:00 2001 From: 3DSinghVFX Date: Mon, 11 Dec 2023 17:02:18 +0530 Subject: [PATCH 05/13] Revised the code. --- animation_nodes/data_structures/lists/special_list_types.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/animation_nodes/data_structures/lists/special_list_types.json b/animation_nodes/data_structures/lists/special_list_types.json index c1327f186..d9ad1cb4a 100644 --- a/animation_nodes/data_structures/lists/special_list_types.json +++ b/animation_nodes/data_structures/lists/special_list_types.json @@ -100,7 +100,7 @@ "To PyObject" : "(value.v1, value.v2)", "Additional Methods" : "", "Declarations" : [ - "cdef struct Int2:\n int v1, v2" + "from ... math.vector cimport Int2" ] } } From 188f55f3ad17f0b3c88687c0ff5994558a0867ee Mon Sep 17 00:00:00 2001 From: 3DSinghVFX Date: Tue, 12 Dec 2023 18:45:38 +0530 Subject: [PATCH 06/13] Fix Int2 Virtual List code. --- .../data_structures/lists/special_list_types.json | 7 ++++--- animation_nodes/math/conversion.pxd | 6 +++++- animation_nodes/math/conversion.pyx | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/animation_nodes/data_structures/lists/special_list_types.json b/animation_nodes/data_structures/lists/special_list_types.json index d9ad1cb4a..8038a0191 100644 --- a/animation_nodes/data_structures/lists/special_list_types.json +++ b/animation_nodes/data_structures/lists/special_list_types.json @@ -96,11 +96,12 @@ "Type" : "Int2", "Buffer Type" : "int", "Equals" : "not memcmp(&(\\1), &(\\2), sizeof(Int2))", - "Try Conversion" : "if len(value) == 2: target.v1, target.v2 = value[0], value[1]\nelse: raise TypeError(\"length has to be 2\")", - "To PyObject" : "(value.v1, value.v2)", + "Try Conversion" : "setInt2(target, value)", + "To PyObject" : "toPyInt2(value)", "Additional Methods" : "", "Declarations" : [ - "from ... math.vector cimport Int2" + "from ... math.vector cimport Int2", + "from ... math.conversion cimport setInt2, toPyInt2" ] } } diff --git a/animation_nodes/math/conversion.pxd b/animation_nodes/math/conversion.pxd index 70771910b..df36678f8 100644 --- a/animation_nodes/math/conversion.pxd +++ b/animation_nodes/math/conversion.pxd @@ -1,7 +1,7 @@ from . color cimport Color from . euler cimport Euler3 from . quaternion cimport Quaternion -from . vector cimport Vector2, Vector3, Vector4 +from . vector cimport Vector2, Vector3, Vector4, Int2 from . matrix cimport Matrix3, Matrix4, Matrix3_or_Matrix4 cdef Matrix4 toMatrix4(value) except * @@ -22,6 +22,10 @@ cdef Vector4 toVector4(value) except * cdef setVector4(Vector4* v, value) cdef toPyVector4(Vector4* v) +cdef Int2 toInt2(value) except * +cdef setInt2(Int2* v, value) +cdef toPyInt2(Int2* v) + cdef Euler3 toEuler3(value) except * cdef setEuler3(Euler3* e, value) cdef toPyEuler3(Euler3* e) diff --git a/animation_nodes/math/conversion.pyx b/animation_nodes/math/conversion.pyx index b8a45c640..c8cb7b64a 100644 --- a/animation_nodes/math/conversion.pyx +++ b/animation_nodes/math/conversion.pyx @@ -52,6 +52,20 @@ cdef setVector4(Vector4* v, value): cdef toPyVector4(Vector4* v): return Vector((v.x, v.y, v.z, v.w)) +cdef Int2 toInt2(value) except *: + cdef Int2 v + setInt2(&v, value) + return v + +cdef setInt2(Int2* v, value): + if len(value) != 2: + raise TypeError("element is not a 2D integer vector") + v.x = value[0] + v.y = value[1] + +cdef toPyInt2(Int2* v): + return (v.x, v.y) + # Matrices ########################################################## From 040aa3181d338f540a3963d1abd1e54c824d7a25 Mon Sep 17 00:00:00 2001 From: 3DSinghVFX Date: Tue, 12 Dec 2023 20:36:00 +0530 Subject: [PATCH 07/13] Revised the code. --- animation_nodes/data_structures/__init__.py | 2 +- .../nodes/mesh/insert_custom_attribute.py | 12 ++---------- animation_nodes/nodes/mesh/set_custom_attribute.py | 14 ++------------ animation_nodes/sockets/int2.py | 4 ++-- 4 files changed, 7 insertions(+), 25 deletions(-) diff --git a/animation_nodes/data_structures/__init__.py b/animation_nodes/data_structures/__init__.py index 3b89d0b14..d24e9f644 100644 --- a/animation_nodes/data_structures/__init__.py +++ b/animation_nodes/data_structures/__init__.py @@ -18,7 +18,7 @@ def importDataStructures(): from . virtual_list.virtual_clists import ( VirtualVector3DList, VirtualMatrix4x4List, VirtualEulerList, VirtualBooleanList, VirtualFloatList, VirtualDoubleList, VirtualLongList, VirtualColorList, - VirtualVector2DList, VirtualQuaternionList + VirtualVector2DList, VirtualQuaternionList, VirtualInt2List ) from . splines.base_spline import Spline diff --git a/animation_nodes/nodes/mesh/insert_custom_attribute.py b/animation_nodes/nodes/mesh/insert_custom_attribute.py index bb125c287..402e8bdf2 100644 --- a/animation_nodes/nodes/mesh/insert_custom_attribute.py +++ b/animation_nodes/nodes/mesh/insert_custom_attribute.py @@ -5,11 +5,11 @@ from ... base_types import AnimationNode, VectorizedSocket from ... data_structures import ( Color, - LongList, FloatList, Attribute, AttributeType, AttributeDomain, + VirtualInt2List, VirtualLongList, VirtualColorList, AttributeDataType, @@ -97,15 +97,7 @@ def execute(self, mesh, customAttributeName, data): if self.dataType == "INT": _data = VirtualLongList.create(data, 0).materialize(amount) elif self.dataType == "INT32_2D": - if self.useDataList: - indices1 = LongList.fromValues(data.asNumpyArray()[::2]) - indices2 = LongList.fromValues(data.asNumpyArray()[1::2]) - else: - indices1 = LongList.fromValues([data[0]]) - indices2 = LongList.fromValues([data[1]]) - _indices1 = VirtualLongList.create(indices1, 0) - _indices2 = VirtualLongList.create(indices2, 0) - _data = createEdgeIndices(amount, _indices1, _indices2) + _data = VirtualInt2List.create(data, (0, 0)).materialize(amount) elif self.dataType == "FLOAT": _data = FloatList.fromValues(VirtualDoubleList.create(data, 0).materialize(amount)) elif self.dataType == "FLOAT2": diff --git a/animation_nodes/nodes/mesh/set_custom_attribute.py b/animation_nodes/nodes/mesh/set_custom_attribute.py index 2d3f87e7b..59eb3b997 100644 --- a/animation_nodes/nodes/mesh/set_custom_attribute.py +++ b/animation_nodes/nodes/mesh/set_custom_attribute.py @@ -5,9 +5,8 @@ from ... base_types import AnimationNode, VectorizedSocket from ... data_structures import ( Color, - LongList, FloatList, - VirtualPyList, + VirtualInt2List, VirtualLongList, VirtualColorList, VirtualDoubleList, @@ -102,16 +101,7 @@ def execute(self, object, customAttributeName, data): if self.dataType == "INT": _data = VirtualLongList.create(data, 0).materialize(amount) elif self.dataType == "INT32_2D": - if self.useDataList: - indices1 = LongList.fromValues(data.asNumpyArray()[::2]) - indices2 = LongList.fromValues(data.asNumpyArray()[1::2]) - else: - indices1 = LongList.fromValues([data[0]]) - indices2 = LongList.fromValues([data[1]]) - _indices1 = VirtualLongList.create(indices1, 0) - _indices2 = VirtualLongList.create(indices2, 0) - _data = createEdgeIndices(amount, _indices1, _indices2) - _data = createEdgeIndices(amount, _indices1, _indices2) + _data = VirtualInt2List.create(data, (0, 0)).materialize(amount) elif self.dataType == "FLOAT": _data = FloatList.fromValues(VirtualDoubleList.create(data, 0).materialize(amount)) elif attribute.data_type == "FLOAT2": diff --git a/animation_nodes/sockets/int2.py b/animation_nodes/sockets/int2.py index 6480e1f41..fbe00792a 100644 --- a/animation_nodes/sockets/int2.py +++ b/animation_nodes/sockets/int2.py @@ -8,7 +8,7 @@ class Int2Socket(bpy.types.NodeSocket, AnimationNodeSocket): bl_idname = "an_Int2Socket" bl_label = "Int2 Socket" dataType = "Int2" - drawColor = (0.625, 0.7, 1.0, 1) + drawColor = (0.35, 0.7, 1.0, 1) comparable = True storable = True @@ -34,7 +34,7 @@ class Int2ListSocket(bpy.types.NodeSocket, CListSocket): bl_label = "Int2 List Socket" dataType = "Int2 List" baseType = Int2Socket - drawColor = (0.625, 0.7, 1.0, 0.5) + drawColor = (0.35, 0.7, 1.0, 0.5) storable = True comparable = False listClass = Int2List From bb52b379f590f87555336051e7dc97da18383b0f Mon Sep 17 00:00:00 2001 From: 3DSinghVFX Date: Wed, 13 Dec 2023 12:10:56 +0530 Subject: [PATCH 08/13] Cleanup. --- animation_nodes/nodes/mesh/insert_custom_attribute.py | 1 - animation_nodes/nodes/mesh/set_custom_attribute.py | 1 - 2 files changed, 2 deletions(-) diff --git a/animation_nodes/nodes/mesh/insert_custom_attribute.py b/animation_nodes/nodes/mesh/insert_custom_attribute.py index 402e8bdf2..626cb321b 100644 --- a/animation_nodes/nodes/mesh/insert_custom_attribute.py +++ b/animation_nodes/nodes/mesh/insert_custom_attribute.py @@ -1,7 +1,6 @@ import bpy from bpy.props import * from ... math import Vector -from . c_utils import createEdgeIndices from ... base_types import AnimationNode, VectorizedSocket from ... data_structures import ( Color, diff --git a/animation_nodes/nodes/mesh/set_custom_attribute.py b/animation_nodes/nodes/mesh/set_custom_attribute.py index 59eb3b997..d5f861713 100644 --- a/animation_nodes/nodes/mesh/set_custom_attribute.py +++ b/animation_nodes/nodes/mesh/set_custom_attribute.py @@ -1,7 +1,6 @@ import bpy from bpy.props import * from ... math import Vector -from . c_utils import createEdgeIndices from ... base_types import AnimationNode, VectorizedSocket from ... data_structures import ( Color, From a74151a1f315486b840751ca1360ab56a47b5400 Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Sat, 23 Dec 2023 15:16:53 +0200 Subject: [PATCH 09/13] Add property to socket and rename to Integer 2D --- animation_nodes/sockets/int2.py | 44 -------------------- animation_nodes/sockets/integer2d.py | 60 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 44 deletions(-) delete mode 100644 animation_nodes/sockets/int2.py create mode 100644 animation_nodes/sockets/integer2d.py diff --git a/animation_nodes/sockets/int2.py b/animation_nodes/sockets/int2.py deleted file mode 100644 index fbe00792a..000000000 --- a/animation_nodes/sockets/int2.py +++ /dev/null @@ -1,44 +0,0 @@ -import bpy -from .. data_structures import Int2List -from .. base_types import AnimationNodeSocket, CListSocket -from . implicit_conversion import registerImplicitConversion - - -class Int2Socket(bpy.types.NodeSocket, AnimationNodeSocket): - bl_idname = "an_Int2Socket" - bl_label = "Int2 Socket" - dataType = "Int2" - drawColor = (0.35, 0.7, 1.0, 1) - comparable = True - storable = True - - @classmethod - def getDefaultValue(cls): - return (0, 1) - - @classmethod - def getDefaultValueCode(cls): - return "(0, 1)" - - @classmethod - def correctValue(cls, value): - if isinstance(value, tuple) and len(value) == 2: return value, 0 - elif isinstance(value, (list, set)) and len(value) == 2: return tuple(value), 1 - else: return cls.getDefaultValue(), 2 - -registerImplicitConversion("Edge Indices", "Int2", "(value.x, value.y)") -registerImplicitConversion("Int2", "Edge Indices", "(value.x, value.y)") - -class Int2ListSocket(bpy.types.NodeSocket, CListSocket): - bl_idname = "an_Int2ListSocket" - bl_label = "Int2 List Socket" - dataType = "Int2 List" - baseType = Int2Socket - drawColor = (0.35, 0.7, 1.0, 0.5) - storable = True - comparable = False - listClass = Int2List - -from .. nodes.mesh.c_utils import convert_EdgeIndicesList_to_Int2List, convert_Int2List_to_EdgeIndicesList -registerImplicitConversion("Edge Indices List", "Int2 List", convert_EdgeIndicesList_to_Int2List) -registerImplicitConversion("Int2 List", "Edge Indices List", convert_Int2List_to_EdgeIndicesList) diff --git a/animation_nodes/sockets/integer2d.py b/animation_nodes/sockets/integer2d.py new file mode 100644 index 000000000..3725099ee --- /dev/null +++ b/animation_nodes/sockets/integer2d.py @@ -0,0 +1,60 @@ +import bpy +from bpy.props import * +from .. events import propertyChanged +from .. data_structures import Int2List +from .. base_types import AnimationNodeSocket, CListSocket +from . implicit_conversion import registerImplicitConversion + + +class Integer2DSocket(bpy.types.NodeSocket, AnimationNodeSocket): + bl_idname = "an_Integer2DSocket" + bl_label = "Integer 2D Socket" + dataType = "Integer 2D" + drawColor = (0.35, 0.7, 1.0, 1) + comparable = True + storable = True + + value: IntVectorProperty(default = [0, 0], size = 2, update = propertyChanged, subtype = "XYZ") + + def drawProperty(self, layout, text, node): + col = layout.column(align = True) + if text != "": col.label(text = text) + col.prop(self, "value", index = 0, text = "X") + col.prop(self, "value", index = 1, text = "Y") + + def getValue(self): + return tuple(self.value) + + def setProperty(self, data): + self.value = data + + @classmethod + def getDefaultValue(cls): + return (0, 0) + + @classmethod + def getDefaultValueCode(cls): + return "(0, 0)" + + @classmethod + def correctValue(cls, value): + if isinstance(value, tuple) and len(value) == 2: return value, 0 + elif isinstance(value, (list, set)) and len(value) == 2: return tuple(value), 1 + else: return cls.getDefaultValue(), 2 + +registerImplicitConversion("Edge Indices", "Integer 2D", "value") +registerImplicitConversion("Integer 2D", "Edge Indices", "value") + +class Integer2DListSocket(bpy.types.NodeSocket, CListSocket): + bl_idname = "an_Integer2DListSocket" + bl_label = "Integer 2D List Socket" + dataType = "Integer 2D List" + baseType = Integer2DSocket + drawColor = (0.35, 0.7, 1.0, 0.5) + storable = True + comparable = False + listClass = Int2List + +from .. nodes.mesh.c_utils import convert_EdgeIndicesList_to_Int2List, convert_Int2List_to_EdgeIndicesList +registerImplicitConversion("Edge Indices List", "Integer 2D List", convert_EdgeIndicesList_to_Int2List) +registerImplicitConversion("Integer 2D List", "Edge Indices List", convert_Int2List_to_EdgeIndicesList) From 459ae8227c76f14c0c175053f5dd31bd3acb37e4 Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Sat, 23 Dec 2023 15:18:06 +0200 Subject: [PATCH 10/13] Fix wrong implicit conversion --- animation_nodes/nodes/mesh/c_utils.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/animation_nodes/nodes/mesh/c_utils.pyx b/animation_nodes/nodes/mesh/c_utils.pyx index c249b509d..c91d0fc0e 100644 --- a/animation_nodes/nodes/mesh/c_utils.pyx +++ b/animation_nodes/nodes/mesh/c_utils.pyx @@ -716,14 +716,14 @@ def convert_EdgeIndicesList_to_Int2List(EdgeIndicesList values): cdef Py_ssize_t i cdef Int2List int2D = Int2List(length = len(values)) for i in range(len(values)): - int2D.data[i].v1 = values.data[i].v1 - int2D.data[i].v2 = values.data[i].v2 + int2D.data[i].x = values.data[i].v1 + int2D.data[i].y = values.data[i].v2 return int2D def convert_Int2List_to_EdgeIndicesList(Int2List values): cdef Py_ssize_t i cdef EdgeIndicesList edges = EdgeIndicesList(length = len(values)) for i in range(len(values)): - edges.data[i].v1 = values.data[i].v1 - edges.data[i].v2 = values.data[i].v2 + edges.data[i].v1 = values.data[i].x + edges.data[i].v2 = values.data[i].y return edges From 730caf3aaacd81d39135054b37f188f33f9abd9e Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Sat, 23 Dec 2023 15:23:33 +0200 Subject: [PATCH 11/13] Update sockets in node --- animation_nodes/nodes/mesh/get_custom_attribute.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/animation_nodes/nodes/mesh/get_custom_attribute.py b/animation_nodes/nodes/mesh/get_custom_attribute.py index 7fb60325f..a2cc9d5bd 100644 --- a/animation_nodes/nodes/mesh/get_custom_attribute.py +++ b/animation_nodes/nodes/mesh/get_custom_attribute.py @@ -11,7 +11,7 @@ ("FLOAT_COLOR", "Color", "", "NONE", 4), ("BYTE_COLOR", "Byte Color", "", "NONE", 5), ("BOOLEAN", "Boolean", "", "NONE", 6), - ("INT32_2D", "Int32_2d", "", "NONE", 7), + ("INT32_2D", "Integer 2D", "", "NONE", 7), ] class GetCustomAttributeNode(AnimationNode, bpy.types.Node): @@ -39,7 +39,7 @@ def create(self): elif self.dataType == "BOOLEAN": self.newOutput("Boolean List", "Values", "data") else: - self.newOutput("Int2 List", "Values", "data") + self.newOutput("Integer 2D List", "Values", "data") self.newOutput("Text", "Type", "type", hide = True) self.newOutput("Text", "Domain ", "domain", hide = True) self.newOutput("Text", "Data Type ", "dataType", hide = True) From 99b457dbfb37bf2818abd22068aa60ee0f5772f4 Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Sat, 23 Dec 2023 15:25:04 +0200 Subject: [PATCH 12/13] Update set node sockets --- animation_nodes/nodes/mesh/set_custom_attribute.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/animation_nodes/nodes/mesh/set_custom_attribute.py b/animation_nodes/nodes/mesh/set_custom_attribute.py index d5f861713..8e3388fe1 100644 --- a/animation_nodes/nodes/mesh/set_custom_attribute.py +++ b/animation_nodes/nodes/mesh/set_custom_attribute.py @@ -29,7 +29,7 @@ ("FLOAT_COLOR", "Color", "", "NONE", 4), ("BYTE_COLOR", "Byte Color", "", "NONE", 5), ("BOOLEAN", "Boolean", "", "NONE", 6), - ("INT32_2D", "Int32_2d", "", "NONE", 7), + ("INT32_2D", "Integer 2D", "", "NONE", 7), ] class SetCustomAttributeNode(AnimationNode, bpy.types.Node): @@ -67,7 +67,7 @@ def create(self): self.newInput(VectorizedSocket("Boolean", "useDataList", ("Value", "data"), ("Values", "data"))) else: - self.newInput(VectorizedSocket("Int2", "useDataList", + self.newInput(VectorizedSocket("Integer 2D", "useDataList", ("Value", "data"), ("Values", "data"))) self.newOutput("Object", "Object", "object") From 59cadd0230a879f03ff670b8b1ac3db49b2368b8 Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Sat, 23 Dec 2023 15:29:57 +0200 Subject: [PATCH 13/13] Update insert node sockets --- animation_nodes/nodes/mesh/insert_custom_attribute.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/animation_nodes/nodes/mesh/insert_custom_attribute.py b/animation_nodes/nodes/mesh/insert_custom_attribute.py index 626cb321b..7dc9ef1ab 100644 --- a/animation_nodes/nodes/mesh/insert_custom_attribute.py +++ b/animation_nodes/nodes/mesh/insert_custom_attribute.py @@ -33,7 +33,7 @@ ("FLOAT_COLOR", "Color", "", "NONE", 4), ("BYTE_COLOR", "Byte Color", "", "NONE", 5), ("BOOLEAN", "Boolean", "", "NONE", 6), - ("INT32_2D", "Int32_2d", "", "NONE", 7), + ("INT32_2D", "Integer 2D", "", "NONE", 7), ] class InsertCustomAttributeNode(AnimationNode, bpy.types.Node): @@ -71,7 +71,7 @@ def create(self): self.newInput(VectorizedSocket("Boolean", "useDataList", ("Value", "data"), ("Values", "data"))) else: - self.newInput(VectorizedSocket("Int2", "useDataList", + self.newInput(VectorizedSocket("Integer 2D", "useDataList", ("Value", "data"), ("Values", "data")))