This tutorial explores how Channel Operators (CHOPs) provide an intuitive and powerful way to work with instancing data in TouchDesigner. CHOPs offer one of the most accessible methods for understanding how instances work and controlling their behavior.

Part 1: Creating Instances with Pattern CHOPs

Setting Up Sine and Cosine Patterns

The first example demonstrates creating instances arranged in a circular pattern using trigonometric functions.

Step 1: Create the Pattern CHOPs

  1. Add a Pattern CHOP to your network
  2. Set the length parameter to 50 samples
  3. Change the channel name to “sin” (this creates a sine wave pattern)

Step 2: Add a Second Pattern

  1. Connect the first Pattern CHOP to another Pattern CHOP
  2. Set the second pattern’s type to “cosine”
  3. Rename the channel to “cosine” to match the pattern type

Step 3: Combine the Patterns

  1. Use a Merge CHOP to combine both sine and cosine patterns into a single operator
  2. Connect the Merge to a Null CHOP
  3. Make the viewer active and right-click inside to select “dots per sample” - this shows a dot for each sample in your multi-sample CHOP

Connecting to Geometry

  1. Add a Circle SOP with a radius of 0.1
  2. Right-click on the Circle’s output and add a Geometry component
  3. On the Geometry component’s Instance page:
    • Turn on instancing
    • Set the Translate OP to your Null CHOP
    • Set Translate X to the “sin” channel
    • Set Translate Y to the “cosine” channel

The result is a new instance for each sample, arranged in a circular pattern where the sine channel controls X positions and the cosine channel controls Y positions.

Scaling the Pattern

To adjust the size of your circular arrangement:

  1. Right-click on the wire between Merge and Null
  2. Select “Insert Operator” and add a Math CHOP
  3. On the Multi-Add page, use the Multiply parameter to scale the diameter

Part 2: Creating a Trailing Instance Effect

This second example creates a more dynamic visualization using noise and trail data.

Setting Up the Noise Trail

Step 1: Create the Noise Source

  1. Add a Noise CHOP to your network
  2. On the Channel page, use pattern expansion t[xyz] to create three channels: TX, TY, and TZ
  3. On the Common page, turn off “Time Slice”

Step 2: Collect Position History

  1. Connect the Noise CHOP to a Trail CHOP
  2. Set the Trail to measure in samples
  3. Set the sample count to 200
  4. Connect to a Null CHOP named “null_inst” (null instances)

Step 3: Connect to Geometry

  1. Add a Box SOP and connect it to a Geometry component
  2. On the Instance page:
    • Turn on instancing
    • Set the Null instance CHOP as your default instance OP
    • Map TX, TY, and TZ channels to their respective translate parameters
  3. Reduce the box size to 0.02 to see all instances clearly

Step 4: Scale the Movement

Insert a Math CHOP after the Noise CHOP and set the Multiply parameter to 3 on the Multi-Add page to increase the spatial coverage.

Part 3: Calculating Rotation Vectors

To orient instances along their trajectory of movement, you need to compute a rotation vector.

Computing the Rotation Vector

Step 1: Capture Past Positions

  1. Add a Delay CHOP after your Math CHOP
  2. Set it to measure in frames with a delay of 1 frame
  3. This represents positions from one frame ago

Step 2: Rename Past Channels

Use a Rename CHOP to rename the delayed channels to past_* (resulting in past_tx, past_ty, past_tz)

Step 3: Collect Past Positions in Trail

Connect the renamed past positions to your Trail CHOP as well.

Step 4: Separate Current and Past Positions

  1. Add a Select CHOP to select current positions (t*)
  2. Add another Select CHOP to select past positions (past_*)

Step 5: Calculate the Vector

  1. Use a Math CHOP to subtract the past positions from current positions
  2. On the Combine CHOPs page, select “Subtract”
  3. Use a Rename CHOP to name the result rotv[xyz] (rotation vector X, Y, Z)

