Jump to content

Loading Asynchronous Objects into array for later use?


Aerion
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

       }

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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