Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game camera override #27742

Merged
merged 1 commit into from
Nov 8, 2019
Merged

Conversation

rxlecky
Copy link
Contributor

@rxlecky rxlecky commented Apr 6, 2019

Added a button to the 2D and 3D editor viewports that toggles replication of the viewport camera into running game.

So far, only 2D camera replication works. 3D is WIP.

@rxlecky rxlecky requested a review from reduz as a code owner April 6, 2019 20:59
@rxlecky rxlecky changed the title [WIP] Implemented editor viewport camera replication [WIP] Editor viewport camera replication Apr 6, 2019
@Calinou
Copy link
Member

Calinou commented Apr 6, 2019

This looks great! I was just about to open an issue requesting this feature 🙂

@rxlecky
Copy link
Contributor Author

rxlecky commented Apr 6, 2019

Hahah, nice. 😃 At least I know it won't go unused.

This is the current progress in 2D
2D_camrep

@akien-mga akien-mga added this to the 3.2 milestone Apr 7, 2019
@OBKF
Copy link
Contributor

OBKF commented Apr 7, 2019

Nice, It would be grate to have the game run inside the editor as well (for tweaking values when using sync scene and script changes) if you have a single monitor.

@rxlecky
Copy link
Contributor Author

rxlecky commented Apr 7, 2019

@OBKF this is already possible. 🙂 When you launch a game, you can make changes to your script while it's running and when you save the script, it is hot-reloaded in a running game. Also changes that you make to values in the inspector are instantly replicated in game.

@groud
Copy link
Member

groud commented Apr 7, 2019

If possible, I think a button in the toolbar would be better.
I know the 3d editor has the preview button displayed on the viewport, but ultimately I think it should be removed in the 3D view, as it kinda clutters the interface.

Else the feature looks cool, nice job. :)

@rxlecky
Copy link
Contributor Author

rxlecky commented Apr 7, 2019

@groud I tend to agree that the less clutter in the viewport the better. However, since you can have multiple active viewports in the 3D view, I thought placing the button in each viewport makes more sense, rather than having a button in the menu where user would have to pick a viewport by an ID or something similar.

Anyway, the UI is still in kind of a prototype state. Maybe to solve the "issue" with multiple 3D viewports, there will be a single button in the toolbar and it will simply replicate the viewport that was used the last. Or each time the user interacts with a different viewport, the replication switches to it. This could be a bit trippy, though.

@OBKF
Copy link
Contributor

OBKF commented Apr 7, 2019

@SeleckyErik I was referring the other way lol.
I mean if you can play the game inside the editor, or the editor get's the state that your game you are at.
For example if you have to tweak a parameter you need to switch back and forth to the editor (unless you have dual monitor or linux desktop where you set game window ontop).

@rxlecky
Copy link
Contributor Author

rxlecky commented Apr 7, 2019

@OBKF I think it was a deliberate design decision to not have a game running inside of the editor.

@Zireael07
Copy link
Contributor

@SeleckyErik I think at first, but then the stance changed. I know it has been attempted at least twice, but never got far enough to actually be tested.

@rxlecky
Copy link
Contributor Author

rxlecky commented Apr 8, 2019

Hmm... I didn't know that. Indeed it would be an interesting feature to have.

@OBKF
Copy link
Contributor

OBKF commented Apr 8, 2019

Most of the times the game runs differently from the editor, for example there is no get_viewport().get_camera() in the editor, so doing something with viewing camera won't be possible and can only be seen in game.
On the other hand, the editor have some slowdowns (mentioned in a few issues), therefore the performance (I suppose) won't be the same as a separated window, but its worth the time saving.
If this feature got implemented it should be optional and the user must have choice to run it in editor or separated window.

@reduz
Copy link
Member

reduz commented Apr 21, 2019

I think the PR is mostly good, but I think the way to override the camera is not so good. This is not your fault, but the fact there is not a clean way to do this. Let me see if I can add relevant functions to Viewport for this, to make your life easier