Step 6: Merge and Apply

  1. Use a Merge CHOP to combine current positions and rotation vectors
  2. Connect this to your null_inst
  3. On the Geometry component’s Instance 2 page, set the Rotate to Vector parameters to rotvx, rotvy, and rotvz

Visualizing the Rotation

To better see the rotation effect, modify your Box SOP by increasing the TZ scale to 0.2. This elongates the boxes so you can clearly see them rotating along their movement vector.

Understanding the Math

The key concept is that the math operation happens for every sample. TX, TY, TZ and past_tx, past_ty, past_tz are subtracted from one another based on their sample index. This per-sample calculation gives each instance its own rotation based on its individual trajectory.

Part 4: Adding Color Based on Position

To add color that changes based on position in the trail:

  1. Add a Pattern CHOP with a “ramp” type
  2. Reference the Trail’s window length for the Pattern’s length parameter
  3. Name the channel “r” (red)
  4. Merge this with your other instance data
  5. On the Geometry component’s Instance 2 page, set the Color R parameter to the “r” channel

The result shows instances transitioning from white (where G, B, A default to 1) to blue as the R channel goes from 0 to 1 along the trail.

Key Concepts Summary

  1. Pattern CHOPs - Generate mathematical patterns (sine, cosine, ramp) that can drive instance positions
  2. Trail CHOPs - Collect a history of values over time, perfect for creating trailing effects
  3. Delay CHOPs - Capture past values for computing velocity and direction vectors
  4. Math CHOPs - Perform arithmetic operations across channels, including subtraction for vector calculation
  5. Sample-Based Operations - All math operations happen per-sample, giving each instance individual control
  6. Rotate to Vector - The Instance 2 page feature that orients instances along a direction vector

Practical Applications

This technique is excellent for:

  • Particle trail visualizations
  • Motion graphics with directional elements
  • Data visualization showing movement over time
  • Creating organic, flowing animations

CHOPs provide an intuitive way to understand and control instancing because you can visualize the data at every step of your network.

本教程探讨通道操作符(CHOPs)如何在TouchDesigner中提供直观而强大的实例化数据处理方式。CHOPs是理解实例工作原理和控制其行为的最易于理解的方法之一。

第一部分:使用Pattern CHOPs创建实例

设置正弦和余弦模式

第一个示例演示如何使用三角函数创建圆形排列的实例。

步骤1:创建Pattern CHOP

  1. 在网络中添加一个Pattern CHOP
  2. 将length参数设置为50个采样
  3. 将通道名称更改为”sin”(这将创建正弦波模式)

步骤2:添加第二个Pattern

  1. 将第一个Pattern CHOP连接到另一个Pattern CHOP
  2. 将第二个pattern的类型设置为”cosine”
  3. 将通道重命名为”cosine”以匹配模式类型

步骤3:合并模式

  1. 使用Merge CHOP将正弦和余弦模式合并到单个操作符中
  2. 将Merge连接到Null CHOP
  3. 激活查看器并在内部右键单击选择”dots per sample”——这将显示多采样CHOP中每个采样的点

连接到几何体

  1. 添加一个半径为0.1的Circle SOP
  2. 右键单击Circle的输出并添加Geometry组件
  3. 在Geometry组件的Instance页面上:
    • 打开实例化
    • 将Translate OP设置为你的Null CHOP
    • 将Translate X设置为”sin”通道
    • 将Translate Y设置为”cosine”通道

结果是每个采样创建一个新实例,排列成圆形模式,其中正弦通道控制X位置,余弦通道控制Y位置。

缩放模式

要调整圆形排列的大小:

  1. 右键单击Merge和Null之间的连线
  2. 选择”Insert Operator”并添加Math CHOP
  3. 在Multi-Add页面上,使用Multiply参数缩放直径

第二部分:创建拖尾实例效果

第二个示例使用噪声和轨迹数据创建更动态的可视化效果。

设置噪声轨迹

