【发布时间】:2021-12-01 06:57:36
【问题描述】:
为了了解引擎,我正在尝试一个非常简单的项目 - 使用编辑器和 gdnative Rust 绑定程序生成一个球体。 我正在尝试跟进使用 GDScript 的 this tutorial 并转换 Rust 的代码。
我无法弄清楚如何访问编辑器中定义的属性。 我已经阅读文档并在网上搜索了一个星期,但是有 一些让我无法理解的事情,我无法理解如何进行。
我想要做的是访问 ArrayMesh 类型的 mesh 属性,就像我在上面链接的教程中一样,并将我为顶点生成的数组附加到它 - 基本上将这些数组绑定到阵列网格。这是我的场景:
[gd_scene load_steps=4 format=2]
[ext_resource path="res://procedural_earth.gdnlib" type="GDNativeLibrary" id=1]
[sub_resource type="ArrayMesh" id=4]
[sub_resource type="NativeScript" id=3]
resource_name = "ProcEarth"
class_name = "ProcEarth"
library = ExtResource( 1 )
[node name="Earth" type="Spatial"]
[node name="Sphere" type="MeshInstance" parent="."]
mesh = SubResource( 4 )
script = SubResource( 3 )
[node name="Camera" type="Camera" parent="."]
transform = Transform( 0.572229, -0.327396, 0.751909, 0, 0.916856, 0.399217, -0.820094, -0.228443, 0.524651, 4.71648, 2.5, 3.45846 )
current = true
我感兴趣的 ArrayMesh 结构,在上面的场景中称为mesh,是名为“Sphere”的节点的一部分(为了清楚起见而提及)。
我有以下 Rust 代码:
#[derive(NativeClass)]
#[inherit(MeshInstance)]
#[register_with(register_properties)]
struct ProcEarth {
// ...
}
impl ProcEarth {
// ...
#[export]
fn _ready(&mut self, owner: &MeshInstance) {
let mut arr = VariantArray::new_shared();
// ...
let blend_shapes = VariantArray::new_shared();
owner.add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arr, blend_shapes, 0);
}
}
但这不起作用,因为我得到的错误是:
no method named `add_surface_from_arrays` found for reference `&gdnative::gdnative_bindings::MeshInstance` in the current scope
method not found in `&gdnative::gdnative_bindings::MeshInstance`rustc(E0599)
有谁知道我如何在 Rust 代码中从编辑器访问该属性,以便正确设置我的 ArrayMesh?是否有任何教程、文章、视频可以说明这一点?
任何指针都受到高度赞赏,因为我目前陷入了这种技术性问题 并且无法进步我的学习。
我在 Linux 上使用带有 gdnative 0.9.3 的 Godot 版本 v3.4.stable.official。
【问题讨论】: