Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    This does seem very workable. There are a number of ways that Mesh Baker could help with this.

    1) You can use the Batch Prefab Baker to make your prefabs that share a material. These are much easier to work with at runtime.
    2) You could use Mesh Baker LOD to do the combining, or, if your case is simple enough you could do the combine your own script. This would give you more control over how and where things are combined.
    3) Adding and deleting parts from a combined mesh is very doable. So it could work to bake bake most of the geometry and only un-bake parts near the player.


    [Edit] Just to be clear, Mesh Baker LOD doesn't generate your LOD meshes like Cruncher does or Decimate Operation in Blender. To do that you need an asset like Cruncher. Mesh Baker LOD just manages the baking of the lod meshes together in your scene.
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    Regarding question 2. The option to skip making textures readable. The Mesh Baker Fast texture packer will do this. It uses the GPU as you describe to blit the textures. Note that it is not as full-featured as the regular texture packer.
     
  3. Drumbledore

    Drumbledore

    Joined:
    May 13, 2019
    Posts:
    8
    Hello, Phong!

    We want to work with Mesh Baker, but the things we try to do doesn't work as planned. We have a game in which we use many warships with towers, airplanes etc. and they all have single animations and consist of many meshes. We thought that with the Mesh Baker we could now reduce each ship to one mesh, but at the same time keep the animations and use it as a prefab in the game. Unfortunately this doesn't work yet.

    We animated the ships in Unity and of course they don't have a rig or anything like that. These are simple keyframe animations created with the Unity Animator. Each ship has an animator on a parent object and underneath there are all the meshes.

    If we bake a ship to only one mesh, the animations will work as long as the mesh is inside the Prefabs and we have baked it as "Skinned Mesh". But if we want to make a new prefab out of it, deactivate all the single meshes and use the one combined mesh in the game, the animations won't work anymore - probably because it's just an instantiation? Right?

    Where is our mistake? Is Mesh Baker even able to do this? Excuse the long text.

    Thanks for your time.

    Greetings
    Sascha
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    Mesh Baker can definitely do this. Check the "Culling Mode" on the Animator component. Likely the Animator component is deciding to not-animate because of that setting. The safest setting is "Always Animate". You might be able to get it to work with other settings if you move the combined mesh so that it is a child of the animator in the hierarchy.

    It does not matter that your source meshes do not have a rig or how the animations are produced. That should not affect anything.

    Remember that the "bones" of your new skinned mesh are the transforms of the original source meshes. When you create your new prefab, those bones need to be a part of the new prefab or your combined-skinned-mesh won't have any bones. Also whatever was animating those bones in the original setup needs to be animating them in the combined mesh prefab. One thing to check is "are those bones being animated".

    Also, are you using output -> "bake into prefab" and is the combined mesh being saved as an asset in the project? If the combined mesh is an instance of a mesh in the scene. Then when you save your new prefab it will loose the mesh reference. Although if that were happening then the boat would simply vanish.
     
  5. Tech-Labs

    Tech-Labs

    Joined:
    Feb 5, 2014
    Posts:
    69
    Hi!
    I've used MeshBaker on a previous project and it helped me big time!
    Now I just want to combine some meshes but the results are all wrong.

    What did I do (Unity 2019.2.15 with newly installed MeshBaker):
    - Create a plane and used PolyBrush to add a little bump on it (it's in a park, so it's just a small item with a low height)
    - Use Polybrush to add a bunch of grass prefabs to the hill. The grass prefabs are pretty small and have only 45 verts each.
    - Because Polybrush created seperate objects in the hierarchy (in contrast to Terrain) I add these grass objects to MeshBaker and just want to combine the meshes (as they all have the same material).
    - The newly create object has all the meshes but 1) not in their original location relative to each other and 2) when I rotate the new single object it warps the grass objects in some sort of spiral that changes size

    The original grass objects all had scale 1 (as sometimes scaling and rotating give these kinds of issues)

    What am I doing wrong here? :)

    thanks!

    Marco
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    Hi Marco, are there Wind settings on the grass shader? The shader is proably expecting the origin of the mesh to be the base of each grass plant. The shader is displacing the vertexes of the plant based on distance from the mesh origin. When the meshes were combined then the origin moved much farther and the whole plant is moving.

    Possible solutions. 1) Set the wind settings to 0 so that there is no wind animation. 2) Modify the shader so that the vertices are displaced based on something other than distance from mesh origin. Perhaps vertex colors.
     
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    To verify that it is the shader that is causing the issue, try temporarily switching the shader to something like "Standard" or "Diffuse" that does not have vertex animations. Are the grass plants in the correct place when you do this? If so then then issue is the shader vertex animations.
     
  8. Tech-Labs

    Tech-Labs

    Joined:
    Feb 5, 2014
    Posts:
    69
    Hi!
    Thanks for getting back to me so quickly!! Appreciate it.
    Y, of course, right. It has a special material including wind. When I changed the material to HDRP/Lit and combined the meshes there was no problem!
    I guess we'll do without wind effect on the grass :)

    Thanks again!

    Marco
     
    Phong likes this.
  9. jeremiah_washburn

    jeremiah_washburn

    Joined:
    Nov 14, 2019
    Posts:
    1
    Using Unity 2019.3 Getting a lot of errors about the Examples:
    Assets\MeshBaker\Examples\BatchPrepareObjectsForDynamicBatching\MB_BatchPrepareObjectsForDynamicBatchingDescription.cs(4,14): error CS0101: The namespace '<global namespace>' already contains a definition for 'MB_BatchPrepareObjectsForDynamicBatchingDescription'
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    Is there any chance you had a previous version of MeshBaker?
    Upgraded from from the eval version?
    Moved an example folder then imported a new version?

    In any case the safest thing to do is to delete the MeshBaker folder completely and re-import MeshBaker. If you still get this error I would do a search in the project for the file that is being reported as an error (in this case):

    MB_BatchPrepareObjectsForDynamicBatchingDescription.cs

    Does this appear more than once in the project. I would expect it to be in the MeshBaker/Examples folder. If it is somewhere else in your project it probably got moved and the other version can be delete.

    I am doing all my new development now in 2019.3 so I know this works. Let me know if you do these steps but still have an issue.
     
  11. Drumbledore

    Drumbledore

    Joined:
    May 13, 2019
    Posts:
    8

    Thanks for the answer Phong!

    Ok, so we tried some more and were able to generate a mesh baked into the prefab. It all worked fine, but the shiops don't show when we start the scene. They're invisible. When looking at the models in the editor, all works fine, animations etc.

    Note that the original ships use "normal" mesh renderers, not skinned mesh renderers. The new skinned meshes doesn't show any bones. Could that be the problem? And if yes, how do we fix it? Would it be possible to contact you directly and send over one of the ships so you may have a look? Let me know!
     
  12. cd_mt

    cd_mt

    Joined:
    Jul 18, 2019
    Posts:
    5
    I'm need some help with baking to a textureArray - Whatever I do I end up with an array opf just 1 slice, with everything atlassed within that single slice.

    It's put 15 source materials into 1 slice .. which sounds like might be the issue....
    upload_2019-12-13_17-26-42.png

    Is there anything blatant that I am overlooking that you can recommend to get this right....
    Thanks.

    upload_2019-12-13_17-29-52.png

    Also.. I keep getting the error
    "You already have some texture array result materials configured. You must remove these before doing this operation." 
    when I try to adjust things - what is the correct procedure to remedy this ?
     
    Last edited: Dec 13, 2019
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    One thing to check if the ships are invisible are the "render bounds" of the SkinnedMeshRenderer. Make sure this bounds encloses the mesh. If you want to send me a ship to look at you can contact me at contact.digitalopus@gmail.com, or PM me.
     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    What is the maxAtlasSize? This is the parameter that limits how big each slice can be. If it is large, then Mesh Baker will just fill up the the first slice with images.

    Regarding the error:

    "You already have some texture array result materials configured. You must remove these before doing this operation."

    If you want to re-generate a configuration of texture arrays, you need to delete the old ones first. There is a little minus sign beside each configuration. Just click that until there are none.
     
    cd_mt likes this.
  15. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    572
    Hi, is there a quick guide on how to copy skin weight etc. after you have baked a character with multiple materials down to one?

    So I have the material and texture atlas, as well as the baked mesh with proper uv, and they render fine with a mesh renderer. But in order to work with skinned mesh renderer, I need to do more, right?

    Is there a short video tutorial for that? Should I use the bone weight copier when I am not making seam meshes?
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    There is this video:



    This procedure is a little bit complicated because it combines any number of skinned animated meshes.

    If you have only one skinned mesh it is a bit easier. You just need to set the renderType to "skinned mesh" and you need to make sure that the baked mesh is saved as an asset (Bake Into Prefab will do this). You can follow the steps in the video or, if there was only one mesh baked, you should be able to duplicate your orginal prefab, switch the mesh and material and it should work.
     
  17. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    572
    Thx, this process works on some of my test models.

    But I ran into some troubles on a particular model: MeshBaker failed halfway and leave my original textures with wrong texture settings.

    mb01.PNG mb02.PNG mb03.PNG

    This is my setting, above errors are logged when I click Bake Materials.

    mb04.PNG

    I am pretty sure my textures should fit on four 4K textures, we have only 6 materials (so 6 * 4 textures), so I don't know why these errors appear.
     
    Last edited: Dec 26, 2019
  18. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    572
    Actually I noticed the problem might be I have multiple materials for the same mesh renderer, instead of multiple mesh renderers, I need to check multi-material baker perhaps.
     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    Hi bitinn,

    It is a concerning bug that the textures were left in the wrong format. That shouldn't happen. Will look into that.

    Usually it is hard to hit the "recursion depth exceeded" error unless you have a huge number of textures or they are very large. Mesh Baker usually gives a report in the console describing the textures that it is trying to combine. How does the report look. Using "Resize Power Of Two" might help as the textures are easier to pack efficiently.
     
  20. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    572
    You are seeing the end of console output (Exception is the last log), so no report log like in other successful cases.

    The mesh setup is something like this, I am not sure MeshBaker handles this case.

    problem.PNG

    Also I face another problem I am not sure MeshBaker support: can I enforce the aspect ratio of each tile if I don't care about the most efficient packing? The reason is we still need to paint the result afterwards, texture stretching is annoying for artists.

    problem2.PNG
     
  21. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,096
    Hello! @Phong How do I use mesh baker on a house that has a gameobject with all meshes as child (roof, wall, floor, windows,doors etc etc etc) and different materials on everything?
     
  22. Pourya-MDP

    Pourya-MDP

    Joined:
    May 18, 2017
    Posts:
    50
    Hello there
    Just want to know any chance that substance materials get support by mesh baker??
    Or is there any way already to bake substance materilas in unity using mesh baker?
     
  23. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    572
    I have yet another issue where most parts of a character is baked fine but some parts of UV are not setup properly, I have tried out of bound mesh uv option to no avail. For example the feet mesh here are not setup according to original mesh uv.

    (The baked texture appears to be fine though)

    problem3.PNG problem4.PNG
     
  24. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    392
    Does Meshbaker or any of your products allow for creating UV2s that are identical across LODs? If not, is this even possible to automate?

    I’m trying to reduce lightmap texture space used in my game as well as reduce visual artifacts when lightmapped objects are swapping LODs when using Unity’s default LODgroup.

    I’ve figured out how to copy, lightmap data between meshes, but they obviously must share the same UV2 coordinates for this to be effective. Otherwise the shadowed area won’t line up.

    I’m trying to avoid manually creating UV2s as this would be very time consuming.
     
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    Thanks for sending the setup. I will see if I can reproduce the issue here.

    Regarding the aspect ratio. If you disable "Force power-of-two atlas", that might help. Then mesh baker doesn't try to resize things to fit. You might want to still have "Resize Power Of Two Textures" turned on as your textures will probably pack much better. Unfortunately with these settings your atlas might no longer be a nice square.
     
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    I was supporting substance for a while, but then Unity deprecated the API and Allegorithmic was going to provide a plugin to provide support for this. Last time I looked the plugin was in beta, so I am holding off supporting it.

    There is a "hacky" way to combine substance materials. You can convert the the "substance" textures to bitmaps:

    https://forum.unity.com/attachments/substancemissingdocumentation-png.64100/

    Then use these in a non-substance version of the material.
     
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    I would use the following workflow:

    • Add an instance of your house.
    • Add a GameObject -> Create Other -> Mesh Baker -> Create Texture Baker and Mesh Baker
    • With the Texture Baker:
      • Drag and drop the root of the house to the "Objects To Be Combined". This will add all the renderers.
      • If there are some radically different shaders (eg. transparent, non-transparent). Then remove the parts of the house that use these.
      • Click "Create Assets For Combined Materials". Save these somewhere.
      • Bake the Textures.
    • With the Mesh Baker
      • Bake
    There are a lot of options. For example you like want to set the Mesh Baker to "Bake Into Prefab". Also you likely have tiling textures (most buildings do). So you then need to set up the Texture Baker to handle the tiling. This video talks about this.

     
    mattis89 likes this.
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    After you tried "out-of-bounds-uv" option and re-baked the textures. Did you re-bake the mesh as well? Sometimes people forget that.

    Are you sure the problem is uv-tiling related? The picture is small so I can't see exactly what the feet look like. Sometimes this can be related to the source materials having different color tints.
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    None of my assets will do this. I think this would only be possible if the LODs were generated by collapsing edges in the higher level LOD meshes (perhaps using decimation). I am not sure if this would work using decimated meshes. Or meshes modeled separately.

    A workflow that ... MIGHT ... work (I have not tried this).
    • Model one, high level LOD
    • Import it into unity using the generate UV2 importer settings.
    • Save the imported mesh as an asset.
    • Use "Simple LOD" or "Cruncher" to generate your lower level LODs
     
  30. grllle

    grllle

    Joined:
    May 4, 2015
    Posts:
    15
    Hi there!
    I purchased MeshBaker and while reading the documentation i realized that my use case seems to be off the usual workflow. I searched the doc & faq but couldn't find a solution. I'm sorry if this was (probably) asked before:

    Question: Can i add pure Meshes without GameObject/Renderer to be processed by MeshBaker?

    I have a custom editor for creating rather large amounts of grass (single blades, not batches) with variable vertices per blade. The editor creates a bunch of meshes (vertex, normal, uv0-2, color) that may not be fully packed (having less then 64k vertices).
    I use a custom material/shader for rendering those meshes via DrawMesh (i will try out instanced rendering in the future if this increases performance in my case). No texturing involved atm, only vertex colors.

    So i want to trigger MeshBaker from my Editor to combine those meshes so i have fewer but tightly packed meshes.
    I can't find a component, where i can add pure meshes in opposite to MeshRenderer-GameObjects?

    Is there a way to use MeshBaker this way?
    Of course i could create a Mesh/Renderer for each Mesh temporarily if MeshBaker needs this for internal referencing.

    Thanks in advance & all the best
    grllle
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    There is no easy way to do this with Mesh Baker without creating renderers for the source meshes. However I think that your use case would be very easy to combine using the unity API Mesh.CombineMeshes, because all your meshes have the same channels and use the same material.

    https://docs.unity3d.com/ScriptReference/Mesh.CombineMeshes.html
     
  32. grllle

    grllle

    Joined:
    May 4, 2015
    Posts:
    15
    Oh wow, never heard of this method. Thanks for the heads-up!
    Although it's not what i need for this. For example: I have 3 meshes with 40k, 15k and 20k vertices respectively and i want them to be packed into 2 meshes, the first having 65k vertices (or at least almost 65k, depending on the topology) and the second the reminding ones.
    It's not too complicated so i just implemented it myself. I just thought maybe i can save the time using mesh baker :)
     
  33. JD_FVTC

    JD_FVTC

    Joined:
    Oct 20, 2017
    Posts:
    22
    I'm a first time user and I'm getting this message 7 objects were excluded because they were hand out of bounds UVs?
    Can you explain how I could fix this error?
     
  34. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,096

    Thanks alot .. this is quite hard if you not really think enough... Problem : I want to delete some objects from the "list" like doors windows and furniture... buuut mesh baker start to nagg if I delete from its list.... any button like "only add selected"?
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    There is a check-box for "Exclude objects with out of bounds UVs". Just uncheck that box and your objects will be included. When you bake the textures you also need to check "consider UVs" or your textures will not look right.

    The textures on the out-of-bounds-uvs objects are being "tiled" on the object. This tiling is accomplished by stretching the UV coordinates for the triangles so that more than one copy of the texture fits on the triangles. When you bake the textures this tiling (multiple copies of the texture) needs to be baked into the atlas.
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    There are a few tools for adding only selected object. You can drag and drop to the box above the "Objects to be combined". There is also a tab on the "Window -> Mesh Baker" called "Search For Meshes To Add". You can use this tab to filter which renderers are added. The filters apply to only selected objects an their children. You can also use these filters to remove objects that match the filters from the list of objects.


     
  37. aidenwain

    aidenwain

    Joined:
    Jun 1, 2019
    Posts:
    3
    Dear author, this is an amazing plugin, but there are some problem in HDRP 2019.3;

    1. When using mesh baker texture packer_Fast, it won't creat texture and report problem "Releasing render texture that is set as Camera.targetTexture!"
    2. When using baker texture packer_Fast on runtime, it won't creat texture and the material is white.

    I hope you can help me. Thanks.
    Best wishes
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,607
    Thanks for alerting me to the problem. I will take a look today and update this post with findings.

    [UPDATE] I just tested in 2019.3 (without HDRP) and it worked. I will try setting up a project with the HDRP to see if that works.

    [UPDATE] I tested in a 2019.3 project (with HDRP) and was able to reproduce the problem(s). It appears that the whole RenderTexture system works differently with the HDRP. This will take me a day or two to rework the MeshBakerTexturePacker_Fast to work with the HDRP RenderTextures.

    [UPDATE] This may take me longer than a few days. The problem is that the SRPs have removed some of the rendering callbacks that MeshBaker used to do custom rendering. The three different RPs all provide different APIs for doing custom rendering. Plus the user can customize the rendering pipeline which may mess with how Mesh Baker does this. I am going to have to spend some time coming up with a solution that works for all pipelines in a reasonably robust way.
     
    Last edited: Jan 29, 2020 at 12:35 AM
  39. aidenwain

    aidenwain

    Joined:
    Jun 1, 2019
    Posts:
    3
    You give me the fastest reply since I used Unity. Looking forward to your next version.
    :)
     
unityunity