Aerion Posted August 21, 2017 Share Posted August 21, 2017 Hi all. I'm trying to return an array of objects loaded by the Mesh Importer for later use. I would like to be able to call a function to load my objects and outside of the function, affect & change each one of them OUTSIDE of the function. Here is the small demo I made :: http://www.babylonjs-playground.com/#1QJUDF#3 Thank you! <3 Mythros Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 21, 2017 Author Share Posted August 21, 2017 I don't understand what is wrong. Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 22, 2017 Author Share Posted August 22, 2017 Anyone? I hope people understand me well enough. Quote Link to comment Share on other sites More sharing options...
SinhNQ Posted August 22, 2017 Share Posted August 22, 2017 Hope help you : http://www.babylonjs-playground.com/#1QJUDF#4 Aerion 1 Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 22, 2017 Author Share Posted August 22, 2017 THANK you! That DOES help! There's one thing that I need to be able to do. And that's call the object of choice in the renderloop so I can update it in the renderloop as well! After that, I will mark it as solved! Thanks again! <3 SinhNQ 1 Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 22, 2017 Author Share Posted August 22, 2017 @SinhNQ: Here's what I'm trying to do : http://www.babylonjs-playground.com/#1QJUDF#14 Quote Link to comment Share on other sites More sharing options...
SinhNQ Posted August 22, 2017 Share Posted August 22, 2017 Try http://www.babylonjs-playground.com/#1QJUDF#15 Aerion 1 Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 22, 2017 Author Share Posted August 22, 2017 Hi @SinhNQ that almost works PERFECTLY! Here's what I'm trying to do : http://www.babylonjs-playground.com/#1QJUDF#17 Thanks again! <3 Quote Link to comment Share on other sites More sharing options...
SinhNQ Posted August 22, 2017 Share Posted August 22, 2017 If you want reuse mesh, you just use clone method. Here: http://doc.babylonjs.com/classes/3.0/abstractmesh#clone-name-newparent-donotclonechildren-rarr-abstractmesh-classes-3-0-abstractmesh- Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 22, 2017 Author Share Posted August 22, 2017 No, @SinhNQ what I'm trying to achieve is being able to load any model into the scene and affect it later on by using 1 parameter to affect it with. An example would be : var mymesh = [ ]; mymesh [ 0 ] = LoadEntity ( 'blah1.obj', whatever other variables here . . . ); mymesh [ 1 ] = LoadEntity ( 'blah2.obj', whatever other variables here . . . ); then in the loop : mymesh [ 0 ].rotation.y += 0.01; mymesh [ 1 ].rotation.x -= 0.001; That's basically all. Thanks again! <3 Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 22, 2017 Author Share Posted August 22, 2017 I hope I explained well enough. Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 22, 2017 Author Share Posted August 22, 2017 It is possible? @SinhNQ Quote Link to comment Share on other sites More sharing options...
SinhNQ Posted August 22, 2017 Share Posted August 22, 2017 I'm sorry, i am busy. I will come back at tonight (GMT +7). Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 22, 2017 Author Share Posted August 22, 2017 ok, @SinhNQ Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 22, 2017 Author Share Posted August 22, 2017 Any luck, brother? @SinhNQ Quote Link to comment Share on other sites More sharing options...
adam Posted August 22, 2017 Share Posted August 22, 2017 Read this: https://doc.babylonjs.com/tutorials/how_to_use_assetsmanager Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 22, 2017 Share Posted August 22, 2017 @adam, doesn't the assetManager STILL leave Mythros stuck inside of an onSuccess func, unable to bring his/her meshes/library back to mainline code? Seems we USED TO be able to define a few variables at a VERY global level, and then NOT have-to be permanently inside-of any onSuccess or other callbacks. We could have a "get the load done" and then continue-on in mainline. Below, I can't even get scene.executeWhenReady to wait for the import's onSuccess to finish. Seems odd. https://www.babylonjs-playground.com/#1QJUDF#22 Here, I've got a classic "hung" executeWhenReady happening (leaves PG stuck in ' Loading assets...Please wait'). I've got some real wide-scope globals up in lines 1 and 2, and I am trying to console.log the loaded meshes array... in about 3 different ways. It seems the ONLY way to get a decent scene.meshes or myMeshes... is line 19, WITHIN an onSuccess func. In line 20 I try to set myMeshes = meshpile (a wide-scope global), but that's not happening. This is definitely a scoping issue, but I tried using assetManager yesterday... on this issue, and I had the same problems. We're stuck inside an onSuccess and can't get out to mainline code. This might be normal, but it sucks. I'm not a very good coder, though... so... closures, etc... not well understood by us rookies. Quote Link to comment Share on other sites More sharing options...
adam Posted August 22, 2017 Share Posted August 22, 2017 25 minutes ago, Wingnut said: doesn't the assetManager STILL leave Mythros stuck inside of an onSuccess func, unable to bring his meshes/library back to mainline code? I'd fill the meshes array with empty meshes (or something else like boxes) and then in onSuccess replace those empty meshes with the real meshes. Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 22, 2017 Author Share Posted August 22, 2017 I am lost... There's GOT to be a simple way to do this. @SinhNQ was VERY close. But I need to return the array of meshes in order to affect the mesh of choice outside of the function. It's basically :: Inside the createScene ( ) function :: var meshes = [ ]; meshes [ 0 ] = LoadEntity ( scene, 'blah1.obj', default_xpos, default_ypos, default_zpos, OTHER VARS HERE, ETC . . . ); meshes [ 1 ] = LoadEntity ( scene, 'blah1.obj', default_xpos, default_ypos, default_zpos, OTHER VARS HERE, ETC . . . ); Then in the MAIN LOOP :: for ( var i = 0; i <= meshes.length; i++ ) { if ( i === 0 ) { UpdateEntity ( scene, meshes [ 0 ], new_xpos, new_ypos, new_zpos, new_xrot, new_yrot, new_zrot, new_xscl, new_yscl, new_zscl ); UpdateEntity ( scene, meshes [ 1 ], new_xpos, new_ypos, new_zpos, new_xrot, new_yrot, new_zrot, new_xscl, new_yscl, new_zscl ); } } Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 22, 2017 Author Share Posted August 22, 2017 Can someone help? Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 23, 2017 Author Share Posted August 23, 2017 I still can't figure it out.. Here's a SORTA' working version but because newMeshes [ ] only is allowing for ONE index which is "0", I cannot load any number of models I want & control them separately OUTside of the LoadEntity ( ) function & / OR INSIDE the UpdateEntity ( ) function. I can only control the 1st loaded model ONLY. http://www.babylonjs-playground.com/#1QJUDF#23 Thank You! <3 Quote Link to comment Share on other sites More sharing options...
SinhNQ Posted August 23, 2017 Share Posted August 23, 2017 Hi @Mythros! You want to load multi model and use them outside function? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 23, 2017 Share Posted August 23, 2017 Pardon my interrupt... I need to make a correction to an older playground. https://www.babylonjs-playground.com/#1QJUDF#24 In a previous version, I was using scene.executeWhenReady... incorrectly (causing playground loader to 'hang'). Dummy me. I'm getting some good console reports, now, even in mainline. But, it seems Mythros will still be required to put most of his entire project... inside-of scene.executeWhenReady wrapper. Not sure. @SinhNQ - I think the objective is: load one model per call. Models are put into a 'library' (and possibly .setEnabled(false), temporarily), where they can be "looked-up" and enabled/instanced/cloned later. (I hope I said that correctly) Looks like M is building a little in-scene database-o-mesh-refs. SinhNQ 1 Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 23, 2017 Author Share Posted August 23, 2017 @Wingnut DING DING DING! YOU WIN THE PRIZE! ONE BOX OF CHOCOLATES FOR @Wingnut! <3 Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 23, 2017 Author Share Posted August 23, 2017 @SinhNQYou & @Wingnut are BOTH right! I want to be able to store the models for later use in other functions! <3 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.