> For the complete documentation index, see [llms.txt](https://stage-precision.gitbook.io/grid/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stage-precision.gitbook.io/grid/touch-designer-integration/tracking-data/control-a-cube-with-tracking-data.md).

# Control a cube with tracking data

Use a Tracker's SPNet Movable output from Grid Studio to control a cube's position, rotation, and size in TouchDesigner.

This example connects a Tracker in Grid Studio to a cube in TouchDesigner.

The Tracker sends its values through an SPNet Map Output configured as **Movable**. The SPNet Data CHOP receives this object, and CHOP exports connect its channels to the cube's parameters.

### 1. Prepare Grid Studio

Complete the setup described in **Send tracking data from Grid Studio**.

For this example, use:

| Setting            | Value          |
| ------------------ | -------------- |
| Source object      | Tracker        |
| SPNet output type  | `Movable`      |
| Outgoing object ID | `1`            |
| Sender destination | `237.37.37.37` |
| UDP port           | `37373`        |

Keep the Tracker's position and rotation at zero initially, then start sending.

```
Tracker
    → SPNet Map Output: Movable, ID 1
    → SPNet Sender
    → TouchDesigner
```

### 2. Add the SPNet Data CHOP

In `/project1`:

1. Add **SPNet Data** from the Custom operators.
2. Rename the CHOP to `spnet_tracking`.
3. On its **Data** page, configure:

| Parameter   | Value           |
| ----------- | --------------- |
| Data Type   | `Tracking`      |
| Output Mode | `Single Object` |
| Object Type | `Movable`       |
| Object ID   | `1`             |
| Timeout ms  | `1000`          |

{% hint style="info" %}
Select Movable because this is the outgoing SPNet format configured on the Tracker. Object ID must match the ID configured in its Map Output.
{% endhint %}

On the **Connection** page, use:

| Parameter         | Value          |
| ----------------- | -------------- |
| Port              | `37373`        |
| Bind Address      | `0.0.0.0`      |
| Multicast Group   | `237.37.37.37` |
| Interface Address | `0.0.0.0`      |

Confirm that `active` is `1`. Change the Tracker's coordinates in Grid Studio and check that the position and rotation channels update.

### 3. Add a Null CHOP

Create a **Null CHOP** named `tracking_out` and connect:

```
spnet_tracking → tracking_out
```

Use this Null CHOP as the source for the parameter exports.

Single Object mode provides one sample per channel containing the selected object's current values.

### 4. Create the cube

1. Create a **Geometry COMP** named `tracked_cube`.
2. Enter the Geometry COMP.
3. Add a **Box SOP**.
4. Set its XYZ size to `1, 1, 1` and its center to `0, 0, 0`.
5. Enable the Box SOP's Display and Render flags.
6. Disable those flags on any other default geometry inside the component.

Return to `/project1`.

On `tracked_cube`:

* Keep its position and rotation at zero.
* Keep its scale at one.
* Set **Rotate Order** to **Rx Ry Rz / XYZ**.
* Enable its Render flag.

### 5. Connect position and rotation

Enable **Viewer Active** on `tracking_out`.

For each mapping below:

1. Drag the channel from the Null CHOP's viewer onto the corresponding parameter on `tracked_cube`.
2. Choose **Export CHOP** from the menu.

| Channel | Geometry COMP parameter |
| ------- | ----------------------- |
| `tx`    | Translate X             |
| `ty`    | Translate Y             |
| `tz`    | Translate Z             |
| `rx`    | Rotate X                |
| `ry`    | Rotate Y                |
| `rz`    | Rotate Z                |

The destination parameters turn green when controlled by CHOP exports.

Ensure the **Export flag** on `tracking_out` is enabled.

{% hint style="info" %}
The SPNet Data CHOP prepares positions and rotations for TouchDesigner. Its rotation channels are XYZ Euler angles in degrees and can be used directly with the configured Rotate Order.
{% endhint %}

### 6. Follow object activity

Open the Geometry COMP's **Render** page.

Export the `active` channel from `tracking_out` to its **Render** parameter.

The cube is now visible in the rendered image while the selected object is available. It becomes hidden when the object is unavailable or the packet timeout expires.

### 7. Add material and lighting

In `/project1`:

1. Create a **Phong MAT** named `cube_mat`.
2. Choose a diffuse color.
3. Assign `/project1/cube_mat` to the Geometry COMP's Material parameter.
4. Create a **Light COMP** named `tracking_light`.
5. Set its Light Type to **Point Light**.
6. Set its Translate XYZ to `2, 3, 5`.

The shaded faces make the cube's orientation easier to see.

### 8. Render the cube

1. Create a **Camera COMP** named `tracking_camera`.
2. Set its Translate XYZ to `0, 0, 5`.
3. Set its Rotate XYZ to `0, 0, 0`.
4. Create a **Render TOP** named `tracking_render`.
5. Configure its scene references:

| Scene reference | Path                        |
| --------------- | --------------------------- |
| Camera          | `/project1/tracking_camera` |
| Geometry        | `/project1/tracked_cube`    |
| Lights          | `/project1/tracking_light`  |

View `tracking_render`.

This camera faces the world origin. Keep the Tracker nearby for the initial test.

### Optional: Follow the received size

To apply the XYZ dimensions supplied by the Movable output, add these exports:

| Channel | Geometry COMP parameter |
| ------- | ----------------------- |
| `sx`    | Scale X                 |
| `sy`    | Scale Y                 |
| `sz`    | Scale Z                 |

The original Box SOP measures one unit across each axis. Received dimensions of `1, 1, 1` therefore produce a cube measuring one meter across each side.

Inspect the size channels to check which dimensions your Grid Studio setup transmits.

### Check the result

Change the Tracker's coordinates in Grid Studio:

* Position X moves the cube horizontally.
* Position Y moves it vertically.
* Position Z moves it along the converted Z axis.
* Rotation changes the cube's orientation.

Stop the SPNet Sender and wait for the configured timeout. The cube should disappear from the rendered image. Restart the sender to make it visible again.

If the cube does not respond, check the outgoing Movable type and ID, the CHOP's `active` channel, and the Null CHOP's Export flag.

If the channels update but the render is empty, check the scene references, Render flag, material, lighting, and camera position.
