Jump to content

How to Clone a Loaded Mesh on Demand


Bricktheworld
 Share

Recommended Posts

Hello everyone!

I am making a multiplayer game where I need to load players on demand whenever they come into the game. I have tried searching for hours but nothing seems to be working, so I came here. The closest thing to what I need was from here but it still doesn't really work for me and here's why. 

I need to clone a mesh on 

//called when a new player other than yourself joins
socket.on('New Player', function(data) {
    
});

and on

//list of current players when you first join
socket.on('listoplayers', function(data) {
    
});

I have loaded the player mesh in an assetsManager and I would like to clone this mesh in these functions. Is there a way to this or a way around doing this? 

Also, here is the playground from the other topic: http://www.babylonjs-playground.com/#8XUNI%234

Hopefully, I explained that properly and if not, I'll explain in the comments.

Thank you!

Link to comment
Share on other sites

Something like this?:

http://www.babylonjs-playground.com/#8XUNI#5

I pushed the loaded mesh into a global array. This way, the mesh can be called from any function outside the createScene, successCallback etc. functions. (For instance, in your socket events).

I assume your players don't connect until After the scene has loaded, but you could simply check whether or not the model is populated in the array. If not, then load it (again).

It does look like the clone function automatically enables the mesh, so no need to setEnable(true).

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