数学库蓝图节点
本文档介绍 @esengine/ecs-framework-math 模块提供的蓝图节点。
注意:这些节点需要安装 math 模块才能使用。
引脚类型说明
Section titled “引脚类型说明” 浮点数 (Float)
Vector2
Fixed32
FixedVector2
Color
Vector2 节点
Section titled “Vector2 节点”2D 向量操作,用于位置、速度、方向计算。
| 节点 | 说明 | 输入 | 输出 |
|---|---|---|---|
Make Vector2 | 从 X, Y 创建 Vector2 | X, Y | Vector2 |
Break Vector2 | 分解 Vector2 为 X, Y | Vector | X, Y |
Vector2 + | 向量加法 | A, B | Vector2 |
Vector2 - | 向量减法 | A, B | Vector2 |
Vector2 * | 向量缩放 | Vector, Scalar | Vector2 |
Vector2 Length | 获取向量长度 | Vector | Float |
Vector2 Normalize | 归一化为单位向量 | Vector | Vector2 |
Vector2 Dot | 点积 | A, B | Float |
Vector2 Cross | 2D 叉积 | A, B | Float |
Vector2 Distance | 两点距离 | A, B | Float |
Vector2 Lerp | 线性插值 | A, B, T | Vector2 |
Vector2 Rotate | 旋转(弧度) | Vector, Angle | Vector2 |
Vector2 From Angle | 从角度创建单位向量 | Angle | Vector2 |
示例:计算移动方向
Section titled “示例:计算移动方向”从起点到终点的方向向量:
Make Vector2
X
0
Y
0
Vector
Make Vector2
X
100
Y
50
Vector
Vector2 -
A
B
Result
Vector2 Normalize
Vector
Result
示例:圆周运动
Section titled “示例:圆周运动”使用角度和半径计算圆周位置:
Vector2 From Angle
Angle
1.57
Vector
Vector2 *
Vector
Scalar
50
Result
Vector2 +
A (Center)
B
Position
Fixed32 定点数节点
Section titled “Fixed32 定点数节点”Q16.16 定点数运算,适用于帧同步网络游戏,保证跨平台计算一致性。
| 节点 | 说明 | 输入 | 输出 |
|---|---|---|---|
Fixed32 From Float | 从浮点数创建 | Float | Fixed32 |
Fixed32 From Int | 从整数创建 | Int | Fixed32 |
Fixed32 To Float | 转换为浮点数 | Fixed32 | Float |
Fixed32 To Int | 转换为整数 | Fixed32 | Int |
Fixed32 + | 加法 | A, B | Fixed32 |
Fixed32 - | 减法 | A, B | Fixed32 |
Fixed32 * | 乘法 | A, B | Fixed32 |
Fixed32 / | 除法 | A, B | Fixed32 |
Fixed32 Abs | 绝对值 | Value | Fixed32 |
Fixed32 Sqrt | 平方根 | Value | Fixed32 |
Fixed32 Floor | 向下取整 | Value | Fixed32 |
Fixed32 Ceil | 向上取整 | Value | Fixed32 |
Fixed32 Round | 四舍五入 | Value | Fixed32 |
Fixed32 Sign | 符号 (-1, 0, 1) | Value | Fixed32 |
Fixed32 Min | 最小值 | A, B | Fixed32 |
Fixed32 Max | 最大值 | A, B | Fixed32 |
Fixed32 Clamp | 钳制范围 | Value, Min, Max | Fixed32 |
Fixed32 Lerp | 线性插值 | A, B, T | Fixed32 |
示例:帧同步移动速度计算
Section titled “示例:帧同步移动速度计算”Fixed32 From Float
Value
5.0
Speed
Fixed32 From Float
Value
0.016
DeltaTime
Fixed32 *
A
B
Result
Fixed32 To Float
Fixed
Float
FixedVector2 定点向量节点
Section titled “FixedVector2 定点向量节点”定点向量运算,用于确定性物理计算,适用于帧同步。
| 节点 | 说明 | 输入 | 输出 |
|---|---|---|---|
Make FixedVector2 | 从 X, Y 浮点数创建 | X, Y | FixedVector2 |
Break FixedVector2 | 分解为 X, Y 浮点数 | Vector | X, Y |
FixedVector2 + | 向量加法 | A, B | FixedVector2 |
FixedVector2 - | 向量减法 | A, B | FixedVector2 |
FixedVector2 * | 按 Fixed32 缩放 | Vector, Scalar | FixedVector2 |
FixedVector2 Negate | 取反 | Vector | FixedVector2 |
FixedVector2 Length | 获取长度 | Vector | Fixed32 |
FixedVector2 Normalize | 归一化 | Vector | FixedVector2 |
FixedVector2 Dot | 点积 | A, B | Fixed32 |
FixedVector2 Cross | 2D 叉积 | A, B | Fixed32 |
FixedVector2 Distance | 两点距离 | A, B | Fixed32 |
FixedVector2 Lerp | 线性插值 | A, B, T | FixedVector2 |
示例:确定性位置更新
Section titled “示例:确定性位置更新”Make FixedVector2
X
10
Y
20
Position
Make FixedVector2
X
1
Y
0
Velocity
FixedVector2 +
A
B
New Position
Color 颜色节点
Section titled “Color 颜色节点”颜色创建与操作节点。
| 节点 | 说明 | 输入 | 输出 |
|---|---|---|---|
Make Color | 从 RGBA 创建 | R, G, B, A | Color |
Break Color | 分解为 RGBA | Color | R, G, B, A |
Color From Hex | 从十六进制字符串创建 | Hex | Color |
Color To Hex | 转换为十六进制字符串 | Color | String |
Color From HSL | 从 HSL 创建 | H, S, L | Color |
Color To HSL | 转换为 HSL | Color | H, S, L |
Color Lerp | 颜色插值 | A, B, T | Color |
Color Lighten | 提亮 | Color, Amount | Color |
Color Darken | 变暗 | Color, Amount | Color |
Color Saturate | 增加饱和度 | Color, Amount | Color |
Color Desaturate | 降低饱和度 | Color, Amount | Color |
Color Invert | 反色 | Color | Color |
Color Grayscale | 灰度化 | Color | Color |
Color Luminance | 获取亮度 | Color | Float |
| 节点 | 值 |
|---|---|
Color White | (1, 1, 1, 1) |
Color Black | (0, 0, 0, 1) |
Color Red | (1, 0, 0, 1) |
Color Green | (0, 1, 0, 1) |
Color Blue | (0, 0, 1, 1) |
Color Transparent | (0, 0, 0, 0) |
示例:颜色过渡动画
Section titled “示例:颜色过渡动画”Color Red
Color
Color Blue
Color
Color Lerp
A
B
T
0.5
Result
示例:从 Hex 创建颜色
Section titled “示例:从 Hex 创建颜色”Color From Hex
Hex
"#FF5722"
Color
Break Color
Color
R
G
B
A