Helps write C# node classes for vvvv gamma — the [ProcessNode] pattern, Update() method, out parameters, pin configuration, change detection, stateless operation nodes, and service consumption via NodeContext (IFrameClock, Game access, logging). Use when writing a node class, adding pins, implementing change detection, accessing services in node constructors, or creating stateless utility methods. Requires [assembly: ImportAsIs]."
vvvv gamma中每个有状态的C#节点都使用[ProcessNode]:
csharp
[ProcessNode]
public class MyTransform : IDisposable
{
private float _lastInput;
private float _cachedResult;
///
/// 带缓存的输入值变换。
///
public void Update(
out float result, // OUT参数放在首位
out string error, // 更多out参数
float input = 0f, // 带默认值的值输入放在后面
bool reset = false)
{
error = null;
if (input != _lastInput || reset)
{
_cachedResult = ExpensiveComputation(input);
_lastInput = input;
}
result = _cachedResult; // 始终输出缓存数据
}
public void Dispose() { / 清理 / }
}
前置条件:[ProcessNode]仅在程序集设置了[assembly: ImportAsIs]时生效。由vvvv创建的项目会自动包含此设置。关于带命名空间/类别参数的库级别ImportAsIs,请参阅vvvv-node-libraries。
当.vl文档引用.csproj源项目时,vvvv在运行时通过Roslyn编译C#。当.cs文件保存时,vvvv重新编译并重启受影响的节点:
对节点作者的影响:
规则是:用户在vvvv的节点浏览器中绝不能看到Node。实现方式如下:
csharp
// 简单方式:类名就是节点名称——不需要后缀
[ProcessNode]
public class Wander { } // vvvv显示:Wander
// 类名包含Node后缀 + Name属性去除后缀——同样可行
[ProcessNode(Name = Scan)]
public class ScanNode { } // vvvv显示:Scan
// 完全不同的内部名称——当类管理另一种类型时可行
[ProcessNode(Name = MeshRenderer, Category = Stride.Rendering.Custom)]
public class CustomMeshRenderer { } // vvvv显示:MeshRenderer
csharp
[ProcessNode(HasStateOutput = true)]
public class ParticleSystem
{
// 节点本身成为一个输出引脚,
// 允许下游节点调用其方法
public void Update(out int particleCount, ...) { ... }
}
替代方案:从方法返回this以暴露实例。
csharp
public void Update(
out Spread
[Pin(Visibility = PinVisibility.OnlyInspector)] out string error,
float input = 0f,
[Pin(Visibility = PinVisibility.Optional)] bool advanced = false)
{
// PinVisibility值:
// Visible — 始终显示(默认)
// Optional — 用户可以显示/隐藏
// Hidden — 不可见,仅通过检查器可见
// OnlyInspector — 仅在检查器面板中可见(用于调试/错误输出)
}
用于vvvv中带有添加/删除按钮的Spread输入:
csharp
public void Update(
out float result,
[Pin(Name = Input, PinGroupKind = PinGroupKind.Collection, PinGroupDefaultCount = 2)]
Spread
{ }
对于无法使用C#字面量表达式的默认值:
csharp
public void Update(
[DefaultValue(typeof(Color4), 0.1, 0.1, 0.15, 1.0)] Color4 clearColor,
[DefaultValue(typeof(Int2), 1920, 1080)] Int2 size,
bool clear = true)
{ }
简单节点(无需特殊上下文):
csharp
public MyNode() { }
需要NodeContext的节点(用于AppHost、服务、Fuse着色器图):
csharp
public MyNode(NodeContext nodeContext)
{
_nodeContext = nodeContext;
// 访问:nodeContext.AppHost.IsExported, nodeContext.AppHost.Services等
}
关于IFrameClock注入、Stride Game访问、日志记录和服务消费模式,请参阅services.md。
csharp
private float _lastParam;
private Result _cached;
public void Update(out Result result, float param = 0f)
{
if (param != _lastParam)
{
_cached = Compute(param);
_lastParam = param;
}
result = _cached;
}
csharp
private int _lastHash;
private Config _cached;
public void Update(out Config config, float a = 0f, int b = 0, string c = )
{
int hash = HashCode.Combine(a, b, c);
if (hash != _lastHash)
{
_cached = new Config(a, b, c);
_lastHash = hash;
}
config = _cached;
}
csharp
if (!ReferenceEquals(newBuffer, _lastBuffer))
{
ProcessBuffer(newBuffer);
_lastBuffer = newBuffer;
}
当多个设置器可能使状态失效时:
csharp
private bool _needsRebuild = true;
public void SetShader(ShaderStage vs) { shader = vs; needsRebuild = true; }
public void Update(out Effect effect)
{
if (_needsRebuild)
{
RebuildPipeline();
_needsRebuild = false;
}
effect = _cachedEffect;
}
| 输入类型 | 比较方式 | 说明 |
|---|---|---|
| 值类型(int, float, bool) | != | 直接比较 |
| 引用类型(对象) |
当节点只有一个主要输出时,可以直接返回而非使用out:
csharp
[ProcessNode]
public class NoiseSteering
{
private SteeringConfig? _cached;
public ISteering Update(
float strength = 2.0f,
float noiseFrequency = 0.05f,
int priority = 0)
{
if (cached is null || cached.Strength != strength ||
cached.NoiseFrequency != noiseFrequency || cached.Priority != priority)
{
_cached = new SteeringConfig(strength, noiseFrequency, priority);
}
return _cached;
}
}
当有一个主要输出加上额外输出时,混合使用return + out:
csharp
public Read
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 vvvv-custom-nodes-1776205561 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 vvvv-custom-nodes-1776205561 技能
skillhub install vvvv-custom-nodes-1776205561
文件大小: 13.63 KB | 发布时间: 2026-4-15 11:27