步骤1:创建噪声源

  1. 在网络中添加Noise CHOP
  2. 在Channel页面上,使用模式扩展t[xyz]创建三个通道:TX、TY和TZ
  3. 在Common页面上,关闭”Time Slice”

步骤2:收集位置历史

  1. 将Noise CHOP连接到Trail CHOP
  2. 将Trail设置为以采样为单位测量
  3. 将采样数设置为200
  4. 连接到名为”null_inst”(null instances)的Null CHOP

步骤3:连接到几何体

  1. 添加Box SOP并将其连接到Geometry组件
  2. 在Instance页面上:
    • 打开实例化
    • 将Null instance CHOP设置为默认实例OP
    • 将TX、TY和TZ通道映射到各自的平移参数
  3. 将盒子大小减小到0.02以清楚地看到所有实例

步骤4:缩放运动

在Noise CHOP之后插入Math CHOP,并在Multi-Add页面上将Multiply参数设置为3,以增加空间覆盖范围。

第三部分:计算旋转向量

要使实例沿其运动轨迹方向定向,需要计算旋转向量。

计算旋转向量

步骤1:捕获过去位置

  1. 在Math CHOP之后添加Delay CHOP
  2. 设置为以帧为单位测量,延迟1帧
  3. 这代表一帧前的位置

步骤2:重命名过去通道

使用Rename CHOP将延迟的通道重命名为past_*(结果为past_tx、past_ty、past_tz)

步骤3:在Trail中收集过去位置

将重命名的过去位置也连接到Trail CHOP。

步骤4:分离当前和过去位置

  1. 添加Select CHOP选择当前位置(t*
  2. 添加另一个Select CHOP选择过去位置(past_*

步骤5:计算向量

  1. 使用Math CHOP从当前位置减去过去位置
  2. 在Combine CHOPs页面上,选择”Subtract”
  3. 使用Rename CHOP将结果命名为rotv[xyz](旋转向量X、Y、Z)

步骤6:合并并应用

  1. 使用Merge CHOP合并当前位置和旋转向量
  2. 将其连接到null_inst
  3. 在Geometry组件的Instance 2页面上,将Rotate to Vector参数设置为rotvx、rotvy和rotvz

可视化旋转

为了更好地看到旋转效果,通过将TZ缩放增加到0.2来修改Box SOP。这会拉长盒子,使你可以清楚地看到它们沿运动向量旋转。

理解数学原理

关键概念是数学运算对每个采样都会发生。TX、TY、TZ和past_tx、past_ty、past_tz根据其采样索引相互减去。这种逐采样计算使每个实例根据其各自的轨迹获得自己的旋转。

第四部分:根据位置添加颜色

要添加根据轨迹位置变化的颜色:

  1. 添加类型为”ramp”的Pattern CHOP
  2. 引用Trail的窗口长度作为Pattern的长度参数
  3. 将通道命名为”r”(红色)
  4. 将其与其他实例数据合并
  5. 在Geometry组件的Instance 2页面上,将Color R参数设置为”r”通道

结果显示实例从白色(G、B、A默认为1)过渡到蓝色,因为R通道沿轨迹从0变为1。

核心概念总结

  1. Pattern CHOPs - 生成可以驱动实例位置的数学模式(正弦、余弦、渐变)
  2. Trail CHOPs - 收集一段时间内的值历史,非常适合创建拖尾效果
  3. Delay CHOPs - 捕获过去的值以计算速度和方向向量
  4. Math CHOPs - 跨通道执行算术运算,包括用于向量计算的减法
  5. 基于采样的操作 - 所有数学运算都按采样进行,为每个实例提供单独控制
  6. Rotate to Vector - Instance 2页面功能,使实例沿方向向量定向

实际应用

此技术非常适合:

  • 粒子轨迹可视化
  • 具有方向性元素的动态图形
  • 显示随时间运动的数据可视化
  • 创建有机的、流动的动画

CHOPs提供了一种直观的方式来理解和控制实例化,因为你可以在网络的每个步骤中可视化数据。