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:
    2,085
    Yes, the "multiple materials" feature handles this.

    You can configure a map that maps source materials to more that one combined material. There is some information in the manual describing how to set it up and this video uses this feature as well.

     
    Pourya-MDP likes this.
  2. Pourya-MDP

    Pourya-MDP

    Joined:
    May 18, 2017
    Posts:
    145
    So much thanks for the reply and this great tool,have a nice time!
     
  3. ManuelMeyer

    ManuelMeyer

    Joined:
    Dec 24, 2018
    Posts:
    10
    Hi,

    I have one small problem:
    How do I trigger the baking process of my MB3_Mesh Baker from script in EditMode?
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    This should do what you want:

    Code (CSharp):
    1.  
    2. MB3_MeshBaker myMeshBaker;
    3. ...
    4. GameObject[] objsToCombine = myMeshBaker.GetObjectsToCombine().ToArray();
    5. myMeshBaker.AddDeleteGameObjects(objsToCombine, null, false)
    6. ...
    7.  
     
  5. ManuelMeyer

    ManuelMeyer

    Joined:
    Dec 24, 2018
    Posts:
    10
    I already tried this. I get a configured MeshBaker on my Gameobject. But I have to press the "Bake"- Button to bake it into my Prefab. I want to automate the Button-Press.
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Baking into prefab requires using a lot of editor only functionality. You should be able to do this with:

    Code (CSharp):
    1.  
    2.  
    3. using DigitalOpus.MB.Core;
    4. using DigitalOpus.MB.MBEditor;
    5.  
    6. public class TestTriggerBakeIntoPrefab : MonoBehaviour
    7. {
    8.  
    9.     public MB3_MeshBaker myMeshBaker;
    10.  
    11.     [ContextMenu("TestBake")]
    12.     public void DoBakeIntoPrefab()
    13.     {
    14.         bool dummyBool;
    15.         MB3_MeshBakerEditorFunctions.BakeIntoCombined(myMeshBaker, out dummyBool);
    16.     }
    17. }
    18.  
    19.  
     
  7. ManuelMeyer

    ManuelMeyer

    Joined:
    Dec 24, 2018
    Posts:
    10
    Ok I got it working.
    Thanks a lot!
     
    Last edited: Oct 22, 2020
  8. BenWoodford

    BenWoodford

    Joined:
    Sep 29, 2013
    Posts:
    116
    Am I missing something with the workflow for baking for use in prefabs (i.e. putting baked prefabs inside a root prefab)? Compared to the other methods it seems rather... "manual"? Especially when using the Baker Grouper, if I regenerate the mesh bakers from the grouper (let's say I change the mesh list) I then have to recreate and re-assign prefabs for each one. It'd be nice if it would auto-create the prefabs and drop them into the destination parent of my choosing immediately upon baking rather than having to do this as a manual process.

    Or can you put multiple mesh bakers into a single prefab...?
     
  9. ManuelMeyer

    ManuelMeyer

    Joined:
    Dec 24, 2018
    Posts:
    10
    Ok. For normal Meshs it work, but for my TextMeshPros I get some warnings:
    upload_2020-10-22_14-9-42.png
    I think the colors are my problem. I dont see white text on white background.
    The buttonpress works fine on the same MeshBakers.
     

    Attached Files:

  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Ideally the channels for the combined mesh should match the channels that exist in the source meshes. If the source meshes lack uv, normal, uv2 and colors, that is a tough problem. Mesh Baker can generate decent normals, and sort-of generate uv, but for colors... Mesh Baker needs to invent colors.

    Does the combined material use a different shader than what is used by the TextMeshPro source meshes? If the combined material uses colors, but the source TextMeshPro mats don't, then you need to:
    • Or Add colors to the TextMeshPro meshes before combining.
    • Or hack Mesh Baker so that it writes a different color that you want to the "colors" channel.
     
  11. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Ben, I agree that the Baker Grouper is problematic if you change the generated bakers (e.g. assigning prefabs to the bakers) and then need to re-do the grouping. I will put some thought into this use case. I am not super happy with the prefab workflow in general so if I improve it I will make sure it handles this case.

    I presume that you want to make prefabs from the generated combined mesh scene objects. Something I have been thinking about for a while is a feature which would convert a combined mesh scene object to a prefab after bake-into-scene-object (save the mesh as an asset and the scene object as a prefab). Perhaps the Mesh Baker Grouper could do this to all of the child bakers.
     
  12. BenWoodford

    BenWoodford

    Joined:
    Sep 29, 2013
    Posts:
    116
    Basically, yeah. I have a small scene as a Prefab and I just started mesh baking it to optimise the draw calls basically. Right now I've got a few prefabs that are written to by MeshBaker that I nested inside that root prefab to enable baked meshes within it
     
    Phong likes this.
  13. batkountry_unity

    batkountry_unity

    Joined:
    Feb 17, 2020
    Posts:
    2
    Hello. Looking for help on using multiple mesh baker and using the grouper component. When I have a single baker i can choose "bake into prefab" but when I click the "bake all child meshbakers" it bakes them into the scene and not as prefabs. Do I have to go and turn all the mesh bakers manually to "bake as prefab" or is there an automated way to set this on all mesh bakers under the texture baker? Maybe I am missing something here and no doubt Unity's prefab system and it's complexities with my misunderstandings of it are part of the problem. Any help would be greatly appreciated
     
  14. ManuelMeyer

    ManuelMeyer

    Joined:
    Dec 24, 2018
    Posts:
    10
    I still do not get it, why its working fine, when you press the Button. I think it should do the same!?
    The Shader is the same and the source TMPs have color.
     
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Unfortunately there is no automated way to set up the prefabs for the child bakers of a MeshBakerGrouper. At this time you need to set these up manually. Someone else requested this feature recently so I will prioritize a way to automate this.
     
    batkountry_unity likes this.
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Would it be possible to create a Repo package with a simple setup (a baker with a few of the problem meshes assigned)? If I could download that I could take a look.
     
  17. kobara-kazuki

    kobara-kazuki

    Joined:
    Apr 15, 2016
    Posts:
    8
    SkinnedMeshRenderer with a BlendShape does not create a mesh when I Bake a Mesh.

    How can I fix this problem?
    MeshBakerQ.PNG
     
  18. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Kobara-kazuki,

    I have seen that model before. A user was experiencing the same problem that you are this August. The problem is that some of the meshes in the face have no bones at all (not even a root bone). These meshes only have blend shapes. The current release 3.31.1 does not handle these kinds of meshes. I have fixed the problem, but have not released the fix yet.

    The next release (will probably go live mid next week) it will contain the fix, or I could PM you a package with the fix if you want it right away.
     
  19. batkountry_unity

    batkountry_unity

    Joined:
    Feb 17, 2020
    Posts:
    2
    Just knowing it is a manual step that helps immensely at this time. Be great to see it in the future, however.
     
  20. kobara-kazuki

    kobara-kazuki

    Joined:
    Apr 15, 2016
    Posts:
    8
    Thanks for the reply.

    I understand. I look forward to your updates.
     
  21. drylightn

    drylightn

    Joined:
    Oct 21, 2014
    Posts:
    8
    Hi everyone! I'm struggling with the best way to use Meshbaker on a particular scene I have. Scene currently looks like this:


    There are many surfaces in the scene that use multiple materials on submeshes like the ones below:






    \\\


    There are 3-6 more these sub mesh style objects with multiple shaders. Watching tutorials online for baking meshes with submeshes, it seems like it really depends on having unique materials on an object to bake properly. Since so many of these materials are mixed and matched between using multiple meshes/submaterials, I'm not sure how to organize/insert them into the mesh baker panel? Any tips on how to go about optimizing these? I'd love to bake the room into one giant mesh!
     
    Last edited: Oct 29, 2020
  22. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    You probably want to use the Multiple Materials feature. You can define mappings that map source materials to submeshes in the combined mesh. Each mapping generates a submesh in the combined mesh. The easiest workflow is to:
    • Add all renderers in the room to a TextureBaker
    • Create Empty Assets For Combined Material
    • Enable the "Multiple Combined Materials"
    • Click the "Build Source To Combined Mapping From Objects To Be Combined"
    • Look at the mappings, you can always delete them and re-generate them with different options. You can also modify the generated mappings.
    This video has some more information on this workflow:

     
  23. Volkerku

    Volkerku

    Joined:
    Nov 23, 2016
    Posts:
    114
    Lightmap UV baking into prefab.
    This is not working for me, maybe I'm doing something wrong:
    1. set the object (a room interior) to static
    2. setup lights to baked
    3. generate lightmap
    4. create gameobject and add Meshbaker component
    5. add room object to MB component
    6. create empty prefab for Meshbaker Output (set to bake into prefab)
    7. tick: Include Normals, Include UV, copy_UV2_unchaged, mesh_renderer
    8. click MB bake
    the resulting prefab does not have any lighting information, and not sure if it even has a UV2 set.

    can someone help pls.
    upload_2020-10-31_9-0-8.png
     
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Copy UV2 unchanged will not actually work if you want to lightmap the combined mesh. The reason is that you will almost certainly have UV2 triangles overlayed on top of each other in UV2 space. You need to use either:
    • Generate new UV2 layout
    • Copy UV2 to separate rects
    These will generate a proper UV2 layout that can be lightmapped. You will need to re-bake the lightmaps using the combined mesh.
     
  25. jamalkeith13

    jamalkeith13

    Joined:
    Jan 15, 2019
    Posts:
    1
    I'm very new to this program and I'm trying to understand how to use it. I currently am trying to use Batch Prefab Baker to combine multiple materials on one mesh into one material and one texture. However, my result from following the instruction is basically an exact copy of the original with no connection to the atlas i made using the texture baker.
     
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    There should be the following differences:
    • The mesh should be a combined mesh asset saved with your new prefab
    • The material should be the combine material
    You should be able to check that each step in the process is successful:
    • After baking the textures, do you have a texture atlas .png file in the project folder? Does is look reasonable? Were there any errors in the console?
    • After baking the prefabs, were there any errors or warnings in the console? What material and mesh are the combined mesh prefab using?
    • If the prefab does not look correct, try turning the log level to debug and rebaking the prefabs (I typically will duplicate the baker and remove all prefab rows except one so that there is minimal clutter in the log). Can you see anything in the logs that might explain what is going on.
    If none of these suggestions help, let me know and I can look into this further.

    There is this tutorial video that shows the process:

     
  27. Rensoburro_Taki

    Rensoburro_Taki

    Joined:
    Sep 2, 2011
    Posts:
    274
    I bought MESH BAKER plus MESH BAKER LOD. The only thing that works right of the box, is simply merging some objects. The texture baker process is not clear, at least for me, the videos make me crazy - STILL - don't understand the whole process. also, I see videos from 2012, or so, in where the texture baking process is implemented inside mehs baker and seem to work automatically when hitting ONE button. Today I have two separate scripts to attach. booth have a bake button..... which one 1st? how to combine? ohh come on.... honestly? in times likes these?

    update: And I AM RIGHT, and why? Look in the thread ... Forum page Nr.60 and people are STILL trying others to explain! and why? Because the author's tool is not comfortable done. Works, or not works, doesn't make quality! 2nd a clear video that everyone understands! And this for how much money?!
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Soil, sorry to hear that you are finding this frustrating. I am in the process of hiring an assistant to re-do the tutorial videos. Should have some new updated videos early in the new year.
     
  29. tushtush91

    tushtush91

    Joined:
    Sep 17, 2019
    Posts:
    14
    I have a small question. I have 3 objects that i want to combine, each mesh has its own material using the same shader. I tried combining them the regular way but it doesn't work well for me, I guess it is because all the 3 materials have different properties (not the tiling, that is the same for all)?
     
  30. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    You can try using "blend non-texture properties" this works well for properties like color, bump. Not so well for properties like parallax-map. If these are using the Standard shader and they differ in "opaque, transparent, cutout" then they won't combine well.
     
  31. tushtush91

    tushtush91

    Joined:
    Sep 17, 2019
    Posts:
    14
    These are the properties of the meshes materials i am trying to combine
     

    Attached Files:

  32. tushtush91

    tushtush91

    Joined:
    Sep 17, 2019
    Posts:
    14
    I have another question, i have a baked scene with objects i want to combine. do i need to rebake it after i combine the meshes?
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Do you mean lightmap baking? Yes, you will need to re-bake the lightmapping after combining the meshes. Note that it is important, when mesh baking, to use one of these UV2 channel options:

    • Generate new UV2 layout
    • Copy UV2 to separate rects (only use this if your source meshes have good UV2)
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Those materials should combine well using the "blend non-texture-properties" when texture baking. Did you try it? how did it go?
     
  35. trojant

    trojant

    Joined:
    May 8, 2015
    Posts:
    89
    How to solve this problem please? mesh baker version 3.23.0
     

    Attached Files:

  36. Berir

    Berir

    Joined:
    Mar 23, 2013
    Posts:
    55
    Hey Could this be used to combine Terrain tiles into one terrain ? also what if they have different textures? if so would the newly created/combined object be a terrain or mesh?

    asking because I use paint hole terrain feature in my game!

    or is it only for Mesh objects to start with ? also how about combining hexagon mesh tiles into one map , but each hex has different texture ? would that work? thanks

    Appreciate any advice thanks
     
  37. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Trojant,

    It appears that you are using the "multiple materials" feature. When using this feature there is a "Source Material To Combined Mapping".

    This mapping connects your source materials to your combined materials. The error is reporting that there are some source materials on the source objects that have not been included in any of the mappings. The materials are listed in the error. An easy way to generate this mapping is to use the "Build Source To Combined Mappings From Objects To Be Combined" button. You can edit the mappings after generating them.

    upload_2020-11-10_16-25-6.png
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    It is not possible to combine Unity Terrain assets because these are dynamic meshes that are constantly changing depending on where the camera is located on the terrain. You can convert terrains to regular meshes (There is an asset Terrain2Mesh that does this). After they have been converted they can (in theory) be combined. However there are some complications. Terrains usually use a splat map material. It would be tricky and probably require modifying the terrain shader to get it working with a splatmap atlas. Also a single giant mesh will disable fustrum culling which could be worse than having multiple drawcalls do draw the terrain.

    If you want to combine a hexagon map, yes they can be combined.
    • First use the TextureBaker to create a combined atlas material and textures.
    • After the atlas has been created use the MeshBaker to combine the tiles. As the tiles are being added to the combined mesh, the UVs are updated to use the atlas.
    The first two tutorials in this playlist show how to do this:

    https://www.youtube.com/playlist?list=PLCzm-udM-shlRUy5f9QHHxqqv-9wP5FBM
     
  39. trojant

    trojant

    Joined:
    May 8, 2015
    Posts:
    89
    (1)Thank you for reply:), I clicked ListShadersInScene first,Then clicked one of GenerateBaker(Objs==374),And MultipleCombinedMaterials was automatically selected. When I clicked BakeMaterialsIntoCombined Material button It reported an error. (2)When I clicked Build Source To Combined Mappings From Objects To Be Combined" button It generates more than 100 individual materials in Conbined Materials, Is this the right result?
     

    Attached Files:

  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    This probably happened because of the two checkboxes above the "Build Source To Combined Mapping From Objects To Combine" button.
    • Put Meshes with Out Of Bounds UV on Submesh
    • Split Atlases If Textures Don't fit

    The first checkbox deals with source meshes UVs outside the range 0..1 (tiling), then Mesh Baker needs to bake the tiling. If there is a small amount of tiling then it is fine to disable this checkbox. If there is a lot of tiling, then you should put these meshes on their own submesh.

    The second checkbox handles very large source textures. If the textures are the same size as the atlas you are trying to create then you will only be able to fit one texture per atlas and you will end up with a lot of combined materials.

    Note that looking at your pictures, you are trying to combine a lot of materials together. If each of these materials has large source textures (eg. 4k) then your atlas will need to be HUGE. You probably need to consider spreading these across several TextureBakers. Check what the maximum texture size is for your build platform and set the Max Atlas Size to this. How big are your source textures? If they are large (eg 4k), Do they need to be this big? Will they ever be close up full screen on a 4k monitor? If not they make them a reasonable size. You can fit four 4k images in an 8k atlas, or sixteen 2k images, or sixty-four 1k images.

    If your srouce images are a reasonable size, try disabling the "Put Meshes with Out Of Bounds UV on Submesh" checkbox and re-generating the mappings. Then try baking the textures to see what the results are like. You may have some materials that have a lot of tiling that use up a lot of space in the atlas and quality is bad. Try removing these source objects or mapping them to their own submesh.

    This tutorial video has more information on the Multiple Combined Materials feature:

     
  41. WHiPerino

    WHiPerino

    Joined:
    Jul 1, 2016
    Posts:
    7
    Would this asset be able to be used in game build?
     
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Yes, many of the features work at Runtime. You can combined textures and meshes at runtime. It is recommended to combine textures in the Editor if it is possible to do so. Texture Baking can take some time. Mesh Baking is quick enough that it can be done in-game.

    You cannot create, modify or replace prefabs or create new assets. You cannot switch texture formats or make non-readable textures readable at runtime. Some features like generating new UV layouts for meshes don't work at runtime.
     
  43. highkite

    highkite

    Joined:
    Aug 28, 2020
    Posts:
    5
    Hello.

    Is it possible to create, modify or save combined texture/atlas in runtime?
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Atlases that are created at runtime are Unity3d Texture2D objects in TrueColor format. These can be saved to PNG, JPG or TGA format:

    Code (CSharp):
    1.                 {
    2.                     Texture2D atlasTex = new Texture2D();
    3.                     // ... baking
    4.                     // there is also EncodeToTGA and EncodeToJPG
    5.                     byte[] bytes = atlasTex.EncodeToPNG();
    6.                     File.WriteAllBytes(pathWhereIwantThisSaved, bytes);
    7.                 }
    You can modify the atlas by getting the colors, modifying them an writing them back to the texture. Don't forget to call Apply:

    Code (CSharp):
    1.                     Color[] pix = tex.GetPixels();
    2.                     // ... modify the colors
    3.                     tex.SetPixels(pix);
    4.                     tex.Apply();
     
    Last edited: Nov 13, 2020
  45. trojant

    trojant

    Joined:
    May 8, 2015
    Posts:
    89
    Hi, Phong!
    The Unity Multipurpose Avatar (UMA) system lets you create customizable characters.Its DynamicCharacterAvatar is to instantiate a character game object(including SkinnedMeshRender component.etc) after running. I can't get the SkinnedMeshRender component of the Character when game is not running. How can I bake texture to combined material? I generated about 40 different characters, so I want to optimize in UMA,Thank you.
     
  46. ShipSimulatorRealistic

    ShipSimulatorRealistic

    Joined:
    Feb 20, 2019
    Posts:
    9
    Hi i ised mesh baker to compbine meshes and meterials. I noticed that the verts increased about 20 from about 6 million but no perfomarce drop. is there a way to fix this or is just like this ?
     
  47. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Trojant,

    You can bake a combined material using other meshes with the materials that you intend to use on your characters. Hopefully the materials are not also being dynamically generated. Just put these materials on some cubes and bake them. The combined material can be used with another baker (just assign the baked material to the 'Material Bake Result' field on the baker.

    If using 'consider UVs' and the meshes you want to bake at runtime have UV tiling, then the proxy source meshes you are using to bake the textures need to have UV tiling as big or larger.

    Also, how does UMA work? Does it mix and match a bunch of body part prefabs together? If so then you might be able to use the batch prefab baker on those prefabs to make them share a material. Then UMA should generate single draw call meshes.
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    One bad thing about combining meshes is that it breaks fustrum culling. If any part of a combined mesh's bounding box intersects the camera fustrum then the mesh is rendered by the graphics card. It could be that most of the vertices in this mesh are off screen so the GPU does a lot of wasted work.

    It is generally a good idea to combine groups of meshes that are close together. It is a bad idea to combine meshes that will never be on screen at the same time.

    The MeshBakerGrouper has some tools for clustering meshes that are close together to help organize your scene.
     
  49. trojant

    trojant

    Joined:
    May 8, 2015
    Posts:
    89

    After running from 2:20 in the video, the DynamicCharacterAvatar component generate 2 sub Game Objects(bones and UMARenderer), as shown in the screenshot below.These sub Game Object are all dynamically generated.UMA_Mat_Lit material properties are program controlled.Can meshbaker work normally??
     

    Attached Files:

  50. ShipSimulatorRealistic

    ShipSimulatorRealistic

    Joined:
    Feb 20, 2019
    Posts:
    9
    its the main ship for example , even with 20 million i got a 80 fps uplift on build so i dont know might this will have issues but for now no
    Thanks for your reply
     
    Phong likes this.