dsman Posted January 10, 2018 Share Posted January 10, 2018 If there are too many similar meshes in my scene, what do I do in unity such that when I export the scene to Babylon, those meshes are instances of one of them and not remain individual meshes in Babylon? Also if there many similar meshes in my scene, which does require separate materials, what do I do in Unity such that when I export the scene to Babylon, those meshes become clones of one of them and not remain individual meshes in Babylon? @MackeyK24 Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted January 10, 2018 Share Posted January 10, 2018 If you place several meshes in the scene, there will be several meshes in the output scene (Unity As Well) weather you have separate material instances for each mesh or not. In the Toolkit by default, materials are SHARED, meaning that only one single 'JSON' exported Babylon Material per material name (Unless lightmap is used, then it gets an internal instance because of the different material.lighptmapTexture and coordinates info used for baked shadow of THAT game object with the same material name). If you need a specific object to use a TOTALLY separate material. Just duplicate the material and give another name and use the dup material as an "Material Instance'... Remember you want has FEW as possible actual materials used in the GPU... Every separate material on a mesh cost you a draw call. Im sure you know all of this, just pointing that out. My toolkit does a few features to help out... if all these meshes that similar are static, they don't move... just put them on the 'Babylon Static' layer in Unity Layers. My static layer will group all static meshes by material and combine them together and used the the merged materials... I also have texture atlas baking tools in there to. You could bake ALL those meshes (or groups of meshes) into a texture atlas. that would put all those meshes on a single material with its UV coordinates adjusted to offset to the texture in the atlas... You can take a WHOLE scene of geometry like 'candyland'... Bake them all into a 4096 texture atlas then all your candyland props will be one a single material even though its over 200 separate meshes. Then put all those candyland props on the 'Babylon Statics' layer in Unity Editor. (Uncheck static mesh vertex limit in Toolkit Exporter Default Settings) if all you had where the candyland environment meshes all combined into a single static mesh using the texture atlas materials and it will only cost 1 single draw call If you really need 'Runtime Instances'... Put the meshes (including any sub mesh hierarchies with script components and everything) on the 'Babylon Prefab' layer in Unity Editor... This will make that mesh a PREFAB that is used just like UNITY prefabs at runtime. You can make MATSER meshes at desgin time... script em up with any components and functionality and make em prefabs: Here is an Example Enemy Ship setup as a prefab with the "Make Instance' Option checked (Prefabs are fully cloned copies... using the make instance clones the mesh as an MeshInstance... so cant change materials on instanced clones like you can a fully cloned copy) then in would use code to instantiate your prefabs at whatever position and rotation you like. In code the Enemy ship gets instantiated: private spawnPlayerHazard():void { if (this.gameOverFlag === true) return; this.spawnTimeIndex = this.manager.time; if (SpaceController.LoadState === true || SpaceController.WaitState === true) return; // Spawn hazard prefab this.spawnCount++; this.hazardIndex++; var enemyRatio:number = BABYLON.Scalar.Clamp(SpaceController.EnemyRatio, 1, 3) + 3; var randomMark:number = (this.spawnCount <= 3) ? 3 : enemyRatio; var randomIndex:number = Math.round(BABYLON.Scalar.RandomRange(1, randomMark)); var hazardPrefab:string = (randomIndex >= 4) ? "Enemy" : "Asteroid_" + randomIndex.toString(); var spawnPosition:BABYLON.Vector3 = new BABYLON.Vector3(BABYLON.Scalar.RandomRange(-this.spawnValues.x, this.spawnValues.x), this.spawnValues.y, this.spawnValues.z); this.manager.instantiatePrefab(hazardPrefab, "Hazard_" + hazardPrefab + "_" + this.hazardIndex.toString(), spawnPosition, BABYLON.Vector3.Zero()); if (this.hazardIndex >= Number.MAX_VALUE) this.hazardIndex = 0; // Validate spawning waves if (this.spawnCount >= SpaceController.HazardCountMark) { this.spawnCount = 0; this.allowSpawn = false; if (SpaceController.GameLevel < 3) { // Wait for next wave SpaceController.WaitState = true; this.manager.delay(()=>{ this.checkWaitStatus(); }, 1000); } else { // Wait for you win SpaceController.WinState = true; this.manager.delay(()=>{ this.checkWinStatus(); }, 1000); } } } Note the: this.manager.instantiatePrefab() I am using that to instance my enemy ship or asteroid My enemy ship the mesh is just visual sugar that is a child of the enemy ship object. its just along for the ride so you have something to see. But it is setup so that when you create a prefab clone copy of the enemy ship called 'Enemy' the actual mesh 'Enemy_Ship' is set to create as a babylon instanced mesh because will not and cannot change the material for that instance. That is part of how i keep the whole space shooter demo under 20 draw calls for all the meshes and laser bolt instances and particle system explosions I hope that helps... I will try to make a video about using my 'babylon art tools' to help you doo all the stuff i said above Check out my Space Shooter Demo ... Still working on particle systems and explosions Quote Link to comment Share on other sites More sharing options...
dsman Posted January 12, 2018 Author Share Posted January 12, 2018 @MackeyK24 You are awesome. While I started to read the answer, a thought came to mind what if there was a good video explaining mesh optimization (combining meshes and creating texture atlas, and resuing meshes as instance )? And then at the end I read you too are thinking about a video. Yes, a video would be great. Anyway, we will try with what you said and try to optimize both mesh count and reuse of mesh using instances. The Babylon toolkit for Unity is clearly a much much better replacement for Babylon Editor. Can't thank you enough for creating this. Quote Link to comment Share on other sites More sharing options...
dsman Posted January 12, 2018 Author Share Posted January 12, 2018 @MackeyK24 Is it like the Babylon Prefab, and hence instance, can be used only in the scripting and it can't be exported in the .bayblon file? Quote Link to comment Share on other sites More sharing options...
ParadoxMaster Posted November 18, 2018 Share Posted November 18, 2018 I do not quite understand if I have a scene with hundreds of identical meshes, e.g trees in a forest. Is there a possible way to have one mesh per babylon scene with many instances? How should such cases be optimized? Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 19, 2018 Share Posted November 19, 2018 Are you speaking in general or through the unity exporter ? In general, instancing will only use 1 draw call vs 1 per tree which is a huge gain of speed as it is all directly managed by the hardware. If you are speaking from the unity exporter, let s ping @MackeyK24 ? Quote Link to comment Share on other sites More sharing options...
ParadoxMaster Posted November 19, 2018 Share Posted November 19, 2018 Yes, it is about the exporter. I'll wait for this Unity exporter's superhero) Sebavan 1 Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted November 19, 2018 Share Posted November 19, 2018 The prefab system is the core tech behind this kind of thing. You have a couple ways of doing this type of thing using prefabs. 1... Manually create instances from prefab meshes 2... Use the built in Tree ? system I made to support Terrains (not complete because I could never get anyone to help me write the terrain shader all the way) I’m sorry, I have company visiting me this week. But when I get a chance I’ll try make a quick video showing the Terrain and Tree Painting so you can use the Editor to scatter trees over the terrain . Including Tree LOD’s ParadoxMaster 1 Quote Link to comment Share on other sites More sharing options...
ParadoxMaster Posted November 20, 2018 Share Posted November 20, 2018 3 hours ago, MackeyK24 said: The prefab system is the core tech behind this kind of thing. You have a couple ways of doing this type of thing using prefabs. 1... Manually create instances from prefab meshes 2... Use the built in Tree ? system I made to support Terrains (not complete because I could never get anyone to help me write the terrain shader all the way) I’m sorry, I have company visiting me this week. But when I get a chance I’ll try make a quick video showing the Terrain and Tree Painting so you can use the Editor to scatter trees over the terrain . Including Tree LOD’s Thanks, I think I realized how to optimize trees using build-in layers. But the video will always be useful to users. You made a amazing and powerful toolkit! The only problem is that there is little documentation and examples, and users need to figure out in many things by yourself. But now I have more questions on another topic: http://www.html5gamedevs.com/topic/41340-textures-for-terrain-painting-in-unity/ Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted November 20, 2018 Share Posted November 20, 2018 This is another area that I repeatedly asked someone to help... Terrain exporting and the shader need to render... I have implemented how Unity does terrain splatmapping but could never really get results I was looking for... so that part is just stuck there in limbo.... FYI... Advance Character Animation and State Machines are I. The same limbo because again ... I can’t get NO ONE to actually help with the code for Calaculate Input Weights (2D) needed to fully implement blend trees... I already did 98% of all the coding for this stuff but can’t get anyone (everyone I asked is too busy to help with my project or just plain and simply refused to help... I even offered to pay several people out of my own pocket... but they all basically told me to screw myself, they won’t help with the Math or coding) Also got some issues with Particle Systems but I’m afraid I will get no help there either Anyways... that’s were my toolkit development is... in limbo. but I will try to make an Non-official video of how i do the whole terrain, instancing and LOD stuff to PAINT your trees on the Terrain and export everything Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 20, 2018 Share Posted November 20, 2018 @MackeyK24 I am happy to look in any bugs on the babylon side of things you might encounter about the other aspects, it is way harder as it requires to deep dive in the exporter itself and time wise I am unfortunately stuck to take on smthg new at the moment. Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted November 22, 2018 Share Posted November 22, 2018 Yo @Sebavan ... I REALLY NEED HELP Calculating Input Weights for 2D Blend Trees (I dont understand the game math used for Polar Gradient Bands create by Rune ... The Unity Locomotion Guy...) If you PLEASE contact me so we can talk... I think i still get your cell, you can text me so we can hook up and i can show you all the details. I really need this to close up and create my Game mechanics stuff (Which most is based of my implementation of the Unity Mechanim Animation State Machine System) Secondary would be the Shader... @NasimiAsl needs to help with that Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 22, 2018 Share Posted November 22, 2018 Calculating Input Weights for 2D Blend Trees ? unfortunately I have even no idea what it is so I am probably the worst place to help on that. I can definitely tackle down issues on the Babylon side if that helps ? Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted November 23, 2018 Share Posted November 23, 2018 what can i do ? notic that ( maybe tile atlas mapping is available if we append texture2DLodExt ) 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.