Numa Posted September 23, 2016 Share Posted September 23, 2016 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(); Thanks SlipperyJim 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 23, 2016 Share Posted September 23, 2016 That's a good idea Just move the parameter at the end to save compat Do you mind submitting a PR? Quote Link to comment Share on other sites More sharing options...
akolymparis Posted November 2, 2016 Share Posted November 2, 2016 Hello. 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: $.ajax({ 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){ console.log(status); } }); 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! Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 7, 2016 Share Posted November 7, 2016 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 9, 2016 Share Posted November 9, 2016 Hey 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.