#bevy-plugin #template #gesture #recognition #recording #mouse #ecosystem

bevy_guessture

封装了 guessture 库的手势识别API的 Bevy 插件

2 个不稳定版本

0.2.0 2024年7月20日
0.1.0 2024年2月23日

#211游戏开发

Download history 127/week @ 2024-07-15 16/week @ 2024-07-22 14/week @ 2024-07-29

157 每月下载

MIT 协议

41KB
384

bevy_guessture

此库将 guessture 库集成到 Bevy 生态系统中。其职责包括

  • 在应用程序启动事件响应下记录鼠标位置数据
  • 为完成录制的窗口提供鼠标路径数据
  • 存储应用程序可访问的手势模板
  • 公开手势模板序列化和资源加载机制

使用 bevy_guessture 的 Bevy 应用程序负责设置手势模板、触发录制窗口和启动与记录的鼠标路径数据的手势匹配。有一个示例应用程序演示了手势识别的视觉集成,以及将手势信息序列化为可加载资源。

要开始,请在您的应用程序中安装 GuessturePlugin 并准备一套手势模板

    App::new()
        .add_plugins(GuessturePlugin::default());

然后准备一套手势模板

fn setup(server: Res<AssetServer>) {
    let _handle: Handle<GestureTemplates> = server.load("data.gestures");
}

要开始录制潜在的手势,发送适当的事件

fn start_record(mut record_events: EventWriter<GestureRecord>) {
   record_events.send(GestureRecord::Start);
}

在发送 GestureRecord::Stop 事件后,等待包含完整录制的 RecordedPath 事件

fn recorded_path(
    mut events: EventReader<RecordedPath>,
    mut state: ResMut<GestureState>,
) {
    for event in events.read() {
        let matched_template = find_matching_template_with_defaults(
            &state.templates,
            &event.path,
        );
        match matched_template {
            Ok((template, score)) =>
                println!("matched {} with score {}", template.name, score),
            Err(err) =>
                println!("failed to match: {:?}", err),
        }
    }
}

Bevy 兼容性

bevy_guessture Bevy
主函数 0.14
0.2 0.14
0.1 0.13

依赖项

~22–57MB
~1M SLoC