-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeshifier.py
74 lines (43 loc) · 2.27 KB
/
Meshifier.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
import bpy, sys
from numpy import number
moduleParentName = '.'.join(__name__.split('.')[:-1])
Types = sys.modules[moduleParentName + '.Constants'].Types
objectProperties = sys.modules[moduleParentName + '.Constants'].objectProperties
Keywords = sys.modules[moduleParentName + '.Constants'].Keywords
GCodeReader = sys.modules[moduleParentName + '.GCodeReader']
ExtruderErrorCreator = sys.modules[moduleParentName + '.ExtruderErrorCreator']
def convertToMesh(curveOB):
deg = bpy.context.evaluated_depsgraph_get()
appliedMatrixWorld = curveOB.matrix_world.copy()
meshData = bpy.data.meshes.new_from_object(curveOB.evaluated_get(deg))
newObj = bpy.data.objects.new(curveOB.name+"_mesh", meshData)
newObj.matrix_world = appliedMatrixWorld
curveOB.users_collection[0].objects.link(newObj)
for attr in curveOB.keys():
if (attr in objectProperties):
newObj[attr] = curveOB[attr]
return newObj
def meshify(collection):
allObjects = list(collection.all_objects)
totalObjects = len(allObjects)
processedObjects = 0
for obj in bpy.context.selected_objects:
obj.select_set(False)
for curveOB in allObjects:
if (curveOB and curveOB.type == "CURVE" and curveOB["type"] == Types.endPoint):
appliedMatrixWorld = curveOB.matrix_world.copy()
for d in curveOB.animation_data.drivers:
if (d.data_path == 'constraints["Follow Path"].offset_factor'):
curveOB.animation_data.drivers.remove(d)
for c in curveOB.constraints:
curveOB.constraints.remove(c)
curveOB.matrix_world = appliedMatrixWorld
if (curveOB and curveOB.type == "CURVE" and curveOB["type"] != Types.endPoint):
curveOB.modifiers.get('split').show_viewport = True
curveOB.data.resolution_u = curveOB.data.render_resolution_u
processedObjects = processedObjects + 1
print("Prepropcessing for meshify done: {}/{}".format(processedObjects, totalObjects), end='\r', flush=True)
curveOB.select_set(True)
print("\nRunning Convert To Mesh Operation")
bpy.context.view_layer.objects.active = allObjects[0]
bpy.ops.object.convert(target="MESH")