3个不稳定版本

0.2.0 2024年7月6日
0.1.1 2024年5月4日
0.1.0 2024年3月10日

#48 in #scene

Download history 157/week @ 2024-04-29 14/week @ 2024-05-06 8/week @ 2024-05-20 4/week @ 2024-06-03 10/week @ 2024-06-10 152/week @ 2024-07-01 25/week @ 2024-07-08 44/week @ 2024-07-29

189 每月下载量
用于 bevy_descendant_collector

MIT 许可证

5KB
68

bevy_descendant_collector

crates.io ci

此crate允许您将复杂的实体树映射到单个组件,前提是这些实体(及其祖先)被命名。

这对于从GLTF模型生成的场景尤其有用,因为您需要复杂的查询来从场景层次结构中检索深层实体。

要求

开发

此仓库使用cargo-make,它将负责安装此仓库中使用的所有必要的cargo扩展和rustup组件。

  1. 运行scripts/setup.sh(或者运行cargo install cargo-make
  2. (可选)使用cargo make setup安装其余的工具和cargo扩展

cargo-make任务

  • cargo make all运行可能导致ci失败的所有内容(以下所有内容)
  • cargo make build构建所有crate
  • cargo make test测试所有crate
  • cargo make format格式化所有crate
  • cargo make lint使用clippyrustfmt对所有crate进行代码风格检查
  • cargo make book-build构建文档手册

示例

运行示例

cargo run -p bevy_descendant_collector --example turret

想象一下,你有一个在Blender中具有以下结构的 模型文件

Collection
├── Armature
   ├── Bone.Root
   │   └── Bone.Neck
   │       └── Bone.Head
   └── Bone.Head.IK_CTRL

你可以定义一个组件,如下所示

#[derive(Component, EntityCollectorTarget)]
#[name_path("Armature")]
pub struct MyTurretArmature {
	#[name_path("Bone.Root")]
	pub base: Entity,
	#[name_path("Bone.Root", "Bone.Neck")]
	pub neck: Entity,
	#[name_path("Bone.Root", "Bone.Neck", "Bone.Head")]
	pub head: Entity,
	#[name_path("Bone.Head.IK_CTRL")]
	pub head_ik_ctrl: Entity,
}

然后,你需要添加一个插件,这个插件将处理该组件的插入

每个不同的 EntityCollectorTarget 需要添加自己的插件!

在这个例子中,这是一个GLTF模型,所以我希望根实体被解析为场景。HierarchyRootPosition::Scene 告诉插件根据 #[name_path("Armature")] 在实体后代中查找根,其中我想要在这个 MyTurretArmature 插入。

app.add_plugins(DescendantCollectorPlugin::<MyTurretArmature>::new(HierarchyRootPosition::Scene));

最后,我需要确定插入 MyTurretArmature 的实体!为此,当您生成这个场景时,将目标组件添加到您的实体中。

fn spawn_turret(mut commands: Commands, turret_model_assets: Res<TurretModelAssets>) {
	commands.spawn((
		SceneBundle {
			scene: turret_model_assets.turret_model.clone(),
			..default()
		},
		DescendantCollectorTarget::<MyTurretArmature>::default(),
	));
}

扩展过程宏

如果您想检查过程宏的输出。

如果您还没有安装 cargo-expand

cargo install cargo-expand
cargo expand --example turret

Bevy 兼容性表格

Bevy bevy_descendant_collector
0.14 0.2
0.13 0.1

依赖关系

~22MB
~401K SLoC