Object picking (#8)

This PR implements basic object selection, with help from `bevy_mod_picking` and
`bevy_mod_outline`.

### Work Done
 * Click to select objects in the world
 * Selected objects become visually highlighted
 * The selected entity is available globally on the `Res<Selection>` resource
 * Selected entities can also be queried via the `Selected` marker component
 * Pressing `F` will "focus" the camera on the selected entity
 * Pressing `Esc` will clear the active selection

### Known Issues
 * We're currently using `bevy_mod_picking`'s "Selection" feature, which isn't 
   aware of our own input events. As a consequence, it will select the object
   under the cursor when releasing `LMB` after orbiting the camera, which is not
   what we want. This should be pretty easily fixable by dropping
   `bevy_mod_picking`'s selection feature and reading the object under the
   cursor in our own click listener that only runs if the LMB event is
   unhandled.
 * The skinned mesh is not currently selectable. This is likely fixable by
   adjusting the logic in `scene::mark_scene_objects`... somehow. The `Gltf`
   data structure is kind of a nightmare to work with, so this will take some
   investigation.

### Future Enhancements
 * For parity with other DCC apps, the "Focus" action should also adjust the
   camera zoom level to "frame" the selected object in the view. Punting on that
   for now because I'm not super confident about the math involved.
 * Group selection with Shift/Ctrl and/or marquee selection would be really nice
   to have, but probably not critical for now.
This commit is contained in:
Danny McGee
2023-11-02 13:32:58 -04:00
committed by GitHub
parent ce6db7fc3c
commit 06751e54f6
30 changed files with 3405 additions and 48 deletions
Generated
+547
View File
@@ -189,6 +189,25 @@ dependencies = [
"num-traits",
]
[[package]]
name = "arboard"
version = "3.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac57f2b058a76363e357c056e4f74f1945bf734d37b8b3ef49066c4787dde0fc"
dependencies = [
"clipboard-win",
"core-graphics",
"image",
"log",
"objc",
"objc-foundation",
"objc_id",
"parking_lot",
"thiserror",
"winapi",
"x11rb",
]
[[package]]
name = "arrayvec"
version = "0.7.4"
@@ -286,6 +305,45 @@ dependencies = [
"bevy_internal",
]
[[package]]
name = "bevy-inspector-egui"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "452f1258251b85c06c5bc9df9ea994d8f3b8c0696f346d43878eec52fce8a09c"
dependencies = [
"bevy-inspector-egui-derive",
"bevy_app",
"bevy_asset",
"bevy_core",
"bevy_core_pipeline",
"bevy_ecs",
"bevy_egui",
"bevy_hierarchy",
"bevy_log",
"bevy_math",
"bevy_pbr",
"bevy_reflect",
"bevy_render",
"bevy_utils",
"bevy_window",
"egui",
"image",
"once_cell",
"pretty-type-name",
"smallvec",
]
[[package]]
name = "bevy-inspector-egui-derive"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a60a8d711fa10879a4e7d10127077505ba9890cead8d1f5ecedc64d14b22b6c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.37",
]
[[package]]
name = "bevy_a11y"
version = "0.11.3"
@@ -477,6 +535,19 @@ dependencies = [
"syn 2.0.37",
]
[[package]]
name = "bevy_egui"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb1c1f6ad293c60fd8559c4502cda5e832e92b0e0f3d994929b33f24d4352d70"
dependencies = [
"arboard",
"bevy",
"egui",
"thread_local",
"webbrowser",
]
[[package]]
name = "bevy_encase_derive"
version = "0.11.3"
@@ -487,6 +558,39 @@ dependencies = [
"encase_derive_impl",
]
[[package]]
name = "bevy_eventlistener"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b089d6bee5e75b1bc2793752ce94c461d4ce581281c15ca44cbd84bb7794073"
dependencies = [
"bevy_eventlistener_core",
"bevy_eventlistener_derive",
]
[[package]]
name = "bevy_eventlistener_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c94b227693f271fd7dad522214f1a371c7856d88cedb6473d4c945e8169103"
dependencies = [
"bevy_app",
"bevy_ecs",
"bevy_hierarchy",
"bevy_utils",
]
[[package]]
name = "bevy_eventlistener_derive"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b88fc692e14d483c9aedd74958d1a39f5adbc6f94d97d87a2b330e27fa6a616"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.37",
]
[[package]]
name = "bevy_gilrs"
version = "0.11.3"
@@ -669,6 +773,53 @@ dependencies = [
"glam",
]
[[package]]
name = "bevy_mod_outline"
version = "0.5.0"
dependencies = [
"bevy",
"bitfield",
"interpolation",
"thiserror",
"wgpu-types",
]
[[package]]
name = "bevy_mod_picking"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aebb845900d5da6314f261cb982079266840820032fa29679341a5a901e2c5b9"
dependencies = [
"bevy_app",
"bevy_core",
"bevy_ecs",
"bevy_eventlistener",
"bevy_math",
"bevy_picking_core",
"bevy_picking_highlight",
"bevy_picking_input",
"bevy_picking_raycast",
"bevy_picking_selection",
"bevy_picking_sprite",
"bevy_picking_ui",
"bevy_reflect",
"bevy_render",
"bevy_text",
"bevy_ui",
"bevy_utils",
"bevy_window",
]
[[package]]
name = "bevy_mod_raycast"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b833e94bd71d2ef27445f3e146b07da4a7922fdb7b464f0f1221521f85a5725a"
dependencies = [
"bevy",
"crossbeam-channel",
]
[[package]]
name = "bevy_pbr"
version = "0.11.3"
@@ -692,6 +843,122 @@ dependencies = [
"radsort",
]
[[package]]
name = "bevy_picking_core"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa8194c5c1baf84c4a377223ece3cb7514fc8b9736c0c758efbc188898d19b27"
dependencies = [
"bevy_app",
"bevy_derive",
"bevy_ecs",
"bevy_eventlistener",
"bevy_math",
"bevy_reflect",
"bevy_render",
"bevy_utils",
"bevy_window",
]
[[package]]
name = "bevy_picking_highlight"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "603a4e422fa60c5d01e4c32b0293fd3cab06b437a700f0b83f314c010cc20461"
dependencies = [
"bevy_app",
"bevy_asset",
"bevy_ecs",
"bevy_picking_core",
"bevy_picking_selection",
"bevy_reflect",
"bevy_render",
"bevy_sprite",
]
[[package]]
name = "bevy_picking_input"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71676712915c8ade223e58bccce29556977f497381497149de435358389d4b5e"
dependencies = [
"bevy_app",
"bevy_ecs",
"bevy_hierarchy",
"bevy_input",
"bevy_math",
"bevy_picking_core",
"bevy_picking_selection",
"bevy_reflect",
"bevy_render",
"bevy_utils",
"bevy_window",
]
[[package]]
name = "bevy_picking_raycast"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05af12237ff5056532bd2e550774a4e89fe976523b2681e5ae7a73e5da6147f0"
dependencies = [
"bevy_app",
"bevy_ecs",
"bevy_mod_raycast",
"bevy_picking_core",
"bevy_reflect",
"bevy_render",
"bevy_transform",
"bevy_window",
]
[[package]]
name = "bevy_picking_selection"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5147eecdc5cd7212a1790aaf8b415a134ed422daf64e2633719454a7c7a86deb"
dependencies = [
"bevy_app",
"bevy_ecs",
"bevy_eventlistener",
"bevy_input",
"bevy_picking_core",
"bevy_reflect",
"bevy_utils",
]
[[package]]
name = "bevy_picking_sprite"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2787e7c0fc71b78bce974f7c90bc2530d7ad0a7673c0532fe2133c87aed44f4"
dependencies = [
"bevy_app",
"bevy_asset",
"bevy_ecs",
"bevy_math",
"bevy_picking_core",
"bevy_render",
"bevy_sprite",
"bevy_transform",
"bevy_window",
]
[[package]]
name = "bevy_picking_ui"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "093df7c568d357edde0b8c114cae35ca985ac5666a2ddea23977883108829393"
dependencies = [
"bevy_app",
"bevy_ecs",
"bevy_math",
"bevy_picking_core",
"bevy_render",
"bevy_transform",
"bevy_ui",
"bevy_window",
]
[[package]]
name = "bevy_ptr"
version = "0.11.3"
@@ -1039,6 +1306,12 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
[[package]]
name = "bitfield"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d7e60934ceec538daadb9d8432424ed043a904d8e0243f3c6446bce549a46ac"
[[package]]
name = "bitflags"
version = "1.3.2"
@@ -1165,6 +1438,17 @@ dependencies = [
"libloading 0.7.4",
]
[[package]]
name = "clipboard-win"
version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362"
dependencies = [
"error-code",
"str-buf",
"winapi",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
@@ -1391,6 +1675,35 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "ecolor"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfdf4e52dbbb615cfd30cf5a5265335c217b5fd8d669593cea74a517d9c605af"
dependencies = [
"bytemuck",
]
[[package]]
name = "egui"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bd69fed5fcf4fbb8225b24e80ea6193b61e17a625db105ef0c4d71dde6eb8b7"
dependencies = [
"ahash",
"epaint",
"nohash-hasher",
]
[[package]]
name = "emath"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ef2b29de53074e575c18b694167ccbe6e5191f7b25fe65175a0d905a32eeec0"
dependencies = [
"bytemuck",
]
[[package]]
name = "encase"
version = "0.6.1"
@@ -1423,6 +1736,21 @@ dependencies = [
"syn 2.0.37",
]
[[package]]
name = "epaint"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58067b840d009143934d91d8dcb8ded054d8301d7c11a517ace0a99bb1e1595e"
dependencies = [
"ab_glyph",
"ahash",
"bytemuck",
"ecolor",
"emath",
"nohash-hasher",
"parking_lot",
]
[[package]]
name = "equivalent"
version = "1.0.1"
@@ -1438,6 +1766,16 @@ dependencies = [
"serde",
]
[[package]]
name = "error-code"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21"
dependencies = [
"libc",
"str-buf",
]
[[package]]
name = "euclid"
version = "0.22.9"
@@ -1526,6 +1864,15 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "form_urlencoded"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
dependencies = [
"percent-encoding",
]
[[package]]
name = "fsevent-sys"
version = "4.1.0"
@@ -1562,6 +1909,16 @@ dependencies = [
"waker-fn",
]
[[package]]
name = "gethostname"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "getrandom"
version = "0.2.10"
@@ -1804,6 +2161,25 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]]
name = "home"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb"
dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "idna"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c"
dependencies = [
"unicode-bidi",
"unicode-normalization",
]
[[package]]
name = "image"
version = "0.24.7"
@@ -1816,6 +2192,7 @@ dependencies = [
"num-rational",
"num-traits",
"png",
"tiff",
]
[[package]]
@@ -1876,6 +2253,12 @@ dependencies = [
"web-sys",
]
[[package]]
name = "interpolation"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3b7357d2bbc5ee92f8e899ab645233e43d21407573cceb37fed8bc3dede2c02"
[[package]]
name = "io-kit-sys"
version = "0.3.0"
@@ -1920,6 +2303,22 @@ dependencies = [
"walkdir",
]
[[package]]
name = "jni"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97"
dependencies = [
"cesu8",
"cfg-if",
"combine",
"jni-sys",
"log",
"thiserror",
"walkdir",
"windows-sys 0.45.0",
]
[[package]]
name = "jni-sys"
version = "0.3.0"
@@ -1935,6 +2334,12 @@ dependencies = [
"libc",
]
[[package]]
name = "jpeg-decoder"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e"
[[package]]
name = "js-sys"
version = "0.3.64"
@@ -2092,6 +2497,15 @@ version = "2.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c"
[[package]]
name = "memoffset"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
dependencies = [
"autocfg",
]
[[package]]
name = "metal"
version = "0.24.0"
@@ -2213,6 +2627,7 @@ dependencies = [
"bitflags 1.3.2",
"cfg-if",
"libc",
"memoffset",
]
[[package]]
@@ -2226,6 +2641,12 @@ dependencies = [
"libc",
]
[[package]]
name = "nohash-hasher"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
[[package]]
name = "nom"
version = "7.1.3"
@@ -2367,6 +2788,17 @@ dependencies = [
"objc_exception",
]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]]
name = "objc-sys"
version = "0.2.0-beta.2"
@@ -2402,6 +2834,15 @@ dependencies = [
"cc",
]
[[package]]
name = "objc_id"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
dependencies = [
"objc",
]
[[package]]
name = "object"
version = "0.32.1"
@@ -2564,6 +3005,12 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "pretty-type-name"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0f73cdaf19b52e6143685c3606206e114a4dfa969d6b14ec3894c88eb38bd4b"
[[package]]
name = "proc-macro-crate"
version = "1.3.1"
@@ -2851,11 +3298,20 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "str-buf"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0"
[[package]]
name = "studio"
version = "0.1.0"
dependencies = [
"bevy",
"bevy-inspector-egui",
"bevy_mod_outline",
"bevy_mod_picking",
"console_error_panic_hook",
"parking_lot",
"wasm-bindgen",
@@ -2974,6 +3430,17 @@ dependencies = [
"once_cell",
]
[[package]]
name = "tiff"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d172b0f4d3fba17ba89811858b9d3d97f928aece846475bbda076ca46736211"
dependencies = [
"flate2",
"jpeg-decoder",
"weezl",
]
[[package]]
name = "tinyvec"
version = "1.6.0"
@@ -3095,12 +3562,27 @@ dependencies = [
"static_assertions",
]
[[package]]
name = "unicode-bidi"
version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-normalization"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-width"
version = "0.1.11"
@@ -3113,6 +3595,17 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "url"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
]
[[package]]
name = "uuid"
version = "1.4.1"
@@ -3250,6 +3743,29 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "webbrowser"
version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b2391658b02c27719fc5a0a73d6e696285138e8b12fba9d4baa70451023c71"
dependencies = [
"core-foundation",
"home",
"jni 0.21.1",
"log",
"ndk-context",
"objc",
"raw-window-handle",
"url",
"web-sys",
]
[[package]]
name = "weezl"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
[[package]]
name = "wgpu"
version = "0.16.3"
@@ -3381,6 +3897,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "winapi-wsapoll"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
@@ -3639,6 +4164,28 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "x11rb"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507"
dependencies = [
"gethostname",
"nix 0.24.3",
"winapi",
"winapi-wsapoll",
"x11rb-protocol",
]
[[package]]
name = "x11rb-protocol"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67"
dependencies = [
"nix 0.24.3",
]
[[package]]
name = "xi-unicode"
version = "0.3.0"