Search Unity

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:
    26
    Thank you! That did the trick!
    Though it takes me many hours just to guess a proper value for max verts. Feature request: why not implement algorithm, which will bake in loop, decreasing max until it finds a good cap?
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    I am certain that the problem of atlases not being created for the green channel is caused by the custom shader property names not being correct. Try to find the shader file in the project. With that selected, all the shader property names should be shown in the inspector. These are probably different from the names in the material inspector.

    Regarding the error message. I don't see where that message can come from unless you clicked bake on an empty TextureBaker or MeshBaker after successfully baking. The previous log message appears to indicate that the mesh was saved correctly. I tested the prefab bake here an it worked for me. Are you able to reproduce the problem?
     
  3. N00MKRAD

    N00MKRAD

    Joined:
    Dec 31, 2013
    Posts:
    210
    Hey there, I have a problem.

    I can't add any meshes to my Texture Baker because all of them have out-of-bounds UVs.

    I know there's an option to fix that, but that option is after adding them to a baker, and I get the error before adding them.

    Any way around that?
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Are you using the Mesh Baker Window to add them? There should be a check box (in the Mesh Baker Window) 'include meshes with out of bounds UVs'. If you check this you will be able to add them.
     
  5. christophercimbaro

    christophercimbaro

    Joined:
    Aug 30, 2017
    Posts:
    12
    Hey,

    It works when I set all parameters of the custom shader. Thanks for the feedback.
     
  6. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    26
    I unchecked "Consider Mesh UVs", now material bake is successful with "All objects use the same textures in this set of atlases. Original textures will be reused instead of creating atlases." message in the log. But the problem, that I lose color information now. Imagine you have two materials for vessels - veins and arteries with different color (_Color is the only shader property). Combined material has only one color, thus all combined meshes are drawn with the same color.
     
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    You, could try "Blend Non-Texture Properties". It looks for non-texture properties such as _Color and creates a small texture with that color. The textures are combined into an atlas.
     
  8. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    26
    Won't work, because shader does not use texture. So when I try to bake combined material with "blend properties", MB does not create atlas. And even if it will be able to create, I have to make a new shader anyway, in order to use texture sampler :)
     
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    I can't think of any way to bake this without modifying the shader. I will try to reproduce this case to see that Mesh Baker can handle this in the future.
     
  10. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    26
    When using Agglomerative cluster type, it is very common situation, when one mesh is not included in any generated baker. So we have this mesh in the list of objects in texture baker, but after clicking "Generate Mesh Bakers", it is not included in either. So I have to manually add it to some of the existing baker, or create another "cluster" with a single mesh. What is very annoying. I tried to turn off and back on "Include cells with only one mesh" option and appears it does not have effect in Agglomerative mode, which is awesome.
     
  11. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    OK I will take a look
     
  12. orkungo

    orkungo

    Joined:
    May 3, 2014
    Posts:
    62
    Hi,

    I also sent an email to contact.digitalopus@gmail.com but after found out that there is a Unity forum thread for support, therefore writing here as well.

    I am trying to use Mesh Baker for my current situation. Briefly, I will use the Mesh Baker in order to combine about hundred static game object meshes to a one and bake lightmap to get a single .exr file at Unity 2017.

    How I do is as following:

    - Creating a new Texture Baker from Component-Other
    - Click on "Open Tools For Adding Objects" under "Objects To Be Combined"
    - Filter all static Gameobjects at the scene
    - Click on "Generate Baker"
    -At the created baker click on "Bake Materials Into Combined Material"

    My question is that, is it possible to use generated mesh to get a single lightmap from Unity 2017 ? It is much more different then the previous Lighting component therefore I really need to get a single lightmap for my multiple static gameobjects on the scene and I thought it would be a appropriate decision to use Mesh Baker.

    Also adding the Screenshots from my workflow.
     

    Attached Files:

    Last edited: Sep 22, 2017
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Yes, if you want to lightmap the combined mesh you should set the UV2 settings to either:

    • copy UV2 to separate rects
    • generate new UV2 layout
    After that lightmapping should work normally for the combined mesh.

    Note that another way to get a single lightmap is to create a "lightmap parameters" asset. Set the "System Tag" to a unique number. Then assign this new lightmap parameters to all of your static objects in the MeshRenderer inspector.
     
  14. ashc91

    ashc91

    Joined:
    Aug 27, 2016
    Posts:
    41
    Stuck with meshbaker issue. Please help .

    I have in my scene 10 boxes which on mouse click will get selected and will come close to the camera and open. After that, the box gets disabled and disappers from scene. But after using meshbaker even after the box is disabled it remains in the scene! .Even when i disable it in inspector in runtime ,same thing ...no matter what the box remains in scene!

    Steps I followed using meshbaker
    I have used meshbaker and using 'open tool for adding objects' added all based on material and since the boxes are moving objects I have used skinned mesh.

    Please tell me what I should do ,as I am stuck with this issue for the last 2 days .

    Thanks in advance for the replies

    issue.jpg
     
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    It looks like you are disabling the skeleton. The skinned mesh renderer will be a separate game object in the scene. Look in the MB3_MeshBaker inspector for the field "result scene object". That is what you want to disable.
     
    ashc91 likes this.
  16. ashc91

    ashc91

    Joined:
    Aug 27, 2016
    Posts:
    41
    Hi,
    thanks for the reply , but I tried to do as you suggested, but I cant find any "result scene object" under mb3_meshbaker in inspector. Kindly check the attached pic.

    You said that skinned mesh renderer will be a separate game object in scene. Will it be one gameobject ?. If so how will I be able to specify which box to disable with just one combined skinned mesh.

    I am a novice in using meshbaker ,just recently purchased it .so sorry if what I am saying makes no sense.
     

    Attached Files:

  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Sorry, I ment to say "Combined Mesh Object"
    The 'Combined Mesh Object' is a parent game object. It will have one or more child objects with Renderer components on them. Usually there is only one Renderer. However if using a MultiMeshBaker you may end up with many Renderers under the 'Combined Mesh Object'.
     
    ashc91 likes this.
  18. ashc91

    ashc91

    Joined:
    Aug 27, 2016
    Posts:
    41
    hi,

    None of the things you have suggested works! Kindly read through my issue completely.

    I saw 'combined mesh object' ,and I can disable it to hide all 10 boxes like what you said .But , that is not what I wanted to do in the first place.

    My issue is that my game was working perfectly fine ,and upon clicking any box it will fly in and disappear (when the box gets disabled via script ). But after using meshbaker , this process of box disappearing stopped working and it remains in the scene forever ! even when its disabled via script.I only want the box that has been clicked to disappear not all the boxes.

    I want to know , why exactly this is happening and how to resolve this issue.

    I tried multimeshbaker but under 'combined-meshmaker-mesh' there is no child objects which I can disable individually for each box.
     

    Attached Files:

  19. ashc91

    ashc91

    Joined:
    Aug 27, 2016
    Posts:
    41
    hi
    Please help me with one more problem.

    After using meshbaker ,I could reduce my setpass calls from 435 to just 70 . So that is fantastic result. But, my tris and verts have gone up from 69 and 97 respectively to 150 and 190 , almost 3 times !.

    Because of this increase in tris and verts my game remains very laggy on mobile even though setpass calls is low.

    How do I resolve this problem?

    Thank you
     
  20. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Apologies, I didn't understand what you were trying to do.

    The individual boxes will not disappear because they have been combined into a single combined mesh. After baking there is only one mesh so it can only be completely disabled or completely enabled.

    If you want to show and hide individual objects in the combined skinned mesh you have three choices.

    • Move the boxes off camera (behind the camera is a good place
    • Use the Mesh Baker show/hide API to hide the boxes
    • Use the Mesh Baker add/delete API to remove the box from the combined mesh
     
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    If meshes that are not visible at the same time are combined then performance can actually decrease because the graphics hardware is trying to render extra off screen geometry that would normally be culled. A good general strategy for rendering optimization is:
    • Use as few materials as possible. The batch prefab baker is good for this
    • Make as much geometry as possible static.
    • Combine objects that are close together, such as a pile of rocks or boxes
    A couple of other thoughts on your situation:

    1) Have you checked the profiler to make sure that rendering is the cause of the performance lag?
    2) Have you checked if you are CPU bound or GPU bound? If you are GPU bound then combining materials and meshes won't help much. You will need to consider fewer lights, faster shaders, turning off shadows, using lightmaps, reduce overdraw.
     
  22. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    26
    Looks like it has been fixed in today's release. Thank you!
     
  23. ashc91

    ashc91

    Joined:
    Aug 27, 2016
    Posts:
    41
    Ok


    Ok thanks a lot for the reply. I'll try everything that you have suggested. Have a good day :)
     
  24. jrhee

    jrhee

    Joined:
    Dec 5, 2013
    Posts:
    74
    Just wondering: Are there any plans to enable merging duplicate vertices in Mesh Baker? I'm experimenting with modular assets that align at the seams, and it would be great if vertices at the same position were welded together on bake. I'm a bit torn between doing level layouts in Blender and exporting a single mesh, or doing levels in Unity and baking them down, and this is one factors I'm considering to help decide.

    If it's not on the roadmap, I'd be happy to take a stab at it on my own, but just wanted to see if there was any reason why it wouldn't be possible to do.
     
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    I had not planned on adding it in the near future. There is some code that does it.

    here: http://answers.unity3d.com/questions/228841/dynamically-combine-verticies-that-share-the-same.html

    Here is a method from the Bullet Unity project that welds vertices. It is an extension method so after you have added it to your project somewhere you should be able to call myMesh.AutoWeldVertices(threshold). This code doesn't take into account normals and UVs.

    Code (CSharp):
    1.        public static void AutoWeldVertices(this Mesh mesh, float threshold = 0.001f)
    2.         {
    3.             Vector3[] verts = mesh.vertices;
    4.  
    5.             // Build new vertex buffer and remove "duplicate" verticies
    6.             // that are within the given threshold.
    7.             List<Vector3> newVerts = new List<Vector3>();
    8.             List<Vector2> newUVs = new List<Vector2>();
    9.  
    10.             int k = 0;
    11.  
    12.             foreach (Vector3 vert in verts)
    13.             {
    14.                 // Has vertex already been added to newVerts list?
    15.                 foreach (Vector3 newVert in newVerts)
    16.                     if (Vector3.Distance(newVert, vert) <= threshold)
    17.                         goto skipToNext;
    18.  
    19.                 // Accept new vertex!
    20.                 newVerts.Add(vert);
    21.                 if (mesh.uv.Length > 0)  //some meshes dont have
    22.                     newUVs.Add(mesh.uv[k]);
    23.  
    24.                 skipToNext:;
    25.                 ++k;
    26.             }
    27.  
    28.             // Rebuild triangles using new verticies
    29.             int[] tris = mesh.triangles;
    30.             for (int i = 0; i < tris.Length; ++i)
    31.             {
    32.                 // Find new vertex point from buffer
    33.                 for (int j = 0; j < newVerts.Count; ++j)
    34.                 {
    35.                     if (Vector3.Distance(newVerts[j], verts[tris[i]]) <= threshold)
    36.                     {
    37.                         tris[i] = j;
    38.                         break;
    39.                     }
    40.                 }
    41.             }
    42.  
    43.             mesh.triangles = tris;
    44.             mesh.vertices = newVerts.ToArray();
    45.             mesh.uv = newUVs.ToArray();
    46.         }
     
  26. local306

    local306

    Joined:
    Feb 28, 2016
    Posts:
    155
    Hello!

    Firstly this asset is great and has made some short work of an ugly mesh I am currently working with for a project.

    One thing I am having troubles with is that the value I set the max vert count for a multi mesh bake is not being respected. I saw someone else earlier in the thread was having the same issue. I tried what was recommended to them but I am not seeing any success. I even went into the code and hard coded the value to some value less than the Unity max and the output meshes are still ~65,000.

    Any help would be greatly appreciated!
     
  27. local306

    local306

    Joined:
    Feb 28, 2016
    Posts:
    155
    Er, slightly disregard my previous post.

    Not sure if it's a bug, but when I was experiencing this problem it was trying to bake down already mesh baked meshes in one combined scene.

    After going back to the original and changing the values, it worked out and respected the limit I set.
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    The inspector won't let you change the values for maxVerts if there are already objects baked into the combined mesh. If you use 'clear buffers after bake' it should work. I will try to improve this so that it is more obvious what is happening.
     
    local306 likes this.
  29. YOAJ1

    YOAJ1

    Joined:
    Jul 17, 2014
    Posts:
    26
    Running "Bone weight copier" will give the following error

    Bone influences do not match bones.
    UnityEditor.PrefabUtility:ReplacePrefab(GameObject, Object, ReplacePrefabOptions)
    MB3_BoneWeightCopierEditor:CopyBoneWeightsFromSeamMeshToOtherMeshes(MB3_BoneWeightCopier) (at Assets/MeshBaker/scripts/Editor/MB3_BoneWeightCopierEditor.cs:167)
    MB3_BoneWeightCopierEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB3_BoneWeightCopierEditor.cs:90)
    UnityEditor.DockArea:OnGUI()
     
  30. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    26
    Just have upgraded project to Unity 2017 and found very weird bug. After baking combined material, I get an atlas of bad (actually terrible) quality. It looks like it was assembled into ~4x lower resolution and then just stretched.
     
    Last edited: Oct 4, 2017
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Thanks for reporting this. I am at Austin Unite this week so I won't be able to look into this until the weekend. I will take a look then.
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Are you using the latest version of Mesh Baker. Is this an atlas that worked in the previous version? Can you post a picture of your inspector settings and the atlas?
     
  33. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    26
    Sure, I'm using the latest version. And I've double checked - baked atlas twice in 2017 with the same (bad) result, then downgraded back to the latest 5.6.x, baked again, and got a perfect quality as it should be.
     

    Attached Files:

  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Would it be possible to send the me a simple scene with the baker, objects and materials?
     
  35. ashc91

    ashc91

    Joined:
    Aug 27, 2016
    Posts:
    41
    hi again ,

    I have used meshbaker to combine the roof and floor texture in my game , and it appears fine on unity player. But when I test it on my phone , the roof area has become white, as seen in the attached picture.

    1st image ---showing the white washed roof.
    2nd image --- how it appears normally in unity and in android emulator.

    Why is this happening ?
    22222.png 1111.jpg
     
  36. ashc91

    ashc91

    Joined:
    Aug 27, 2016
    Posts:
    41

    I think I figured it out , even though I dont know why it happens.

    When i changed all shaders to mobile shaders , problem resolved. :)
     
  37. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Could be a couple of things:

    1) Check the shader that the combined material uses. Make sure this is the same as your source shaders
    2) Check the channels on the Mesh Baker component. Make sure the combined mesh has the same channels as the source meshes.
    3) If the scene is using lightmapping you will nee
     
  38. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    Hi,

    Ive got a question; If my 3D assets are on sperate trexture atlases at the moment, will Mesh Baker be able to create a new common texture atlas in addition to combing their meshes? Or will the atlases allready in place mess things up?

    Thank you.
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    The atlases that are already in place will not mess things up. I would recommend using the 'consider UVs feature'. It will add only the parts of the source atlases that are being used by your meshes to the combined material atlas.
     
  40. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    Thank you for answering my answer and sharing this excelent tip!

    Fred.
     
  41. vladik865

    vladik865

    Joined:
    Feb 22, 2014
    Posts:
    1
    Please update the free version of a plug-in for Unity 2017, there during creation of atlases - "TextureFormat is invalid!"
     
  42. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    26
    Hello, sorry for delay, was too busy. Here is link to the project with sample scene. Combined material was baked and looks corrupted/pixelated. The same project in 5.6 bakes fine.

    Important note: Bug occurs only for Android target, and only if set texture compression override (in build setting) to ASTC
     
    Last edited: Oct 10, 2017
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Will release an update soon.
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Thanks for the build. Looking into the issue.

    [Update] I submitted a new version to the asset store last night which should fix this issue. It should go live over the next few days.
     
    Last edited: Oct 10, 2017
    Sam0waR likes this.
  45. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    306
    Hello, I have a problem with Skinned Mesh

    I am trying to combine the materials of a SkinnedMesh which has a few bones and then save it into a prefab.

    I followed the provided instructions which are very confusing, I also tried following the intructions a video posted by the author. Whatever I do, the resulting SkinnedMesh loses the relation to its bones.

    Please watch this video I made so you can let me know what Im doing wrong.


    Any help is greatly appreciated
     
  46. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    26
    Hi, I've just checked a new MB version and it is still failing to bake correct atlas.
     
  47. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Hi Jorge,

    I noticed in your video when baking that there was an error about the tangents. Check that the generated mesh has vertices. If you select the mesh in the project it should report the number of vertices in the inspector. I suspect your source mesh does not have tangents so you should be able to eliminate this error by unchecking 'tangents' in the inspector.

    After you press the bake button, do the bones work at that moment if you move them around?

    The only thing I saw that looked odd to me was when you switched from 'bake into prefab' to 'bake into scene object'. This step should be necessary. At that point the instantiated prefab in the scene should have the baked mesh. You should be able to add the bones at that point.

    If you are still having issues after these suggestions, feel free to sent me the model.
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Hmmm, I read your post more carefully and noticed that you said that you overrode the compression in the build settings. I had assumed that you were talking about setting the platform override for each texture (which has been fixed). Will look into fixing this issue.

    [Update] I think I have a fix for this. Will get this into the next release.
     
    Last edited: Oct 15, 2017
  49. Sam0waR

    Sam0waR

    Joined:
    Nov 30, 2015
    Posts:
    26
    One more question on texture packer. Assume I have a lot of textures, which could not be placed on target atlas size. I was expecting, that MeshBaker packer in order to fit all textures onto the atlas will scale source textures proportionally to their size (after applying import settings). But found something really weird. For example, if texture import setting is 512x512 - texture goes to atlas as is (full size 512x512). But all other textures with 4k, 2k or 1k size go to atlas scaled to 1k regardless of their import settings. And it is wrong, because I'm losing details on high-res textures.
     
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    There are a few things that can affect texture size in the atlas.

    1) If there are multiple maps on a material ([bump 1024], [maintex 512], etc...). Then the maintex will be scaled up to the size of the largest map. This is necessary for the rectangles in the atlases to be the correct size.

    2) The setting in the inspector for the current platform (up to the maximum texture size).

    There should be a report in the console that describes how the textures are being sized. Does this make sense for your situation?