-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mesh custom attributes #1931
Mesh custom attributes #1931
Conversation
I am not particularly happy that we are using EdgeIndicesList for that. We should probably add an Int2List type and a corresponding socket. Then provide implicit conversion between edges indices and this new list. We will not provide any kind of processing support, just reading of those attributes and conversion to edge indices list. |
@OmarEmaraDev Okay. So, where I can add the New Int2List type? |
It can be added in the |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a bit too complicated. Can we just create a virtual list for int2?
See the virtual_clist_types.json
file. And maybe add Int2 to math/vector.pxd
to make things easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
I would just move the conversion code to the conversion file to fix this: diff --git a/animation_nodes/data_structures/lists/special_list_types.json b/animation_nodes/data_structures/lists/special_list_types.json
index d9ad1cb4..8038a019 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 70771910..df36678f 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 b8a45c64..c8cb7b64 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
########################################################## |
This patch will fix the Custom Attributes Nodes for Blender3.6.