RPC / Scripting in Terragen

Started by Kevin Kipper, July 13, 2023, 06:48:49 PM

Previous topic - Next topic

Kevin Kipper


In version 6.31, Terragen 4 Professional introduced the Remote Procedure Call (RPC) feature which allows third party applications to communicate with Terragen.  This means that the end-user can write programs and scripts that modify the active Terragen project.

Some practical examples of this are:
* Adding and removing items from the project, such as cloud layers and 3D objects, etc.
* Modifying the parameters of an item in the project, such as its position, rotation, and scale, etc.
* Modifying camera and render settings, etc.

Over the last few months we've been refining the online documentation for RPC and simplifying its installation process, and we've just released two new blog posts to help you get started using it.  These blog posts walk you step-by-step through the program writing process, as well as showing you how to install Terragen RPC using Python's "pip" command.

Hello RPC! - Part 1 Scripting for Terragen
Hello RPC! - Part 2 Error Handling

Building upon the entry-level examples described in these posts, we've created additional Python scripts to give you an idea of what's possible with RPC, and hopefully to inspire you to write and share your code with the Terragen community at-large.  These resources are available for download at Github.

tg_landmark.py - A script that can add a Landmark object at the origin of the project, or at any coordinates you've chosen.  How might you modify the script to change the shape or colour of the Landmark object?

tg_landmark_GUI.JPG


tg_sunlight01_heading_elevation.py - A script that modifies the heading and elevation of the Sunlight 01 node in the project.  How might you modify the script in order to select from multiple Sunlight nodes in the project if they exist?

tg-sunlight01-heading-elevation.jpg


tg_transform_to_origin.py - A script to center a terrain feature at the origin of the project.

tg_transform_to_origin_GUI.JPG

We'll be adding even more examples to illustrate the power of this new feature, and hope that you find these resources helpful and instructive, while looking forward to seeing how you incorporate Terragen RPC into your own projects and workflow.

Kevin Kipper

#1
tg_camera_bookmark.py is a new Python script written to take advantage of Terragen 4 Professional's Remote Procedure Call (RPC) feature.

tg_camera_bookmark_gui.jpg


In a nutshell, you can "bookmark" a camera's position, rotation and focal length; storing it to computer memory or disk.  You can then apply the bookmark data to any other camera in the project.

tg_camera_bookmarks_composition.jpg


For more information, and to download the script and example content check out the Github repository below:
https://github.com/RedMawVFX/tg-camera-bookmarks.git

Kevin Kipper

#2
tg_kelvin_temperature.py is a new Python script written to take advantage of Terragen 4 Professional's Remote Procedure Call (RPC) feature and allow the user to apply a Kelvin temperature value to a selected Sunlight node in the active Terragen project.

Blog_Kelvin_14_GUI_ApplyButton.JPG

Be sure to check out the Script-it-Yourself: Kelvin Sunlight Colour with Terragen RPC blog post for step-by-step instructions to creating this script![/color]

Blog_Kelvin_19_Comparision.jpg
 
For more information, and to download the script and example content check out the Github repository below:
https://github.com/RedMawVFX/tg-kelvin-temperature.git

Kevin Kipper

tg_rename_1_1_1_nodes.py is a new Python script written to take advantage of Terragen 4 Professional's Remote Procedure Call (RPC) feature.

In Terragen, whenever a node is duplicated or an item is loaded into the project with the same name as an existing item, the suffix "_1" is automatically appended to the name to keep it unique.  When there are many such items in the project, these names can seem unmanageable and not very descriptive.  This script attempts to remedy this situation by renaming nodes ending in "_1" with a more logical numeric extension.

tg_rename_1_1_1_render_node_layout_before_after.jpg

tg_rename_1_1_1_nodes_gui_v2.jpg

Click on the "Analyze project/Refresh list" button. The script will read through the Terragen project looking for nodes that end in "_1" and display the results. This may take awhile, depending on the number of nodes in your project.

Select the nodes you want to rename. Clicking the "Select all" button will select all the nodes, whilst clicking "Select none" will deselect all the nodes.

Click the "Rename nodes" button to rename the selected nodes.

For more information, and to download the script and example content check out the Github repository below:
https://github.com/RedMawVFX/tg-rename-1-1-1-nodes.git

Kevin Kipper

tg_crop_region_presets.py is a new Python script written to take advantage of Terragen 4 Professional's Remote Procedure Call (RPC) feature.

tg_crop_region_presets_gui.jpg

The script allows you to apply crop region presets to a selected renderer.  You can also copy and save custom crop region settings to memory or disk and later recall them.

tg_crop_region_presets_gui_custom.jpg

For more information, and to download the script and example content check out the Github repository below:
https://github.com/RedMawVFX/tg-crop-region-presets.git

Kevin Kipper

tg_add_random_cloud.py is a new Python script written to take advantage of Terragen 4 Professional's Remote Procedure Call (RPC) feature.

Have you ever wanted to quickly add some clouds to a project, while not really caring about the type of cloud layer it is?  Perhaps you just need a cloud layer to test with, or are looking for some arbitrary inspiration?  This script randomly adds a cloud layer to the project based on one of the cloud presets located in the Terragen GUI or the Quick Node Palette.

tg_add_random_cloud_presets.jpg

This script has no interface, but an icon image is included should you wish to create a shortcut on your desktop for the script and assign the icon to the shortcut.  Clicking on the shortcut icon will run the script.

tg_add_random_cloud_before_after.jpg

For more information and details about the script, and to download the script check out the Github repository below:
https://github.com/RedMawVFX/tg-add-random-cloud.git

aknight0

Does the RPC allow for any heightfield or terrain editing?  Someone was asking about my TerraRoad app (https://aknight0.gitbook.io/terraroad/) today, and it got me wondering if anything in the RPC would make it easier to integrate something like this more closely with Terragen.  

Kevin Kipper

Hey aknight0,

With RPC, you can access nodes in a project and modify the values of the node's parameters.  

So in theory, you could access a Heightfield Generate node, for example, and change its "Feature scale" parameter.  Currently, I don't think you can access the "Generate Now" button on the Heightfield Generate node, so we probably need to look into adding that functionality.  

If you're asking if RPC can modify the existing values of the heightfield asset (EXR, TIF, etc.) then I don't think so.  You would have to do that via the Python script, as you're currently doing in the TerraRoad app.

Kevin Kipper

tg_replace_image_map_paths.py is a Python script which allows you to re-path the filename parameter for Image Map Shader nodes in the current project.  This can be useful if your texture maps have been relocated to another drive, etc.

tg_replace_image_map_paths_gui.jpg

It's available for download at git-hub: https://github.com/RedMawVFX/tg-replace-image-map-paths

Kevin Kipper

tg_file_compare.py is a new Python script that can be used to quickly compare node parameters between two Terragen project files saved to disk. 

Nodes that are unique to either Terragen project, or common to both projects but have different parameter values are displayed in the "Nodes of interest" window.  When one of these nodes are selected, the "Attribute values" window will display the parameters and values for the node from each of the project files.

tg_compare_files_gui.jpg

To download the script check out the Github repository below:
https://github.com/RedMawVFX/tg-compare-files.git

Matt

Really useful tool. Thanks again Kevin!
Just because milk is white doesn't mean that clouds are made of milk.