-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathblenddata_to_svdata2.py
109 lines (88 loc) · 4.01 KB
/
blenddata_to_svdata2.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
from bpy.props import BoolProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import (updateNode)
class SvObjectToMeshNodeMK2(SverchCustomTreeNode, bpy.types.Node):
'''Get Object Data'''
bl_idname = 'SvObjectToMeshNodeMK2'
bl_label = 'Object ID Out MK2'
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_OBJECT_ID_OUT'
is_animation_dependent = True
replacement_nodes = [('SvGetObjectsData',
None,
dict(VertexNormals='Vertex Normals',
PolygonAreas='Polygon Areas',
PolygonCenters='Polygon Centers',
PolygonNormals='Polygon Normals'))]
modifiers: BoolProperty(name='Modifiers', default=False, update=updateNode)
def sv_init(self, context):
self.inputs.new('SvObjectSocket', "Objects")
self.outputs.new('SvVerticesSocket', "Vertices")
self.outputs.new('SvVerticesSocket', "VertexNormals")
self.outputs.new('SvStringsSocket', "Edges")
self.outputs.new('SvStringsSocket', "Polygons")
self.outputs.new('SvStringsSocket', "PolygonAreas")
self.outputs.new('SvVerticesSocket', "PolygonCenters")
self.outputs.new('SvVerticesSocket', "PolygonNormals")
self.outputs.new('SvMatrixSocket', "Matrices")
def sv_draw_buttons(self, context, layout):
row = layout.row()
row.prop(self, "modifiers", text="Post modifiers")
def process(self):
objs = self.inputs[0].sv_get()
if isinstance(objs[0], list):
objs = objs[0]
o1,o2,o3,o4,o5,o6,o7,o8 = self.outputs
vs,vn,es,ps,pa,pc,pn,ms = [],[],[],[],[],[],[],[]
if self.modifiers:
sv_depsgraph = bpy.context.evaluated_depsgraph_get()
ot = objs[0].type in ['MESH', 'CURVE', 'FONT', 'SURFACE', 'META']
for obj in objs:
if o8.is_linked:
ms.append(obj.matrix_world)
if ot:
if self.modifiers:
obj = sv_depsgraph.objects[obj.name]
obj_data = obj.to_mesh(preserve_all_data_layers=True, depsgraph=sv_depsgraph)
else:
obj_data = obj.to_mesh()
if o1.is_linked:
vs.append([v.co[:] for v in obj_data.vertices])
if o2.is_linked:
vn.append([v.normal[:] for v in obj_data.vertices])
if o3.is_linked:
es.append(obj_data.edge_keys)
if o4.is_linked:
ps.append([p.vertices[:] for p in obj_data.polygons])
if o5.is_linked:
pa.append([p.area for p in obj_data.polygons])
if o6.is_linked:
pc.append([p.center[:] for p in obj_data.polygons])
if o7.is_linked:
pn.append([p.normal[:] for p in obj_data.polygons])
obj.to_mesh_clear()
for i,i2 in zip(self.outputs, [vs,vn,es,ps,pa,pc,pn,ms]):
if i.is_linked:
i.sv_set(i2)
def register():
bpy.utils.register_class(SvObjectToMeshNodeMK2)
def unregister():
bpy.utils.unregister_class(SvObjectToMeshNodeMK2)