MCPcopy Create free account
hub / github.com/BabylonJS/BabylonNative / RefreshBabylon

Function RefreshBabylon

Apps/Playground/Win32/App.cpp:90–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88 }
89
90 void RefreshBabylon(HWND hWnd)
91 {
92 Uninitialize();
93
94 runtime = std::make_unique<Babylon::AppRuntime>();
95
96 RECT rect;
97 if (!GetWindowRect(hWnd, &rect))
98 {
99 return;
100 }
101
102 // Initialize console plugin.
103 runtime->Dispatch([rect, hWnd](Napi::Env env) {
104 Babylon::Polyfills::Console::Initialize(env, [](const char* message, auto) {
105 OutputDebugStringA(message);
106 });
107
108 Babylon::Polyfills::Window::Initialize(env);
109 Babylon::Polyfills::XMLHttpRequest::Initialize(env);
110
111 // Initialize NativeWindow plugin.
112 auto width = static_cast<size_t>(rect.right - rect.left);
113 auto height = static_cast<size_t>(rect.bottom - rect.top);
114 Babylon::Plugins::NativeWindow::Initialize(env, hWnd, width, height);
115
116 // Initialize NativeEngine plugin.
117 Babylon::Plugins::NativeEngine::InitializeGraphics(hWnd, width, height);
118 Babylon::Plugins::NativeEngine::Initialize(env);
119
120 // Initialize NativeXr plugin.
121 Babylon::Plugins::NativeXr::Initialize(env);
122
123 auto& jsRuntime = Babylon::JsRuntime::GetFromJavaScript(env);
124 inputBuffer = std::make_unique<InputManager::InputBuffer>(jsRuntime);
125 InputManager::Initialize(jsRuntime, *inputBuffer);
126 });
127
128 // Scripts are copied to the parent of the executable due to CMake issues.
129 // See the CMakeLists.txt comments for more details.
130 std::string scriptsRootUrl = GetUrlFromPath(GetModulePath().parent_path().parent_path() / "Scripts");
131
132 Babylon::ScriptLoader loader{*runtime};
133 loader.Eval("document = {}", "");
134 loader.LoadScript(scriptsRootUrl + "/ammo.js");
135 loader.LoadScript(scriptsRootUrl + "/recast.js");
136 loader.LoadScript(scriptsRootUrl + "/babylon.max.js");
137 loader.LoadScript(scriptsRootUrl + "/babylon.glTF2FileLoader.js");
138 loader.LoadScript(scriptsRootUrl + "/babylonjs.materials.js");
139 loader.LoadScript(scriptsRootUrl + "/meshwriter.min.js");
140
141 std::vector<std::string> scripts = GetCommandLineArguments();
142 if (scripts.empty())
143 {
144 loader.LoadScript(scriptsRootUrl + "/experience.js");
145 }
146 else
147 {

Callers 2

InitInstanceFunction · 0.85
WndProcFunction · 0.85

Calls 9

InitializeGraphicsFunction · 0.85
UninitializeFunction · 0.70
GetUrlFromPathFunction · 0.70
GetModulePathFunction · 0.70
GetCommandLineArgumentsFunction · 0.70
InitializeFunction · 0.50
DispatchMethod · 0.45
EvalMethod · 0.45
LoadScriptMethod · 0.45

Tested by

no test coverage detected