Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mesh Baker by Digital Opus [RELEASED]

Discussion in 'Assets and Asset Store' started by Phong, Nov 20, 2012.

  1. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Hey guys, My first major optimization with mesh baker is out and it will hit production later this month, very exiting :D
    One trade off with baked meshes are the occlusion will not be as efficient, here are the numbers before and after the bake, dont look at the FPS its in editor mode and not playmode so numbers are off.

    occlussion.png

    As you can see I have decreased batching is down to 42% and draw calls are at 54% while the tricount as risen with 133%

    Do you think this is good, or should I make the bakes into smaller pieces so its better occluded?

    Target platform is PC and SteamVR
     
  2. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Bottom line is performance for me. If occlusion is not as good, but I'm getting better fps then works for me.
     
    AndersMalmgren likes this.
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi Anders,

    It looks like most of your scene is static. Often a good approach for scenes like this is to use the Batch Prefab Baker to create modified prefabs that share a material. Then set everything to static so you can let Unity's static batcher do its work. The static batcher is very good and can take advantage of other optimization systems like LOD, fustrum culling and occlusion culling. Also pay particular attention to Setpass calls. They are really the thing you are trying hardest to reduce through mesh combining.
     
  4. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    We have some pretty detailed meshes like the rails, i think one of the biggest performance hoggers was when the CPU would batch these to a bigger mesh. (each part of the rail is only 2 meters so there was a lot of them to batch)
     
  5. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Guys, quick question, i want to save some more draw calls by grouping some props together that uses the same material for each "hall" in our subway. Question, will this change how the reflection probes are applied to the reflective props? We have alot of local probes that only effect one or two props to get most out of the PBR workflow. What will happen if this mesh is combined into a bigger mesh that cover more probes?
     
  6. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    372
    Hi,

    This looks like a great tool. Though after watching a number of the tutorial videos I'm not quite sure how to solve our usecase:
    • We have a scenario where we'll be creating characters at runtime from a mix of heads and body skinned meshes.
    • These pieces are all their own rigged fbx's - They are not all in a single file like one of the video examples suggests.
    • They do share the exact same rig.
    • The animations are in a separate fbx file with the animation alone (No mesh data).
    • We are using the Mecanim humanoid config.
    • They will be using different materials as they will have their own textures. We are not yet interested in auto-atlasing - I think by the time the game is out that GPU instancing will be a better option.
    How can I use this plugin to combine the skinned meshes together from different fbx files? Ignore material combining for now (Having multiple materials under a single skinned mesh is okay).
     
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi Anders, sorry for the slow response, I was travelling for the past two days. I haven't used reflection probes much so this may not be correct. According to the manual, it appears that each material only uses one reflection cubemap per render. Unity probably chooses the closest reflection based on the render bounds center of the Renderer. You can override which probe is used. If you combine many hall sections then the combined mesh will only be affected by one reflection probe.
     
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi strich,

    This will be tricky. Have you tested whether this works without mesh combining? Here is the problem I think you will run into. When you import each model, unity creates a ModelPrefab for each FBX file. When you create an instance in the scene of each FBX file, (for example "head", "torso"). You will end up with two distinct bone hierarchies of transforms in the scene. At the top of each bone hierarchy will be an Animator. To animate these you will need to keep both Animators in perfect synch. Unity will need to animate all the bones for every body part used. Mesh Baker will not recognize that some of these bones are supposed to be the same bone. It will combine all the bones into a huge skinned mesh with a massive number of bones.

    If you want to go this route I would suggest writing a script to process the models after you import them so they share the same rig (same meaning the same transforms in the scene).

    Your script would need to:
    • Create an instance of each body part in the scene.
    • Get the bones array of each skinned mesh renderer of each body part
    • Pick one bones array to be the master that all SMRs will use
    • Check that the bones in each array are in the same order as the master. If not you will need to get the mesh of that SMRs and reorder the bindposes and fix the bone indexes in the bone weights.
    • Assign the master bones array to each SMR and assign the mesh if modified.
    • Move all the SMR game objects so they are in the master rig.
    • Create a new prefab of the master rig.
    At this point you could use Mesh Baker to combine these meshes into a single Skinned Mesh. If you don't want to combine textures you would need to use the multiple materials feature to map each material to its own submesh.
     
  9. PatrickKa

    PatrickKa

    Joined:
    Apr 30, 2014
    Posts:
    245
    Very cool. I'm using exactly this assets and I also tried to optimize with Mesh Baker but some textures come out plain white and the overall result looks a bit messed up and I also receive tons of "Dynamic batching: index buffer source is NULL" errors... Could you please share how you did setup Mesh Baker? :)
     
  10. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    I see that you managed to fix it at your games news page (you are the author of BAM right?). Good work, what's your maximum draw calls as of now? Our scopes uses a stencile buffer plus render texture which increases draw calls when scope is rendering, very hard to reach stable 90 fps
     
  11. Enoch

    Enoch

    Joined:
    Mar 19, 2013
    Posts:
    198
    Any kind of support for Un-baking (maybe an idea for a new asset store editor tool). I find myself wanting to take the baked atlases assets I get on the asset store and replace/update some of the textures. Or rebake the atlases in more optimised configuration for the assets I am using.

    You have UV coords there should be a way to figure out which part of the atlas a given prefab is using and essentially un-bake it bake to its component images and reset the uvs for it based on the new un-atlased material.

    Otherwise great asset, thanks for making this.
     
  12. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    You should be able to do this with the consider UVs feature. Create a baker, add one of the meshes. Check "consider UVs". I would also uncheck "force power of two" and bake the textures. The atlas will have only the used part of the original atlas. Then bake the mesh.

    Repeat this with several meshes. You can then bake the combined meshes together to recreate the atlas that you want.
     
    Enoch and hopeful like this.
  13. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Hey Phong. Just remembered our conversation about Reflection probes, I just tried and the reflection probe is calculated for the entire mesh. So you cant have too big grouped meshes with PBR textures becasue PBR textures need local reflection probes to look good. Its even worse with highly reflective materials like glass. Those need really, really local probes to look good.
     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Thanks for
    Thanks for letting me know.
     
  15. xBoxRedDot

    xBoxRedDot

    Joined:
    Aug 8, 2016
    Posts:
    6
    Does mesh baker works with alloy shaders/textures?
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    As long as the textures are regular Texture2D textures then Mesh Baker should work. If the textures are RenderTextures or Substance Textures then you may not be able to create atlases.
     
  17. arcdragon1

    arcdragon1

    Joined:
    Oct 15, 2012
    Posts:
    116
    Hi Phong.
    I have instantiated models such as desks, chairs and paper.
    I want to atlas only these material.
    In other words, it only performs atlas, and I won't combine 3D models.
    because I am thinking of moving the model separately.
    If I disabled Same as texture, and I thought I can make models one by one.
    I tried to bake to the prefab.
    After i baked only the first desk into prefab, next then i baked only the chair.
    The mesh of the desk has disappeared.
    Prefabs are using different ones.
    How can I do it?
     
  18. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    If you are using the same MeshBaker you are probably re-using the Mesh for the second and third bakes which would overwrite the previous bake. Try clearing the "Mesh" field in the MeshBaker inspector before baking the next mesh. Mesh Baker will create a new mesh in this case.

    You may want to try the Batch Prefab Baker. It is a more efficient workflow for this.

     
  19. arcdragon1

    arcdragon1

    Joined:
    Oct 15, 2012
    Posts:
    116

    Thanks Phong!
    It's extraordinarily useful!
    Thank you for introducing the tutorial. It worked very well and very easily.
     
  20. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    this is my setting

    this what prefabs looks like

    so what's wrong i did ?
     
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I see you have "multiple materials" checked but I don't see any source to combined mappings for the materials. Also I don't see any Materials listed in the Material Bake result. Did you bake the materials? What did Unity report in the console when that happened?
     
  22. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    Sry didn't notice the error log it's say clone does not have mesh filter or a skinned mesh render I don't know what wrong same object was working fine on old version of mesh Baker
     
  23. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,079
    If we combine trees together what about wind system? does it still work?


    Also it's only works with static objects? I'm using floating origin script that doesn't works with static objects. is there a way for this issue?
     
    Last edited: Jan 14, 2017
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Check that that exact object has a MeshRenderer on it. Perhaps it is the parent and the MeshRenderer was moved to be a child object.
     
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    You can combine dynamic objects. Mesh Baker doesn't care if they are static or not. The baked trees do work with the wind system, but make sure you are baking the same channels that original mesh uses. I think wind often uses vertex colors. Also sometimes the wind uses displacement based on distance from mesh origin. This doesn't work well if several trees are baked with the roots of some displaced from the origin.

    If you are shifting the origin you can use the StaticBatchingUtility to batch your meshes after shifting them to take advantage of static batching even though you objects are not static at build time.
     
    ksam2 likes this.
  26. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    i'm using unity 5.6.0
    this what it's looks like after baking
    MB3_Texture baker
    1.png 2.png
    MB3_mesh baker
    3.png
    and this is log and object with mesh render
    4.png
     
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    This is very strange. I am downloading 5.6 to see if I can reproduce the problem. One thing that I notice is that the log looks like it is for the Batch Prefab Baker. I take it that is what you are using?

    Are you following the steps in the tutorial video?

    [UPDATE] Just tested the Batch Prefab Baker in 5.6 and it worked. One thing I notice is that the object in the console log is named "Alley_O4_Top(Clone)" and in the inspector it is "Alley_O4_Top". These are not the same game objects. When I run the batch prefab baker my objects do not have the "(Clone)" added to them. Are you using project folder prefabs with the Batch prefab baker or scene objects? I think you need to use project folder prefabs.


     
    Last edited: Jan 15, 2017
  28. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    When attempting to bake/combine meshes that use substances (as materials), the following console error is presented:
    "testObject in the list of objects to mesh uses a Texture that is not a Texture2D. Cannot build atlases."

    Do you plan on supporting materials that use substances at some point?

    If you're having trouble supporting substances, there appears to be a method of fetching the pixels already on the forum:
    https://forum.unity3d.com/threads/substance-proceduralmaterial-to-material-possible.200767/
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    It has been a while since I have looked at Substance. It looks like it is now possible to read the bitmaps. I will see if I can add this functionality in the next version. I won't know until I test it but will take a look.

    In the meantime you won't be able to use atlases, but you can combine meshes that use the same material. You may need replace the materials with a temporary non-substance material for the bake and apply the substance material after.
     
    ilmario and 3Duaun like this.
  30. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    sry i didn't have internet connection last week and yes i always make batch prefabs and after bake all prefabs i delete old this decrees project size and game files after remove blend non-texture and consider mesh everything work fine thanks again
     
  31. C_Sharp_Soliloquy

    C_Sharp_Soliloquy

    Joined:
    Jan 16, 2014
    Posts:
    1
    Hoping someone can help here. We are definitely seeing gains from using the Mesh Baker system but need more. We have the latest version of Mesh Baker and purchased the latest version of Mesh Baker LOD to try to gain more using LOD's.

    We have followed the tutorials to a point, now I say a point because we are having an issue with MB2 being produced for the Combined Material but the LOD Manager wants an MB3 and will not take the MB2.

    The Texture Baker says "MB3_Texture Baker" yet only produces an MB2.

    We are sure it is possible this is somewhere in the documentation but have yet to find it.

    Can anyone advise of why this is the case? The tutorials show an MB2 used in the LOD Manager yet ours will just not take the baker into the exposed link in the inspector.
     
  32. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    1- put all prefabs on scene add them to MB3_TextureBaker Object to be combined
    2- create empty asset for combined Material
    3- Bake materials
    4- MB3_MeshBaker output Bake Mesh Assets In Place
    5- MB3_BatchPrefabBaker set Prefab Row and put prefabs from folder not scene
    after bake it's look same but why it's give me an error ?
    test.png
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I have not been able to reproduce that error, but you are the second person who has reported this problem. I looked in the code and the line numbers don't match with mine. Which version of MeshBaker are you using (The Release Notes file should say).
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi, I apologize for any confusion about the MB2, MB3. The tutorial videos were made when version two was out. Now you should use the version three components if available. The TextureBakeResult was left as MB2 to maintain compatibility when Mesh Baker 3 was released.

    The MB3_TextureBaker should generate an MB2_TextureBakeResult.

    The objects you drag into the MB2_LODManager should be MB3_MeshBaker objects. Are you using MB3_MultiMeshBaker components? These won't work.
     
  35. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    Hello. I'm very new to Mesh Baker, so sorry if this was answered earlier. I'm working on an infinite 2d side scrolling game. Would it make sense to use Mesh Baker for it? If so, could you point me to the relevant information? Thanks a lot!
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hello,

    There is a series of tutorials here:

    http://digitalopus.ca/site/mesh-baker-videos/

    The manual also has a lot of good information. It can be used for a lot of different things.
     
  37. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    Version 3.19 December 31, 2016

    - Modified can bake without baking textures first. Now collects all materials and maps each mat to its own submesh
    - Removed limitiation where first mesh must have all materials
    - Fixed bug with MeshCombiner checking objsInCombined list if user has deleted some of these
    - Batch Prefab Baker calls .ClearMesh before trying to bake so combiner isn't contaminated by previous bakes
    - TextureCombiner creates temporary textutures for missing textures earlier in pipeline. Fixes bugs with
    consider mesh UVs if some materials don't have textures.
     
  38. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    new question is there way to make non static objects ( characters - zombie - human ) bake as prefabs and at same time to combine them meshes separated i want to spawn enemy at runtime ?
    thanks
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I would recommend, creating an atlas for the materials and creating modified versions of the meshes with adjusted UVs. The Batch Prefab Baker will do this. Then at runtime it is very easy to combine these meshes with a Mesh Baker because they already all use the same material.

    I also have a tutorial video showing how to create and combine skinned mesh body parts that can the be baked together in different combinations at runtime.

     
    xxhaissamxx likes this.
  40. congtrungvnit

    congtrungvnit

    Joined:
    Jul 18, 2016
    Posts:
    14
    Hi Phong. I'm using grid cluster to create mesh bakers for my objects in my scene. It works perfect most of the time, but I don't know why sometime the console confirm that it "Found 8 cells with Renderers. Creating bakers.", but it only create 7 cells for me. So there are some object not clustered, therefore not combined. Do you have any ideas on why this problem happens? Thank you!
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    It could be that one of the cells has only one renderer in it. In that case Mesh Baker doesn't create a cluster because it doesn't make much sense to bake a combined mesh with a single mesh in it.
     
  42. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Hello Phong!

    First off, you have developed a great asset. As a team of primarily programmers you've made texture and model optimization an attainable goal and I thank you for that!

    After using your asset for a bit now I feel that I'm getting the hang of it and I've been able to reduce batches quite a bit in some of our scenes. However, there are two different groups of objects that I'm having trouble batching and I'm hoping that you can help me out (it is possible that they are related so we will stick with just one for now and hopefully it will help me figure out the other).

    Basically, when I combine the textures and meshes of some of my rocks they just turn a solid color instead of actually using the textures that are created. Actually, any texture that I apply to the joined mesh just becomes one solid color.

    Before:
    RockTestBefore.png

    After:
    RockTestAfter.png

    Again, I'm not sure what is different about these rocks than the much more complicated bakes and combines I've done previously. None of the rocks use tiling, both materials (the three in front use the same material) are standard shaders and use the same images (diffuse, normal, occlusion, and secondary maps [detail albedo and normal] ).

    I have noticed that the combined normal map is strangely tiled (again, the rocks' UVs don't exceed the 0,1 threshold), although the other two textures are not tiled at all. I know this type of effect can happen if you select "Consider Mesh UVs" during the texture baking, but it was not and, again, neither the diffuse nor occlusion map are tiled in such a way.

    RocksCombined-mat-_BumpMap-atlas1.png

    At this point I'm at a complete loss as to what could be causing this and any help would be greatly appreciated. Let me know if you need me to attach any more images. The settings I used for baking should be visible in the before and after pictures.

    -Andy
     

    Attached Files:

  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi Andy,

    Have you tried with "consider mesh UVs" enabled? You could get this effect if there are out of bounds UVs causing the tiling. Also check the console log after the texture bake. If there are any warnings they can help identify what could be causing the issue. There should be a "suggested treatment" log message as well. What does it say? Is there any chance there are missing channels in the source mesh (colors perhaps) that are not in the combined mesh?
     
  44. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    I've tried with and without the "Consider Mesh UVs" option enabled with no visible difference. I've also opened the rocks up in Blender and verified that none of the rocks have UVs out of bounds.
    RockUV.png

    There doesn't appear to be any warnings in the console after merging the textures but there are two lines that stand out:

    Textures in material(s) do not all use the same material tiling. This set of textures will not be considered for merge: [GAME_OBJS=Rock1A,MATS=Rock1,]
    Textures in material(s) do not all use the same material tiling. This set of textures will not be considered for merge: [GAME_OBJS=Rock2,MATS=Rock2,]

    There is also no "suggested treatment" statement as, again, there does not appear to be any warning or errors. The above statements strike me as a bit odd only because, again, there is no tiling involved with the rocks' UVs. I also find it curious that it tiles the normal maps when merging the textures but perfectly creates the diffuse and occlusion textures (two 2048 textures side by side with no tiling).

    ...

    After writing the above I tested a bit more and found that if I leave the normal maps out of the materials while combining them it works fine (as fine as models can look in a PBR world without normal maps). There is definitely something wrong there, but when comparing the normal map and model import settings with other objects that I've been able to successfully combine I can't see any glaring differences.

    I also threw some normal maps of objects that I was able to successfully bake onto the rock material just to see if the rock normal maps were the issue and the resultant texture was still tiled (AKA regardless of what normal map I throw onto the material it comes out tiled and the rock looks like a single color).

    Any insight? I think I've got myself a doozy here. The good news is that the more I play around with this the more I think whatever is affecting these rocks is also affecting the other group of objects that I'm having trouble combining. Fix one and we should be able to fix the other!

    -Andy
     
  45. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Also, after posting this I went ahead and did the entire process without the normal map in the materials and then merged the normal maps by hand in GIMP. When doing this the normal maps worked perfectly for the merged rocks and they look incredible while using only a handful of batches. There seems to be something with merging these particular meshes that messes up the normal map atlasing. Not sure what, but I'm just trying to provide as much information as possible.

    -Andy
     
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    O.K. I think I have run into this recently with some other rocks (possibly the same asset). The Standard shader has one set of tiling settings that is supposed to be used for all textures. However, I think this rock material at some point used a different shader that allowed tiling to be controller per texture. Those per-texture tiling settings are still serialized in the Material file but not visible in the inspector with the shader set to Standard. Mesh Baker is reading the serialized values associated with the bump texture where the Standard shader somehow ignores them.

    Try temporarily switching the shader on the source material(s) to "Bump Diffuse". You should see the tiling settings beside each texture. Some of these are probably set to something other than offset 0,0.. scale 1,1. They should all be the same and probably be 0,0..1,1. You can change them. Then switch the shader back to Standard and they should bake correctly.
     
  47. ZoneOfTanks

    ZoneOfTanks

    Joined:
    Aug 10, 2014
    Posts:
    128
    Does it work with Unity 5.5? o_O
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Yes, definitely works in 5.5.
     
  49. congtrungvnit

    congtrungvnit

    Joined:
    Jul 18, 2016
    Posts:
    14
    Hi. Can I use this to optimize particle system objects and how? Thank you!
     
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    If your particle system uses meshes with more than one material you can use MeshBaker to combine the materials and create a version of the mesh with adjusted UVs to use that material. To create the atlas you can create a temporary set of objects with MeshRenderer, MeshFilters on the them. Apply the particle meshes and materials to the MeshRenderers and MeshFilters. Bake those. You can then use the generated material an mesh with your particle system.
     
    hopeful likes this.