SceneLoader.RegisterPlugin decrypts cipher code of file in importMesh

Hello,

I want to encrypt some .babylon file with the .ebabylon extension.

Then I would like to decrypt the files when ImportMesh is called.

I saw BABYLON.SceneLoader.RegisterPlugin() but I’m not sure how to use it to decrypt the code when ImportMesh is called.

I did the encryption and decryption functions (but I don’t understand how the RegisterPlugin works)

For the moment I did this as an example of what I want to do. It’s not supposed to work as is, it’s just for example and to know if I’m on the right track.
I’m just trying to see if it’s doable.

Thanks for your help.

Hey there!

RegisterPlugin basically just indexes the plugin object by its extension, so the SceneLoader will know to use it for later. To register a plugin, you’ll need it to extend ISceneLoaderPlugin Babylon.js/sceneLoader.ts at master · BabylonJS/Babylon.js (github.com) or ISceneLoaderPluginAsync Babylon.js/sceneLoader.ts at master · BabylonJS/Babylon.js (github.com). I put an example here that just uses the exising GLTFFileLoader plugin to do the work: Test Register Plugin | Babylon.js Playground (babylonjs.com)

3 Likes

Thanks for the example. I will try to understand it.

2 Likes

Ok, I didn’t understand how to use the registerPlugin.

I saw that you could use base64. so I did like this:

1 I base64 encode the.babylon files and give them the ebabylon extension
2 with ajax I will read the encode file and return the result
3 I am using ImportMesh using "data:;base64," +code

And it works.

I would like to do the same with something other than base64 for the encoding. But it seems more complex than I thought.

1 Like

Hi @Dad72,
Here is a working example, in case you still want it

Cheers! :beers:

5 Likes

Thank you very much MarianG. It’s better than what I had done, even though I had come up with a solution that worked.

Thanks again for your solution