Jump to content

Using xhr to load a text file


Brunex92
 Share

Recommended Posts

Hey everyone,

I'm doing a visual application where I need to load a text file with coordinates and display them on the canvas.
At first I was using the FileReader API, now I want to load a file from an URL, and using xhr is the better option.

The problem is, I have no idea how to use it with babylon.js, can anyone provide a playground that uses it?

Basically what I need is load a file from an URL, put the coordinates that are on this file into a matrix, and display them on the canvas

Thanks :)

Link to comment
Share on other sites

Hi guys!  Can I ride along?  http://playground.babylonjs.com/#1ZF16Z#0

I've always wondered if off-domain text files could be sucked into a playground.  So far, no go.  Not like I know what I'm doing, though.  I seem to be reaching outside of my scope, both origin-wise and intelligence-wise.  :D  Perhaps I should ONLY use Ajax as a scouring powder.  heh

Link to comment
Share on other sites

On 7/27/2016 at 8:07 PM, Wingnut said:

Hi guys!  Can I ride along?  http://playground.babylonjs.com/#1ZF16Z#0

I've always wondered if off-domain text files could be sucked into a playground.  So far, no go.  Not like I know what I'm doing, though.  I seem to be reaching outside of my scope, both origin-wise and intelligence-wise.  :D  Perhaps I should ONLY use Ajax as a scouring powder.  heh

If you have the option of changing the text file, you could change the format to:

{

text: "<all your text goes here>"

}

Then you should be able to use your ajax call by changing the dataType to jsonp.

Link to comment
Share on other sites

3 minutes ago, Nabroski said:

Oh, so the file needs to be in a server to be used? Didn't know about that, thanks for the help :D
Now I've to do what I need for my application
 
One other question, is there any way to load a file from my computer, by using a button, and then pass it to the AssetsManager? This is really important for what I am doing

Link to comment
Share on other sites

No sorry, its a playground thing, you need to crossorgin the file.

Also you forgot to call

assetsManager.load();

here is an working "reallife" example

http://doc.babylonjs.com/tutorials/how_to_use_assetsmanager

Sorry, im out of time now, maybe later.


One other question, is there any way to load a file from my computer, by using a button. Yes!
@Wingnut, he will probably writing you an working ajax example on this

Keep it up!
 

Link to comment
Share on other sites

As long as you don't get any cross-origin errors from your browser, everything should be fine. You have to cross domain on your server
 

[]

 

@Brunex92
you have to debug it, the button you requested at least makes things far more complicated. You need a File reader to get the file path. you can use new BABYLON.Tools.FileReader 


Good luck

 

assets.zip

Link to comment
Share on other sites

I'll be a little more direct then.
This is what I have so far:

brunex92.github.io

I've been using the FileReader API, to read a file, with a bunch of thrash that I don't need, and then I skip this reading until it reach a keyword, in this case '[ARESTAS]' just like this example: http://pastebin.com/VH6H9AMb

Then I start to put the coordinates and colors after this keyword into a matrix.

After that, I get these coordinates and colors to draw spheres.

 

The problem is, after I load a file, when I unmark the checkboxes for grid options and axis options, some graphical bugs happens, like this, this and this

So I thought I should make use of another way to read the file, or maybe I'm doing something absolutely wrong when I update my scene after I load the file, the problem is, I have absolutely no idea what could it be.

My knowledge on JS is really poor, I did all of this learning by myself, but this is the only problem I'm having right now, if anyone can help me, I would be really grateful :)

I made this PG http://www.babylonjs-playground.com/#GP88V#5

But it's not functional in parts, since I don't know how to update the scene after I load the file with playground.
It actually reads the file and put the coordinates into the matrix, then it shows on console.

 

Edited by Brunex92
Link to comment
Share on other sites

hmm. i cant reproduce your error. your app i tested 3 times for about 2-5 min and again re invoke from running in the background


the console window of my browser gives me a lot of error messages, can you first get rid of them ? before we continue

also in your case:check when the file is fully loaded
engine.dispose();
engine = null;

i think i has also something to do with the drawcalls of the datgui.
can you sync draw calls of dat.gui to babylonjs - i dont know, i got a feeling(not tested) like the gui is really implemented in babylonjs, ergo runs faster, slower, as a separate layer. also look for a function in babylonjs, i forgot about, but is something that lets you get the render loop synch more to a (external) function - something like toanimationratio.

also experiment a bit with the engine, currently you got a simple app, without textures or something, so shut down half of it 
var engine = new BABYLON.Engine(canvas, false,{ antialias: false, preserveDrawingBuffer: true, limitDeviceRatio:1.0, generateDepthBuffer: false, generateMipMaps: false, samplingMode: 2 },false);
https://doc.babylonjs.com/classes/2.4/Engine


try to shutdown so many things as possible and the turn one by an other on again. this is the process of debug

i programming from time to time. i have absolutely no idea :)



 

 

 

 

 

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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