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

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I've been working with this tool all Labor Day weekend and trying to find the best workflow and get the best results, but I'm still not there yet. Right now I have a dungeon scene that I want to optimize and am trying to figure out the best approach. I'm considering the Clustering approach and use a grid pattern. This would combine meshes in chunks that could work well with the occlusion system. I have a concern about how the tool works though. If the entire dungeon uses fundamentally the same prefab segments to make up the corridors and rooms then each combined mesh is going to have atlases that may end up being the same. Will mesh Baker re-use atlases or is it going to create dozens of duplicate texture atlases for the scene?
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi Niels, that is great news. could you send me the MeshCombinerSimple file via email at contact.digitalopus@gmail.com? I don't have a public repository.
     
  3. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I'm not sure that clears it up for me. If I'm getting blotches then should I make the value larger than .005 or smaller?

    Standard shader.
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Make the value larger.

    Hmmm, the standard shader should work. Can you set the log level to trace and send me the output PM or email?
    If you use the MeshBakerGrouper, you will end up with one texture baker with several mesh bakers as children. All the Mesh Bakers will use the same atlas generated by the texture baker. You can re-use the atlas in another scene by assigning the "Material Bake Result" asset to a Mesh Baker. You can delete the Texture Baker component in this other scene if you are not using it.
     
  5. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Thanks. I'll give that a try.
     
  6. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Any update on this issue?
     
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I have just finished implementing a fix in the last hour. I am doing some testing and should be able to push up a new version tomorrow.
     
  8. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Fantastic. I look forward to trying it out.
     
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I have submitted a new version of Mesh Baker to the Unity Asset Store. It should be live early this week. Changes:

    • Fixed bug with "consider UVs" generating. "Could not find a tiled rectangle ..." error.
    • Converted the texture bake pipeline to a coroutine so it bakes across several frames instead of freezing the game. Still more work to do here.
    • Fixed bug with "Open Tools For Adding Objects" window. Texture Baker foldout didn't work
    • Fixed bug with "Bake Meshes In Place" if folder path is not set
     
    magique and hopeful like this.
  10. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    It's live now!
     
  11. SelfExpressionArts

    SelfExpressionArts

    Joined:
    Jun 10, 2013
    Posts:
    6
    It's live and I updated it...
    And I've got warnings :(
    it's not really problem... everything is just that there are variables are declared but never used...
    the warnings just look ugly :)

    Assets/MeshBaker/Examples/BakeTexturesAtRuntime/BakeTexturesAtRuntime.cs(59,19): warning CS0219: The variable `t1' is assigned but its value is never used

    Assets/MeshBaker/Examples/BakeTexturesAtRuntime/BakeTexturesAtRuntime.cs(49,27): warning CS0219: The variable `meshbaker' is assigned but its value is never used

    Assets/MeshBaker/scripts/core/MB3_TextureCombiner.cs(1536,23): warning CS0219: The variable `ruv' is assigned but its value is never used

    Assets/MeshBaker/scripts/core/MB3_UVTransform.cs(164,19): warning CS0219: The variable `altasRect' is assigned but its value is never used

    Assets/MeshBaker/scripts/core/MB3_UVTransform.cs(161,19): warning CS0219: The variable `rawUV' is assigned but its value is never used

    Assets/MeshBaker/scripts/core/MB3_TextureCombiner.cs(526,15): warning CS0414: The private field `DigitalOpus.MB.Core.MB3_TextureCombiner._maxTimePerFrameForCoroutine' is assigned but its value is never used

    Assets/MeshBaker/scripts/core/MB3_TextureCombiner.cs(1893,30): warning CS0414: The private field `DigitalOpus.MB.Core.MB3_TextureCombiner.HasFinished' is assigned but its value is never used
     
  12. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Thanks for the heads up. I will definitely remove those references for the next build.
     
  13. nxtboyIII

    nxtboyIII

    Joined:
    Jun 4, 2015
    Posts:
    280
    Hi Phong,
    Every time I try to use AddDeleteGameObjects at runtime it tells me that read/write is not enabled on the mesh, even though it is. How do I fix this?
     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I can't reproduce this. Do any of the examples work? Specifically the ones that do runtime baking? What version of Unity are you using?
     
  15. nxtboyIII

    nxtboyIII

    Joined:
    Jun 4, 2015
    Posts:
    280
    Nevermind, I found out why, they were marked as Batching Static
     
  16. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    353
    Hi,

    I tried the free version. In the mesh baker description it's written that it only takes used areas of old textures to the new atlas.

    I exported the created object from unity and looked in 3d max because the newly created atlas doesn't seem correct.

    It included unused part of old textures as seen in the image below. Is this because of free version? If that's not the case and it's working correctly on the full version, I'd be very happy to buy and use it in my project.
     

    Attached Files:

  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Do you have 'consider mesh UVs' checked in the MB3_TextureBaker? If not then the entire source texture will be copied over to the atlas. There were some bugs with this feature so it is possible it won't work correctly in the current Mesh Baker Free version. I will release a new version of Mesh Baker Free next week with the latest fixes.
     
  18. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    353
    Yes I that option checked. I'll wait for the updated version and try again then, thanks
     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    There is a new version of Mesh Baker now available with a trio of new features:
    • Support for Blend Shapes
    • Combine ‘Optimized’ Skinned Meshes
    • Bake textures at runtime as a coroutine
    I will be submitting an updated version of Mesh Baker Free this afternoon (takes a few days to go live).
     
  20. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Hello there!
    Maybe is silly to ask, but can combine SMRs that move relative to each other?

    Edit: to be more specific, this feature points to combine parts of a same character, or can combine different characters with independent transforms and animations? In my specific case I have multiple characters using the same model (SMR). Unity wont combine them as they move relative to each other, neither batch them as per the SMR. Would your asset help?

    Thanks!
     
    Last edited: Sep 30, 2016
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Yes, Mesh Baker can combine skinned mesh parts and multiple skinned meshes into a single skinned mesh:

    Combining Multiple Skinned Meshes:


    Character customization:


    Combining MeshRenderer Meshes into Skinned Meshes
     
    Novack likes this.
  22. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Outstanding man, thanks for the quick answer. *The combined characters have to be done at edit time? In my case a lot of characters are created dinamically at runtime.
     
    Last edited: Oct 1, 2016
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    It is recommended to bake the textures at edit time, but the mesh baking is fast enough to do at runtime without problems.
     
    Novack likes this.
  24. bukerbear

    bukerbear

    Joined:
    Feb 16, 2015
    Posts:
    11
    Hey, I always got "TextureFormat is invalid!"

    here is my basic setting so far
    ps.I already set up texture format to ARGB32
     

    Attached Files:

    Last edited: Oct 2, 2016
    kuight likes this.
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Are you trying to bake at
    Is there a platform override for that texture? On the texture inspector look at the bar above the "Max size", "Format" there are some icons/tabs. Check those to see if there is a platform override set.
     
  26. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    is there max for baking prefabs ? coz i baked a lot and end like that 50 material and 200 prefabs legacy shaders Bumped Diffuse
     
    Last edited: Oct 3, 2016
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    There is no max, but
    There is no max number of prefabs, but there is a max size for the created atlas. For most platforms it is 4096x4096. Your source textures will be squeezed into this. If you have a lot of source textures or there is a lot of tiling, then there can be a quality loss. If your source prefabs use small textures or re-use/share textures then you can bake a lot of prefabs.
     
    xxhaissamxx likes this.
  28. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Hello there, Im testing functionality with MeshBaker Free.

    Studying how to use it at runtime, I am instancing multiple characters (using SMR). Each character also has perks using MeshRenderers. Characters and perks share the same material, so Im not using the asset material baking side at all.

    I am including a MB3_MeshBaker script in the scene, and pass it to my script.

    So as I instance characters, Im adding the character gameobjects to an array, and then passing it like: meshbaker.AddDeleteGameObjects(objsToCombine, null, true);

    However when I call meshbaker.Apply(); I receive this error:

    Result Scene Object was not set.
    UnityEngine.Debug:LogError(Object)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:ValidateTargRendererAndMeshAndResultSceneObj()
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:Apply(Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, GenerateUV2Delegate)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:Apply(GenerateUV2Delegate)
    MB3_MeshBakerCommon:Apply(GenerateUV2Delegate) (at Assets/MeshBaker/scripts/MB3_MeshBakerCommon.cs:147)
    MeshBaking:Add(GameObject) (at Assets/Scripts/tests/NuggetsLab/MeshBaking.cs:26)

    The Meshbaker setup is nearly stock, and looks like:



    Any hints on what I am missing?
    Thanks!
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    You could create an empty game object in the scene and assign it to the "Combined Mesh Object" field. That should fix the problem. I am a little troubled though because Mesh Baker usually creates a game object automatically if it does not exist so I am wondering if there was another earlier error.
     
  30. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    yes i think i have a lot of source textures (50 maybe ), is there anyway to make quality better or make it same ?
    thanks
     
    Last edited: Oct 4, 2016
  31. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I also use Mesh Baker and I think the only way to get what you want is to have multi-material meshes. There's just no way to retain the texture quality if your atlas has to be packed with so many textures that they require re-sizing to fit. You might be able to get away with 8192x8192 texture atlases, which should help, but even at that size you could only atlas eight 1024x1024 textures.
     
    xxhaissamxx likes this.
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I would take a look at the atlas texture to see what is happening. Here are a couple of suggestions:
    • Experiment with turning on 'resize power of two textures'. Without atlases often pack very inefficiently.
    • Look for tiling. This can eat up a lot of space in the texture atlas very quickly. As magique said, you can use the multiple materials feature to bake the tiling textures to their own submesh. If you do this then the tiling does not need to be baked.
    • Use the multiple materials feature to split the atlas into several atlases.
    • Mesh Baker tries to preserve the original image sizes when it copies them to atlases. If some of your source textures are huge relative to others (eg. some are 4096, others are 512). Then when they are copied to the atlas the 4096 one will take up a huge amount of space in the atlas. If you create a smaller copy of the huge textures so that most of the textures are about the same size then they will pack better.
     
    xxhaissamxx likes this.
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    A warning to anyone using the Unity 5.5 beta. Unity has changed the API for handling texture formats which Mesh Baker relies on heavily. This breaks the current version of Mesh Baker. I will get a new version up which should be live by early-mid next week which will work with the new API.
     
  34. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Thanks for the help man. I did that and got further errors:

    Target Renderer was not set.
    UnityEngine.Debug:LogError(Object)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:ValidateTargRendererAndMeshAndResultSceneObj()
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:Apply(Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, GenerateUV2Delegate)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:Apply(GenerateUV2Delegate)
    MB3_MeshBakerCommon:Apply(GenerateUV2Delegate) (at Assets/MeshBaker/scripts/MB3_MeshBakerCommon.cs:147)
    MeshBaking:Add(GameObject) (at Assets/Scripts/tests/NuggetsLab/MeshBaking.cs:26)
    ...

    Your site example for runtime use, mentions an "ApplyAll" method that is not present (not at least on the free version Im using for tests). So Im using meshbaker.Apply();

    May be this that is related to the issues?
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I don't think that is
    I don't think that is the problem. If the target renderer didn't get set then something must have gone wrong earlier. Are there any errors previous to this? You might want to set the log level to trace to get a more verbose output.
     
  36. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    There are no errors at all. There is a MeshBaker specific log level flag?
     
  37. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Oh right got some progress. I found the log level, and set it to trace, but got no difference.

    I did however found the initial issue, looking at how your runtime scene example was setup.

    The MeshBaker script will generate the required object and mesh if the "Bake" button is hit on the editor. There is no obvious automatic generation as you describe, and the example scene includes it from stock.

    This baking requires adding meshes or skinned meshes manually, to the list of object to be combined in the inspector. This is not detailed in the docs, at least not in relation to the runtime use, but was the only way to solve the aforementioned errors.

    So I simply added a character, the same that is going to be instantiated multiple times at runtime. Once this is done, the target object/mesh is generated, and no more errors are thrown when the code (from the runtime example) is executed.

    However, it wont do anything either. If I disable the renderers of the objects I instantiate, nothing is rendered. This may be related to not using the texture baking? Remember I dont use it given that I only use one material for everything (To recap, my setup is a character with an SMR + a mesh renderer, both elements sharing material. This character is instantiated multiple times at runtime).

    Thanks again.
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Glad to here that it is baking now. When you say it won't do anything, is it not Animating, not rendering?

    There are a number of steps that need to be taken with skinned meshes after baking:
    • The bones of the original source mesh need to be moved to the target game object. This is because those bones are the ones animations know about.
    • To move the baked mesh you need to move the original bones.
    • If animations aren't working check the culling settings on the source animator
    • If you are prefabing the skinned mesh, the process is tricky. It is described in the FAQ and the video link bellow.
     
  39. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Is not rendering. Im not prefabing them, just want to follow the simplest way possible, just instantiating similar objects and adding them to the "objects to combine" array as I add them.

    But they are not being rendered at all, and nothing is displayed if I disable the renderers on the original objects.

    Have you actually tried something like this before? Seems like a simple case, but does not look like the example scene for runtime use covers this case.
     
  40. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Is there any other communication channels by which we can have a more fluid communication?
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    You can contact me via email contact.digitalopus@gmail.com. If it's possible to export the scene and send a link where I can download it that would be great.
     
  42. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Thank you. I will work on a minimalistic replica and send it to you.
     
  43. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Hey guys, I have a couple of question before buying Mesh baker. We have problems with Occlusion culling in one of our scenes. Background here https://forum.unity3d.com/threads/occlusion-culling-not-working.436502/#post-2823053

    A guess I have now is that this is caused by too small building blocks in the asset we use, would mesh baker help here by grouping the building blocks and create larger meshes that I can bake oclussion against?

    A tunnel system like this scene, whats best, bake each tunnel segment together? The bigger open halls as one big mesh?

    Will it reuse the texture between grouped meshes or will the memory and disk usage grow like crazy after mesh bake?
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Mesh Baker could definitely bake many of your smaller meshes into larger meshes. If too many meshes is the problem then this would help.

    You should avoid baking meshes together that will never be on screen at the same time, so your suggestion of baking the tunnel sections together and rooms together is a good one. For long tunnels and large rooms you may want to bake these into several sections.

    It is easy to re-use atlases and materials. If you bake objects that all use the same material then the material is re-used. If you bake an atlas that combines several materials then this can be re-used many times and in different scenes as long as the meshes you are baking use the materials that were baked into the atlas.
     
  45. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Thanks, and do you think it can also help with the occlusion side effects I show above?
     
  46. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I have a feature request. In my scenes I have many modular components that make up various structures. In one case I have various ruin prefabs to build an area of climbable ruins. These modular components all use mostly the same set of materials and there are lots of the same pieces re-used. I'm wanting to just combine the entire area of ruins into a single combined mesh. However, all the prefab components are LOD groups with 3 LOD levels. What I'd like to be able to do is have Mesh Baker automatically combine each LOD level into 3 separate meshes and then put these all into a single root object with an LOD group to switch between them.

    Doing all this manually is a very involved task so I thought it would be nice to have such a feature built into Mesh Baker. Would you consider something like this in a future version?
     
  47. Rend

    Rend

    Joined:
    Nov 3, 2013
    Posts:
    5
    Hello, I've been testing Mesh Baker and light-mapping for a few days now and without success.
    I made a simple scene for testing where I only use the mesh baker, since the material already is an atlas texture.
    The floor is made up from a single repeating tile with a mobile diffuse material, which is then made into a single mesh with Mesh Baker. I added different types of light, emissive, point, spotlight and area light, with the lights in the front set to Baked and those in the back set to Realtime. I've set all objects to lightmap static. The 4 boxes are using the standard shader with 2 of them set as light map static and are placed for reference.

    Added screenshots with the original meshes and MB generated mesh using all available light mapping uvs options.
    None of them seem to get light mapped properly. Using 5.4.0f3.

    standard setup.PNG
    MB light baked ignore.PNG
    MB light baked UV2 unchanged.PNG
    MB light baked Gen New.PNG
    MB light baked UV2 rects.PNG

    Am I missing out something, or is this some issue with the new lighting system in Unity?
     
  48. Phong

    Phong

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

    The only options that will work for lightmapping are "generate new UV2 layout" and "Copy UV2 unchanged to separate rects". I would recommend the first option. Make sure you re-bake the meshes after changing the option. Mark the combined mesh as lightmap static and re-bake the lighting.

    You should be able to see the generated UV2 layout in the lightmapping window for the combined mesh. Does it look reasonable?

    I will check with 5.4.0 on my end to make sure it is working. I can't think of any reason why this wouldn't work. Mesh baker uses Unity's own API to generate the UV2 layout (same thing the importer uses).
     
  49. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    I was just going to ask this very question, there is no support for LODs?
     
  50. Rend

    Rend

    Joined:
    Nov 3, 2013
    Posts:
    5
    This is the uv chart generated by "generate new UV2 layout" and I notice it is different than my previous tests, looks fine, however it still does not get baked lighting, only realtime emissive looks the way it should.
    I'll keep testing with different scenarios and see what comes up.

    UV chart.PNG gen UV2 shaded.PNG

    Thank you for your reply