Coder Social home page Coder Social logo

babylonjs / babylonnative Goto Github PK

View Code? Open in Web Editor NEW
743.0 743.0 125.0 66.25 MB

Build cross-platform native applications with the power of the Babylon.js JavaScript framework

License: MIT License

C++ 81.79% C 0.11% JavaScript 4.43% CMake 4.31% Java 0.97% Objective-C 0.14% Objective-C++ 7.54% Swift 0.71%
babylon cpp native

babylonnative's People

Contributors

acoget avatar alex-msft avatar andy-fillebrown avatar bghgary avatar cedricguillemet avatar chrisfromwork avatar coprez avatar darraghjburke avatar dependabot[bot] avatar docedub avatar drigax avatar ericbeetsofficial-opuscope avatar giraphics avatar glangstonb avatar ioridev avatar jiyagupta-cs avatar jomcclan avatar jp833 avatar okwasniewski avatar polygonalsun avatar rgerd avatar rickfromwork avatar ryantrem avatar satyapoojasama avatar sergiorzmasson avatar shial4 avatar syntheticmagus avatar trevordev avatar tymlipari avatar zhuoyitao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

babylonnative's Issues

CURL and https

I tried to download .js script instead of loading resource assets using https on the GitHub raw repo. I get an CURLE_UNSUPPORTED_SCHEME error code from curl_url_set. Apparently it has something to do with proxies (?)

Feature Backlog

BROWSER CAPABILITIES

  • Complete implementation of XMLHttpRequest
  • Investigate Web workers
  • Investigate WebAssembly

ARCHITECTURE

  • Propose and implement proper InputManager

NATIVE ENGINE

  • Finalize Babylon Native contract
  • Correctly support device loss
  • Skyboxes
  • Fix stub for URL.createObjectURL in engine
  • Fix stub for URL.revokeObjectURL in engine
  • Fix stub for Blob in engine
  • Investigate BGFX multi-threading
  • drawElementsType and drawArrayType should be more robust
  • Refactor NativeEngine.ts to share more with other engines
  • Implement setViewport
  • Fix TODO's in NativeEngine.ts
  • Complete implementation of NativeEngine.createTexture
  • Implement instancing support
  • Implement XHR progress support
  • Implement GLB support
  • Ensure proper support for Unicode file paths
  • Revise Tools.LoadScript to not depend on document
  • Handle backbuffer, depth, and stencil in ViewClearState
  • Ensure BindFrameBuffer is setting all the necessary state
  • Investigate limiting frame buffer SetUpView to only happen after reset (may not have meaningful perf impact)
  • Refactor OpenXR support to minimize/eliminate per-frame allocations

TEST INFRASTRUCTURE

  • Continuous integration
  • Pass all asset generator tests
  • Pass all Babylon.js tests
  • Create test automation

DOCUMENTATION

  • Create React Native sample project
  • Create Vue sample project
  • Create InputManager sample project
  • Automate documentation (if API is large enough?)
  • Document Babylon Native contract
  • Investigate XAML example

CROSS PLATFORM

  • Support Android
  • Support iOS
  • Support macOS
  • Support XAML by implementing ISwapChainPanel constructor
  • Ensure proper support for used texture types across platforms

JAVASCRIPT INFRASTRUCTURE

  • Enable V8 debugging
  • Correctly propagate and handle JavaScript errors
  • Investigate JSI support

Android issues

