def configure_sca_layer(self, lower_upper_n_sca, root_center_distance, leaf_cloud_center, eden_layer_center, n_leaves, leaves_spread, growth_dist, branch_thickenss): # list to store sca objects sca_layer = [] # choose random number of SCAs n_sca = np.random.randint(lower_upper_n_sca[0], lower_upper_n_sca[1]) # generate root centers of every sca on circle around eden layer center segment = 2 * math.pi / n_sca root_centers = [] for i in range(n_sca): x = eden_layer_center[0] + math.sin( segment * i) * root_center_distance y = eden_layer_center[1] + math.cos( segment * i) * root_center_distance z = eden_layer_center[2] + 0 root_centers.append([x, y, z]) # generate leaf cloud centers leaf_centers = [] for i in range(n_sca): leaf_centers.append(leaf_cloud_center) # create objects and store for i in range(n_sca): sca_layer.append( SCA(root_centers[i], leaf_centers[i], leaves_spread, n_leaves, growth_dist, branch_thickenss)) return sca_layer
def initialize_sca_forest(self, scene): segment = 2 * np.pi / self.n_sca_trees # create bevel object for volume (ini: 0 volume) bpy.ops.curve.primitive_nurbs_circle_add() bpy.context.object.scale = (0,0,0) self.bevel_object = bpy.context.object for n in range(self.n_sca_trees): # configure sca root position xr = self.center[0] + np.cos(segment * n) * self.root_circle_radius yr = self.center[1] + np.sin(segment * n) * self.root_circle_radius zr = self.center[2] + 0 # configure sca leaf center position xl = self.center[0] + np.cos(segment * n) * self.leaf_center_radius yl = self.center[1] + np.sin(segment * n) * self.leaf_center_radius zl = self.center[2] + 0 sca = SCA(root_position=[xr,yr,zr], leaves_cloud_center=[xl, yl, zl], leaves_spread=self.leaves_spread, n_leaves=self.n_leaves, growth_dist={"min":0.5,"max":4}) # play with params # grow sca.grow() # create mesh bm = bmesh.new() for branch in sca.branches: if branch.parent == None: continue v1 = bm.verts.new(branch.position) v2 = bm.verts.new(branch.parent.position) interpolated = self.interpolate_nodes(v1, v2, 2, 0.5, bm) for i in range(len(interpolated)-1): bm.edges.new((interpolated[i], interpolated[i+1])) # add a new mesh data sca_data = bpy.data.meshes.new(self.name+str(n)+"_data") # add a new empty mesh object using the mesh data sca_object = bpy.data.objects.new(self.name+str(n)+"_object", sca_data) # make the bmesh the object's mesh # transfer bmesh data do mesh data which is connected to empty mesh object bm.to_mesh(sca_data) bm.free() # add sca object to scene, convert to curve, add bevel scene.objects.link(sca_object) sca_object.select = True bpy.context.scene.objects.active = sca_object bpy.ops.object.convert(target='CURVE') sca_object.data.bevel_object = self.bevel_object # add color material = bpy.data.materials.new(self.name+str(n)+"_material") material.diffuse_color = self.color sca_object.active_material = material # store sca_objects self.sca_forest.append(sca_object)
def initialize_sca_forest(self, scene): """ Confiure and grow the set of the SCA objects. Args: scene (Blender scene object): scene where SCA objects will be placed. Yields: list of Blender curve objects. """ segment = 2 * np.pi / self.n_sca_trees # Create bevel object for volume (ini: 0 volume). bpy.ops.curve.primitive_nurbs_circle_add() bpy.context.object.scale = (0, 0, 0) self.bevel_object = bpy.context.object # For every SCA model. for n in range(self.n_sca_trees): # Configure SCA root position. xr = self.center[0] + np.cos(segment * n) * self.root_circle_radius yr = self.center[1] + np.sin(segment * n) * self.root_circle_radius zr = self.center[2] + 0 # Configure SCA leaf center position. xl = self.center[0] + np.cos(segment * n) * self.leaf_center_radius yl = self.center[1] + np.sin(segment * n) * self.leaf_center_radius zl = self.center[2] + 0 # Configure SCA and grow. sca = SCA(root_position=[xr, yr, zr], leaves_cloud_center=[xl, yl, zl], leaves_spread=self.leaves_spread, n_leaves=self.n_leaves) sca.grow() # Create mesh. bm = bmesh.new() for branch in sca.branches: if branch.parent == None: continue v1 = bm.verts.new(branch.position) v2 = bm.verts.new(branch.parent.position) interpolated = self.__interpolate_nodes(v1, v2, 4, 0.5, bm) for i in range(len(interpolated) - 1): bm.edges.new((interpolated[i], interpolated[i + 1])) # Add a new mesh data. sca_data = bpy.data.meshes.new(self.name + str(n) + "_data") # Add a new empty mesh object using the mesh data. sca_object = bpy.data.objects.new(self.name + str(n) + "_object", sca_data) # Make the bmesh the object's mesh. # Transfer bmesh data do mesh data which is connected to empty mesh object. bm.to_mesh(sca_data) bm.free() # Add sca object to scene, convert to curve, add bevel. scene.objects.link(sca_object) sca_object.select = True bpy.context.scene.objects.active = sca_object bpy.ops.object.convert(target='CURVE') sca_object.data.bevel_object = self.bevel_object # Add color. material = bpy.data.materials.new(self.name + str(n) + "_material") material.diffuse_color = self.color sca_object.active_material = material # Store self.sca_forest.append(sca_object)
# add a new empty mesh object using the mesh data layer_mesh_object = bpy.data.objects.new("object", layer_mesh_data) # make the bmesh the object's mesh # transfer bmesh data do mesh data which is connected to empty mesh object bm.to_mesh(layer_mesh_data) bm.free() bpy.context.scene.objects.link(layer_mesh_object) sca = SCA(root_position=[0, 0, 0], leaves_cloud_center=[0, 0, 0], leaves_spread=[15, 15, 0], n_leaves=100, growth_dist={ "min": 0.5, "max": 4 }) sca.grow() bm = bmesh.new() max_r = 1 for branch in sca.branches: if branch.parent == None: continue v1 = bm.verts.new(branch.position) v2 = bm.verts.new(branch.parent.position)