Skip to content

Instantly share code, notes, and snippets.

@aokcubcg
Created November 6, 2022 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aokcubcg/4a138b0fbeb3347f9bcaa08f2529017a to your computer and use it in GitHub Desktop.
Save aokcubcg/4a138b0fbeb3347f9bcaa08f2529017a to your computer and use it in GitHub Desktop.
Create a node by RPC and make linkage
import terragen_rpc as tg
try:
root = tg.root()
# add easy cloud
new_cloud = tg.create_child(root, 'easy_cloud')
# link Planet Atmosphere and easy cloud created before.
atmos = root.children_filtered_by_class('planet_atmosphere')[0]
new_cloud.set_param_from_string('input_node', atmos.name())
new_cloud.set_param_from_string('gui_group', atmos.get_param_as_string('gui_group'))
# make the position of the added node just below right of Planet Atmosphere.
base_pos = atmos.get_param_as_list('gui_node_pos')
print("Base position is: " + str(base_pos))
cloud_pos = base_pos
cloud_pos[0] = cloud_pos[0] + 80
cloud_pos[1] = cloud_pos[1] - 50
new_cloud.set_param('gui_node_pos', cloud_pos)
new_pos = new_cloud.get_param_as_list('gui_node_pos')
print("gui_node_pos is set to: " + str(new_pos))
# link Planet and easy cloud.
planet = root.children_filtered_by_class('planet')[0]
planet.set_param_from_string('atmosphere_shader', new_cloud.name())
except ConnectionError as e:
print("Terragen RPC connection error: " + str(e))
except TimeoutError as e:
print("Terragen RPC timeout error: " + str(e))
except tg.ReplyError as e:
print("Terragen RPC server reply error: " + str(e))
except tg.ApiError:
print("Terragen RPC API error")
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment