@@ -13,6 +13,7 @@ class TreeMesherNode(bpy.types.Node, MtreeNode):
13
13
14
14
radial_resolution : bpy .props .IntProperty (name = "Radial Resolution" , default = 32 , min = 3 , update = on_update_prop )
15
15
smoothness : bpy .props .IntProperty (name = "smoothness" , default = 4 , min = 0 , update = on_update_prop )
16
+ tree_object : bpy .props .StringProperty (default = "" )
16
17
17
18
def init (self , context ):
18
19
self .add_output ("mt_TreeSocket" , "Tree" , is_property = False )
@@ -24,19 +25,28 @@ def draw_generate(self, container):
24
25
properties .function_name = "build_tree"
25
26
26
27
28
+ def has_valid_tree_object (self ):
29
+ return bpy .context .scene .objects .get (self .tree_object , None ) is not None
30
+
31
+
27
32
def draw_properties (self , container ):
28
33
container .prop (self , "radial_resolution" )
29
34
container .prop (self , "smoothness" )
30
35
31
36
def draw_distribute_leaves (self , container ):
32
- properties = container .operator ("mtree.add_leaves" , text = "Add leaves" )
33
- properties .object_id = self .get_current_tree_object ().name
37
+ if self .has_valid_tree_object ():
38
+ properties = container .operator ("mtree.add_leaves" , text = "Add leaves" )
39
+ properties .object_id = self .get_current_tree_object ().name
40
+
41
+ def draw_current_tree_object (self , container , context ):
42
+ container .prop_search (self , property = "tree_object" , search_data = context .scene , search_property = "objects" , text = "" )
34
43
35
44
def draw (self , context , layout ):
36
45
valid_tree = self .get_tree_validity ()
37
46
generate_row = layout .row ()
38
47
generate_row .enabled = valid_tree
39
48
self .draw_generate (generate_row )
49
+ self .draw_current_tree_object (layout , context )
40
50
self .draw_properties (layout )
41
51
leaves_row = layout .row ()
42
52
leaves_row .enabled = valid_tree
@@ -60,11 +70,14 @@ def mesh_tree(self, tree):
60
70
return mesh_data
61
71
62
72
def get_current_tree_object (self ):
63
- tree_obj = bpy .context .object
73
+ tree_obj = bpy .context .scene . objects . get ( self . tree_object , None )
64
74
if tree_obj is None :
65
75
tree_mesh = bpy .data .meshes .new ('tree' )
66
76
tree_obj = bpy .data .objects .new ("tree" , tree_mesh )
67
77
bpy .context .collection .objects .link (tree_obj )
78
+ self .tree_object = tree_obj .name
79
+ bpy .context .view_layer .objects .active = tree_obj
80
+ tree_obj .select_set (True )
68
81
return tree_obj
69
82
70
83
def output_object (self , cp_mesh ):
0 commit comments