Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Mesh Baker by Digital Opus [RELEASED]

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

  1. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    20
    Just have found, that the bug has place only if "Consider mesh UVs" flag is set. When un-set and re-bake combined material, texture area in atlas become proportional to source import size. There are no multiple maps, because it is simplest "Mobile/Unlit+Lightmap" shader.

    Also, while experimenting with atlas size, when I set it to 32768, script crashed with OOM on Texture2D constructor, and it is not a problem, but it changed import settings for all source textures to uncompressed with read/write enabled. So I have to manually restore import settings. Maybe it is worth to wrap baker with try-finally block?
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    For the 'consider UVs' case, does the mesh that is using that texture have UVs outside the range 0..1. Is it tiled in the atlas? That would explain why it is taking up more space.

    Mesh Baker does have a try-finally block specifically for the purpose of restoring texture formats. If there is an error then texture formats are restored. However in the case of a crash then the finally block is never reached. I thought the maximum texture size in Unity is 8k?
     
  3. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    20
    UV is not tiled in the atlas. Probably some of the meshes, that use source texture have out-of-bound UVs, but the texture is definitely not tiled.

    As for the crash, I've just did a simple test, and get import settings changed (not restored) after failed bake.
    You're right, looks like unity does not support >8k texture size, but MB allows to put arbitrary number there like 32k, so it should handle errors properly.
     

    Attached Files:

  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    Yes, I will add a limit to the texture size.
     
  5. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    739
    Hi,

    I followed your thread since about 2 years, because I did not was in the development process to start modeling.

    We use an advances technique to build models with single textures for City buildings. Textures have all the same fixed width = 256 or 512 and a dynamic height between 4 and 512 All objects UVs are tiled horizontally only.

    In the end the atlas should have a fixed width. The UVs per mesh override 0 and 1 in horizontal, but never override the height between 0 and 1 for the single texture.

    Untitled-1.jpg

    For example a height of a building with 10 floors is build of 10 repeated floors.

    So normally, each mesh of these buildings can be combined and having the same texture width. by creating an atlas height up to 8k. The new combined mesh part reduce only it's UV in height.

    If 8K texture height is reached then the baking process starts with next combined mesh.
    That goes along with the new warp modes 'mirror once'. This is not that easy to understand. :)

    If mesh baker would be able to read the UV's of a mesh, and recognize if the UV didn't override the height between 0 and 1, then it can bake a single texture into a atlas as above and combine the meshes as long the Texture 8K is not reached.

    Do you think that would be possible with Mesh Baker? Would be a great addition to MB.
    Artist have the freedom to escalade in UV'S width, and the technical engineers to economy the ram amount.

    You can PM me if you like.
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    That is a very clever idea. I have often wondered about that approach the approach of having an atlas that allows tiling in the x or y direction only by stacking the textures horizontally or vertically. To be honest I will have to take a look at the code to see how difficult it would be. Will get back to you.
     
    Quatum1000 likes this.
  7. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    739
    Great, thank you. Hope that works.

    Are there any information or tutorials explain when a mesh (with one material, multi-materials, submeshes ) requires additional drawcalls? Or does mesh baker disaplays how many drawcalls any combined mesh with an atlas texture require?

    Thank you.
     
    Last edited: Oct 17, 2017
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    There is a lot of information but it is spread around. I don't know of a great single source. It is best to focus on reducing Setpass calls first, then batches, then drawcalls as they are expensive in that order. This has a surprisingly good list:

    https://blogs.unity3d.com/2017/04/03/how-to-see-why-your-draw-calls-are-not-batched-in-5-6/

    Mesh Baker doesn't display number of drawcalls required by a mesh.
     
    Quatum1000 likes this.
  9. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    750
    Hello,

    For what I understand now your tool can create atlases also for textures used for tiled UVs?
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    Yes, the tiling will be baked into the atlas. This works well but can use a lot of space in the atlas if there is a lot of tiling.
     
  11. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    739
    Hi, do you have some news about?
     
  12. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    Not yet. I have some time to look into this today.

    [UPDATE]
    I had a look a this. It would be fairly easy to add. I won't be able to get to it soon but you could probably manage it yourself. In MB3_TexturePacker.cs there is a function called GetRects which takes a list of rectangles and packs them into an atlas. The atlas you are describing is very simple. The rectangles would be put in a horizontal or vertical row. This would be simple to write.


    One concern is that Unity wants the textures to be no more than a factor of two different in width and height. For iOS it wants textures to be square, so if the atlas is 8000 pixels high then unity will scale it to be at least 4000 pixels wide.
     
    Last edited: Oct 24, 2017
    Quatum1000 likes this.
  13. Erethan

    Erethan

    Joined:
    Apr 27, 2015
    Posts:
    14
    I used the MultiMeshBaker component then tried to bake some lighting. At the clustering stage I've got the following error wich froze the process:

    "Clustering job failed for system: 0xe7b938509020413a57c03cb9eddfddc9, error: 2 - 'Failed reading Clustering Output file.'."


    When I remove the baked meshes from the hierarchy, the problem solves.
    What could be wrong?
     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    What setting are you using for "Lightmapping UVs" on the baker. You probably want "Copy UV2 to separate rects" or "generate new UV2 layout".
     
  15. Erethan

    Erethan

    Joined:
    Apr 27, 2015
    Posts:
    14
    That solved the problem! Thanks!
     
  16. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    739
    Thanks for the info.

    But this factor of two restriction depend on the source file format png and progressed jpg in some cases.
    tif, real jpg, bmp, tga does not have these restrictions since unity 4.0.

    try!

    Untitled-1.gif

    CliffHeight.jpg

    4x8192

    16-2017-10-24-02-16-55-91.jpg
     
  17. xSpirite

    xSpirite

    Joined:
    Oct 12, 2017
    Posts:
    2
    Hello, I’m a beginner with Unity 3D and Mesh Baker.

    Currently I work on a project of optimization. I have a 3D model with 342 components. Each component has a color but they don’t have texture. Some component can have the same color.
    Vvario.png
    I try to make an atlas of all the colors to reduce the drawcalls.

    Like this:

    test-mat0-_MainTex-atlas0.png
    To create my atlas, I do the following manipulation:

    -TextureBaker and MultiMeshBaker

    -Open tools for adding objects

    -Search for meshes to add

    -I don’t exclude meshes without of bounds UVs

    -I add selected meshes to target

    -Multiple combined Materials

    -build source to combined mapping from objects to be combined

    -Bake materials into combined material

    -Bake

    combinedMat.png option.png

    Result:

    resut.png

    As you can see I don’t have an atlas and test-mat0 is blue when different component should be black, grey and green. I can’t change the color because the components with test-mat0 are group together.

    I don’t understand what does mean the warning, I had search during 1 week with tutorials and videos but I don’t understand how solve my problem. I try lot of thing but I fail all the time.

    Regards,
     
  18. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    I am realizing it is a while since I last looked into this so my information may be out of date.

    My understanding is that the factor of two restriction is a limitation of the compression format for some GPUs (mostly mobile). The big issue is with iOS which uses 'pvrtc' and requires square textures. I think you are right for desktop GPUs which can now handle non-power of two textures.
     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    Does the shader you are using have no texture slot or an empty texture slot?

    If there is no texture slot then this will be impossible because the combined material will try to use the shader but there is nowhere to use the atlas. If there is an empty texture slot then this should work.

    Make sure you are using the latest version of Mesh Baker. There were some bugs with this feature two versions back.

    I would suggest not using the 'multiple materials' feature and turn on the 'blend non-texture properties'.

    You don't want to use the multiple materials because you want a single atlas and material shared by all objects. Multiple materials would break out your objects to different atlases.

    'blend non texture properties' will tell mesh baker to grab the color, make a tiny texture and add that to the atlas. Check the name of the color and texture properties used by your shader. If the names are '_MainTex' and '_Color' you should be good to go. Otherwise you will have to create a texture blender for your shader. I would suggest you duplicate the file TextureBlenderLegacyDiffuse.cs. Edit it so it uses the name of your shader and the property names used by your shader.

    Use lots of padding because the textures are tiny and it is easy for them to bleed into each other. You might want to try setting the filter mode of the generated atlas texture to 'Point' to prevent textures bleeding into each other.
     
    ilmario likes this.
  20. xSpirite

    xSpirite

    Joined:
    Oct 12, 2017
    Posts:
    2
    Hello phong,

    Thank a lot for your answer.

    I will try your suggest. I come back as soon as possible to
    make you by my results.
    And yes my shader don't have texture slot or an empty texture slot.

    regards,
     
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    Hi xSprite,

    If you read my post you will notice that if your shader does NOT have a texture slot then none of this will not work. Mesh Baker will not find any maps in the source materials to make an atlas for and even if it did there is no place in the combined material to put the atlas. You will need to add a Texture slot to your atlas and ensure that the color is a blend of the tint color and the atlas color. Or use a shader that uses a texture and a tint color.
     
    xSpirite likes this.
  22. Enoch

    Enoch

    Joined:
    Mar 19, 2013
    Posts:
    193
    I am using Mesh Baker to Runtime Bake my randomly generated levels room by room (so each room in a dungeon has its own MB3_MultiMeshCombiner and bakes just the stuff in its own room.

    So the issue I am running into may or may not be a problem. Using the stats button in the editor this is what I am seeing in the exact same locations (once with baking on and once without):

    ON Batches 1771 81-84fps
    tris:2.8M Verts:13.2M

    OFF Bacthes 2382 61-65FPS
    Tris: 629K Verts:989K

    In another area:
    On Batches 2517 61-65FPS
    Tris: 4.5M Verts: 23.3M

    Off Batches: 3397 47-49FPS
    Tris: 958K Verts: 1.4M

    Now clearly MB is helping (I still need to find out why I have so many batches even after baking but that might be for other reasons). But the question I have is why is the Tri and Vert count going up so ridiculously much? Is this a Unity makeing this measurement in a weird way thing? Are these truely the stats? Is this typical for baked meshes, or is there something else going on here? I am quite a bit concerned about this. Especially the ratio of verts to tris. I can't understand why it gets this bad. Tris go up x4 and verts something like x 16. However framerate overall improved so its obviously helping.
     
    MoribitoMT likes this.
  23. seedtts

    seedtts

    Joined:
    Jul 17, 2017
    Posts:
    3
    Can I specify the number of meshes I want to combine?
     
  24. scraft

    scraft

    Joined:
    Feb 13, 2015
    Posts:
    3
    Does Mesh Baker handle multi-pass materials (i.e. a single material that has a shader which has more than one pass)? A good chunk of my scene is made up from multi-pass materials for an outline shader style effect, which is (in general) breaking static batching in Unity - I can't work out from the documentation and YouTube videos if Mesh Baker will help here?
     
    Last edited: Oct 29, 2017
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    Hi Enoch, that is a huge jump in verts and tris. There is often an increase in verts and tris with combined meshes because geometry that would otherwise be culled is now part of a larger mesh and the bounds of that larger mesh intersects the camera fustrum, but this seems excessive. For this reason it is important to avoid combining meshes that are far apart. It is hard for me to tell what is going on. Are the static, shadow and render settings on the combined mesh similar to the source meshes?

    I would suggest trying some controlled experiments. Try a scene with a few rooms. Disable various things (lights, effects, shadows) to see what the effects are. Try moving the camera to see how it affects verts and tris.
     
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    You must provide a list of meshes to be combined so yes you are specifying the number of meshes.
     
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    With mesh baker the combined material on the combined mesh(es) will usually use the same shader as the source meshes. So your case this would still be a multi-pass material so you would still get multiple passes. Mesh Baker can help make more objects use the same material. It can also help combine objects using the same material into a single mesh which you could use in place of static batching. However you want to only combine geometry that is close together.
     
  28. scraft

    scraft

    Joined:
    Feb 13, 2015
    Posts:
    3
    So, would my understanding be correct, that right now, say I have 10 objects, each with the same multi-pass material, Unity doesn't like to statically batch these materials (Unity 5.6 tells me this is because of the multi-pass nature of the material). If I use mesh baker, and combine these 10 objects into two groups of 5, I'll end up with a draw call saving in a ratio of 5 to 1. It won't mean the first five and second five objects will batch together (due to the Unity limitation) but it will mean that I am getting the reduction for anything I bake?

    Over all this all sounds good; I think I will bite and give it a go. My project is actually a VR project where you can turn your head and see the entire level, which is quite scary on Gear VR in terms of performance. Effectively I need to try and bake my entire level into as few draw calls as possible (although I'm fairly sure I'm just going to hit vertex and fill limits next, but I'll just look at draw calls for now)!

    Thanks.
     
  29. Enoch

    Enoch

    Joined:
    Mar 19, 2013
    Posts:
    193
    Than this is really unusal result for Mesh Baker, thats good information for me. It means I must be doing something really strange. I can't imagine what it might be, perhaps I am double baking (baking all my rooms and then again trying to bake all of those results or something weird like that). I will trace this down. Good advice I'll probably try limiting the number of rooms on the level to 1 or so first and see what the result is.

    In any case this is at least a testament to How ridiculously important draw calls are even on the desktop. I increased my verts/tris by a literal order of magnitude but reduced draw calls by around 500-600 hundred and got better frame rate somehow. Modern Graphics cards can crush out some tris.
     
  30. seedtts

    seedtts

    Joined:
    Jul 17, 2017
    Posts:
    3
    Thank you for a reply.
    How can you set provide a list?
    Please tell me in simple English.
    I'm sorry
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    If you are working in the Unity Editor then create an object TextureBaker And Mesh Baker:

    Create Object -> Mesh Baker -> Texture Baker And Mesh Baker

    Create your texture atlases the normal way as described in the manual and tutorial videos.

    In the MB3_MeshBaker inspector uncheck "Same As Texture Baker".

    Add meshes you would like to combine to the "Custom List Of Objects To Be Combined".

    "Bake"

    Does this answer your question?
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    A heads up for everyone that baking skinned meshes is broken in Unity 2017.2. Trying to assign the mesh to a SkinnedMeshRenderer generates an error:

    SkinnedMeshRenderer: Trying to set a mesh ("") that is unfit for use with SkinnedMeshRenderer. Most likely it doesn't have Skin information and/or is only assigned to the renderer during runtime, in which case Unity isn't aware of its use with SkinnedMeshRenderer. Mark the mesh as Readable or assign it to the renderer in the Editor before building.

    I am looking into the issue.
     
  33. seedtts

    seedtts

    Joined:
    Jul 17, 2017
    Posts:
    3
    Thank you for a reply.

    500 mesh of the number became 150 when I baked it.
    However, please tell me the method that I want to summarize in one from 500


    After having baked it, does the object come to have a bigger file size than the front to bake?

    Is there the method to prevent from growing big if file size becomes big?
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    The file size increases because:

    Before baking you have many copies of the same mesh in your scene. Unity only needs to save the mesh once and can re-use that mesh many times.

    After baking the copies have been made into a single large mesh. All the vertices and triangles need to be saved.

    You can reduce the size of your scene by saving the meshes as assets. The scene file will be smaller but the project will still be just as large because you will have a mesh asset in your project.
     
  35. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    365
    Is there a way to speed up baking for lots of items?

    Here is my scenario:
    I want to make piles of junk, trash etc in my scenes

    I want to combine about 70 items into one 4k Texture, but I want to create individual meshes. (I still want 70 meshes).

    I need to have the them separate, so I can place them in the scene...I will then bake the meshes together depending on where they are placed.

    Right now I have to manually create each mesh by baking them separately. Is there a way to just bake the Texture...then bake 70 meshes in on shot?
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    Have you tried the Batch Prefab Baker?

     
    ilmario likes this.
  37. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    365
    The video is out of date (the component seems different) but it has pointed me in the right direction....thanks!
     
  38. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,645
    I haven't used this in a long time, but am looking at trying it again in a project I'm working on. Has there been a solution implemented yet for scenes that have LOD Groups? I would like it to retain the LOD Groups, but combine meshes within groups all the while retaining their group hierarchy.
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    Hi Magique,

    There is a checkbox on the MeshBakerGrouper 'Cluster By LOD Level'. So you can:

    • Bake Textures
    • Mesh Baker Grouper -> Generate Mesh Bakers with 'Cluster By LOD Level' checked
    • Bake each baker into a combined mesh. There should be one combined mesh per LOD Level.
    • You need to manually add the combined meshes to an LOD group.
     
  40. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,645
    Maybe I'm reading it wrong, but it sounds like you're saying that it can't do what I want. Your last step indicates that I have to manually add combined meshes to an LOD group, but the scene already has hundreds, if not thousands, of LOD groups. I want to preserve all that. It sounds like you're saying it can build the combined meshes from existing LOD groups, but that I would then have to take those combined meshes and add them back into the original groups one by one. That would be non-trivial to do that for so many objects.
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    I am assuming you are working with prefabs. I would suggest the following.
    1. Open a new scene
    2. Create instances of the prefabs containing the LODs
    3. Bake the textures
    4. Generate bakers using the split LOD feature
    5. Configure each baker to 'bake into prefab' create a new prefab in the project for these
    6. Bake the meshes (I would recommend using the 'center mesh to render bounds' feature)
    7. Replace the LOD renderers in step 2 with these new baked versions.
    8. Apply the prefab
    All the hundreds of objects in the scene with LODs in the other scene should update.
     
  42. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,645
    Yes, they are all prefabs. OK, I think it may work. When I get to that step I'll back up my scene and give this a try. Thanks for helping.
     
  43. MoribitoMT

    MoribitoMT

    Joined:
    Jun 1, 2013
    Posts:
    298
    Hi,

    I have 8 rock models with different materials ( all use same shaders and same size textures ). I need to combine the materials to single material with 1 texture atlas, but not combine the meshes ( I need separate meshes of 8 rocks ).

    I use the texture baker to combine materials and textures, everything just ok in this point. However this create new material, how can I apply this new material to my 8 rocks without combining their meshes ? Or How can I create 8 new prefabs / game objects with new meshes without touching originals ?

    I am confused here.

    Regards
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    The easiest approach is to use the 'Batch Prefab Baker'.



    Alternatively you can do it with a mesh baker component and set the out put to 'bake meshes in place', but you need to do a lot of the tedious work yourself.
     
    MoribitoMT likes this.
  45. musolo

    musolo

    Joined:
    Sep 12, 2014
    Posts:
    222
    Hi Phong!!! Will your assets be part of black friday sell? I dont have enough money to get them at current price. This 20 november big hope to get some usefull tools.
    Thanks!!!
     
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    Hi Musolo, Sadly no. I am participating in the Asset Store Essentials pack promotion currently, which will last until December. I won't be able to participate in any other sales until that finishes.
     
  47. JDrem1

    JDrem1

    Joined:
    Jun 24, 2017
    Posts:
    171
    Can anyone help please.

    Wen I bake every shader in scene I get this console warning.

    Need to set Texture Bake Result on MeshBaker-Standard-LM-1 (MB3_TextureBaker)
    UnityEngine.Debug:LogError(Object)
    MB3_MeshBakerRoot:DoCombinedValidate(MB3_MeshBakerRoot, MB_ObjsToCombineTypes, MB2_EditorMethodsInterface, MB2_ValidationLevel) (at Assets/MeshBaker/scripts/MB3_MeshBakerRoot.cs:82)
    <CreateAtlasesCoroutine>c__Iterator0:MoveNext() (at Assets/MeshBaker/scripts/MB3_TextureBaker.cs:222)
    DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32)
    MB3_TextureBaker:CreateAtlases(ProgressUpdateDelegate, Boolean, MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/MB3_TextureBaker.cs:359)
    MB3_MeshBakerEditorWindow:drawTabAnalyseScene() (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorWindow.cs:249)
    MB3_MeshBakerEditorWindow:OnGUI() (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorWindow.cs:82)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    I have no idea what to do.

    Apologies if its self explanatory, or its a thick question.
    I did a google search but came up with nothing.

    Thanks for any help.
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,577
    Will take a look. Are you using the full version or the free version?
     
    JDrem1 likes this.
  49. JDrem1

    JDrem1

    Joined:
    Jun 24, 2017
    Posts:
    171

    Hi and thank you very much.

    Only the free version at the moment.
     
  50. antony57

    antony57

    Joined:
    Sep 9, 2017
    Posts:
    28
    Hello Ian,

    I need your help I think I am using mesh baker pretty wrong.
    I try to optimize a modular house that I've build. I've also furnished every room from this house. All the house, materials and prefabs are HQ.

    So when I enter playmod I get in the stats 400k tris and 800k verts or the other way around I am unsure.
    The thing is, when I bake the meshes together... walls, roof, props and so on and that I disable render on source object.
    I end up with 1M tris and 17M verts (or the other way around) so I am really not sure what I have been doing wrong...?

    My method. Create other - Mesh and Material Baker.
    Then I assign the folders and display all meshes on scene. Generate bakers and bake and disable renderers....

    Am I missing something?

    Thank you very much

    a.