Jump to content

Cannot access model after import.


eljuko
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.  :)

Link to comment
Share on other sites

// 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 :P 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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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 :P

Link to comment
Share on other sites

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  :lol:

Link to comment
Share on other sites

@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?

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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!

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