Table of Contents

Switching Sources - Rotating PIP

The description is relevant for software version 2.9.116.100 and later. The project has been prepared in Godot version 4.1.1.

Description of the Godot demo project that implements switching between two sources during a speaker’s speech in a news studio.

GodotDemo_election3d_map_and_bars.zip contains sub folders:

Project Files

The ‘’GodotDemo_rotating_3d_pip’’ project has 4 scenes:

The project also includes:

Let’s look closer at the content of each scene.

Scenes pip1.tscn and pip2.tscn

2D scenes containing SLVideoStreamPlayer nodes that play signals from external lines. In the project, signals are simulated by playing the “Transportation HD” and “CityViews2 HD” files from the first local media database of the Skylark SL NEO server. To output real signals from external lines, use Capture modules and Live-clips created in the media database (‘’New→Local Stream…’’ menu in the Media Browser window).

The players’ sound is muted, given that the host’s live speech is in progress. If, however, the sound must be output from the PIP being switched, use the AnimationPlayer node to control the “Volume dB” parameter.

Pip1_and_pip2.tscn Scene

A 3D scene that provides overlaying first and second line signals on opposite sides of the 3D box and the box rotation animation.

The RotatingBox (CSGBox3D) node is the basis of the composition, performing two functions at once:

The front side of the box has the PIP1 (Sprite3D) node, and the back side has the PIP2 (Sprite3D) one. A y-axis transformation equal -180 is applied to PIP2 to ensure that the output image has the correct orientation after the box is rotated. Initially, PIP1 and PIP2 display the colorbars.png file, useful for scaling and positioning the Sprite3D node in space. When the scene is rendered, the texture will be replaced with the signal from the studio via GD Script.

PIP1 and PIP2 are embedded in RotatingBox, so animating its rotation will be enough for all objects to rotate.

The AnimationPlayer (AnimationPlayer) node has two animations:

The corresponding animation is called from GD Script upon receiving a user command.

SubViewportPIP1 (SubViewport) and SubViewportPIP2 (SubViewport) nodes provide capturing pip1.tscn and pip2.tscn scenes.

The DirectionalLight3D (DirectionalLight3D) node is used to create the scene lighting.

The Camera3D (Camera3D) node is used to create a perspective view of the scene objects.

The root node of the scene has a script attached that ensures assigning textures properly and calling the animation.

pip1_and_pip2.gd
extends Node
 
# Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _ready():
    var texture = $SubViewportPIP1.get_texture()
    var texture2 = $SubViewportPIP2.get_texture()
 
    # Assigning textures to Sprite3D nodes. Allows to output the result of rendering scenes loaded to Viewport
    $RotatingBox/PIP1.texture = texture
    $RotatingBox/PIP2.texture = texture2
 
# Called when user input is detected in the Godot window
func _input(event):
    if event is InputEventKey:
            print(event)
 
    # If the combination corresponding to the cam1 Action is pressed in the Godot window
    if event.is_action_pressed("cam1"):
            $AnimationPlayer.play("pip1->pip2") # Start animation “pip1->pip2”
 
    # If the combination corresponding to the cam2 Action is pressed in the Godot window
    if event.is_action_pressed("cam2"):
            $AnimationPlayer.play("pip2->pip1") # Start animation “pip2->pip1”

Rotating_3d_pip.tscn Scene

The main project scene displayed at startup. The left part of the scene outputs the signal from the studio with the host, and the right one outputs the scene with signals from pip1_and_pip2.tscn external lines.

Management

‘’1’’ and “2” keys are assigned in the project settings to launch the cam1 and cam2 Actions.

The project’s program logic only serves to demonstrate functionality. In real-world projects, keystroke monitoring is added to ensure the correct order and timeliness of switches.