Ordered by complexity

  • the project compiles for x86 and x86_64 but has never been tested on the simulator
  • V8 .so are poorly handled in the APK for the Native Activity project. It needs to be fixed before it can run
  • V8 must be installed manually for local builds. This should be done automatically in CMake
  • Screen ratio is not updated with screen rotation
  • Add support for SSL
  • Shader compliance and parsing between BJS and bgfx is not great for OpenGL. Expect issues when dealing with more complex shaders
  • Front facing is inverted (you see the inside of the cube). A bgfx repo update will be done shortly and should be done on Master @CedricGuillemet
  • Asset loading is using a callback mecanism that supports APK assets loading. It will be replaced by a plugin extension (#101)
  • getHostDocument is missing in native engine definition ( https://github.com/BabylonJS/BabylonNative/pull/30/files#diff-61eebfcda2bd45c2180b579c8f4fcd42R51 ) => PR : BabylonJS/Babylon.js#7286

XR is broken in master

Call stack:

>	TestApp.exe!bx::debugBreak() Line 38	C++
 	TestApp.exe!bgfx::CallbackStub::fatal(const char * _filePath, unsigned short _line, bgfx::Fatal::Enum _code, const char * _str) Line 70	C++
 	TestApp.exe!bgfx::fatal(const char * _filePath, unsigned short _line, bgfx::Fatal::Enum _code, const char * _format, ...) Line 438	C++
 	TestApp.exe!bgfx::setViewFrameBuffer(unsigned short _id, bgfx::FrameBufferHandle _handle) Line 4714	C++
 	TestApp.exe!babylon::NativeEngine::SetViewPort(const Napi::CallbackInfo & info) Line 1349	C++
 	TestApp.exe!Napi::ObjectWrap<babylon::NativeEngine>::InstanceVoidMethodCallbackWrapper::__l2::<lambda>() Line 3409	C++
 	TestApp.exe!Napi::details::WrapCallback<void * <lambda>(void)>(Napi::ObjectWrap<babylon::NativeEngine>::InstanceVoidMethodCallbackWrapper::__l2::void * <lambda>(void) callback) Line 61	C++
 	TestApp.exe!Napi::ObjectWrap<babylon::NativeEngine>::InstanceVoidMethodCallbackWrapper(napi_env__ * env, napi_callback_info__ * info) Line 3411	C++
 	TestApp.exe!`anonymous namespace'::ExternalCallback::Callback(void * callee, bool isConstructCall, void * * arguments, unsigned short argumentCount, void * callbackState) Line 172	C++

Looks like the ViewID mechanism is no longer functioning as it used to.

Console outputs

Remove the win32 code in console.cpp and allow for the client to register output functions/lambda. Test apps will be responsible for the output (outputDebugString, android_log_output,...)

Curl and local file access

To access local files in the APK (scripts/*.js), Android asks to use an asset manager. You can't open the file directly and basically, it's not even a file in the filesystem but a bunch of bytes in a zip. For now, I've added a function, per platform that does the job if curl doesn't succeed at loading the resource.

XR basic input

Add support for extremely basic input (comparable to OpenXR's Khronos simple_controller) for XR scenarios, including full routing up to Babylon. This will make it easier for Babylon.js to test and iterate on WebXR support using knowable and controllable inputs from the underlying implementation.

Investigate using BGFX's built-in multithreaded capabilities

We're currently forcing BGFX to be single-threaded, which isn't its favorite thing to do, only because it aligned more directly with how we prototyped the integration. Evaluate what it would take/mean to enable multithreading in BgfxEngine.cpp.

Testapp project

When generating project with CMake, you can only create one testapp target.

  • win32 or UWP on Windows
  • ios or macos on Mac
    I was wondering if we should not create a testapp_win32 and testapp_UWP target on Windows, in the same generated project.
    and both targets on mac as well.

Establish and adhere to CMake platforms pattern

We currently have a mixture of patterns for checking platforms throughout our CMakeLists.txt files, mixing variables like WINDOWS_STORE and APPLE in with our usage of BABYLON_NATIVE_PLATFORM. Let's discuss (here in this issue?) what the preferred pattern should be, then propagate pattern everywhere that makes sense and, if there are exceptions where the pattern should be broken, clearly designate these exceptions with comments.

TODOs and hacks remaining in NativeEngine implementation

Apparent memory leak

Repro steps:

  1. Launch default TestApp experience
  2. Wait for experience to finish loading, then press "R" to recreate the Babylon Native Runtime.

Result:
Every time the Runtime is recreated, memory usage climbs.

Expected Behavior:
All Runtime resources should be discarded successfully when the Runtime is recreated, so there should be no leftovers to occupy memory after pressing "R".

CURL issues

Centralising all the CURL issues here. This might be used as requirements for a CURL replacement.

  • Support non-blocking curl
    Our usage of libcurl is currently the blocking synchronous version. We should use the non-blocking asynchronous version.
  • UWP with broad file system access in libcurl fails
    For UWP, we have <rescap:Capability Name="broadFileSystemAccess" /> set in the manifest and have enabled in the settings to allow the app.
  • Curl doesn't handle binary to text conversions. We need to deal with the BOM and text-encoding, etc. See here.

libcurl eventually calls the C open API (which eventually calls CreateFileW), but this returns -1.

We currently have a fallback mechanism to use Windows::Storage::StorageFile::GetFileFromPathAsync instead, but it would be nice to see if we can get libcurl to work with broadFileSystemAccess.
Curl and local file access
To access local files in the APK (scripts/*.js), Android asks to use an asset manager. You can't open the file directly and basically, it's not even a file in the filesystem but a bunch of bytes in a zip. For now, I've added a function, per platform that does the job if curl doesn't succeed at loading the resource.
Issue moved to plugin #119

  • Remove workaround for cURL integration in UWP
    # TODO: Certain parts of cURL's functionality are gated behind WINAPI checks
    # that cause the functionality to become unavailable in UWP. Find a better way
    # to ensure that functionality is enabled, then remove the following workaround.
    if(WINDOWS_STORE)
    target_compile_definitions(libcurl PRIVATE "WINAPI_PARTITION_DESKTOP=1")
    endif()
  • CMake libcurl taking too much time
    CMake 3min40 to generate solution per target on Azure with at least 2min30 taken only by libcurl
    There must be some flags to change to speed up the solution generation time.
  • Security issue on Android with OpenSSL. I had to disable host and peer verification because of curl unable to check that. This is far beyond my knowledge and should be addressed by someone competent.
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);

Support non-blocking curl

Our usage of libcurl is currently the blocking synchronous version. We should use the non-blocking asynchronous version.

Remove workaround for cURL integration in UWP

# TODO: Certain parts of cURL's functionality are gated behind WINAPI checks
# that cause the functionality to become unavailable in UWP. Find a better way
# to ensure that functionality is enabled, then remove the following workaround.
if(WINDOWS_STORE)
target_compile_definitions(libcurl PRIVATE "WINAPI_PARTITION_DESKTOP=1")
endif()

x86 Chakra build is broken

Looks like something became incompatible as a result of the Promise work done for the OpenXR integration.

HttpStatusCode crossplatform

Replace winrt::Windows::Web::Http::HttpStatusCode in XMLHttpRequest.h with something crossplatofmr (custom enum?)

Design flaw: storing NAPI constructors as static persistent references is not sustainable

In many places where we create JavaScript types using NAPI, we store off a copy of the constructor as a private static Napi::FunctionReference within the C++ type. This will probably not work if/once we have multiple simultaneous runtimes as the constructors for the second runtime will replace those of the first. Moreover, this is not probably not necessary, since the constructors should be owned by the JavaScript global context (at least in the majority of cases) and probably shouldn't be kept by native at all.

CMake libcurl taking too much time

CMake 3min40 to generate solution per target on Azure with at least 2min30 taken only by libcurl
There must be some flags to change to speed up the solution generation time.

Make XR begin and end session asynchronous

Work will require the XrPlugin to have access to the task chain, so should be undertaken after the work to switch NativeEngine to us runtime global state stored with NAPI so that XrPlugin can take advantage of the same mechanism.

RuntimeImpl order of destruction

The order of destruction is not quite working as intended in RuntimeImpl::BaseThreadProcedure right now. As it's currently written, the JavaScript environment (env) is correctly tied to the lifetime of the thread on which it was created, which is strictly less than the lifespan of the RuntimeImpl itself. However, the dispatcher and task chain which represent the thread are actually members of the RuntimeImpl; therefore, they outlive the thread and are destroyed after the the thread has terminated; in other words, they strictly outlive env. The problem with this is that the capturing lambdas we use inside the task system end up holding onto unsafe references (i.e., Napi::FunctionReference) to objects that are owned by env. These objects are of course destroyed when the env dies, and the dispatcher and task chain's attempts to destroy them again therefore cause the program to crash on close.

I can currently think of two ways to address this. Option 1 is to manually clear the task chain and dispatcher in the shutdown phase of the thread, thereby causing them to be empty before the env is destroyed (this will require changes to Arcana). Option 2 is to make the dispatcher and task chain not be members of the RuntimeImpl, but instead make them beholden to the thread in the same way env is, perhaps by encapsulating all this thread state in an object which can be used to guarantee destruction order. Option 2 is probably the more correct of these alternatives; it'll just require some minor rearchitecting of the RuntimeImpl to achieve the desired result without losing the ability to enqueue work before the thread has actually started.

NativeEngine may be doing more copying than is necessary

In a number of places, NativeEngine.cpp is using bgfx::copy to create locally owned copies of data from Babylon.js (this line, for example). This is probably redundant, as Babylon.js is already keeping copies to deal with device loss and other problems, so it should be possible to have the NativeEngine operate on refs alone so long as it's given access to the permanently-stored versions of data on the JavaScript side, not temporary copies. Fixing will require changes on both managed and native sides.

Investigate pluggable pattern for extending the runtime

As a starting point, we want to try to separate out the Console callbacks in the runtime constructor and the NAPI object wrap of the Console into its own "module" and the TestApp is responsible for adding it if needed.

Future runtime objects will all be done using this kind of pattern.

V8 and Android

V8 is not part of the repo. We will use Nugget or another package mgmt. to download it during build.
V8 .so must be placed in TestApp\Source\Android\app\src\main\jniLibs${ABI}
It's used to link against the Android app and copied by the gradle build system into the apk for dynamic JNI linking. .so for arm64, arm32, x86, x86-64 must be present when releasing a public apk.

Headers include is set in CMakeLists.txt external build of the Android TestApp.

Take care of commented deletion
https://github.com/BabylonJS/BabylonNative/pull/18/files#diff-0ac7323dc9a9ce79677fe03a04509a80L53
As GetArrayBufferAllocator method doesn't seem to be present

Default backbuffer clearing to wrong color

image

The purple color visible in this screenshot is the default color we provide to BGFX, but Babylon.js should be overriding this color with the Playground's blue. This is indicative that the clear state may not be being set properly for the default view.

Platform issues

Here are the issues so far I've found while trying to compile for Android:

  • Exception with string and missing noexcept keyword in Arcana. Will do a PR for that
  • libcurl Win32 headers conflict. I had to hack it with a 'set(CMAKE_USE_WINSSL 0)' in the cmakelists. There must be a better fix/config
  • bgfx.cmake just a couple lines for Android. There might be more than that to do. Will do a PR
  • V8. Unable to compile for Android arm/arm64. I tried various tags, various toolchains, manually tried to create the .a. there is always something failing. Compiles and link with the nugget package!
  • Clang templates shitstorm. I commented the lines to get something compiled. No fix yet. I will try to make a repro on Windows with clang so anyone can try to find a solution.

Metal / things to do

  • Find a way to rename uniform buffers in the compiler like what shaderc does. Instead of string search and replace

OpenGL(ES) and uniforms

Some problems I encountered:

  • shader uniforms inside a struct named 'Frame' when linking shader, the size of that struct differs between VS and FS resulting in a non linking shader. I did a string replace for now to remove it as bgfx doesn't support uniform struct
  • bgfx only supports mat4x4 and vec4 uniform I get a driver error when trying to set a vec4 on a vec3 uniform
  • for now, I tweak the shader string instead of passing in glslang. It might not be useful to pass the shader with glslang on Android. I see multiple benefits: smaller binary, faster shader loading. Might evaluate that in the future.

Implement NAPI for JavaScriptCore

JSC needs more work:

  • handle dispose & destructor callback
  • find a way to link externals and c++ object on the JSC side, without another map
  • private object on class instead of std::map
  • test with gltf loading
  • reference counting
  • define_class is the Hotpoint for all the method and properties definition.

Support XAML for UWP apps

Right now, the only known missing feature for this is the ISwapChainPanel constructor path for RuntimeUWP. TODO and implementation starting point here:

// TODO: Allow creation from swap chain, which is required by XAML apps.
// explicit RuntimeUWP(ABI::Windows::UI::Xaml::Controls::ISwapChainPanel* panel, const std::string& rootUrl = {});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.