3danimation Posted September 10, 2021 Share Posted September 10, 2021 Hi What is the proper C++ code to add the water feature and all the different water materials? I would like to have a button that turns on the world water system and a menu of all the water materials Similar to how it works in the unigine editor. If u could help me post the codes to do this i would be so grateful Thank you. Also i would like a sun position changer implemented in my project using maybe Imgui. Link to comment
thomalex Posted September 13, 2021 Share Posted September 13, 2021 Hello @3danimation, Let me answer some of your questions. On 9/10/2021 at 8:56 PM, 3danimation said: What is the proper C++ code to add the water feature and all the different water materials? I would like to have a button that turns on the world water system and a menu of all the water materials First of all, water is UNIGINE is represented by two types of objects: ObjectWaterMesh - finite mesh-based water basins ObjectWaterGlobal - an infinite global ocean. Depending on what you need, you can create a corresponding object like so: #include <UnigineObjects.h> /* .. */ // create a new ObjectWaterGlobal node ObjectWaterGlobalPtr water = ObjectWaterGlobal::create(); // enable rendering of water in the world in case it was disabled Render::setWaterEnabled(true); It's not really clear for me what "a button that turns on the water system" means, but if you could create a WidgetButton that would be accountable for toggling the water rendering: Spoiler int AppWorldLogic::init() { // create a water node ObjectWaterGlobalPtr water = ObjectWaterGlobal::create(); // create a button widget and add a callback GuiPtr gui = Gui::get(); WidgetButtonPtr toggle = WidgetButton::create(gui, "Toggle Water"); toggle->setToggleable(1); toggle->setFontSize(24); toggle->setPosition(128, 128); gui->addChild(toggle, Gui::ALIGN_OVERLAP); toggle->addCallback(Gui::CLICKED, MakeCallback(this, &AppWorldLogic::toggleWater)); return 1; } // toggle water on button pressed callback void AppWorldLogic::toggleWater() { Render::setWaterEnabled(!Render::isWaterEnabled()); } For a list of water materials you can use WidgetListBox or WidgetComboBox. Check out the examples in the dedicated API docs. On 9/10/2021 at 8:56 PM, 3danimation said: Also i would like a sun position changer implemented in my project using maybe Imgui. I can't speak for ImGui right now, but the most natural way to adjust the sun rotation is by using the WidgetManipulatorRotator, why not use it? Please, clarify a bit more details about the desired behaviour so we can find the most appropriate solutions. Thanks! Link to comment
3danimation Posted September 14, 2021 Author Share Posted September 14, 2021 (edited) The code is showing a build error. Are u sure this is right? toggle->addCallback(Gui::CLICKED, MakeCallback(this, &AppWorldLogic::toggleWater)); return 1; } // toggle water on button pressed callback void AppWorldLogic::toggleWater() { Render::setWaterEnabled(!Render::isWaterEnabled()); } This is not working... Everything else worked How do i actually make the button perform water on and water off command?? Edited September 14, 2021 by 3danimation Link to comment
thomalex Posted September 15, 2021 Share Posted September 15, 2021 That's just a code snippet showing the use case, but it must be workable. Make sure you have included all the necessary headers and defined all the methods and class members in the AppWorldLogic.h. If it's not the case, please attach the build log with errors so we check the problem. You can also check out the following sample that I prepared for you, it is capable of toggling water rendering on and off and provides a list of default water materials assigned to the global water object when selected. AppWorldLogic.cpp AppWorldLogic.h Thanks! 1 Link to comment
3danimation Posted September 16, 2021 Author Share Posted September 16, 2021 Thank you so much. Im creating my own menu using QT Is there a tutorial for how exactly ill add the QT menu to my unigine project? Link to comment
Recommended Posts