@rxlecky
Copy link
Contributor Author

rxlecky commented Apr 21, 2019

If you can give me some pointers on what is not so well done and what would be your proposed solution, I can attempt implementing it myself. I can only imagine you have more than enough tasks on your to-do list.

@rxlecky
Copy link
Contributor Author

rxlecky commented May 13, 2019

@reduz any update on this? Will you have time to work on this any time soon or explain me what needs to be changed? I will be working on the watches now, but afterwards I want to get back to this PR.

@rxlecky
Copy link
Contributor Author

rxlecky commented Jun 5, 2019

Addressed the mentioned issues: Reworked the 3D camera override API in the Viewport as discussed with @reduz. Moved the button to trigger the tool to the top toolbar as suggested by @groud. Also cleaned up the code so this should be now ready to merge.

@rxlecky rxlecky changed the title [WIP] Editor viewport camera replication Editor viewport camera replication Jun 5, 2019
@rxlecky rxlecky force-pushed the camera-replication branch 2 times, most recently from fb3c8ee to 74d8ab9 Compare June 11, 2019 13:04
@rxlecky
Copy link
Contributor Author

rxlecky commented Jun 11, 2019

Squashed all commits

editor/plugins/canvas_item_editor_plugin.cpp Outdated Show resolved Hide resolved
scene/main/viewport.cpp Outdated Show resolved Hide resolved
scene/main/viewport.cpp Outdated Show resolved Hide resolved
scene/main/viewport.cpp Outdated Show resolved Hide resolved
@rxlecky
Copy link
Contributor Author

rxlecky commented Jun 11, 2019

Noted. Will make the changes and get back to you. :)

@rxlecky
Copy link
Contributor Author

rxlecky commented Jun 20, 2019

I believe I addressed all the issues that you pointed out @reduz. The only thing I am not sure about is whether the SpatialIndexer in World needs to be aware of the override camera. If it does, it would be problematic since it keeps track of all cameras in form of Camera node pointers and I'm now only using Camera RID.

Also, I'd say that when the camera override is used, the overriding camera should be used for the spatial sound, rather than the in-game camera. However, since theSpatialSoundServer is currently disabled/not implemented, I did not implement this functionality. This will have to be additionally fixed once the spatial sound is implemented again.

@rxlecky rxlecky force-pushed the camera-replication branch 2 times, most recently from a152824 to a2b5fc9 Compare October 15, 2019 14:31
@rxlecky rxlecky requested a review from a team as a code owner October 15, 2019 14:31
@rxlecky rxlecky force-pushed the camera-replication branch 3 times, most recently from 6ff63be to 83f08c9 Compare October 15, 2019 15:03
@rxlecky
Copy link
Contributor Author

rxlecky commented Oct 22, 2019

Summary of what was discussed at the Godot Sprint:

  • The PR should be good to merge now to get feedback on the tool from the users. Later when Pedro's PR (Live view panel #29136) is ready for 4.0, small tweaks might be needed.

  • It would be cool if this worked even when the game is paused from the editor. I'm currently working on implementing this.

  • Currently the tool uses camera node icon. More distinct icon that illustrates the tool functionality better would improve readability. Maybe @Calinou could give me a hand here?

@rxlecky rxlecky changed the title Editor viewport camera replication Game camera override Oct 23, 2019
Implemented uniform API in Viewport class to override 2D and/or
3D camera.

Added buttons in 2D and 3D editor viewport toolbars that override
the running game camera transform with the editor viewport camera
transform. Implemented via remote debugger protocol and camera
override API.

Removed LiveEditFuncs function pointers from ScriptDebugger class.
Since the debugger got access to the SceneTree instance (if one
exists), there is no need to store the function pointers. The live
edit functions in SceneTree are used directly instead. Also removed
the static version of live edit functions in SceneTree for the same
reason. This reduced the SceneTree -> Debugger coupling too since
the function pointers don't need to be set from SceneTree anymore.

