timetocode Posted May 15, 2018 Share Posted May 15, 2018 What's the right way to load multiple models from blender (or anything), and then spawn them many times into the game world? Let's say I have a tree.obj and a house.obj... and then I want to load it, without rendering anything yet, and then I'm going to programmatically generate terrain and add 200 trees and 20 houses. I've tried LoadAssetContainer, but I couldn't seem to invoke scene.createMesh or createMaterial on the data... all I could get to work was container.addAllToScene(). Also is there a friendly name for the loaded model? I was able to position it by doing container.meshes[0].position.y = 30, but I assume there's another way to interact with it. So the questions are: which file format for the blender objects (obj, babylon.. then one model per file..?) which loader to use how to load without spawning the object into the world how to spawn multiple of the object into the world (clone..? then position+rotate?) how to remove individual objects without unloading the source mesh Thanks for the help Quote Link to comment Share on other sites More sharing options...
Amarth2Estel Posted May 15, 2018 Share Posted May 15, 2018 Hi Timetocode ! Well, for points 1 and 2.. I don't think there is a perfect solution. it depends of what you need. I suggest that if you want to have a 'master' tree model to spawn on your scene, then using a OBJ loader (https://doc.babylonjs.com/how_to/obj) should be enough. But maybe GLTF or .babylon could be better, especially if you want additional information like lights etc... 3. You just have to disable the mesh. try setEnabled(false) and your mesh won't appear. It is better way than just setting the opacity to 0 or isVisible to false because a disabled mesh is not taking in account during hidden babylon computation. 4. You may use instances : https://doc.babylonjs.com/how_to/how_to_use_instances From my experience, you will get better performances by cloning your 'master' mesh, and then merging all the clones : https://doc.babylonjs.com/how_to/how_to_merge_meshes It is incredibly powerful if theses clones don't need to be edited later, but then it is gonna be harder to remove/modify individual objects as said in 5. (Do not forget to make sure clones or instances are enabled !) 5. Easy using instances. You may use subMesh to do it while working with a big mesh made from merged clones, but it is way heavier. To conclude : I guess you should use instances if you know your loaded-and-spawned meshes will be modified later. Clones and Merge otherwise. Hope it will help ! timetocode 1 Quote Link to comment Share on other sites More sharing options...
Guest Posted May 15, 2018 Share Posted May 15, 2018 3. AssetContainers can helped a lot here: http://doc.babylonjs.com/how_to/how_to_use_assetcontainer timetocode 1 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.