Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,028
    Hi,
    I just picked this up for a procedural project to try and optimize it for mobile.

    I've created my core game object from prefabs, but when I try and meshbaker.AddDeleteGameObjects(statics.ToArray(), null);
    (where statics is a list of the prefab gameobjects that make up the composite object)

    I get

    "Object Platform3(Clone) does not have a MeshRenderer or a SkinnedMeshRenderer component"

    The prefabs are empty game objects (ie: just transforms) with a number of sub gameobjects that have the meshes and renderers on them.

    You can have this structure can't you?

    ty!
     
  2. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,010
    Is there a way to control the size or how many textures are baked together? I have many buildings that I need to bake together, they use the same shaders and a few different textures. If I bake them all together, the textures become so small that they're blurred in the game.

    Ideally I'd like to be able to select all my objects, and specify a maximum of say 4 textures baked to 1 Meshbaker calculates the rest, is that possible?

    Thanks
     
  3. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    570
    How does MeshBaker treat procedural materials aka substance archives (sbsar files)?
    Will runtime changes to a substance propagate right into the texture atlas MeshBaker creates/updates at runtime?
     
  4. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,279
    I have one question, I would like to combine the textures of 4 models into one atlas, they use the same shader, is there a way to make the required UV changes to the separate prefabs without having to combine them all? The models are not in the hierarchy because they are instantiated at runtime.

    Thanks
     
  5. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,279
    I'm trying to bake a few textures and they are in compressed PVRTC, it may be nice to have some automation going on here.

    Can mesh baker convert them to true color for baking and then later convert the import setting to what they were?
    This would save a lot of time and above all I may forget sometimes to put combined textures back to compressed. Thanks
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    The array that you pass in needs to contain the game objects with meshes attached. You will need to:

    • Instantiate your prefabs
    • Call FindComponentsInChildren<MeshRenderer> or FindComponentsInChildren<SkinnedMeshRendererer> on each game object
    • Combine the collected arrays into one big array or list
    • Pass this into meshbaker.AddDeleteGameObjects(statics.ToArray(), null);
     
    Last edited: Jan 23, 2013
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    There are four things that can cause resizing:
    • Textures are shrunk by the "padding" value so that the resulting atlas is packed more efficiently. I doubt this is your problem. You can turn this off.
    • Unity sometimes sets the size of the generated atlas texture asset size to 1024x1024 even though the .png file is larger. Check to make sure the combined material texture asset size is the same as the generated atlas size.
    • Your generated altas exceeds the maximum size 4096 x 4096 and the texture packer may resize some of the textures.
    • Some of your materials use tiling and MeshBaker is trying to bake the tiling. This is probably what is going on. This is a tough problem. There is a field for setting the maximum tiliing bake size. You could increase it but your atlas may end up being huge. One thing you could try is to have one MeshBaker object (combined mesh) for each texture. If there is only one texture in the combined material atlas then you don't have to bake the tiling and you can tile the combined material instead. The only drawback is that all you meshes will share the same tiling parameters.

    Also look at the output in the console. MeshBaker will tell you when it is resizing and baking tiling. This should help to understand what is going on.

    I am not sure what you mean when you say 4 textures baked to 1 Meshbaker calculates the rest. Could you clarify?
     
    Last edited: Jan 23, 2013
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    To be honest I haven't considered substances until you asked. I am 99.9%certain that changes to the substance would NOT propagate to the atlas. You may be able to copy the dirty substance texture to the correct rectangle in the atlas youself with a script. Not sure what performance would be like for that. Alternatively you may be able to build the combined mesh and assign it a substance material. If you did this, then the same material would apply to the whole mesh.

    Thanks for asking the question this is something I will try to look into.
     
    Last edited: Jan 23, 2013
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Great feature suggestion. Something I will try to add.
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    The following steps should work:
    • Create a new scene
    • Create a new MeshBaker/TextureBaker object
    • Add the raw prefabs. If the meshes are on sub-objects of the prefabs you may need to instantiate them first, then add them. If you instantiate them make sure they are positioned at 0,0,0
    • Create a combined material and use the "bakeMeshesInPlace" option. This will create four new mesh assets in your project with adjusted UVs
    • You can discard your new scene now
    • Replace the meshes in your prefabs with the new generated (adjusted uv) meshes. Replace the material in your prefabs with the combined material.
    • Now, when you instantiate your prefabs, you should end up with separate meshes that share a material (textures combined into an atlas)
     
    Last edited: Jan 23, 2013
  11. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,279
    I was just thinking about particles and I see that in my scenes they create 10 draw calls because they all use different textures, although they are small in size I think it will speed up, If I can somehow to optimise them.

    Is there a way to make an atlas texture for all the particles that are used in the scene?

    That would save a lot of draw calls . I don't mean baking the particle effects into a texture, what I mean is making an atlas for all the textures that are used in the particles materials in a scene. And use this atlas for the particle materials automatically. Without having to set all the texture offsets by hand.
     
    Last edited: Jan 24, 2013
  12. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    This is not something I have looked at, but is a good feature suggestion. I will add it to my list of things to investigate. Meshbaker could build an atlas. The problem the UV coordinates on each particle. I will let you know if I discover an easy way to do this. Won't be able to look at it until next week though.
     
  13. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,279
    Thanks for looking :) I have found one thing which I can't get to work:

    When I open the mesh baker editor, and want to select all Using Shader, I can only select of type material, is this intentional?

    I would assume I could drag a shader from the project window in there and it would look in the hierarchy which objects use this shader.
     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Thanks Lars,

    I will take a look. I think that was a short cut, that I never got back to cleaning up. It actually looks at the shader in the material that is dragged to that field, but its not very intuitive and would be better to have a shader chooser.
     
  15. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,279
    Could you also have a look at the objects to be combined list, sometimes I would like to delete one object from the beginning of the list, and since the only way to delete is to replace or the shrink the array, it's sometimes a little inconvenient to select all objects again and add to selection.
    nothing major just a workflow improvement. :)
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Hi Lars, here are a couple of undocumented Unity features that help with this. These work with all lists of objects in the inspector, not just MeshBaker: I should probably mention these in the help:

    Edit > Delete (Command-Delete on Mac OS X; Delete or Shift-Delete on Windows)

    Remove the selected element in an array. The element will be deleted, the array length will be reduced by one and subsequent elements will each have their indices reduced by one.

    Edit > Duplicate (Command-D on Mac OS X; Ctrl-D on Windows)

    Duplicate the selected element. The element will be duplicated, with the duplicate inserted after the selected element. The array length will be increased by one, and all subsequent elements will have their indices increased by one.

    One other useful feature I learned about recently is the little lock at the top of the inspector. This locks the inspector so that it stays on the current object even when other objects are selected in the scene. This is useful when you want to drag a bunch of objects to fields in the inspector and don't want to accidentally loose the focus on the object you are dragging things to.
     
  17. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,279
    Ok thats helps :)

    Is there any change to up the max atlas to 2048 when iPhone is selected as build setting? I have to wait hours to switch a platform to a new build setting.
    Is this a Unity limitation?
     
  18. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    I believe this is a limitation with the iPhone platform that Unity enforces. The older (iPhone 3 and older) phones can only handle 1024 x 1024. The newer devices can handle 2048x2048. See this thread
     
    Last edited: Jan 28, 2013
  19. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,279
    I just tested it and actually the limit is not 1024 because I just created an 2048 atlas while in iOS build target.
     
  20. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,279
    Would it be possible to use a normal mesh render for the non skinned meshes when using bake in place with skinned mesh option.
    I'm trying to create an atlas of multiple objects. some skinned some static.
     
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    I think this should work. I tried it and it appears to work. The "bakeMeshesInPlace" option ignores the "render type" field and uses the render type from each source object. The generated meshes are essentially duplicates of the originals with UVs adjusted so they can be used with the atlas. Let me know if you have problems.
     
    Last edited: Feb 2, 2013
  22. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,279
    I'm having some difficulty with converting a skinned mesh renderer that has a few animations, the resulting new mesh, when applied back to the model has it's vertices all over the place, and I get an error :
    Number of bind poses doesn't match number of bones in skinned mesh.

    Please let me know what I'm doing wrong :)


     
    Last edited: Feb 2, 2013
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Please let me know what I'm doing wrong :)

    Hi Lars,

    It sounds like the result mesh doesn't have skinning information. What were the baking options for "output" and "renderer"? If the "output" option is set to "bakeIntoPrefab" then the "renderer" should be set to "skinnedMeshRenderer". If the "output" option is set to "bakeInPlace" then the "renderer" shouldn't matter but you could try to set it to "skinnedMeshRenderer" to see if that makes a difference.

    Does the source model have a skinnedMeshRenderer on it when it is baked? If not Mesh Baker won't detect and treat it as a skinned mesh.

    One other thing that might cause this the source mesh being shifted away from the origin when being baked. Check that the source mesh is at zero position, zero rotation, one scale. However this should only affect MeshRenderers, not SkinnedMeshRenderers.
     
  24. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    What's the performance increases on mobile devices? Do you have a comparison on mobile with and without this?

    Thanks,
     
  25. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,279
    Source has skinned mesh and is positioned at 0.0.0 with scale 1, bake settings are :

    bakeInPlace
    skinnedMeshRenderer

    I still get some strange results, I even get this one with only one mesh on the list with a list size of 1

    The list of objects to combine contains nulls.
    UnityEngine.Debug:LogError(Object)
    MB_Utility:doCombinedValidate(MB2_MeshBakerRoot, MB_ObjsToCombineTypes) (at Assets/MeshBaker/scripts/MB_Utility.cs:349)
    MB2_MeshBakerEditorInternal:_bakeMeshesInPlace(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:252)
    MB2_MeshBakerEditorInternal:bake(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:193)
    MB2_MeshBakerEditorInternal:DrawGUI(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:163)
    MB2_MeshBakerEditorInternal:OnInspectorGUI(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:98)
    MB2_MeshBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:28)
    UnityEditor.DockArea:OnGUI()
     
  26. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,279
    I think I found one bug in the mesh baker editor window, when I try to bake the material from there it does nothing, and when I run form the inspector it runs.
     
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    I haven't published stats because be performance increase varies a huge amount based on whats in your scene. It would be easy for me to create a scene with hundreds of separate meshes that would get 1 fps. Combine them and get 60 fps. But you would only see this benefit if you had a similar scene.

    You could try a simple calculation like this:
    • Try to calculate how much of each cycle is dedicated to AI,Physics,Shadows,GUI,Rendering etc... (With most games about 2/3 of the cycle is dedicated to rendering)
    • For the rendering there is an almost linear relationship between the number of drawcalls and performance. If you have 100 meshes in your scene and you reduced them to 50, you would probably see a 40-50% increase in the rendering performance. If you reduced the number of meshes to 5 or less then you could see an 80-90% increase in rendering performance (50% overall).
    Unfortunately it is not quite so simple because there are a number of other performance killers out there. Blob Shadow Projector is brutal for performance. Lights also have an enormous effect. Choice of shaders can have a huge effect too.
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Thanks, will fix this. I have some time to work on MeshBaker this week.
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Hi Lars, check the list of "Objects to be combined". Make sure none of the slots say "None". Also check that "Same As Texture Baker" is checked or that the "Custom list of objects to be combined" does not have any "None" slots either.
     
  30. starvanger

    starvanger

    Joined:
    Oct 4, 2010
    Posts:
    14
    Hi Phong,

    this tool looks very professionel to me, so I want to use it. But I don't want my meshes to be baked together, as I need them to be still moveable.
    Is this possible, too?

    Thanks in Advance

    Starvanger
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Yes. The tool is divided into two components. TextureBaker and MeshBaker, you can choose to just add a texture baker component. The texture baker component generates atlases for each texture property in the source materials and adds these to a combined material. It also generates a special asset called a combined material. You can select it in the project view and in the inspector you will see a list of source materials that were combined and the corresponding UV rectangles in the atlases.

    If you want to use static or dynamic batching mesh baker can "bake in place". This feature creates a combined material and duplicates of your meshes with adjusted UVs that can use the combined material. The meshes are not baked together but are capable of sharing a material so that Unity can batch them.
     
    Last edited: Feb 4, 2013
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    A new version of MeshBaker is available in the Asset Store.

    This version will automatically change the format of textures when baking atlases and restore the previous format when baking is complete. It also includes a number of bug fixes for the bakeInPlace feature.
     
  33. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,028
    Hi,
    Is it possible to get Meshbaker to automatically create more meshes if the vertex limit is approaching the maximum?

    ty!
     
    Last edited: Feb 8, 2013
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    The current version does not do this but I will add this to the list of desired features.
     
  35. sefou

    sefou

    Joined:
    Aug 30, 2011
    Posts:
    287
    Cool . Great improvement.
     
  36. Ali-Nagori

    Ali-Nagori

    Joined:
    Apr 9, 2010
    Posts:
    138
    thanks for the update , i just want you to educate us if there is any possibility to create and manage the material bake result at runtime (not talking about editing but creating it) please note the in my project my models creates the materials and assigns the textures to it at spawning at run time , in other words it's has no materials on it at editor time
     
  37. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Originally I had planned not to support this, but it seems to be a feature that a lot of people are requesting, so I will look into it. I have not tried it recently so I don't know if it currently works. There will be some limitations.

    • Compressed textures cannot be combined so all textures to be combined must be in truecolor format. (format can't be changed at runtime)
    • For performance reasons resizing should be avoided.
    • Baking tiling at runtime should be avoided

    I will make this a priority for the next version.
     
  38. Ali-Nagori

    Ali-Nagori

    Joined:
    Apr 9, 2010
    Posts:
    138
    looking forward to it make it sooner please
     
  39. Kreyg

    Kreyg

    Joined:
    Dec 31, 2012
    Posts:
    37
    LOVE Mesh Baker. However, I have an issue with my textures when I bake. The textures lose quality. I could provide screenshots if needed. I managed to take a fully textured building that was putting out about 1000-1500 draw calls, and with Mesh Baker I was able to reduce it to 100-200 MAX. It's exactly what I need! However, the texture issue presents the biggest problem. Is there a way around losing the texture quality when baked? Thanks!
     
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    There could be a few things that are causing the quality loss.

    1) Click on the combined texture atlas' in the inspector. Look in the preview at the bottom and see what the actual size of the image is. Then look at the "Maximum Image Size" field. Sometimes unity sets the Maximum Image Size to a low number. If you change the "Maximum Image Size" in the inspector to match the actual atlas size it may eliminate your quality loss. Hopefully this is your problem as it is easy to fix.

    2) Another place you may be loosing quality is baked tiling. If you look in the console at the output you should see a warning if MeshBaker is baking tiling. If the baked tiling exceeds "Max Tiling Bake Size" then the baked texture is being shrunk to fit and there could be quality loss. Not much that can be done about this one. You may be able to bake all the meshes that share the tiled texture together and you could tile the combined mesh.

    3) Another place quality can be lost is in the texture packing. Each platform has a maximum texture size. iOS = 2048, PC = 4096. If your combined atlas exceeds this then textures will be shrunk as they are added. You should be able to get an idea from the report in the console if this has happened. Not much can be done other than splitting the combined mesh into several combined meshes or sharing more textures.

    4) MeshBaker has a "Resize Power of Two" textures option. This shrinks textures as they are being added so they have a border of "padding" around them. The reason for this is so power-of-two textures can be packed efficiently into an atlas that is also a power of two. Without this feature packing can be very inefficient (almost 75% wasted space). It is possible although unlikely that this is causing the quality loss. Try baking with and without "Resize Power of Two" to see.

    Hope this helps.
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    A new version of MeshBaker is now available in the AssetStore. It is possible to bake materials (with some limitations) at runtime. It includes an example scene with a script showing how to use it. Baking textures at runtime does incur a serious performance hit. In the tests that I ran on my Android phone it took 1-6 seconds to bake an atlas at runtime.

    For building atlases at runtime it is very important that:
    • textures be in trucolor/RBGA32 format
    • textures have read flag set

    It is also Highly recommended to avoid resizing
    • build padding into textures in editor
    • don't use padding when creating atlases
    • don't use tiled materials
    If you are having problems look at the Debug Log on the device
     
  42. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,033
    I'm getting some errors with Mesh Baker that seem to kill the material generation process. See attached. I've got all meshes and materials assigned properly, so I don't know what to do -- how do I bake textures first?
     

    Attached Files:

  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Looks like one of your meshes has a submesh with zero triangles which is breaking the material creation process. Here is how to fix the problem: In file MeshBaker/scripts/MB_Utility.cs add the line 97 indicated with the stars and arrow below:

    Code (csharp):
    1.  
    2. 90  public static bool hasOutOfBoundsUVs(Mesh m, ref Rect uvBounds, int submeshIndex = -1){
    3. 91      Vector2[] uvs = m.uv;
    4. 91      if (uvs.Length == 0) return false;
    5. 93      float minx,miny,maxx,maxy;
    6. 94      if (submeshIndex > m.subMeshCount) return false;
    7. 95      if (submeshIndex >= 0){
    8. 96          int[] tris = m.GetTriangles(submeshIndex);
    9. 97***>      if (tris.Length == 0) return false;
    10. 98          minx = maxx = uvs[tris[0]].x;
    11. 99          miny = maxy = uvs[tris[0]].y;
    12. 100         for (int idx = 0; idx < tris.Length; idx++){
    13. 101             int i = tris[idx];
    14. 102             if (uvs[i].x < minx) minx = uvs[i].x;
    15. 103             if (uvs[i].x > maxx) maxx = uvs[i].x;
    16. 104             if (uvs[i].y < miny) miny = uvs[i].y;
    17. 105             if (uvs[i].y > maxy) maxy = uvs[i].y;
    18. 106         }          
    19. 107     }
    20.  
    I will submit this fix to the asset store. Please let me know if this fix doesn't work.
     
  44. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,033
    Thanks! That did eliminate one error, but I'm still getting several other errors. I think this model is not perfect -- it's a space probe model from NASA and I suspect made on the quick. The model and prefab (latter has full set of materials) is attached in an export package, in case you want to see if you can get Mesh Baker to work on it, though it may be too quirky for that.

    Errors:

    Failed getting triangles. Submesh index is out of bounds.
    UnityEngine.Mesh:GetTriangles(Int32)
    MB_Utility:hasOutOfBoundsUVs(Mesh, Rect, Int32) (at Assets/MeshBaker/scripts/MB_Utility.cs:96)
    MB_TextureCombiner:__combineTexturesIntoAtlases(ProgressUpdateDelegate, MB_AtlasesAndRects, List`1, List`1, List`1, Int32, Boolean, Boolean, Int32) (at Assets/MeshBaker/scripts/MB_TextureCombiner.cs:223)
    MB_TextureCombiner:_combineTexturesIntoAtlases(ProgressUpdateDelegate, MB_AtlasesAndRects, Material[], List`1, List`1, Int32, List`1, Boolean, Boolean, Int32) (at Assets/MeshBaker/scripts/MB_TextureCombiner.cs:185)
    MB_TextureCombiner:combineTexturesIntoAtlases(ProgressUpdateDelegate, MB_AtlasesAndRects, Material[], List`1, List`1, Int32, List`1, Boolean, Boolean, Int32) (at Assets/MeshBaker/scripts/MB_TextureCombiner.cs:99)
    MB2_TextureBaker:CreateAtlases(ProgressUpdateDelegate) (at Assets/MeshBaker/scripts/MB2_TextureBaker.cs:93)
    MB2_TextureBakerEditorInternal:_bakeTexturesOnly(MB2_TextureBaker) (at Assets/MeshBaker/scripts/Editor/MB2_TextureBakerEditor.cs:204)
    MB2_TextureBakerEditorInternal:bake(MB2_TextureBaker) (at Assets/MeshBaker/scripts/Editor/MB2_TextureBakerEditor.cs:180)
    MB2_TextureBakerEditorInternal:DrawGUI(MB2_TextureBaker) (at Assets/MeshBaker/scripts/Editor/MB2_TextureBakerEditor.cs:167)
    MB_MeshBakerEditorWindow:OnGUI() (at Assets/MeshBaker/scripts/Editor/MB_MeshBakerEditorWindow.cs:69)
    UnityEditor.DockArea:OnGUI()


    Object LEFT_BACK (UnityEngine.GameObject) in the list of objects to combine has overlapping submeshes. This object can only be combined with objects that use the exact same set of textures. There may be other undesirable side affects as well.
    UnityEngine.Debug:LogError(Object)
    MB_Utility:validateSubmeshOverlap(MB2_MeshBakerRoot) (at Assets/MeshBaker/scripts/MB_Utility.cs:435)
    MB_Utility:doCombinedValidate(MB2_MeshBakerRoot, MB_ObjsToCombineTypes) (at Assets/MeshBaker/scripts/MB_Utility.cs:370)
    MB2_MeshBakerEditorInternal:_bakeIntoCombined(MB2_MeshBaker, MB_OutputOptions) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:222)
    MB2_MeshBakerEditorInternal:bake(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:189)
    MB2_MeshBakerEditorInternal:DrawGUI(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:163)
    MB2_MeshBakerEditorInternal:OnInspectorGUI(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:98)
    MB2_MeshBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:28)
    UnityEditor.DockArea:OnGUI()
     

    Attached Files:

  45. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Thanks for sending the model. I am gradually developing a collection of nasty models for testing.

    Fixed the problems. MeshBaker can bake the model now. Submitted a new version to the asset store. Make sure you check "Fix Out-Of-Bounds UVs". The meshes use out of bounds uvs to tile textures. This wreaks havoc with atlases.
     
    Last edited: Feb 20, 2013
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    A new version is available in the asset store that fixes a few bugs with meshes that have empty submeshes and more materials than submeshes.
     
  47. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,033
    Got the update, thanks. The material baking works now, but Mesh Baking fails with two errors -- on the same Sojourner model I posted. Is there anything I can do to get this model to work with Mesh Baker?


    Object LEFT_BACK0 (UnityEngine.GameObject) in the list of objects to combine has overlapping submeshes. This object can only be combined with objects that use the exact same set of textures. There may be other undesirable side affects as well.
    UnityEngine.Debug:LogError(Object)
    MB_Utility:validateSubmeshOverlap(MB2_MeshBakerRoot) (at Assets/MeshBaker/scripts/MB_Utility.cs:456)
    MB_Utility:doCombinedValidate(MB2_MeshBakerRoot, MB_ObjsToCombineTypes) (at Assets/MeshBaker/scripts/MB_Utility.cs:391)
    MB2_MeshBakerEditorInternal:_bakeIntoCombined(MB2_MeshBaker, MB_OutputOptions) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:222)
    MB2_MeshBakerEditorInternal:bake(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:189)
    MB2_MeshBakerEditorInternal:DrawGUI(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:163)
    MB2_MeshBakerEditorInternal:OnInspectorGUI(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:98)
    MB2_MeshBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:28)
    UnityEditor.DockArea:OnGUI()


    System.ArgumentException: An element with the same key already exists in the dictionary.
    at System.Collections.Generic.Dictionary`2[UnityEngine.Material,UnityEngine.Rect].Add (UnityEngine.Material key, Rect value) [0x0007e] in /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404
    at MB2_TextureBakeResults.GetMat2RectMap () [0x00047] in /Users/davidtschaller/Documents/Clients/Golf Solar System/Putting Game/Assets/MeshBaker/scripts/MB2_TextureBakeResults.cs:20
    at MB2_MeshBaker._addToCombined (UnityEngine.GameObject[] goToAdd, UnityEngine.GameObject[] goToDelete, Boolean disableRendererInSource) [0x0006d] in /Users/davidtschaller/Documents/Clients/Golf Solar System/Putting Game/Assets/MeshBaker/scripts/MB2_MeshBaker.cs:337
    at MB2_MeshBaker.AddDeleteGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject[] deleteGOs, Boolean disableRendererInSource, Boolean fixOutOfBoundUVs) [0x00106] in /Users/davidtschaller/Documents/Clients/Golf Solar System/Putting Game/Assets/MeshBaker/scripts/MB2_MeshBaker.cs:1076
    at MB2_MeshBakerEditorInternal._bakeIntoCombined (.MB2_MeshBaker mom, MB_OutputOptions prefabOrSceneObject) [0x000ba] in /Users/davidtschaller/Documents/Clients/Golf Solar System/Putting Game/Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:229
    at MB2_MeshBakerEditorInternal.bake (.MB2_MeshBaker mom) [0x0000b] in /Users/davidtschaller/Documents/Clients/Golf Solar System/Putting Game/Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:189
    UnityEngine.Debug:LogError(Object)
    MB2_MeshBakerEditorInternal:bake(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:196)
    MB2_MeshBakerEditorInternal:DrawGUI(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:163)
    MB2_MeshBakerEditorInternal:OnInspectorGUI(MB2_MeshBaker) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:98)
    MB2_MeshBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:28)
    UnityEditor.DockArea:OnGUI()
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    It worked for me using a single combined material (not using multi-materials).

    I think that is the only way you will be able to get this model to work. The problem is that some of the faces are shared across multiple submeshes and have different materials applied to the same triangle. That's what the first error is about. This is tough for MeshBaker to deal with because the triangle's vertices each have only one UV value, but will need to map to multiple UV points in the resulting atlas.

    I noticed that the only objects with submeshes are the wheels and the antenae. You could try to leave these out of the combined mesh or bake them in. Meshbaker will combine all the submeshes in this case.
     
  49. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,033
    Ah, that worked! I didn't even think about the single/multiple materials, and it's perfectly fine for it to use a single combined material. So unchecking that box eliminates the errors, and now I have a model with a single drawcall. Beautiful!
     
  50. Ecocide

    Ecocide

    Joined:
    Aug 4, 2011
    Posts:
    292
    This tool seems to be extremely useful! Please correct me if I'm wrong:
    I can make a building in SketchUp (worst case), put some roof and brick texture on it (using tiling!!!) and MeshBaker changes the UVs so I get a new material with both, roof and brick texture combined on one map and it still looks the same ??