juanmajr93 Posted December 12, 2016 Share Posted December 12, 2016 Hi, this is my code: for(var t = 0; t < edificios_texto.length; t++){ var loader = new BABYLON.AssetsManager(scene); //console.log(edificios_texto[n]); var edificio = loader.addMeshTask(t, "", "http://localhost:8080/modelos2/"+edificios_texto[t]+"/",edificios_texto[t]+".obj"); edificio.onSuccess = function (task) { //console.log(task.loadedMeshes.length); console.log(edificio.name); task.loadedMeshes.forEach(function(b) { b.scaling = new BABYLON.Vector3(5,5, 5); b.rotation.y = Math.PI; // cambiar las X var vertex_data = BABYLON.VertexData.ExtractFromMesh(b); for (var i = 0; i < vertex_data.normals.length; i+=3) { vertex_data.positions[i] *= -1; } vertex_data.applyToMesh(b); for (var i = 0; i < edificios.length; i++) { // console.log(edificios[i].texto); // console.log(t); if(edificios[i].texto == edificios_texto[t]){ var utmPlaceZ = edificios[i].x; var utmPlaceX = edificios[i].z; var utmPlaceXFromCentre = utmPlaceX - mapCentreX; var utmPlaceZFromCentre = utmPlaceZ - mapCentreZ; var x = utmPlaceXFromCentre/scaleX; var z = utmPlaceZFromCentre/scaleZ; b.position.x = x; b.position.z = z; break; } } }); } /* edificio.onFinish = function() { engine.runRenderLoop(function () { scene.render(); }); }; */ loader.load(); } I have to use the var edificios_texto[t] inside this function, How can I do it? JuanMa J.R Quote Link to comment Share on other sites More sharing options...
RaananW Posted December 12, 2016 Share Posted December 12, 2016 Hola Juan, Actually, nothing stops you from using this variable inside any function declared in this scope. As long as it is not a class member (accessed with "this"). Should be working... Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted December 12, 2016 Author Share Posted December 12, 2016 Sorry, @RaananW I cant get the value inside callback, I think that I have to send vector (edificios_texto) as parameter of function to access after... The before code started with the init of vector: var edificios_texto = ['C6','A4']; Thanks.. Quote Link to comment Share on other sites More sharing options...
RaananW Posted December 12, 2016 Share Posted December 12, 2016 Yep, find the problem. Try using forEach instead of the for loops. Your problem will be solved. The variable t and i change after each call, but you reference them inside an asynchronous function. Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted December 12, 2016 Author Share Posted December 12, 2016 Thanks. Perfect!!! The problem is resolved!!! 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.