Moved script_debugger_remote.h/cpp from 'core/' to 'scene/debugger/'.
This is because the remote debugger is now using SceneTree directly
and 'core/' classes should not depend on 'scene/' classes.
Comment on lines +360 to +365
// This is for the camera override to stay live even when the game is paused from the editor
loop_time_sec = (OS::get_singleton()->get_ticks_usec() - loop_begin_usec) / 1000000.0f;
VisualServer::get_singleton()->sync();
if (VisualServer::get_singleton()->has_changed()) {
VisualServer::get_singleton()->draw(true, loop_time_sec * Engine::get_singleton()->get_time_scale());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made camera override work even when the game is paused from the editor.

@Calinou
Copy link
Member

Calinou commented Oct 28, 2019

@rxlecky What do you think about an icon like the one below? It's based on the CameraTexture icon, but with a larger camera icon and a thinner rectangle (1 pixel instead of 2 pixels).

1x: "Camera sync" icon (1x)

2x: "Camera sync" icon (2x)

Optimized SVG: icon_camera_sync.zip

@rxlecky
Copy link
Contributor Author

rxlecky commented Oct 28, 2019

@Calinou I'm not sure if that quite gets the idea across. I was thinking of something illustrating two cameras being linked together. But that seems like a difficult thing to fit in an icon. Maybe something simpler like a combination of camera icon and a panning tool would do?

obrázok

Not quite like this but you get the idea 😄

@akien-mga
Copy link
Member

It's now a bit late for 3.2 given the release freeze, but as this was reviewed extensively over the past few months by @reduz and we approved it at the Godot Sprint, let's make an exception.

@akien-mga akien-mga merged commit 621dc70 into godotengine:master Nov 8, 2019
@akien-mga
Copy link
Member

Thanks!

@aaronfranke
Copy link
Member

So far, only 2D camera replication works. 3D is WIP.

I assume this text is out of date, because this PR changes spatial_editor_plugin.cpp.

@Calinou
Copy link
Member

Calinou commented Nov 23, 2019

@aaronfranke Indeed, it works well in 3D from my testing. However, I noticed that camera FOV is only set if you set it while the preview is enabled. If you disable camera replication, change the camera FOV in the View settings and enable it again, it won't use the new FOV value (#33847).

realkotob added a commit to realkotob/godot-docs that referenced this pull request Apr 6, 2020
The mentioned disadvantage of godot is now obsolete since godotengine/godot#27742 was merged for 2D and 3D, and the game camera can be overridden from the editor to explore from multiple angles.
Calinou pushed a commit to godotengine/godot-docs that referenced this pull request Apr 6, 2020
The mentioned disadvantage of godot is now obsolete since godotengine/godot#27742 was merged for 2D and 3D, and the game camera can be overridden from the editor to explore from multiple angles.
@rxlecky rxlecky deleted the camera-replication branch September 1, 2021 10:11
@geekley
Copy link

geekley commented Nov 24, 2021

Suggested improvement to this feature from godotengine/godot-proposals#1864 (comment)

A simple feature that would help as a first step towards this is improving the Project Camera Override mode to optionally allow to select remote objects by clicking them in game window.
I imagine this would be simple enough that it could even be back-ported to current editor versions with just a tool script.

As a native editor feature, here's some alternative ways this toggle could be implemented:

  1. As a button next to the "Project Camera Override" icon (maybe only visible when it's enabled); or
  2. As a menu checkbox option when you right-click the "Project Camera Override" icon; or
  3. Automatically enabled when both "Project Camera Override" is enabled and "Remote" is selected in the scene tree view

Of course, 2 or 3 would require an appropriate tooltip in "Project Camera Override" button to help discover the feature.

A "live preview" mode like Unity's is still ideal, but this simple feature would help a lot as a stopgap, because at least selecting one among multiple similar-named objects for inspection would be much easier.

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

Successfully merging this pull request may close these issues.

None yet

9 participants