forked from nortikin/sverchok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_VectorNormal.py
54 lines (42 loc) · 2.12 KB
/
node_VectorNormal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import bpy, bmesh, mathutils
from mathutils import Vector, Matrix
from node_s import *
from util import *
class VectorNormalNode(Node, SverchCustomTreeNode):
''' Find Vector's normals '''
bl_idname = 'VectorNormalNode'
bl_label = 'Vector Normal'
bl_icon = 'OUTLINER_OB_EMPTY'
def init(self, context):
self.inputs.new('VerticesSocket', "Vertices", "Vertices")
self.inputs.new('StringsSocket', "Polygons", "Polygons")
self.outputs.new('VerticesSocket',"Normals","Normals")
def update(self):
# достаём два слота - вершины и полики
if 'Centers' in self.outputs and self.outputs['Centers'].links or self.outputs['Normals'].links:
if 'Polygons' in self.inputs and 'Vertices' in self.inputs and self.inputs['Polygons'].links and self.inputs['Vertices'].links:
#if type(self.inputs['Poligons'].links[0].from_socket) == StringsSocket:
pols = SvGetSocketAnyType(self,self.inputs['Polygons'])
#if type(self.inputs['Vertices'].links[0].from_socket) == VerticesSocket:
vers = SvGetSocketAnyType(self,self.inputs['Vertices'])
normalsFORout = []
for i, obj in enumerate(vers):
mesh_temp = bpy.data.meshes.new('temp')
mesh_temp.from_pydata(obj,[],pols[i])
mesh_temp.update(calc_edges=True)
tempobj = []
for v in mesh_temp.vertices:
tempobj.append(v.normal[:])
normalsFORout.append(tempobj)
bpy.data.meshes.remove(mesh_temp)
#print (normalsFORout)
if 'Normals' in self.outputs and self.outputs['Normals'].links:
SvSetSocketAnyType(self,'Normals',normalsFORout)
def update_socket(self, context):
self.update()
def register():
bpy.utils.register_class(VectorNormalNode)
def unregister():
bpy.utils.unregister_class(VectorNormalNode)
if __name__ == "__main__":
register()