Skip to content

Conversation

@Milotrince
Copy link
Contributor

@Milotrince Milotrince commented Nov 17, 2025

Description

nice-to-have feature, allows users to integrate interactive viewer plugins.

Related Issue

N/A

Motivation and Context

  • ViewerPlugin enables directly interfacing with pyviewer mouse/keyboard controls.
  • Replaces pynput
  • Keybind callback registration

How Has This Been / Can This Be Tested?

added tests/test_viewer.py

Screenshots (if appropriate):

Screen.Recording.2025-11-17.at.18.03.51.mov

Checklist:

  • I read the CONTRIBUTING document.
  • I followed the Submitting Code Changes section of CONTRIBUTING document.
  • I tagged the title correctly (including BUG FIX/FEATURE/MISC/BREAKING)
  • I updated the documentation accordingly or no change is needed.
  • I tested my changes and added instructions on how to test it for reviewers.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@duburcqa
Copy link
Collaborator

This feature looks very convenient!

@Milotrince
Copy link
Contributor Author

  • Should we keep under genesis/ext/pyrender/interaction/plugins/ or genesis/vis/plugins ?
  • Do we want to use Vec3, Quat, Color, Ray, etc. classes in the codebase?
  • now that pyrender viewer mouse/keyboard interaction is exposed, we can get rid of pynput in examples

@duburcqa
Copy link
Collaborator

Should we keep under genesis/ext/pyrender/interaction/plugins/ or genesis/vis/plugins ?

Do you consider this as a "universal" plugin or something pyrender-specific? This would give you the answer :)

Do we want to use Vec3, Quat, Color, Ray, etc. classes in the codebase?

I'm not a fan of these objects. Overly complicated and not very pythonic in my view.

now that pyrender viewer mouse/keyboard interaction is exposed, we can get rid of pynput in examples

That would be great! But we need a way to expose this in a clean way.

@Milotrince Milotrince force-pushed the viewer_plugin branch 2 times, most recently from 98601bb to 1e672b0 Compare November 24, 2025 21:42
@duburcqa
Copy link
Collaborator

duburcqa commented Jan 1, 2026

@Milotrince If you could finish this PR I would be happy to review it and merge it :)

@Milotrince Milotrince marked this pull request as ready for review January 11, 2026 04:56
@Milotrince
Copy link
Contributor Author

Milotrince commented Jan 11, 2026

@duburcqa Could I get your opinion on the state of the PR? there are some design decisions I'd like your input on!

  • removed pynput, see examples/* changes for new usage
  • I kept the mouse spring interaction implementation and moved it as a plugin
  • there existed a register key system in pyrender viewer but was not exposed in genesis viewer. I made a Keybind/Keybindings class and exposed register_keybind to viewer

I still need to add tests.

@duburcqa
Copy link
Collaborator

Could I get your opinion on the state of the PR? there are some design decisions I'd like your input on!

Sure ! I will do it this week ! Could you fix the conflicts in the meantime? Thank you :)

@Milotrince Milotrince force-pushed the viewer_plugin branch 2 times, most recently from 7639573 to 0a14941 Compare January 13, 2026 04:17
@duburcqa
Copy link
Collaborator

Comment on lines 81 to 82
# Register keybindings
from pyglet.window import key
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add from pyglet.window import key in your new keybindings module, so that users can do:

from genesis.ext.pyrender.interaction.keybindings import key

This would avoid breaking encapsulation of pyglet, that should be an implementation details for users.

Similarly, it would be great to expose your keybindings module outside ext, that is also supposed to be an implementation details for the end user. This would be relaying not the same mechanism I just mentioned. Ideally the user should be able to replace genesis.ext.pyrender.interaction.keybindings by genesis.vis.keybindings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving a note here: on mac (untested with other machines), when i import pyglet or pyglet.window.key at the top level before viewer does, I get

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication macOSVersion]: unrecognized selector sent to instance 0x1618b7df0'

*** First throw call stack:
(
        0   CoreFoundation                      0x0000000198f498ec __exceptionPreprocess + 176
        1   libobjc.A.dylib                     0x0000000198a22418 objc_exception_throw + 88
        2   CoreFoundation                      0x000000019902b7e8 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
...
        87  python3.12                          0x000000010436e1f0 builtin_exec + 404
        88  python3.12                          0x00000001042bb45c cfunction_vectorcall_FASTCALL_KEYWORDS + 92
        89  python3.12                     
libc++abi: terminating due to uncaught exception of type NSException

By claude's suggestion I added it as a lazily loading module to safely expose key at genesis.vis.keybindings.

@duburcqa
Copy link
Collaborator

Could you split the introduction of ViewerPlugin feature, with the ability to interactively add markers on geometries from the viewer? Because this PR is getting quite bug already and both features are quite orthogonal. It would make my life easier for the review.

You can open a (stacked) PR for the second part right away, merging on top of this branch instead of main (with draft status).

ray_direction_world = ti_normalize(ti_transform_by_quat(ray_dir_local, link_quat), gs.EPS)

# --- 2. BVH Traversal ---
# FIXME: this duplicates the logic in LBVH.query() which also does traversal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why FIXME disappeared? You actually implemented the fix?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because I think the FIXME note isn't quite accurate, raycaster.py does ray-AABB tests while LBVH.query() checks AABB-AABB. There might be a bit of duplicated logic but i think it'd be more complicated to split it up into smaller ti.funcs so may as well leave as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants