godot.lerp errors for Vector3 not using the correct type
- 主要语言
- C++
- 星标
- 1.1k
- 派生
- 80
- PR 合并指标
- 30 天内没有已合并 PR
描述
Hi, getting an error trying to use godot.lerp for Vector3 types (positions).
```
E 0:00:01.095 call_method: JavaScript Error at lerp (native)
at _process (res://src/Camera.jsx:22)
Call builtin function error lerp: Argument of type 'Vector3' is not assignable to parameter #0 of type 'float'
modules/ECMAScript/quickjs/quickjs_binder.cpp:2125 @ call_method()
```
The documentation in godot.d.ts says that the function should accept Vector2, Vector3, or Color arguments, but it seems like it's only expecting floats at runtime.
```javascript
/** Linearly interpolates between two values by a normalized value. This is the opposite of `inverse_lerp`.
If the `from` and `to` arguments are of type `int` or `float`, the return value is a `float`.
If both are of the same vector type (`Vector2`, `Vector3` or `Color`), the return value will be of the same type (`lerp` then calls the vector type's `linear_interpolate` method).
gdscript
lerp(0, 4, 0.75) # Returns 3.0
lerp(Vector2(1, 5), Vector2(3, 2), 0.5) # Returns Vector2(2, 3.5)
*/
function lerp(p_from: any, to: any, weight: number) : any;
```
I was able to easily get around this by writing a vector3 lerp function in typescript, but it would be nice to be able to use the builtin function:
```typescript
function Vector3Lerp(
a: godot.Vector3,
b: godot.Vector3,
t: number
): godot.Vector3 {
return new godot.Vector3(
a.x * (1 - t) + b.x * t,
a.y * (1 - t) + b.y * t,
a.z * (1 - t) + b.z * t
);
}
```
贡献指南
调研方向
首先复现 src/Camera.jsx:22 中的 Vector3 调用,然后检查 modules/ECMAScript/quickjs/quickjs_binder.cpp 中的 lerp 处理逻辑,报告的类型错误就产生于此处。将运行时行为与 godot.d.ts 中的 lerp 声明和文档进行比较。当内置 lerp 能够按照文档接受匹配的 Vector3 参数且不再出现 float 类型错误时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- cpp, javascript, typescript
- 领域
- api, backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100