Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #45 from pthom/fix_runtimmecompil
Browse files Browse the repository at this point in the history
Fix runtimmecompil
  • Loading branch information
samdauwe authored Nov 3, 2019
2 parents f539202 + d4f803d commit 368738c
Show file tree
Hide file tree
Showing 82 changed files with 187 additions and 96 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

The goal of BabylonCpp is to fully implement the relevant portions of the excellent Babylon.js 3D framework/engine in C++17, facilitating the creation of lightweight, cross-platform 3D games and applications with native performance.

[![BabylonCpp](https://img.youtube.com/vi/HwvctC80qho/0.jpg)](https://www.youtube.com/embed/HwvctC80qho "BabylonCpp")
It includes more than 200 examples, a graphical inspector for all 3D objects (based on [ImGui](https://github.com/ocornut/imgui)), as well as an interactive playground for live coding and experiments.

[![BabylonCpp](doc/assets/babylon_demo_video.png)](https://youtu.be/McU8_vIEJfQ "BabylonCpp")

# Get the Sources

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/samples_current/BulbSelfShadowScene.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/samples_current/CellShadingMaterialScene.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/samples_current/CustomRenderTargetsScene.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/samples_current/EnvironmentScene.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshots/samples_current/HighlightLayerScene.jpg
Binary file modified assets/screenshots/samples_current/PBRMaterialORMWoodScene.jpg
Binary file modified assets/screenshots/samples_current/PBRMaterialScene.jpg
Binary file modified assets/screenshots/samples_current/ShaderMaterialSeascapeScene.jpg
Binary file modified assets/screenshots/samples_current/WaterMaterialScene.jpg
62 changes: 62 additions & 0 deletions assets/screenshots/scripts/compare_screenshots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# pip install --upgrade scikit-image
# pip install --upgrade imutils

from skimage.measure import compare_ssim
import argparse
import imutils
import cv2
import os
import os.path
import numpy as np
import shutil

THIS_SCRIPT_DIR=os.path.dirname(os.path.abspath(__file__))

def compare_image(image_file1, image_file2) -> (float, np.array):
imageA = cv2.imread(image_file1)
imageB = cv2.imread(image_file2)
grayA = cv2.cvtColor(imageA, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(imageB, cv2.COLOR_BGR2GRAY)

# compute the Structural Similarity Index (SSIM) between the two
# images, ensuring that the difference image is returned
(score, diff) = compare_ssim(grayA, grayB, full=True)
diff = (diff * 255).astype("uint8")
return score, diff

def list_images(folder):
r = []
for root, dirs, files in os.walk(folder, topdown=False):
for file_name in files:
if file_name[-4:] == ".jpg":
r.append(file_name)
return r

CURRENT_IMAGES_FOLDER = THIS_SCRIPT_DIR + "/../samples_current/"
NEW_IMAGES_FOLDER = THIS_SCRIPT_DIR + "/../samples_new"
UPDATE_IMAGES_FOLDER = THIS_SCRIPT_DIR + "/../samples_updated"

def do_compare():
current_images_files = list_images(CURRENT_IMAGES_FOLDER)
new_images_files = list_images(NEW_IMAGES_FOLDER)
if (os.path.isdir(UPDATE_IMAGES_FOLDER)):
shutil.rmtree(UPDATE_IMAGES_FOLDER)
os.mkdir(UPDATE_IMAGES_FOLDER)

for image_file in new_images_files:
new_image_fullpath = NEW_IMAGES_FOLDER + "/" + image_file
shall_update = False
if image_file in current_images_files:
current_image_fullpath = CURRENT_IMAGES_FOLDER + "/" + image_file
score, diff = compare_image(current_image_fullpath, new_image_fullpath)
print("{} : score {}".format(new_image_fullpath, score))
if score < 0.7:
shall_update = True
else:
print("{} : NEW".format(new_image_fullpath))
shall_update = True

if shall_update:
shutil.copyfile(new_image_fullpath, UPDATE_IMAGES_FOLDER + "/" + image_file)

do_compare()
Binary file added doc/assets/babylon_demo_video.png
6 changes: 3 additions & 3 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ endif()

# RuntimeCompiledCPlusPlus
if (NOT APPLE)
option(BABYLON_BUILD_SANDBOX "Build the interactive sandbox (modify and run the sandbox code interactively without exiting)" ON)
option(BABYLON_BUILD_PLAYGROUND "Build the interactive playground (modify and run the playground code interactively without exiting)" ON)
else()
option(BABYLON_BUILD_SANDBOX "Build the interactive sandbox (modify and run the sandbox code interactively without exiting)" OFF)
option(BABYLON_BUILD_PLAYGROUND "Build the interactive playground (modify and run the playground code interactively without exiting)" OFF)
endif()
if (BABYLON_BUILD_SANDBOX)
if (BABYLON_BUILD_PLAYGROUND)
set (RuntimeCompiledCPlusPlus_Dir ${CMAKE_CURRENT_SOURCE_DIR}/RuntimeCompiledCPlusPlus/Aurora)
SET(BUILD_EXAMPLES OFF CACHE BOOL "Build RuntimeCompiledCPlusPlus examples" FORCE)
add_subdirectory(${RuntimeCompiledCPlusPlus_Dir})
Expand Down
2 changes: 1 addition & 1 deletion external/RuntimeCompiledCPlusPlus
4 changes: 2 additions & 2 deletions src/BabylonImGui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ target_compile_definitions(${TARGET}
$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:${TARGET_UPPER}_STATIC_DEFINE>
)

if (BABYLON_BUILD_SANDBOX)
target_compile_definitions(${TARGET} PRIVATE -DBABYLON_BUILD_SANDBOX)
if (BABYLON_BUILD_PLAYGROUND)
target_compile_definitions(${TARGET} PRIVATE -DBABYLON_BUILD_PLAYGROUND)
endif()

# Compile options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace BABYLON {

struct SandboxCompilerStatus
struct PlaygroundCompilerStatus
{
std::shared_ptr<IRenderableScene> _renderableScene = nullptr;
bool _isCompiling = false;
Expand All @@ -30,9 +30,9 @@ namespace BABYLON {
using HeartbeatCallback = std::function<void(void)>;
std::vector<HeartbeatCallback> _heartbeatCallbacks;

// this callback is used by the sandbox compiler
using SandboxCompilerCallback = std::function<SandboxCompilerStatus(void)>;
SandboxCompilerCallback _sandboxCompilerCallback;
// this callback is used by the playground compiler
using PlaygroundCompilerCallback = std::function<PlaygroundCompilerStatus(void)>;
PlaygroundCompilerCallback _playgroundCompilerCallback;
};

void runSceneWithInspector(
Expand Down
48 changes: 24 additions & 24 deletions src/BabylonImGui/src/babylon_imgui/run_scene_with_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class BabylonInspectorApp {
BabylonInspectorApp() {
std::string exePath = BABYLON::System::getExecutablePath();
std::string exeFolder = BABYLON::Filesystem::baseDir(exePath);
std::string sandboxPath = exeFolder + "/../../../src/SamplesRunner/sandbox.cpp";
sandboxPath = BABYLON::Filesystem::absolutePath(sandboxPath);
_sandboxCodeEditor.setFiles({ sandboxPath });
std::string playgroundPath = exeFolder + "/../../../src/SamplesRunner/playground.cpp";
playgroundPath = BABYLON::Filesystem::absolutePath(playgroundPath);
_playgroundCodeEditor.setFiles({ playgroundPath });
}
void RunApp(
std::shared_ptr<BABYLON::IRenderableScene> initialScene,
Expand All @@ -76,12 +76,12 @@ class BabylonInspectorApp {
bool r = this->render();
for (auto f : _appContext._options._heartbeatCallbacks)
f();
if (_appContext._options._sandboxCompilerCallback)
if (_appContext._options._playgroundCompilerCallback)
{
SandboxCompilerStatus sandboxCompilerStatus = _appContext._options._sandboxCompilerCallback();
if (sandboxCompilerStatus._renderableScene)
setRenderableScene(sandboxCompilerStatus._renderableScene);
_appContext._isCompiling = sandboxCompilerStatus._isCompiling;
PlaygroundCompilerStatus playgroundCompilerStatus = _appContext._options._playgroundCompilerCallback();
if (playgroundCompilerStatus._renderableScene)
setRenderableScene(playgroundCompilerStatus._renderableScene);
_appContext._isCompiling = playgroundCompilerStatus._isCompiling;
}

return r;
Expand All @@ -100,8 +100,8 @@ class BabylonInspectorApp {
Scene3d,
SamplesCodeViewer,
SampleBrowser,
#ifdef BABYLON_BUILD_SANDBOX
SandboxEditor,
#ifdef BABYLON_BUILD_PLAYGROUND
PlaygroundEditor,
#endif
};
static std::map<BabylonInspectorApp::ViewState, std::string> ViewStateLabels;
Expand Down Expand Up @@ -166,7 +166,7 @@ class BabylonInspectorApp {
ImGui::BeginGroup();

ShowTabBarEnum(ViewStateLabels, &_appContext._viewState);
ImGui::SameLine(0.f, 80.f);
ImGui::SameLine(0., ImGui::GetContentRegionAvailWidth() - 100.f);
BABYLON::BabylonLogsWindow::instance().render();
ImGui::SameLine();
if (ImGui::Button(ICON_FA_DOOR_OPEN " Exit"))
Expand All @@ -183,9 +183,9 @@ class BabylonInspectorApp {
_samplesCodeEditor.render();
else if (_appContext._viewState == ViewState::SampleBrowser)
_appContext._sampleListComponent.render();
#ifdef BABYLON_BUILD_SANDBOX
if (_appContext._viewState == ViewState::SandboxEditor)
renderSandbox();
#ifdef BABYLON_BUILD_PLAYGROUND
if (_appContext._viewState == ViewState::PlaygroundEditor)
renderPlayground();
#endif

ImGui::EndGroup();
Expand Down Expand Up @@ -265,9 +265,9 @@ class BabylonInspectorApp {

void render3d()
{
#ifdef BABYLON_BUILD_SANDBOX
bool isInSandboxMode = (_appContext._viewState == ViewState::SandboxEditor);
ImVec2 sceneSize = isInSandboxMode ? getSceneSizeSmall() : getSceneSize();
#ifdef BABYLON_BUILD_PLAYGROUND
bool isInPlaygroundMode = (_appContext._viewState == ViewState::PlaygroundEditor);
ImVec2 sceneSize = isInPlaygroundMode ? getSceneSizeSmall() : getSceneSize();
#else
ImVec2 sceneSize = getSceneSize();
#endif
Expand All @@ -276,10 +276,10 @@ class BabylonInspectorApp {
renderHud(cursorPosBeforeScene3d, sceneSize);
}

void renderSandbox()
void renderPlayground()
{
ImGui::BeginGroup();
ImGui::Text("Sandbox : you can edit the code below!");
ImGui::Text("Playground : you can edit the code below!");
ImGui::Text("As soon as you save it, the code will be compiled and the 3D scene will be updated");
render3d();
ImGui::EndGroup();
Expand All @@ -289,9 +289,9 @@ class BabylonInspectorApp {
BabylonLogsWindow::instance().setVisible(true);
}
if (ImGui::Button(ICON_FA_PLAY " Run"))
_sandboxCodeEditor.saveAll();
_playgroundCodeEditor.saveAll();

_sandboxCodeEditor.render();
_playgroundCodeEditor.render();

}

Expand Down Expand Up @@ -345,16 +345,16 @@ class BabylonInspectorApp {

AppContext _appContext;
ImGuiUtils::CodeEditor _samplesCodeEditor = ImGuiUtils::CodeEditor(true); // true <-> showCheckboxReadOnly
ImGuiUtils::CodeEditor _sandboxCodeEditor;
ImGuiUtils::CodeEditor _playgroundCodeEditor;
}; // end of class BabylonInspectorApp


std::map<BabylonInspectorApp::ViewState, std::string> BabylonInspectorApp::ViewStateLabels = {
{ BabylonInspectorApp::ViewState::Scene3d, ICON_FA_CUBE " 3D Scene"},
{ BabylonInspectorApp::ViewState::SampleBrowser, ICON_FA_PALETTE " Browse samples"},
{ BabylonInspectorApp::ViewState::SamplesCodeViewer, ICON_FA_EDIT " Samples Code Viewer"},
#ifdef BABYLON_BUILD_SANDBOX
{ BabylonInspectorApp::ViewState::SandboxEditor, ICON_FA_FLASK " Sandbox"},
#ifdef BABYLON_BUILD_PLAYGROUND
{ BabylonInspectorApp::ViewState::PlaygroundEditor, ICON_FA_FLASK " Playground"},
#endif
};

Expand Down
49 changes: 27 additions & 22 deletions src/BabylonImGui/src/inspector/samples_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,41 +85,46 @@ class SamplesBrowserImpl
void render_filter()
{
bool changed = false;
ImGui::Text("Filter");
if (ImGui::InputText_String("", _query.query))
ImGui::PushItemWidth(200);
if (ImGui::InputText_String("Filter", _query.query))
changed = true;
if (ImGui::Checkbox("Include failing", &_query.includeFailures))
changed = true;
ImGui::SameLine();
if (ImGui::Checkbox("Only failing", &_query.onlyFailures))
changed = true;

if (changed)
fillMatchingSamples();

ImGui::Text("Matching samples : %zi", nbMatchingSamples());

if (OnLoopSamples)
{
ImGui::SameLine(ImGui::GetContentRegionAvailWidth() - 150.f);
if (ImGui::Button("Loop filtered samples"))
{
if (OnLoopSamples) {
ImGui::SameLine(0.f, 50.f);
if (ImGui::Button("Loop filtered samples")) {
std::vector<std::string> filteredSamples;
for (const auto & kv : _matchingSamples)
{
for (const auto& kv : _matchingSamples) {
for (auto sampleName : kv.second)
filteredSamples.push_back(sampleName);
}
OnLoopSamples(filteredSamples);
}
}

float rightMargin = 150.f;
if (_query.includeFailures)
rightMargin = 300.f;
ImGui::SameLine(ImGui::GetContentRegionAvailWidth() - rightMargin);
if (ImGui::Checkbox("Include failing", &_query.includeFailures))
changed = true;
if (_query.includeFailures)
{
ImGui::SameLine();
if (ImGui::Checkbox("Only failing", &_query.onlyFailures))
changed = true;
}

if (changed)
fillMatchingSamples();

ImGui::Text("Matching samples : %zi", nbMatchingSamples());
}

void render_list()
{
ImGui::Checkbox("Show original screenshots", &_showOriginalScreenshots);
ImGui::SameLine();
ImGui::Checkbox("Show current screenshots", &_showCurrentScreenshots);
//ImGui::Checkbox("Show original screenshots", &_showOriginalScreenshots);
//ImGui::SameLine();
//ImGui::Checkbox("Show screenshots", &_showCurrentScreenshots);

enum class CollapseMode
{
Expand Down
4 changes: 2 additions & 2 deletions src/SamplesRunner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ target_link_libraries(${TARGET}
Samples
)

if (BABYLON_BUILD_SANDBOX)
target_compile_definitions(${TARGET} PRIVATE -DBABYLON_BUILD_SANDBOX)
if (BABYLON_BUILD_PLAYGROUND)
target_compile_definitions(${TARGET} PRIVATE -DBABYLON_BUILD_PLAYGROUND)
target_link_libraries(${TARGET} PRIVATE RuntimeCompiler RuntimeObjectSystem)
endif()

Expand Down
8 changes: 4 additions & 4 deletions src/SamplesRunner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include "spawn_screenshots.h"
#include "run_standalone_imgui.h"

#ifdef BABYLON_BUILD_SANDBOX
#ifdef BABYLON_BUILD_PLAYGROUND
#include <SamplesRunner/rtc/rtc_manager.h>
#endif

int main(int argc, char** argv)
{
#ifdef BABYLON_BUILD_SANDBOX
#ifdef BABYLON_BUILD_PLAYGROUND
BABYLON::rtc::RtcManager runtimeCompiler;
runtimeCompiler.Init();
#endif
Expand Down Expand Up @@ -68,8 +68,8 @@ int main(int argc, char** argv)
options._sceneName = sampleName;
options._appWindowParams.FullScreen = flagFullscreen;

#ifdef BABYLON_BUILD_SANDBOX
options._sandboxCompilerCallback = [&runtimeCompiler]() {
#ifdef BABYLON_BUILD_PLAYGROUND
options._playgroundCompilerCallback = [&runtimeCompiler]() {
auto compilerStatus = runtimeCompiler.Heartbeat();
return compilerStatus;
};
Expand Down
Loading

0 comments on commit 368738c

Please sign in to comment.