Jump to content

Starting with Editor Plugins


photo

Recommended Posts

Posted

Hello,

I want to create an Editor Plugin that can help us placing objects, querying the landscape, and showing some info, as demonstrated in the sample CameraTerrainFetchSample.

To begin with, I wanted to simply query the editor player and do some basic intersection under the mouse cursor, but with no success so far. Here is the very basic content of the plugin so far:

class EditorWorldLogic : public Unigine::WorldLogic
{
public:
	int update() override {
		auto player = Editor::getPlayer();
		if (!player) {
			Log::error("Editor player is NULL\n");
			return 1;
		}
		auto p = player->getWorldPosition();
		auto mouse = Input::getMousePosition();
		Log::message("Player is %s: %f %f %f, mouse is %d %d\n", player->getName(), p.x, p.y, p.z, mouse.x, mouse.y);
		Vec3 a, b;
		player->getDirectionFromMainWindow(a, b, mouse.x, mouse.y);
		Log::message("     a: %f %f %f, b: %f %f %f\n", a.x, a.y, a.z, b.x, b.y, b.z );
    }
};

The WorldLogic is added to the engine in the init() of the plugin. So far, so good. BUT:

  • the pointer of the player actually seen by the world logic is actually only updated when I click on the editor viewport. So If I have two players PA and PB in the scene plus the "Editor Player", and if I iterate through all 3 in the Editor combobox, the plugin will only print "Editor Player", unless i actively click in the viewport. Strange.
  • getDirectionFromMainWindow does not work: a and b are always 0,0,0. I guess there is no "main window" in the editor, but how can I find the window viewport actually below the mouse cursor?

Thanks!

Posted

Hi Stephane,

You can check the similar functionality in the ImGuiSample plugin from store: https://store.unigine.com/add-on/1efb3c7d-5082-6e82-8692-7342af84d483/description

The relevant code is in the SampleSplineEditor.cpp (line 443):

const ivec2 mouse_pos = viewport->getMousePos();
	const Vec3 player_pos = player->getWorldPosition();
	const Vec3 player_dir = Vec3(
		player->getDirectionFromScreen(mouse_pos.x, mouse_pos.y, 0, 0, win_size.x, win_size.y));

Editor API is different from the engine a bit. More Viewport methods descriptions you can find here: https://developer.unigine.com/en/docs/2.20/api/editor/class_unigine_editor_1_1_viewport_window.html

Hope that helps :)

Thanks!

  • Like 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Posted

Nice, it works!

New question: is there any way from an Editor Plugin to get and/or set the state of the Helpers mode? For example, I'd like to show additionnal info when the Helper Object Info is enabled, or when the Surface Wireframe is enabled, or even to add my own custom buttons for an easier and quicker access to these functions...

Posted

Hi Stephane,

Right now, the Helpers menu isn't exposed in the Editor API. I've opened a ticket to add this capability, but it may take some time because the menu needs an internal refactor before we can make it public :)

In the meantime, you can create a small custom helpers menu with your own tools.

Thank you!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Posted

I added a checkable QAction to an existing menu, it works great! But how can I save to disk the checked state in the Editor configuration file? I don't want to use the default.user, as it's more for the runtime application, not really for the Engine. Of course, I could make my own config file, but I'd rather use the Editor's one if it is accessible already.

Posted

Hi Stephane,

As far as I know there is currently no API for handling custom settings exists. Of course, you can try to load Editor's config (.cfg file from <USER>\AppData\Local\Unigine\Editor\editor1.1.cfg) via JSON class and modify it, but more likely it would be overridden by Editor occasionally.

Separate config file for your plugin doesn't look too bad as for me :)

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

×
×
  • Create New...