eljuko Posted July 14, 2015 Share Posted July 14, 2015 Hello all, Finally had some time to play around with Babylon.js. Having (probably) kinda silly problem here. So I'v imported models from blender successfully, nothing fancy. No textures or so. But, after the BABYLON.SceneLoader.ImportMesh function, i simply cannot access the mesh anymore. like so....BABYLON.SceneLoader.ImportMesh("Cube", "models/", "playah.babylon", scene, function (newMeshes) { // I can apply location, rotation, scaling here with ease var doge = newMeshes[0]; doge.position.x = placeIntegerHere;});// Can't access it here anymore :'(doge.position.x = iWannaChangeThisLaterOn;I'v tried to append sceneloader to variable ect. but nothing seem to work. Any ideas? Quote Link to comment Share on other sites More sharing options...
davrous Posted July 14, 2015 Share Posted July 14, 2015 Hi, It's a pure JavaScript problem . You need to declare the doge variable outside the scope of the callback function.Bye,David Quote Link to comment Share on other sites More sharing options...
eljuko Posted July 14, 2015 Author Share Posted July 14, 2015 I'm not quite sure if i understood you right. But for example...var doge;BABYLON.SceneLoader.ImportMesh("Cube", "models/", "playah.babylon", scene, function (newMeshes) { doge = newMeshes[0]; alert(doge.name);});alert(doge.name); //returns "undefined"So, still having the issue. could you hit me with an example hammer Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 14, 2015 Share Posted July 14, 2015 Hi again, E! What happens when you simply alert(doge) ? Or maybe check newMeshes.length? Are you sure newMeshes[0] even HAS a .name property? Here's what I would do. Somewhere in there, set window.mydoge = newMeshes[0]. Run. Now open your browser console... and type window.mydoge (enter) The console might show you an abbreviated dump of an object. Now click on that dump text, and an Object Inspector should open, showing you window.mydoge. Check to see what its .name property looks like, or if it exists. Make sure you HAVE an object, and then make sure you HAVE a good .name property on it. I suspect your mesh has no .name property on it, for some reason. I'm no expert, though. Temechon's advice on getting the doge variable outside-of the importMesh() scope... is great advice, and it looks like you have done it correctly. But, that won't help you if .name is missing. var doge;BABYLON.SceneLoader.ImportMesh("Cube", "models/", "playah.babylon", scene, function (newMeshes) { doge = newMeshes[0];});window.doge = doge;// alert(doge.name); //returns "undefined"alert(doge);alert(doge.id);alert(doge.material); // fun stuff to tryalert(sphere.getScene()); // fun stuff to try// After running this, you can even type window.doge.name (enter) in the console... // and you'll quickly find out if doge object exists, and if doge.name exists.Good luck, keep us posted. eljuko 1 Quote Link to comment Share on other sites More sharing options...
eljuko Posted July 14, 2015 Author Share Posted July 14, 2015 Hi there Wignut! I'll let you know as soon as i get back to my computer. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
iiceman Posted July 14, 2015 Share Posted July 14, 2015 // 1) this gets called and starts importing the meshBABYLON.SceneLoader.ImportMesh("Cube", "models/", "playah.babylon", scene, function (newMeshes) { // 3) about now the loading of the mesh is done and the mewMeshes gets assigned to "doge" // I can apply location, rotation, scaling here with ease var doge = newMeshes[0]; doge.position.x = placeIntegerHere;});// 2) this gets calledand says: What the heck are you talking about, there is no "doge", dude!?// Can't access it here anymore :'(doge.position.x = iWannaChangeThisLaterOn;That's what I think is happening a playground to show: http://www.babylonjs-playground.com/#1JMXJK How to fix: do stuff in the callback function. you can use function to make it look cleaner, but you have to make sure the mesh is actually loaded and that's what the callback function is for, I think. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 14, 2015 Share Posted July 14, 2015 Hey, nice job, Ice! I had it wrong (common for me). Elkyu, I think Iceman has our butts covered, thank goodness. Yep, that's a callback function. Sometimes I don't see that function() { hanging out on the end of things. I'm getting old. I need mine formatted like this...BABYLON.SceneLoader.ImportMesh( "Cube", "models/", "playah.babylon", scene, function (newMeshes) { // Loading of the mesh is done and the mewMeshes gets assigned to "doge" // I can apply location, rotation, scaling here with ease var doge = newMeshes[0]; doge.position.x = placeIntegerHere; });Or maybe this...var doge;var doneLoading = function(meshArray) { doge = meshArray[0]; alert(doge);};BABYLON.SceneLoader.ImportMesh( "Cube", "models/", "playah.babylon", scene, doneLoading(newMeshes));I think that would work. *shrug* Functions packed into parameter slots is just SO ugly. I should go take a nap, now, I'm old. Quote Link to comment Share on other sites More sharing options...
iiceman Posted July 14, 2015 Share Posted July 14, 2015 I know the old folks hate it when the youngsters run around their front lawn making all that noise playing and laughing. But you don't seem old Wingy, Somehow I imagine you running and screaming around on somebodies front lawn all the time (despite the age that I found on your profile O_o ) You know what, they say, you are as old as you feel... or something like that. Anyways, hope it helped Quote Link to comment Share on other sites More sharing options...
eljuko Posted July 14, 2015 Author Share Posted July 14, 2015 Thanks for all the responses! Ok, call me stupid when i ask the following: but what if i wanted to change the position of the "doge" mesh inside render loop? Currently i'v a box which moves with arrowkeys and i simply wanted it to have a bit better look by bringing my 2 minute model from blender Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 14, 2015 Share Posted July 14, 2015 @ice "running and screaming?" I'm happy to accomplish trudging and grunting. heh E... now you're just milking us. http://playground.babylonjs.com/?10 Lights demo has orbiting. I like orbiting. So does the shadows demo. Simpler one... http://playground.babylonjs.com/#5SWSQ I think Eljuko is getting a little lazy. A bit early in the week, no? Quote Link to comment Share on other sites More sharing options...
eljuko Posted July 14, 2015 Author Share Posted July 14, 2015 Hehe, might be but the problem was i couldn't access the imported model within render loop so the problem still presists. Quote Link to comment Share on other sites More sharing options...
iiceman Posted July 14, 2015 Share Posted July 14, 2015 http://playground.babylonjs.com/#18U5SO flying rabbit (orbiting for wingy ) eljuko and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
eljuko Posted July 14, 2015 Author Share Posted July 14, 2015 thank you iice! that'll do the trick Quote Link to comment Share on other sites More sharing options...
gryff Posted July 14, 2015 Share Posted July 14, 2015 iice's nice demo raises a question for me - I see that it imports the rabbit.babylon file from a directory "scenes/". Is there a list somewhere of all the .babylon files available like this ? I know the skull is, but are there any others? cheers, gryff Quote Link to comment Share on other sites More sharing options...
Temechon Posted July 14, 2015 Share Posted July 14, 2015 Yes there is ! https://github.com/BabylonJS/MeshesLibrary Quote Link to comment Share on other sites More sharing options...
iiceman Posted July 14, 2015 Share Posted July 14, 2015 But but... the rabbit is not in the list... or am I looking in the wrong place? I only know about the rabbit, the skull and the dude so far. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 14, 2015 Share Posted July 14, 2015 Orbiting rabbits. hehe. Hey Gryff... you DL'd the pgdb right? Look in playground_resources or whatever I named it. There is a folder called scenes/ that is a clone of the playground /scenes. /textures is there too. Party on! Quote Link to comment Share on other sites More sharing options...
Temechon Posted July 15, 2015 Share Posted July 15, 2015 The rabbit is here https://github.com/BabylonJS/Samples/tree/master/Scenes/Rabbit 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.