forked from MaximeHerpin/modular_tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
234 lines (185 loc) · 7.3 KB
/
__init__.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
bl_info = {
"name": "Modular trees",
"author": "Herpin Maxime",
"version": (3, 0, 0),
"blender": (2, 79, 0),
"location": "View3D > Tools > Tree > Make Tree",
"description": "Create natural trees with the node editor",
"wiki_url": "https://github.com/MaximeHerpin/modular_tree/wiki",
"tracker_url": "https://github.com/MaximeHerpin/modular_tree/issues/new",
"category": "Add Mesh"}
import os
from . import addon_updater_ops
from .nodes import node_classes_to_register, node_categories, get_last_memory_match, get_tree_parameters_rec, get_change_level
from .wind import ModalWindOperator, FastWind
from .toolbar_functions import TrunkDisplacement, Twigoperator
from .color_ramp_sampler import ColorRampSampler,ColorRampPanel
import bpy
from bpy.types import Operator
from bpy.props import IntProperty, FloatProperty, EnumProperty, BoolProperty, StringProperty
import nodeitems_utils
class Preferences(bpy.types.AddonPreferences):
bl_idname = __package__
auto_check_update = bpy.props.BoolProperty(
name="Auto-check for Update",
description="If enabled, auto-check for updates using an interval",
default=True,
)
updater_intrval_months = bpy.props.IntProperty(
name='Months',
description="Number of months between checking for updates",
default=0,
min=0
)
updater_intrval_days = bpy.props.IntProperty(
name='Days',
description="Number of days between checking for updates",
default=7,
min=0,
)
updater_intrval_hours = bpy.props.IntProperty(
name='Hours',
description="Number of hours between checking for updates",
default=0,
min=0,
max=23
)
updater_intrval_minutes = bpy.props.IntProperty(
name='Minutes',
description="Number of minutes between checking for updates",
default=0,
min=0,
max=59
)
def draw(self, context):
layout = self.layout
addon_updater_ops.update_settings_ui(self, context)
class WindPanel(bpy.types.Panel):
bl_label = "Modular tree wind"
bl_idname = "mod_tree.wind_panel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_context = "objectmode"
bl_category = 'Tree'
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("mod_tree.modal_wind_operator", icon="FORCE_WIND")
row.operator("mod_tree.fast_wind", icon="FORCE_WIND")
class DetailsPanel(bpy.types.Panel):
bl_label = "Tree tools"
bl_idname = "mod_tree.details_panel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_context = "objectmode"
bl_category = 'Tree'
def draw(self, context):
layout = self.layout
layout.operator("mod_tree.bark_materials")
layout.operator("mod_tree.trunk_displace", icon="MOD_DISPLACE")
layout.operator("mod_tree.twig")
class ModalModularTreedOperator(Operator):
"""real time tree tweaking"""
bl_idname = "object.modal_tree_operator"
bl_label = "Modal Tree Operator"
_timer = None
node = None
tree = None
def modal(self, context, event):
if event.type in {'ESC'}:
self.cancel(context)
self.node.auto_update = False
return {'CANCELLED'}
if event.type == 'TIMER':
new_memory = get_tree_parameters_rec("", self.node, None)
# level = get_last_memory_match(new_memory, self.node.memory)
level = get_change_level(new_memory, self.node.memory)
if level != "unchanged":
print(level)
delete_old_tree(level)
self.node.memory = new_memory
self.tree = self.node.execute(level, self.tree)
if self.tree is None:
self.report({'ERROR'}, "Invalid Node Tree")
self.node.auto_update = False
return {'CANCELLED'}
return {'PASS_THROUGH'}
def execute(self, context):
wm = context.window_manager
self.node = bpy.context.active_node.id_data.nodes.get("BuildTree")
self._timer = wm.event_timer_add(0.1, context.window)
wm.modal_handler_add(self)
self.node.auto_update = True
delete_old_tree(level="gen")
self.tree = self.node.execute()
# self.node = bpy.context.active_node.id_data.nodes.get("BuildTree")
return {'RUNNING_MODAL'}
def cancel(self, context):
wm = context.window_manager
self.node.auto_update = False
wm.event_timer_remove(self._timer)
class MakeTreeFromNodes(Operator):
"""makes a tree from a node group"""
bl_idname = "mod_tree.tree_from_nodes"
bl_label = " Make Tree"
bl_options = {"REGISTER", "UNDO"}
node_group_name = StringProperty()
node_name = StringProperty()
def draw(self, context):
pass
def execute(self, context):
delete_old_tree()
# node = bpy.data.node_groups.get("NodeTree.002").nodes.get("BuildTree")
node = context.active_node.id_data.nodes.get("BuildTree")
tree = node.execute()
if tree is None:
self.report({'ERROR'}, "Invalid Node Tree")
node.auto_update = False
return {'CANCELLED'}
# bpy.ops.object.subdivision_set(level=1)
return {'FINISHED'}
class VisualizeWithCurves(Operator):
"""makes a tree from a node group"""
bl_idname = "mod_tree.visualize"
bl_label = " visualize Tree"
bl_options = {"REGISTER", "UNDO"}
node_group_name = StringProperty()
node_name = StringProperty()
def draw(self, context):
pass
def execute(self, context):
bpy.ops.object.delete(use_global=False)
print("tree")
print(self.node_name)
print(self.node_group_name)
node = bpy.data.node_groups.get("NodeTree.002").nodes.get("BuildTree")
node.execute()
# bpy.ops.object.subdivision_set(level=1)
return {'FINISHED'}
def delete_old_tree(level="gen"):
obj = bpy.context.object
bpy.ops.object.select_all(action='DESELECT')
if obj is not None:# and obj.select: #and obj.get("is_tree") is not None:
print(obj.select)
if level == "gen":
print("selecting")
obj.select = True
if obj.get("amt") is not None and level in {"amt", "gen"}:
amt = bpy.context.scene.objects.get(obj.get("amt"))
if amt is not None:
amt.select = True
if obj.get("emitter") is not None and level in {"emitter", "gen"}:
emitter = bpy.context.scene.objects.get(obj.get("emitter"))
if emitter is not None:
emitter.select = True
bpy.ops.object.delete(use_global=False)
def register():
addon_updater_ops.register(bl_info)
nodeitems_utils.register_node_categories("MODULAR_TREE_NODES", node_categories)
bpy.utils.register_module(__name__)
def unregister():
addon_updater_ops.unregister()
nodeitems_utils.unregister_node_categories("MODULAR_TREE_NODES")
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()