Skip to content

Commit

Permalink
Added Int2 List and socket type.
Browse files Browse the repository at this point in the history
  • Loading branch information
3DSinghVFX committed Nov 30, 2023
1 parent cb81e63 commit d132077
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion animation_nodes/data_structures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions animation_nodes/data_structures/attributes/attribute.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions animation_nodes/data_structures/lists/special_list_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
4 changes: 2 additions & 2 deletions animation_nodes/extend_bpy_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down
22 changes: 21 additions & 1 deletion animation_nodes/nodes/mesh/c_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ from ... data_structures cimport (
Mesh,
VirtualLongList,
VirtualDoubleList,
EdgeIndices
EdgeIndices,
Int2List
)

from ... math cimport (
Expand Down Expand Up @@ -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 = <unsigned int>values.data[i].v1
int2D.data[i].v2 = <unsigned int>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 = <unsigned int>values.data[i].v1
edges.data[i].v2 = <unsigned int>values.data[i].v2
return edges
2 changes: 1 addition & 1 deletion animation_nodes/nodes/mesh/get_custom_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion animation_nodes/nodes/mesh/insert_custom_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")))


Expand Down
2 changes: 1 addition & 1 deletion animation_nodes/nodes/mesh/set_custom_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
44 changes: 44 additions & 0 deletions animation_nodes/sockets/int2.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d132077

Please sign in to comment.