As I can see, there are no example of loading scene, created in editor, in Samples folder. Maybe there are some other example, how to load such scene and access objects from C++?
[solved] How to load scene from resources?
So, now I have following project structure:
[ul]
[]Build[/]
[]Source
[list]
[]CMakeLists.txt[/] []mainApp.cpp[/] []mainApp.h[/] []scenes
[list]
[]mainMenu.xml[/] []uiLayout.xml[/]
[/ul]
[/]
[/list:u]
[/]
[/list:u]
On mainApp.cpp I’m trying to load scene . Maybe later I will have to use Deserializer class to read xml, but for now for some reason I can’t find this file:
[code]#include “mainApp.h”
DEFINE_APPLICATION_MAIN(MainApp)
MainApp::MainApp(Context* context): Application(context)
{
}
void MainApp::Start()
{
Urho3D::Application::Start();
// Called after engine initialization. Setup application & subscribe to events here
SubscribeToEvent(E_KEYDOWN, HANDLER(MainApp, HandleKeyDown));
LoadMainMenu();
}
void MainApp::HandleKeyDown(StringHash eventType, VariantMap& eventData)
{
using namespace KeyDown;
// Check for pressing ESC. Note the engine_ member variable for convenience access to the Engine object
int key = eventData[P_KEY].GetInt();
if (key == KEY_ESC)
engine_->Exit();
}
void MainApp::Setup()
{
Urho3D::Application::Setup();
}
void MainApp::Stop()
{
Urho3D::Application::Stop();
}
void MainApp::LoadMainMenu()
{
ResourceCache* cache = GetSubsystem();
XMLFile *mainMenuScene = cache->GetResource(“scenes/mainMenu.xml”);
//ERROR: Could not find resource scenes/mainMenu.xml
}
[/code]
Why this error can be occurred?
By default, Urho3D specifies the folders Data and CoreData (located in the root of the execution path) as the places to look for data. If you wish to have it look elsewhere, you need to specify the path(s) using the -p command line parameter, as per the documentation.
Thank you, now file can be found, but I still see only black screen. I saw the angelscript code to load the scene from ninja snow war, and wrote some analog with c++: ResourceCache* cache = GetSubsystem<ResourceCache>();
Scene *mainMenu = new Scene(context_);
XMLFile *sceneFile = cache->GetResource<XMLFile>("Scenes/mainMenu.xml");
mainMenu->LoadXML(sceneFile->GetRoot());
For now I have to setup camera? Is it some documentation about loading scene process exists? I found only few sentences there: urho3d.github.io/documentation/1.32/_scene_model.html
For a black screen make sure you are initializing the viewport. A camera has to be assigned to a viewport.
There are no written tutorials on how to do something. There are the c++ api docs which you found that describes the api, there is the the general documentation that explains urhos architecture and some of the decisions made in the engine, and there are the samples. My recommendation is to pick a language (c++, angelscript, lua) and hit the samples. The particular instance of loading a scene isn’t well covered. The documentation really only takes the api first approach, which is a bit unfortunate since urho’s lightweight asset pipeline is pretty decent.
Here is the general documentation: urho3d.github.io/documentation/1.32/index.html
Here is the c++ docs: urho3d.github.io/documentation/1 … tated.html
The samples are in the source tree.
C++ samples - Source/Samples
Angelscript - Bin/Data/Scripts
Lua - Bin/Data/LuaScripts
[quote=“friesencr”]For a black screen make sure you are initializing the viewport. A camera has to be assigned to a viewport.
There are no written tutorials on how to do something. There are the c++ api docs which you found that describes the api, there is the the general documentation that explains urhos architecture and some of the decisions made in the engine, and there are the samples. My recommendation is to pick a language (c++, angelscript, lua) and hit the samples. The particular instance of loading a scene isn’t well covered. The documentation really only takes the api first approach, which is a bit unfortunate since urho’s lightweight asset pipeline is pretty decent.
Here is the general documentation: urho3d.github.io/documentation/1.32/index.html
Here is the c++ docs: urho3d.github.io/documentation/1 … tated.html
The samples are in the source tree.
C++ samples - Source/Samples
Angelscript - Bin/Data/Scripts
Lua - Bin/Data/LuaScripts[/quote]
Still can not display anything:(
Here is my MainApp.h:
http://pastebin.com/tmFiKRmr
MainApp.cpp:
http://pastebin.com/AbTzvE5M
Layout:
http://pastebin.com/5XKqHStw
Log:
http://pastebin.com/TiAZCycK
Loading the layout file will populate a ui component but it does not add it to the ui subsystem. You will need to AddChild on the ui subsystem root node.
Thank you, now I see my layout, but there are something wrong with styles, I think:
Yes, try to use SetStyleAuto(true).
No effect:(
I try ResourceCache* cache = GetSubsystem<ResourceCache>();
XMLFile *layout = cache->GetResource<XMLFile>("UI/mainMenu.xml");
_loadedLayout = GetSubsystem<UI>()->LoadLayout(layout);
_loadedLayout->SetStyleAuto();
GetSubsystem<UI>()->GetRoot()->AddChild(_loadedLayout);
I also tried invoke SetStyleAuto() on RootElement, but this has no effect too
Did you load DefaultStyle.xml?
Now there is an example of loading scene and UI in Urho3D source, so I will examine it to find, what’s was incorrect