I am creating a simple WebGL project and need a loading method in the model. I decided to use the OBJ format, so I need a way to download it. The file (will) be stored on the server, and my question is: how does one of the JS load into a text file and scan it line by line, token using a token (for example, with streams in C ++)? I am new to JS, so my question is. The simpler the better.
UPDATE: I used your solution, broofa, but I'm not sure if I did it right. I am loading data from a file into the forEach loop that you wrote, but outside of it (that is, after all your code), the object that I filled with data has "undefined". What am I doing wrong? Here is the code:
var materialFilename; function loadOBJModel(filename) { // ... var req = new XMLHttpRequest(); req.open('GET', filename); req.responseType = 'text'; req.onreadystatechange = function() { if (req.readyState == 4) { var lines = req.responseText.split(/\n/g); lines.forEach(function(line) { readLine(line); }); } } req.send(); alert(materialFilename); // ... } function readLine(line) { // ... else if (tokens[0] == "mtllib") { materialFilename = tokens[1]; } // ... }
source share