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

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Yikes, my apologies for being a whole week late responding. For a while now I have been receiving emails from the forums whenever there was a new post so I had stopped checking this thread daily. Visiting it only when there was a new post. This seems to have stopped working so I will go back to checking the thread daily.

    At the moment I do not have plans to add support for meshes with multiple submeshes to the auto generate. This is because the auto generate is very conservative and tries to restrict itself to combining meshes that are very likely to produce good results. I will consider this.

    I do plan to add support for clustering to the auto generate so that meshes that are close together are combined together. One problem with the existing system is that meshes spread across the entire scene are combined which helps reduce drawcalls but can increase total vertices rendered.
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Sorry for the late response. As mentioned my notifications when posts were added to this thread seems to have broken.

    To add the bones, you need to drag the rigs for the skinned meshes you are combining so they are children of the combined mesh. For example if I had a hierarchy like:

    • CombinedMesh-Soldiers
    • Soldier1
      • Pelvis
        • LegR
        • LegL
    • Soldier2
      • Pelvis
        • LegR
        • LegL
    I would need to drag the pelvises over so it looked like:

    • CombinedMesh-Soldiers
    • Pelvis
    • LegR
    • LegL
    • Pelvis
    • LegR
    • LegL
    • Soldier1
    • Soldier2
     
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I am not sure I understand the question.

    You can add and remove objects from the MeshBaker at runtime. This is done in the example Skinned Mesh Renderer scene. As you instantiate objects you can add them to the combined mesh and when you destroy them you can remove them from the combined mesh.

    You can also prefab combined meshes for use in other scenes although this procedure can be complex for skinned meshes because you need to include the rigs and animations of the source objects in the prefab.
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I can't tell for sure but your hierarchy does not look correct.

    The thing you will need to prefab is the CombinedMesh-MeshBaker0-Mesh object. The bones and animations need to be children of this object.

    I will try to add a tutorial showing how to combine skinned meshes.
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    This is very strange, it is the first report I have had of the report crashing the system. How many objects are in the scene? If this is repeatable could you send me the editor log?

    I think I know the cause of this. It has come to my attention that Unity has added a new read/write flag to meshes in Unity 4.5. If this is set to false then Mesh Baker cannot read the mesh and an error is written to the console. If the scene is large it takes considerable time to process these error messages and can exceed a buffer which causes the freeze.

    The immediate fix is to set these flags to true on all your meshes. I will try to get a fix up this week that handles this automatically.
     
    Last edited: Sep 22, 2014
  6. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    I noticed something weird happen to my Unity scene after I did mesh baking... the Scene is now 130 MB compared to before I Mesh Baked the Scene was only 10 MB, does Mesh Baker cause the Scene to increase in size? Is this normal?
     
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    It is certainly possible. The reason is that Unity tries to share meshes as much as possible and combining meshes defeats this. Consider this example:

    A scene with a tree prefab (1000 verts) used 1000 times. Before combining this is one mesh that is sent to the graphics card 1000 times. After combining this is two, very large (50,000 vert) meshes sent to the graphics card once each.

    There are a few things you can do that will help:

    1) Delete the MeshBakers out of the scene once you are finished baking if you don't need them. The MeshBakers maintain a copy of the mesh data in a buffer. Alternatively you can call the "clear" method in the API to clear the buffers in the mesh baker object.

    2) You can combine your meshes at runtime when your level is loading (bake the textures ahead of time). This way you can keep your build small and still have a small number of meshes at runtime.
     
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Unity has added a Read/Write to mesh assets in Unity 4.0. If this flag is set to false and you are trying to bake at runtime then an error is generated and the baking fails. Baking in the editor works fine.

    I will try to release an update that generates better error messages this week.
     
    Last edited: Sep 22, 2014
  9. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    Thank you Phong! I will try to remove the MeshBakers, and just maintain a Backup Copy of the Scene. My issue was pushing updates to Github, as Git did not want to accept my Unity Scene due to the file size. So I can keep an offline backup, and push the Scene without the MeshBackers. Thanks again.
     
  10. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    Hi Phong, I have really strange issue... I'm trying to group up my Grass Meshes so I can Mesh Bake groups of Meshes like you suggested to help reduce the Triangles / Verts being rendered. Previously I had one big Mesh for the Grass and it was rendering 1.5M Triangles or More... so I'm trying to break it down into groups in my scene but I am unable to select multiple grass Meshes (see screenshot), I know this is not 100% related to Mesh Baker and may not be your problem, but I thought maybe you'd have an idea so I can continue with my Mesh Baking... Let me know if you can, otherwise I'll wait for a response from Unity Support. Very odd...

     
  11. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    Nevermind, a simple close, restart of Unity did the trick lol! damn Unity... I wish at least it would throw an error or something.
     
  12. Phong

    Phong

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

    If it were me I would consider writing a little editor script to do this. Here is a short untested script. Save it to a file called MiscOperationsEditorWindow in a folder called Editor. It has a button that should select all MeshRenderers in the scene with name "grass" (change this if the name is different). This script should be easy to modify to add filters to select grass only in a square.

    You could even modify this to group the grass into groups and create a mesh baker for each group and add these meshes to those mesh-bakers


    Code (CSharp):
    1. // C# example:
    2. using UnityEngine;
    3. using UnityEditor;
    4. using System.Collections.Generic;
    5.  
    6. public class MiscOperationsEditorWindow : EditorWindow {
    7.    
    8.     // Add menu named "My Window" to the Window menu
    9.     [MenuItem ("Window/Misc Operations")]
    10.     static void Init () {
    11.         // Get existing open window or if none, make a new one:
    12.         MiscOperationsEditorWindow window = (MiscOperationsEditorWindow)EditorWindow.GetWindow (typeof (MiscOperationsEditorWindow));
    13.         Debug.Log(window);
    14.     }
    15.    
    16.     void OnGUI () {
    17.         if (GUILayout.Button("Select grass")){
    18.                 MeshRenderer[] mrs = (MeshRenderer) GameObject.FindAllObjectsOfType(typeof(MeshRenderer));
    19.                 List<Transform> myGrasses = new List<Transform>();
    20.                 for (int i = 0; i < mrs.Length; i++){
    21.                     if (mrs[i].name.Equals("grass")){
    22.                         myGrasses.Add(mrs[i].transform);
    23.                     }
    24.                 }
    25.                 Selection.transforms = myGrasses.ToArray();
    26.         }
    27.     }
    28. }
     
  13. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    Nice! very impressive, maybe you should add this to mesh baker as a minor update if it helps others. = )
    I just saw this now after going through finally grouping all the grass manually, it was painful lol! but it was able to do it manually, baked the grass into multiple groups, but sadly i didnt get the full results i was looking for. It didn't really increase my FPS, but I saved about 800,000 Tris from being Rendered now, so I guess that might be good performance gain for lower end systems. Previously I was Rendering Tris: 2.3M, now Tris: 1.5M.
     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I have created a couple of new tutorial videos focusing on combining skinned meshes and saving skinned meshes as a prefab.

    Combining Mesh Renderer Objects Into A Skinned Mesh


    Combining Skinned Meshes And Saving As A Prefab
     
    jonkuze likes this.
  15. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    I havent gone through the entire thread so this may have been answered.

    Does mesh baker have options for edge texture padding? for example if i made a floor that is a bunch of quads... each quad is the texture... its set up to repeat, but just adds geometry.. so quad per repeat. Now this only works if the texture is created so that there is a gap between the edges... the uvs get scaled in some and the colors get extended outside the bounds of the uvs.

    Basically what i am asking is if i just have a prop that extends all the way from 0 -1 in the uv space... is there an option to shrink its uvs and add uv padding to it? Or even some sort of uv txture padding alone in the atlas?
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    There is a field for setting the padding in the atlas. There is also an option for "resize power of two". This shrinks textures by the padding so that they are the same size in the atlas with padding that they were in the original. Using this feature ensures that combining four 512x512 textures results in a 1024x1024 texture not a (1024 + padding) x (1024 + padding) texture. Mesh Baker does NOT attempt to extend the colors into the padding (although this would be a good feature to add now that I think about it).

    MeshBaker will shrink and translate the UVs in the combined mesh to fit the texture in the atlas exactly. There is no option to shrink the UVs more than this. If you build your quads with uvs that don't quite extend to the edge of the texture, then they would have the padding you want when you combine them.

    You could try this in the evaluation version to see if it works.
     
  17. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    Yes sir please add the color extend as soon as possible. Only reason I ask is because if you want to have repeating textures with geometry... mip mapping destroys that illusion by creating seems between them as distance goes on if the color doesnt match up.

    I used to do this stuff by hand by scaling the uvs then having the texture repeat again in areas the uvs werent even at.. just to maintain mipmapping.
     
    Last edited: Oct 8, 2014
  18. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I will try to add the texture bleeding in a future version. In the meantime, Flaming Pear has a free filter for Photoshop that does an excellent job of filling in the transparent areas of a texture with the nearest color (solidify B). You could use this on the generated atlas texture to fill in the padding with color.

    http://www.flamingpear.com/goodies.html
     
  19. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    I know what that is , but that wouldnt work out so well... i need the color to be solid up to a half way point... not blended gradually. Otherwise mipmappign over along range will be noticeable. Normally i would use this for characters and props, but you need a lot of space typically to remove the mip map from say a repeating ground texture.
     
  20. alexman

    alexman

    Joined:
    Jul 11, 2012
    Posts:
    17
    Hi, I got a helm, sword and a shield which use 1 texture each, so 3 draw calls. I want to get them to use the same texture to get the draw call down to 1, but not combining them into 1 mesh as i need to disable any of them randomly, plus the sword and shield's position can change when attacking or dropped to ground. Is it doable? If so how? I'm new to this, thanks, I know how to back everything into one model and one texture, but don't know how to do this.

    Thanks.
     
  21. alexman

    alexman

    Joined:
    Jul 11, 2012
    Posts:
    17
    Anyone?
     
  22. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,676
    @alexman, Keep in mind that the forum is spotty about notifying the thread owners about new posts. Send him a PM if you need an answer right away.
     
  23. juliastorybored

    juliastorybored

    Joined:
    Nov 5, 2014
    Posts:
    1
    I have a scene and assembled a big city environment, I first separated the walls into another scene and tried baking it into one using the mesh baker but it seems an error...

    "Object wallPillar(my prefrab) in the list of objects to mesh uses a Texture that is not a Texture2D. Cannot build atlases.
    UnityEngine.Debug:LogError(Object)"

    ...was generated right after i clicked the "Bake Material Into Combine Material".
     
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Sorry for not replying earlier, It has been a while since I checked this forum. The alerts don't seem reliable. Are you using a RenderTexture on one of the walls? Do you have a video wall? You won't be able to combine this into an atlas because its pixels will be constantly changing. Try omitting this mesh.
     
  25. davem250

    davem250

    Joined:
    May 28, 2013
    Posts:
    186
    Hi Phong, i have just updated Mesh Baker today and unfortunately i cannot run it... i am using Unity 5.0.0b9 but as for now there is only one error, and i will insert a screenshot of the console message!



    I have no idea how to change that (i usually do not play around with things that work ;)) but like you can see on the screenshot, then it is only one error and i have tried to mess with it just to see if it was actually true what the console said, and it is! i cannot get access to r.lightmapTilingOffset where r is Renderer! it still exists according to this code, it is just either protected or private ??? anyway if you have a cool solution i wouldn't mind listening :p
     
  26. davem250

    davem250

    Joined:
    May 28, 2013
    Posts:
    186
    Hello again Phong... well i have actually made it working in Unity 5.0.0b9 :D i had to do some manual tweaking beside using r.lightmapScaleOffset instead of r.lightmapTilingOffset... it still works the same only, it works in Unity 5 :D it's Awesome ;) and i would say that if I can tweak Mesh Baker to work in Unity 5 then anyone can ;)
     
  27. Phong

    Phong

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

    Great to hear that you managed this. I have not tested in Unity 5 yet, but it sounds like it will be fairly easy.

    BTW you should be able to delete the Legacy directory out of the scripts folder. It has old version 2 classes that are only included for backwards compatibility. Hopefully nobody is using those anymore.
     
  28. Phong

    Phong

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

    I am considering dropping support for Unity 3 when Unity 5 comes out. Is anyone still using Unity 3?
     
  29. daisySa

    daisySa

    Joined:
    Dec 29, 2011
    Posts:
    341
    Mesh Baker seems to be working well so far under Unity 50b11; e.g. combining skinned mesh renderers into scene objects works perfectly.
     
  30. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Check the value in the "Combined Mesh Prefab" field in the inspector. This needs to be a prefab asset from the project folders, not a scene object.
     
  31. daisySa

    daisySa

    Joined:
    Dec 29, 2011
    Posts:
    341
    Thanks Ian - yes, it's working now, that was the issue, I realised it just after I posted.

    I actually haven't come across any problems at all yet with Mesh Baker in Unity 5.
     
  32. Razmot

    Razmot

    Joined:
    Apr 27, 2013
    Posts:
    346
    That would be extremely useful for my game too !
     
  33. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Hi Phong,

    thanks for posting the tutorials for baking skinned mesh renderers into prefabs. I will be looking into that as I think it will have a big impact on my projects. I noticed that you used it to bake multiple models into one prefab. In my case, all I want to do is bake all the meshes of a single character into one prefab. My characters tend to have optional objects like shoulder pads, shields, weapons, helmets etc. that are extra draw calls. All I want to do is combine all of those into one mesh so as to have fewer draw calls ... at the moment, I just disable the mesh renderers on those items. So will that be simpler than the example you have? Anything I would do differently?

    Secondly, do you know if this will work if I'm using LOD's and LOD Groups on my models? Would I have to do anything differently to bake skinned mesh characters where the parent object for the character has an LOD Group component with different LOD's of each mesh on it?
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I hope to release a version today that will bleed colors into the padding.
     
  35. Phong

    Phong

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

    The situation you describe should be simpler than the more complicated case of combining multiple characters together. The basic process is the same.

    For LOD's and LOD Groups, you can bake everything in the editor for each LOD level (if you have three LOD levels you will end up with three combined mesh assets). Then use these combined meshes in your LOD.

    Or you could write a script that would bake visible meshes when the LOD switches at runtime. Haven't tried this, it could be complicated.

    Or you could use Mesh Baker LOD
     
  36. digO

    digO

    Joined:
    Mar 20, 2014
    Posts:
    23
    I have Unity Indy, i'm going to be able to use all the resources in this package?
     
  37. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    Does this support creating alpha channels as well with the atlas?

    Also does it support unity 5s new material? I would liek to be able to make atlasses of every texture slot.
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Yes, the package has been tested very thoroughly on the Indy version. Indy users are our main target market because they don't have access to the LOD built into Unity.
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Yes. It relies on Mesh Baker to do the texture baking so if Mesh Baker can do it, then Mesh Baker LOD can do it.
    If you are talking about the "Standard Shader". Yes, this will work.
     
  40. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    How does the work flow go if i want to combine every object in a single room, but then the next room has some of the same objects but also other objects as well. Is there a way to have 2 different combined meshes that both work on the same atlas?
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Yes, the atlas creation component is the MB3_TextureBaker. It generates an atlas texture for every texture in the target shader and also an MB_TextureBakeResult component that stores a material to uvRectangle map. This atlas creation can happen in a separate scene or even project.

    Baking meshes is a completely separate stage. It is handled by an MB3_MeshBaker component. You need to give it an MB_TextureBakeResult. Once this has been done, it can bake together any objects that use materials in that MB_TextureBakeResult. The MB_TextureBakeResult is reusable in any scene.
     
  42. digO

    digO

    Joined:
    Mar 20, 2014
    Posts:
    23
    I just bought this asset and played with the examples and they all worked, but when im trying to add the objects in my own scene to combine i'm getting this message:

    "Added 0 objects. Make sure some or all objects are selected in the hierarchy view. Also check ths 'Only Static Objects', 'Using Material' and 'Using Shader' settings".

    Im not sure what im doing wrong, can u help me? Thanks
     
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Do you have some objects selected in the hierarchy? The filters will be applied to the whatever is selected in the hierarchy and its children.
     
  44. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Hi Phong, did you ever answer the question from this user? I would like to know the answer as well. Thank you

     
  45. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I would suggest baking the atlas ahead of time in a setup scene. See the example scene "SkinnedMeshRendererSetup" to see an example.

    The example scene "SkinnedMeshRenderer" shows how you can add and delete items from a combined skin mesh at runtime using a script. In this a hat, glasses and sword are added and removed from the combined skinned mesh. The transform on each added object becomes a bone so the player can drop the item and walk away if they wish (the item on the floor is still part of the skinned mesh). The Mesh Baker in that scene uses the atlas assets generated in the Setup scene.

    Mesh Renderer objects can be baked into a skinned mesh so that they become part of the skinned mesh. The can also be removed from the skinned mesh when the player drops the shield and the regular MeshRenderer on the shield can be re-enabled.

    If you don't want to use a script you could bake everything together in the editor into a skinned mesh and hide the shield, sword, helmet etc.. by moving them behind the camera. This approach is a bit of a hack though and gets messy if the player drops items and moves a long distance away from them.
     
  46. digO

    digO

    Joined:
    Mar 20, 2014
    Posts:
    23
    Yeah. I got some messages:

    "Object tree12_LOD1(Clone) uses uvs that are outside the range (0,1)this object can only be combined with other objects that use the exact same set of source textures (one image in each atlas) unless fix out of bounds UVs is used"

    "607 objects did not match lightmap filter."

    "Added 0 objects. Make sure some or all objects are selected in the hierarchy view. Also check ths 'Only Static Objects', 'Using Material' and 'Using Shader' settings"

    Im not sure what i need to do :(
     
  47. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    So the dropped item has to be uncombined at runtime in order to be hidden through disabling right? Otherwise maybe it can be pushed through the ground to be hidden, I'm thinking...
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Correct. The API does have a ShowHide method which leaves the vertices for the item in the combined mesh but removes the triangles for that item. However it would be more efficient to remove the item from the combined mesh in order to hide it.
     
  49. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    The safest filter settings (no filter) are show in the attached image. I would start with that and gradually add filter items one at a time until it is adding the meshes you want. It sounds like your "using lightmap field" setting is causing your meshes to be excluded. Try setting it to "don't filter on lightmapping". You might want to run the report to find out which lightmap index your meshes are using.
     

    Attached Files:

  50. digO

    digO

    Joined:
    Mar 20, 2014
    Posts:
    23
    Thanks, i have one more question.
    Im developing a moba game and if the user clicks in the hero or in the monster it get selected and get an outline border.
    b4 i was changing the outlinecolor in the renderer(renderer.material.SetColor("_OutlineColor", outlineColor)), but now i cant do that, do u have any tip for me to do that with this asset?
    Thanks