Claude/fix obs zoom script b f bh m#96
Conversation
obs_sceneitem_get_info and obs_sceneitem_set_info were renamed to obs_sceneitem_get_info2 / obs_sceneitem_set_info2 in OBS 29 and removed in later releases, causing a nil-call crash on script_update. Add a compatibility shim at startup: if the old names are missing, alias them from the new _info2 variants. This keeps the script working on both old and new OBS versions. Also fix a pre-existing bug in the zoom reset path: it was calling obs_sceneitem_get_info (read) instead of obs_sceneitem_set_info (write) when restoring the original transform, so the scene item was never actually reset after zooming out. https://claude.ai/code/session_01Rq3ZDgoKcZu6LZzFLsk9F6
|
fix in new obs versions |
There was a problem hiding this comment.
Pull request overview
This PR updates the OBS “zoom-to-mouse” Lua script to improve compatibility with newer OBS scripting APIs and to better restore state when zooming ends.
Changes:
- Add an OBS API compatibility shim mapping
obs_sceneitem_get/set_infoto*_info2when the older names aren’t available. - Fix transform reset logic to call
obs_sceneitem_set_info(...)when restoring the original transform info. - Reset crop filter settings back to the original crop when a zoom-out animation completes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| -- When we finished zooming out we remove the timer | ||
| if zoom_state == ZoomState.ZoomingOut then | ||
| log("Zoomed out") | ||
| set_crop_settings(crop_filter_info_orig) |
There was a problem hiding this comment.
After calling set_crop_settings(crop_filter_info_orig) when zooming out finishes, the OBS filter state is reset to the original crop, but the in-memory crop_filter_info table is left at its last interpolated value. If zoom_speed overshoots 1 (e.g., 0.6), the last interpolation step may be far from the original crop, causing a visible jump on the next zoom/follow frame when set_crop_settings(crop_filter_info) is called again. Consider also copying crop_filter_info_orig into crop_filter_info (or otherwise re-syncing crop_filter_info with the applied settings) at this point.
| set_crop_settings(crop_filter_info_orig) | |
| set_crop_settings(crop_filter_info_orig) | |
| -- Keep the in-memory crop state in sync with the crop we just applied. | |
| for key in pairs(crop_filter_info) do | |
| crop_filter_info[key] = nil | |
| end | |
| for key, value in pairs(crop_filter_info_orig) do | |
| crop_filter_info[key] = value | |
| end |
The previous animation used lerp(current_pos, target, ease_in_out(t)) where current_pos changed every frame. Because the "from" point moved each tick, the ease function never operated on a fixed range and the motion collapsed to near-linear. Fix by storing zoom_from_crop at the moment each zoom starts, then always interpolating lerp(zoom_from_crop, target, eased_t). This gives a clean, predictable curve over the full duration. Apply direction-specific cubic easing: - Zoom in: ease_in (t^3) — starts slow, accelerates into the zoom - Zoom out: ease_out (1-(1-t)^3) — snaps away fast, settles smoothly Also add standalone ease_in() and ease_out() helpers alongside the existing ease_in_out() function. https://claude.ai/code/session_01Rq3ZDgoKcZu6LZzFLsk9F6
No description provided.