Add a Select node that picks one of two values by a condition
Choosing between two values meant a Branch with the whole action twice behind it, for example two Play animation nodes that differ only in the animation. Every later change had to be made in both. Select picks the value, so the action stays single. - Select is a data node with the inputs condition, false and true and the output value. It passes on "true" if the condition holds, else "false". An unconnected condition counts as false, and an empty picked input gives null. - The ports are named false and true, not a and b, so nobody has to guess which input is which. The order false, true follows Unreal's Select and Blender's Switch. - false, true and value share one type through `sharedType`, like First not empty. With two Animation literals plugged in, value takes their type and fits Play animation directly. - Both inputs are always evaluated. Data nodes have no side effects, so that does not matter. Tests: - ./check.sh: 160 files, 2363 tests, CHECK EXIT 0 (before 2356). - 5 cases in tests/core/node-catalog.test.ts and 2 in tests/core/shared-port-type.test.ts. - Counter checks: with the inputs swapped all 5 catalog cases fail, without sharedType exactly the type test fails. - No e2e change, the sum stays at 1380. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
89048413f1
commit
5dbac3a8df
4 files changed
+77
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import { asBoolean } from '../../values';
|
||||
import { any, bool } from '../shared';
|
||||
|
||||
export const Select: NodeDef = {
|
||||
type: 'Select',
|
||||
label: 'Select',
|
||||
category: 'data',
|
||||
description: '"true" if the condition holds, else "false". One action, two values – Branch picks actions.',
|
||||
inputs: [bool('condition'), any('false'), any('true')],
|
||||
outputs: [any('value')],
|
||||
// Whatever goes in comes out: with both inputs on the same type, `value` is that type too (#207).
|
||||
sharedType: { inputs: ['false', 'true'], outputs: ['value'] },
|
||||
params: [],
|
||||
run: (_ctx, inputs) => ({
|
||||
outputs: { value: (asBoolean(inputs.condition) ? inputs.true : inputs.false) ?? null },
|
||||
}),
|
||||
};
|
||||
@@ -74,6 +74,7 @@ import { Properties } from './data/Properties';
|
||||
import { Parent } from './data/Parent';
|
||||
import { Random } from './data/Random';
|
||||
import { Round } from './data/Round';
|
||||
import { Select } from './data/Select';
|
||||
import { Self } from './data/Self';
|
||||
import { Sqrt } from './data/Sqrt';
|
||||
import { Substring } from './data/Substring';
|
||||
@@ -195,6 +196,7 @@ export const BUILT_IN_NODES: readonly NodeDef[] = [
|
||||
Equals,
|
||||
Compare,
|
||||
FirstNotEmpty,
|
||||
Select,
|
||||
And,
|
||||
Or,
|
||||
Not,
|
||||
|
||||
Reference in new issue
Block a user