Babylon native load script

Hello, my question will probably sound fairly dumb. I have installed Babylon Native and I’m running the sample models contained in the experience.js file (Scripts folder) on my Android emulator (Android Studio) without any problem. In order to play with the tool, I was trying to see if it was possible to run some of the Babylon.js demos as well on the emulator. However, I am having some problems figuring out what I should do, where I should paste the demo Javascript code, whether I should just export the scene as a glb/gltf file, and what function I should use in experience.js in order to have it running in my emulator. Thank you!

The native team being on a well deserved break for the next 2 weeks, you might have to be a little patient for the answer but I have no doubt @bghgary @Cedric or @syntheticmagus will answer as soon as they are back.

Happy hollidays,

2 Likes

Hi @fede17

To load and run new scripts, you can change this loadscript call and add new loadscript calls:

If you want to add new .js scripts, you will have to copy them in the assets folder thanks to this gradle script function:

Or you can add them manually by copying into the assets/scripts folder

2 Likes

Thank you @Cedric! So theoretically I could copy the JavaScript code from a demo (e.g. this code https://playground.babylonjs.com/#KBS9I5#1031) into a new js script (say, sample.js), add sample.js into the Scripts folder, and then call it like this? mView.loadScript(“app:///Scripts/sample.js”);

Yes and no. The playground running in your browser uses the code in the editor with a little bit more code.

So, you will also to run this script:

Basically, your activity code will look this this:

mView.loadScript("app:///Scripts/code_of_the_playground.js");
mView.loadScript("app:///Scripts/playground_runner.js");

Thank you @Cedric so much! It worked! One last question: I can’t seem to move around the scene on my emulator by clicking and dragging with my cursor. The scene is just still and I cannot change my point of view. Is there anything I can do to fix this? Thank you again!

User input is not fully supported yet. But you can provide some code to handle it like in this simple function:

1 Like

Thank you very much! Happy holidays!

1 Like

@Cedric One very last question, skyboxes still aren’t supported on Babylon Native right? How about textures and materials?
Thank you so much!

Skybox is supported, most of material as well but NME ones.
This PG works in BN for example:
Deterministic lockstep sample | Babylon.js Playground

Ok, thank you @Cedric . I was asking because I hsve tried to load demos such as Babylon.js Playground or https://playground.babylonjs.com/#3I55DK#0 and I could not get them to work, all I got from my emulator was a black screen. If I load the js script of the demo you posted as an example and the script for the playground_runner it should all work with no code changes? Android Studio is giving me this error “GetStringUTFChars received NULL jstring” but this is probably not related to the demo. Thank you so much again.

Can you provide a callstack for the failing GetStringUTFChars ?

@Cedric
Just curious if the canvas polyfill has been merged yet? I checked last week and it was still passing some checks…and last time I rebuilt I noticed babylon.gui.js was included but not working in the playground

@Cedric thank you very much, I solved the issue by pasting the babylonjs textures folder in my Babylon Native Scripts folder and by using the file:/// and app:/// protocols in the Javascript code to load the textures files. Thanks for the support and happy new year!!

1 Like

@waverider404 Happy new year!

Nop, it’s not been merged yet. I’ll continue working on it the coming weeks.

1 Like

Happy new year!