javascript - parsing obj files on webgl, XMLHttpRequest issue -
javascript - parsing obj files on webgl, XMLHttpRequest issue -
i making loader of .obj models webgl on javascript, , problblem i'm having appears xmlhttprequest method, allow me explain;
var texturearray=[]; loadtexture=function(name){ var request = new xmlhttprequest(); request.open("get", name+'.mtl'); request.onreadystatechange = function () { if (request.readystate == 4) { //do stuff set textures in texturearray } } request.send(); } and let's method uses this:
loadobjmodel=function(name){ loadtexture(name); //check if texture loaded } the thing is, when "check if texture loaded", variable "texturearray" it's empty, if check after "do stuff set texture in texturearray" (inside onreadystatechange function) show textures loaded correctly. found problem is, takes time read file , loop through lines, @ moment "check if texture loaded" hasn't finished, when @ end of "do stuff set texture in texturearray" sows loaded correctly because had wait load , show texturearray had.
the big problem here that, when seek utilize textures loaded @ "check if texture loaded", can't...because aren't there, , have seen webgl loaders douing in exact way , not having problem. wat douing wrong?, thoughts :)
you can create ajax phone call synchronous adding false when phone call open method:
request.open("get", name+'.mtl', false); this should create script wait until loadtexture() returns before doing 'check if texture loaded' stuff.
javascript parsing xmlhttprequest webgl .obj
Comments
Post a Comment