From e42a9beacdb8a54617b9e6391e0af34b8c0ebc16 Mon Sep 17 00:00:00 2001 From: elm <71685838+not-elm@users.noreply.github.com> Date: Tue, 19 Aug 2025 12:45:27 +0900 Subject: [PATCH] fix: mesh pointer (#4) Fixed so that webview can detect pointers correctly even if it is not the root entity. --- .gitignore | 2 +- CHANGELOG.md | 6 ++++++ examples/.DS_Store | Bin 6148 -> 0 bytes src/system_param/pointer.rs | 18 ++++++++++++++++-- 4 files changed, 23 insertions(+), 3 deletions(-) delete mode 100644 examples/.DS_Store diff --git a/.gitignore b/.gitignore index 66d6cb2..8a26db3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ target/ .idea/ book/ -.DS_Store \ No newline at end of file +.DS_Store**/.DS_Store diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a46e2c..22899d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +### Bug Fixes + +- Fixed so that webview can detect pointers correctly even if it is not the root entity. + ## v0.1.0 First release \ No newline at end of file diff --git a/examples/.DS_Store b/examples/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 { (&'static GlobalTransform, &'static WebviewSize), (With, Without), >, - parents: Query<'w, 's, &'static ChildOf>, + parents: Query<'w, 's, (Option<&'static ChildOf>, Has)>, } impl WebviewPointer<'_, '_, C> { @@ -22,7 +22,7 @@ impl WebviewPointer<'_, '_, C> { where P: Clone + Reflect + Debug, { - let webview = self.parents.root_ancestor(trigger.target); + let webview = find_webview_entity(trigger.target, &self.parents)?; let pos = self.pointer_pos(webview, trigger.pointer_location.position)?; Some((webview, pos)) } @@ -44,6 +44,20 @@ impl WebviewPointer<'_, '_, C> { } } +fn find_webview_entity( + entity: Entity, + parents: &Query<(Option<&ChildOf>, Has)>, +) -> Option { + let (child_of, has_webview) = parents.get(entity).ok()?; + if has_webview { + return Some(entity); + } + if let Some(parent) = child_of { + return find_webview_entity(parent.0, parents); + } + None +} + fn pointer_to_webview_uv( cursor_pos: Vec2, camera: &Camera,