Jump to content

load scene with :data defaults to babylon loader. why??


Recommended Posts

Hi guys, you've recently added these lines:

// use babylon file loader directly if sceneFilename is prefixed with "data:"
        SceneLoader._getDirectLoad = function (sceneFilename) {
            if (sceneFilename.substr && sceneFilename.substr(0, 5) === "data:") {
                return sceneFilename.substr(5);
            return null;


What if someone (me) wants to load a data string that's not a babylon file (obj in my case)? Could we have something like:

BABYLON.SceneLoader.Append = function (rootUrl, sceneFilename, scene, extension, onsuccess, progressCallBack, onerror) {

with an extra extension parameter to decide which plugin to load? so In my case I would just pass ".obj".


// Turn this:
var registeredPlugin = directLoad ? BABYLON.SceneLoader._getDefaultPlugin() : BABYLON.SceneLoader._getPluginForFilename(sceneFilename);

// Into this:
var registeredPlugin = extension ? BABYLON.SceneLoader._getPluginForExtension(extension) : BABYLON.SceneLoader._getDefaultPlugin();



Link to comment
Share on other sites

  • 1 month later...


I've just started using(/learning) babylon js and i find amazing.

I was hoping I could load some meshes from objs that I serve directly from a node server and I was trying

to use SceneLoader.ImportMesh without success.
What i am doing is sending an Ajax request to my server, which - after some processing - returns the obj as text and i tried to use that with the data: prefix in the call:

   url : "/api/svobj",
   type : "GET",
   data : {'uri' : uri + "/" + encodeURIComponent(objUrn), 'auth' : auth},
           success : function(result){
                 if (engine) {
                     BABYLON.SceneLoader.ImportMesh("", "", "data:" + result, scene, function(){
                                    //do things...
           error : function(xhr, status, error){

I've also tried to create the GET request manualy and use that as the rootURL parameter, but that didn't work for me either.

I found this post wile searching for an answer, and it seemed to me quite relative to my issue, so if I may ask: is there a way to load an obj from an online source if we assume that we request for the object and it is returned as text?

Thank you!

Link to comment
Share on other sites

Hi @akolymparis... welcome to the forum.  Sorry for no answers, yet.  I have not seen anyone import text in this way.  But, look at this playground... http://www.babylonjs-playground.com/#12282I#1  See lines 1-5.  POSSIBLY... you could use this method to import a JSON object with a single property (perhaps object.text)... which contains ALL the text you want to import.  Then, in your scene, you can process the text in any way you wish.

At your server, you will need to "package" your text... into a json/js file... so the dynamic <script> element can retrieve it in an acceptable format. 

I'm not sure if this will work, but it is another thing to try, perhaps.  I don't do much importing, and I have no expert answers.  But, my comment will bump this message to the top of the forum list.  Perhaps, if you do not get replies within a few days, please re-post your message as a new forum thread.  Thanks.

Link to comment
Share on other sites


the "data: " moniker should work: http://doc.babylonjs.com/classes/2.4/SceneLoader#static-importmesh-meshesnames-rooturl-scenefilename-scene-onsuccess-progresscallback-onerror-rarr-void

Do you see any error on the console? Do you already have a scene setup with light and camera? Are you sure your server returns a correct .babylon file?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...