Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,686
    He might be on a summer vacation. :)
     
    buttmatrix likes this.
  2. StudioEvil

    StudioEvil

    Joined:
    Aug 28, 2013
    Posts:
    66
    Hi!
    I just bought Mesh Baker Pro and testing it out. It works flawlessly, execpt on some models.
    I have a house model made of 1611 vertices, 900 triangles, 8 submeshes.
    I create the atlased material with the option "Consider Mesh UVs2" because of tiling of some of the textures used (roof and wall, for example).
    The i try to bake the model, but i have the error:

    "Could not find a tiled rectangle in the atlas capable of containing the uv and material tiling on mesh casa22"

    How could i investigate on that issue?

    Thanks for your time!

    Chris
     
  3. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Almost two weeks with no response (?)
     
  4. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,686
    Send a PM or email. Maybe @Phong isn't getting notification of new comments on his thread. That happens A LOT.
     
  5. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Hi @buttmatrix, I agree with hopeful. Try and contact him directly. I contacted him via private messages via this forum in the past. I have experienced nothing but fantastic help from this dev. Really good service. If he is not responding I'd expect either he is not aware of your messages or something else is preventing him answering. Nothing serious hopefully. I am not affiliated to him in any way.

    Re your problem though there is a known problem with colors with unity and speedtrees in linear that is a mess at the moment. I think the fix is needed on unity's side. If you look on the speedtree thread it is briefly discussed. They was planning on fixing it in 5.4 but last I heard it had been put back to 5.5. I wouldn't be suprised that this problem is somehow caused by this.

    Can't be more help beyond that.

    doc
     
  6. plmx

    plmx

    Joined:
    Sep 10, 2015
    Posts:
    308
    Hi,

    a couple of questions regarding this tool:

    a) If I have dynamic objects (that move) I can't combine their meshes because they'd move together otherwise. So I need to use the combine-material-without-combining-meshes-feature. Right? (Except for the "skinned renderer" trick, which feels too risky to me).

    b) Combining textures without meshes seems very complicated, as I 1) have to have prefabs, which I currently don't, and 2) I have to create empty prefabs-with-gameobjects for each output separately. Is the batch prefab maker really the fastest way to do this? Can't I just replace all meshes in the original elements somehow?

    c) It seems I can't combine materials if substances are involved. Is this a limitation or am I doing something wrong?

    Thanks!
     
  7. AndresPGC

    AndresPGC

    Joined:
    Mar 20, 2014
    Posts:
    10
    Hello!
    I've been purchased this asset recently on unity assetstore.
    I just have one question about creating atlas at runtime.
    Currently, i've the code:

    Code (CSharp):
    1.  
    2. MB3_MeshBaker meshbaker = bakerM;
    3. MB3_TextureBaker textureBaker = bakerT;
    4. textureBaker.textureBakeResults = ScriptableObject.CreateInstance<MB2_TextureBakeResults>();
    5.  
    6. textureBaker.CreateAtlases();
    7.  
    8. meshbaker.ClearMesh();
    9. meshbaker.textureBakeResults = textureBaker.textureBakeResults;
    10.  
    11. meshbaker.AddDeleteGameObjects(textureBaker.GetObjectsToCombine().ToArray(), null, true);
    12.  
    13. meshbaker.Apply();
    14.  
    This code is just to create atlas, and bake at runtime.
    Everything is working fine, but when i create the atlas my game freezes, and i can't do anything until the process is finished.

    So, i would like to know if i can create the atlas using coroutine or thread-safe, and do the whole process in background.

    Thanks!
     
  8. Phong

    Phong

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

    Thanks for posting this. I will definitely fix these. Sorry about the very slow response. I have been relying on the forum alerts, which apparently are not very reliable.
     
  9. Phong

    Phong

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

    Sorry for the very slow response I have been on vacation for the past few weeks and relaying on the forum alerts. Unfortunately they are not very reliable. I will look into this and report back shortly.

    [EDIT]
    Did you include the 'colors' channel when you baked the meshes? This may explain the color difference. I am still investigating the windzone. There was a script that worked with tree creator shaders but it doesn't seem to work with speed trees.

    [EDIT]
    I did some further investigation. I doesn't look like it is possible to get wind working with combined speedtree meshes. It looks like Unity speedtree meshes are special. They have extra information packed into them that cannot be written through the Mesh API. http://www.speedtree.com/forum/show...ow-to-add-speedtree-wind-to-custom-grass-mesh
     
    Last edited: Aug 24, 2016
    buttmatrix likes this.
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    If the dynamic objects move independently of each other then the skinned mesh renderer trick is the only option. Try it out, it is not really a trick. Its a perfectly valid skinned mesh. If there are a lot of verts then it may not be practacl but for lots of low poly meshes it works like a dream.

    Substance materials cannot be part of an atlas because the textures are procedural. If you export the procedural materials into textures then you can use them in an atlas. You can also combine the meshes if they all use the same material.
     
  11. Masashi-Wada

    Masashi-Wada

    Joined:
    Jul 6, 2010
    Posts:
    89
    Hi phong,

    There is a simple model that has a different material colors and multiple materials. Texture without.
    I want to reduce the model to 1drawcall.
    Does this tool will have feature?
    (For example, bake the material color to vertex color, bake the material color to the new texture)
     
  12. Phong

    Phong

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

    Mesh Baker has an option to combine color with texture when a texture is added to an atlas. This can result in the same texture being added multiple times to the atlas with different tint. Also it only works out of the box with Standard and Diffuse shaders. It is possible to customize it to work with other shaders. At this time there is no option to bake color to vertex color but I have thought of this and would like to add it at some point.
     
  13. NielsTerHeijden

    NielsTerHeijden

    Joined:
    Mar 4, 2014
    Posts:
    20
    Hello Phong,

    I'm trying to combine multiple identical objects into a single Mesh using the MB3_Mesh Baker. This works well but the new combined mesh misses the correct Lightmapping UV's. The option "Generate_new_UV2_Layout" kinda works but the new layout isn't perfect. Is there a way to generate the new lightmapping UV's based on the UV layout of the original objects? The option "Copy_UV2_unchanged" doesn't seem to do this.

    The end effect I see now after a Unity Light bake are hard shadow edges on round(ish) objects that where combined while these effects are not visible when lightbaking the original separate objects.
     
  14. Phong

    Phong

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

    Copy UV2 unchanged won't work because all the objects will end up using the same part of the lightmap. They will all receive exactly the same lighting. Unfortunately the only option is Generate new UV2 Layout.
     
  15. NielsTerHeijden

    NielsTerHeijden

    Joined:
    Mar 4, 2014
    Posts:
    20
    Hi Phong,

    Thanks for the fast reply, Is there a reason why the old UV (scaled to a new shared UV space) won't work? Do you have plans to add it? or would it be possible to program it in my self? I've looked into the code already but I'm missing the overview at the moment to pin point the location where the new UV layout is created. Any help would be much appreciated. Mesh Baker is critical in out project to keep things running smooth. We had a increase from 45 fps to a solid 90 FPS (oculus) thanks to mesh baker. And our artist is dreading the task to manually combine all the separate object.
     
  16. Phong

    Phong

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

    I had not planned on adding it. The place to do it would be the method:

    _copyAndAdjustUV2FromMesh

    In MeshCombinerSimple.cs. This method gets the UV2 channel from the mesh or cache and copies into the correct location of the UV2 array that will be passed to the combined mesh. You could modify the UV2s here. However it will be tricky because you will need to offset and scale the UV2 layout for each source object to a different place in the atlas. The "dgo" object that is passed in contains info about the source object currently being visited. You might be able to use this to somehow calculate an offset.

    Let me know how it goes.
     
  17. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I've tried several different similar assets and have not yet been satisfied with the results of any of them. I have a particular situation, which I am hoping to optimize, but I don't know if this tool or any tool could help. I basically have a series of dungeon prefabs that consist of corridor and room segments. The segments sometimes have up to 5 materials applied to them for the various parts of the segment such as floor, ceiling, walls, trim, etc. Currently, the textures for each material are a separate texture. I understand that because the various parts of a segment are mapping to their own UV coordinates that I couldn't get this reduced down to a single material per segment, but could this tool combine the textures for the various materials and combine them into an Atlas? So, then I would have a dungeon segment with 5 materials, but all the materials would have the same atlased albedo texture? If so, would that even give me a performance benefit? I assume there would still be 5 draw calls, but at least there wouldn't be texture thrashing.

    EDIT: Or am I missing something and it's actually possible to reduce the number of materials as well?
     
    Last edited: Aug 29, 2016
  18. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Hi @magique, sounds like you have a similar problem to me. I bought an asset that is perfect for the game but a crazy amount of materials per item. Phong did provide help but as they where custom shader made materials it is more difficult. If your are not custom shader based you may have a chance.

    The only other option that worked for my characters was I used blender to add only one material per character and vertex painted them. I then used an excellent vertex shader that comes with probuilder(probably not intended for such use). It has slots for normal and diffuse and sliders for metallic and gloss. 1 material per character and 1 draw call per character with both slots occupied although only need the normal map one, but you can add more detail to you models without an increase in verts! Works really well if you get stuck and it's not too much work then can only recommend it.
     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Are the five materials similar (e.g. they are all standard shader with different textures and material property settings)? If so then you should be able to eliminate materials possibly down to one material. If the materials are different (some are transparent etc..) or have extensive tiling, or rely hevily on non-texture material properties. Then you may not be able to do this. If you have five materials after atlasing you will still have five drawcalls so there would be little benefit.
     
  20. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Yes, they are all using Standard Shader with different textures and material settings. I went ahead and bought the package last night on the strength of the tutorial videos and your response is very encouraging. I will be giving this a try as soon as I have the bandwidth.
     
  21. mpgholden

    mpgholden

    Joined:
    Aug 21, 2014
    Posts:
    38
    Hey Phong!

    Absolutely love MeshBaker. Used it on our last two projects and it's saved us a ton of time with optimization. :)
    I upgraded to the latest version, though, and now getting an error when I try to generate new UV2s with the batch prefab baker:

    Code (CSharp):
    1. No GenerateUV2Delegate method was supplied. UV2 cannot be generated.
    2. UnityEngine.Debug:LogError(Object)
    3. DigitalOpus.MB.Core.MB3_MeshCombinerSingle:Apply(Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, GenerateUV2Delegate) (at Assets/AssetStore/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1545)
    4. DigitalOpus.MB.Core.MB3_MeshCombinerSingle:Apply(GenerateUV2Delegate) (at Assets/AssetStore/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1440)
    5. DigitalOpus.MB.Core.MB3_MeshCombiner:Apply() (at Assets/AssetStore/MeshBaker/scripts/core/MB3_MeshCombiner.cs:156)
    6. DigitalOpus.MB.Core.MB3_BakeInPlace:BakeOneMesh(MB3_MeshCombinerSingle, String, GameObject) (at Assets/AssetStore/MeshBaker/scripts/Editor/core/MB3_BakeInPlace.cs:63)
    7. MB3_BatchPrefabBakerEditor:_bakePrefabs() (at Assets/AssetStore/MeshBaker/scripts/Editor/MB3_BatchPrefabBakerEditor.cs:274)
    8. MB3_BatchPrefabBakerEditor:OnInspectorGUI() (at Assets/AssetStore/MeshBaker/scripts/Editor/MB3_BatchPrefabBakerEditor.cs:104)
    9. UnityEditor.DockArea:OnGUI()
    10.  
    Here's what the baker's settings look like:


    Any suggestions?
    (Also, the "create empty result prefabs" button is wonderful)
     
  22. PatientZero

    PatientZero

    Joined:
    Apr 8, 2015
    Posts:
    31
    Hi Phong!

    When I generate multiple bakers via the MB3_Mesh Baker Grouper and then try to bake the meshes I get the following Error:

    Code (CSharp):
    1. Material M_Glas could not be found in the Material Bake Result
    2. UnityEngine.Debug:LogError(Object)
    3. DigitalOpus.MB.Core.MB3_MeshCombinerSingle:_addToCombined(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:934)
    The error itself makes sense since the Material M_Glas isn't a material I want to bake with the baker (its a transparent material, while the baker should only bake opaque materials). The question is why is the baker even trying to use that material.
    If I use a single MultiMeshBaker to bake the meshes everything works fine, so the error needs to happen when multiple bakers are generated via the MB3_Mesh Baker Grouper.
    Could it be a problem that a Renderer with the M_Glas material is parented to an object that should be baked?
    Another thing that might cause the problem is that I am using custom search filters which group the materials based upon their RenderMode (opague, transparent etc) and the texture slots they have assigned (so that renderer with only albedo textures don't get combined with ones that have albedo + normalmap).

    I hope you understand what I mean.
    If you need it I can propbably set up a small project which illustrates the problem.

    Thx in advance.
     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    In file MB3_BakeInPlace.cs change line 67 from:

    Code (CSharp):
    1.  
    2. mom.Apply();
    3.  
    to:

    Code (CSharp):
    1.                 mom.Apply(new MB3_MeshCombiner.GenerateUV2Delegate(MB3_MeshBakerEditorFunctions.UnwrapUV2));
    2.  
     
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I am looking into the problem. I will let you know if I am having trouble reproducing the problem.

    [EDIT] I discovered what the problem was and will push up a new build shortly.
     
    Last edited: Sep 2, 2016
  25. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @Phong I just wanted to say how amazed and impressed I am with Mesh Baker. I actually never expected it to be able to do as much as it does. As my first test I took one of my dungeon segments with 4 materials, including detail textures, and I combined them into a single material. The initial default settings didn't quite work, but with one checkbox turned on, the materials combined perfectly. I only selected a single object so far, but will eventually combine multiple segments for the final scene. But just knowing that the multi-material problem is solved is going to save me so many draw calls that I am certain I'll be able to hit my target frame rate on the Wii U with plenty to spare for extras.

    I have tried 3 other optimization tools and while one of them still has a nice feature that I can use, none of them were able to handle this complicated atlasing problem. Congratulations on a superb product!
     
    hopeful likes this.
  26. NielsTerHeijden

    NielsTerHeijden

    Joined:
    Mar 4, 2014
    Posts:
    20
    Hello Phong,

    I've adjusted your scripts to copy and rescale the existing UV2 coordinates to the new UV2 map. I've added the following lines in the MeshCombinerSimple script (around line 1861)
    Code (CSharp):
    1. else if (lightmapOption == MB2_LightmapOptions.copy_UV2_unchanged)
    2.             {
    3.                 // Copy and rescale the original light maps into the new one.
    4.                 float unroundedNumberOfDGOSqrt = Mathf.Sqrt(totalNumberOfDGO);
    5.  
    6.                 // Round up to the biggest integer number
    7.                 float roundedNumberOfDGOSqrt = Mathf.Ceil(unroundedNumberOfDGOSqrt);
    8.                 float scale = 1 / roundedNumberOfDGOSqrt;
    9.  
    10.                 int DGOIndexX = Mathf.FloorToInt(DGOIndex % roundedNumberOfDGOSqrt);
    11.                 int DGOIndexY = Mathf.FloorToInt(DGOIndex / roundedNumberOfDGOSqrt);
    12.  
    13.                 Vector2[] adjustedNuv2s = new Vector2[nuv2s.Length];
    14.                 for (int index = 0; index < nuv2s.Length; index++)
    15.                 {
    16.                     float newX = nuv2s[index].x * scale + DGOIndexX * scale;
    17.                     float newY = nuv2s[index].y * scale + DGOIndexY * scale;
    18.  
    19.                     // Debug.Log(string.Format("Copying UV for object {0} to new lightmap {1}, {2} -> {3}, {4}", DGOIndex, nuv2s[index].x, nuv2s[index].y, newX, newY));
    20.  
    21.                     adjustedNuv2s[index] = new Vector2(newX, newY);
    22.                 }
    23.  
    24.                 // Debug.Log(string.Format("Copying UV for object {0} to new lightmap {1} | {2}, {3} | {4}", DGOIndex, DGOIndex, DGOIndexX * scale, DGOIndexY, DGOIndexY * scale));
    25.  
    26.                 adjustedNuv2s.CopyTo(uv2s, vertsIdx);
    27.             }
    And added the DGOIndex and totalNumberOfDGO to the function parameters.

    This seems to work well if you ignore the less than efficient layouting and lack of padding.

    Checking the generated UV2's using "UV Preview" shows me the new UV2's as I wanted. But when I lightbake the scene the Combined mesh is completely ignored during the lightbake. When I use "Generate new lightmap UV" option then the mesh isn't ignored by the light bake.

    Could it be that because I abuse the "Copy UV Unchanged" option that some flag is set on the mesh to be ignored during lightbake? Or do you have any other suggestions on why the combined mesh is ignored during lightbake?
     
  27. mpgholden

    mpgholden

    Joined:
    Aug 21, 2014
    Posts:
    38
    Looks like the editor just freezes when I hit bake after making that change (I let it sit for well over an hour, and it usually only takes a minute or two).
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I can't think of any reason why this shouldn't work. What do you see when you select the combined mesh object and look at the lightmaps tab of the lighting window? If I remember you should see the adjusted UV2 layout overlayed on the lightmap. I take it the object is marked lightmap static? Is there anything suspect on the Object tab of the the lighting window for the combined mesh object?
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Are any of the source meshes very large (40k + verts)? If so the generateUV2 may be exceeding the 64k limit for meshes which can cause Unity to freeze.
     
  30. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I just had a very strange result from baking another one of my prefab dungeon segments. This one was a room segment that has 7 materials. 3 of the materials don't have a normal map on the main map, but otherwise all other parameters are the same for all materials and they all use the Standard Shader. The resulting atlas material ended up being set as Legacy Diffuse Shader and no normal map atlas was generated. I am assuming that it had issues with the 3 materials that didn't have a normal map, but why would it make the result into Legacy Diffuse instead of Standard? If I want it to use a normal map atlas do I have to have all materials with a normal map?

    EDIT: I solved the normal map issue by generating maps for the materials that didn't have it. Then after creating a new empty material and re-baking, it properly made the combined Standard Shader material with atlased normal maps.
     
    Last edited: Sep 2, 2016
    hopeful likes this.
  31. NielsTerHeijden

    NielsTerHeijden

    Joined:
    Mar 4, 2014
    Posts:
    20
    I've compared the combined object with my new UV layouting against a combined object with a "create new lightmap uvs" option. And the most obvious difference is that under "Baked Lightmap" The values of Tiling (X, Y) and Offset (X, Y) are set on Infinity and NaN. Are these options I need to set myself?
     
  32. Phong

    Phong

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

    Mesh Baker looks at the shader used by the result material and generates maps based on that. When you use the "Create Empty Assets For Result Material" mesh baker creates a result material and sets the shader to be the same as the shader used by the first object in the list of objects to combine. You can set it to something else after that. If the shader on the result material is correct then Mesh Baker should generate neutral normal maps for any of the missing normal maps.
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Sounds like that would be the problem. I think there is a lightmapScaleOffset field on the renderer. try setting that to new Vector4(1,1,0,0) (I think it is scalex,scaley,offsetx,offsety). Let me know if this works. Looking at MeshCombinerSimple.cs it looks like I am not assigning this field in the renderer.

    [edit] Now that I think about it this may not work. I think that this is the rectangle in the lightmap One would think that it has to be assigned by enlighten. I am not sure when enlighten assigns this.
     
    Last edited: Sep 2, 2016
  34. mpgholden

    mpgholden

    Joined:
    Aug 21, 2014
    Posts:
    38
    Biggest mesh is around 1.5k verts, so don't think I'm running into the 64k limit.
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I am not able to reproduce this bug. I have tried with the code I sent you and I also tried:

    mom.Apply(MB3_MeshBakerEditorFunctions.UnwrapUV2);

    Both work for me. Would it be possible to send me a scene where this doesn't work?
     
  36. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    This tool continues to amaze and impress me. I do have some feature requests though that I think are much needed.

    1. Some sort of pre-check button. This would essentially analyze the mesh bakers and detect if there are any issues that might be encountered during the baking process. Currently, you might be in the middle of an hour long bake on a big scene only to discover that there was a missing mesh on one of your objects and so the entire process aborts and has to be restarted.
    2. The ability to automatically remove null objects from a mesh baker list. For example, I have a huge level that I already baked, but I want to make modifications to the level and then re-bake it. In the process of editing the level I may have removed some objects, which will now be null in the list because they no longer exist. If my list is 6000 items long it's quite difficult to find the null object and remove it manually. I'd like to be able to click a button and have it remove those objects automatically.
    3. It would also be nice to have the mesh bakers ignore offending objects that it's going to abort a bake on and simply report warnings that there were issues with them and they were excluded. The most important thing is to be able to let a bake start and then go away and come back hours later knowing that it will definitely complete the process even if there were a few issues.

    [EDIT]
    4. This might exist, but I couldn't find it. I'd like to be able to select a hierarchy of objects from the scene hierarchy and simply right click and tell it to add a Mesh/Material baker for it.
     
  37. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I'm seeing an issue that is puzzling. I have my max atlas size set to 4096, but the largest size I'm getting in my output is 2048. And the results I'm seeing in my large scene are low-res, blurry textures. I'm wondering if I could be doing something wrong to cause the low-res output that I'm getting.

    [EDIT]
    Actually it's worse than I thought. I'm getting incorrect texturing as well. I will post before and after images for comparison shortly.

    Here are the before and after shots of one area. You can see one of the pillars is wrong, some brick texturing near the left edge of the building, and the ground in the right bottom area. Those are the most prominent issues.

    http://imgur.com/OY6o0Pk
    http://imgur.com/JrXTXwW
     
    Last edited: Sep 3, 2016
  38. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I've decided to re-do the scene differently. The first attempt was just to let Mesh Baker add the entire scene automatically and bake the whole thing, which is not a very good idea. So now I'm taking individual buildings in the town scene and baking them separately into prefabs. I think this will give better results. So far texturing is better, but I still see some degradation in the quality, which I'd like cleaned up if possible.

    But I'm also seeing another issue. I baked a single building into a combined mesh and the resulting CombinedMesh-MultiMeshBaker has a single child object called -mesh. If I look at the Mesh filter, it definitely has something, but there's no name for the mesh. So, I'm wondering why there is no name and how can I find this mesh object in my Assets? Where does mesh baker put these combined mesh assets?
     
  39. Phong

    Phong

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

    You have been busy. Thanks for the feature suggestions. It is always useful to hear from users. Often you are stressing the tool in ways I haven't and it insightful. I will add these ideas to my features list.

    Regarding the incorrect textures. I think you are running into tiling with multiple materials. This is a particularly complex situation. This video explains what is going on and how to fix it:



    Regarding the atlas size. Can you check if the PNG in the filesystem are 2048 or 4096? The size in the inspector is not always correct. Sometimes Unity sets the maximum size in the inspector to be smaller than the files on the file system.

    Regarding the mesh with no name. When you use "bake into scene object" mesh baker creates a mesh instance in the scene, It doesn't exist in the project folder only in this scene. If you want the mesh saved as an asset you should use "bake into prefab". You will need so supply a prefab with an empty game object. The mesh will be saved as an asset in the project folder. These workflows are separate because Mesh Baker can be used at runtime when it is not possible to save assets to the project folder.
     
  40. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Thanks for all the help and information. I've since been able to get 4096 textures, but have no idea what changed.
     
  41. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I'm seeing very different results in the look of a scene after mesh baking and re-baking lightmaps. Here is an example of a before and after. The left image is the original object and the right image is after mesh baking and re-baking lighting. First off, everything becomes brighter for some reason. Second, and not so obvious in this particular shot, is that subtle dark areas become more pronounced and can sometimes appear as ugly black blotches.

    http://imgur.com/zyBQUSq

    For this particular attempt I did not re-size power of 2 textures and I used Generate_new_UV2_layout. Previously I used resizing power of 2 textures and Ignore_UV2. Both result in pretty much the same thing visually.

    [EDIT]
    I figured out the brightness issue. Apparently, the resulting material bake did not set the Albedo color, which was slightly gray in my source materials. Still investigating some other issues though.
     
    Last edited: Sep 5, 2016
  42. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I just got another strange issue. I was combining all the sections of a modular room into a single combined mesh, but th resulting combined material contains a metallic map even though none of the source materials have a metallic map. Also, when trying to bake the mesh it complains about the following:

    Could not find a tiled rectangle in the atlas capable of containing the uv and material tiling on mesh port_Room2x Wall Straight

    It actually reports this same tiling issue on 4 different meshes to be combined. None of the source materials have anything but tiling of 1,1. They all have a detail texture that is tiled, but the tiling is all the same and anyway the detail textures are not part of the atlas anyway. It simply has the detail texture on the atlas material with the correct tiling. Any ideas why this would complain about tiling or why it would create a metallic map?

    [EDIT]
    The only thing I can think of for the tiling issue is that since there are multiple connected wall segments sharing the same material that in the combined mesh it uses tiling across the combined mesh. If that's true then I would need to combine the mesh in parts instead of as a whole. Is this correct?

    [EDIT 2]
    So much for that theory. I tried just combining the wall segments and it has the same issue. I also tried increasing the baked tile size and no success. This seems to be some other issue I don't understand.

    [EDIT 3]
    I feel like I'm talking to myself in here, but here's another question. If I check the "Multiple Combined Materials" will that solve this issue?

    [EDIT 4]
    I solved it. I first put the room in a separate scene and then used the mesh baker tool to list all shaders in scene and generate a mesh baker. This automatically gave me a multi-material setup. Then I baked it, making sure that I didn't have the "Consider Mesh UVs" turned on. This resulted in a single mesh, but with multiple materials. It would be great to have a single material in this case, but that's just not possible obviously. However, having a combined mesh with multiple materials that results in 8 draw calls is certainly better than 19 objects with 4-5 draw calls each. At least I think so. Still testing to see the result as far as performance goes.
     
    Last edited: Sep 5, 2016
    hopeful likes this.
  43. Phong

    Phong

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

    The black blotches are probably due to not enough padding in the Generate_new_UV2_Layout settings. If you look at the Lightmaps Tab of the Lighting Window with the combined mesh selected you should be able to see the problem. If the resolution is fairly low then a texel can span the padding gap between two lightmap islands resulting in strange blotches.
     
  44. Phong

    Phong

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

    The "Could not find a tiled rectangle in the atlas capable of containing the uv" is a bug in the consider UVs feature. I am working on it at the moment and will report back tomorrow.
     
    hopeful likes this.
  45. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    The value in Generate_new_UV2_Layout defaults to a margin of .005, but the docs don't say what this means. How do I make it better if I see black blotches? Should I go smaller or larger? .005 is very small and gives me the impression that small values make a big difference.

    Also, the docs also don't say anything about the "Include Colors" checkbox. I tried using it because my materials are not getting the colors from the source materials, but nothing changed. I have Blend Non-Texture Properties on for all mesh bakers, but all materials end up with an Albedo color of full white. How can I retain the color?
     
    Last edited: Sep 6, 2016
  46. mpgholden

    mpgholden

    Joined:
    Aug 21, 2014
    Posts:
    38
    I can put together a test scene. One note though, it looks like the thing you told me to change is actually line 63, not line 67 in my version of MB3_BakeInPlace (latest from the asset store). Perhaps we're out of sync?
     
  47. NielsTerHeijden

    NielsTerHeijden

    Joined:
    Mar 4, 2014
    Posts:
    20
    Hallo Phong,

    I've succeeded to fix the problem. I had to change the UV2 Vector2's to Vector4's and use the GetUvs() and SetUvs() functions. These changes are all over the MeshCombinerSimple.cs file so I can't post the line changes here. It also requires a bit of improvement probably and it's own enum option instead of Copy_UV2_Unchanged. Do you have a public repository I could copy my suggested changes to?
     
    FuDaNing likes this.
  48. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Thanks. I hope this will improve the results I can achieve. Any ideas on the color issue?
     
  49. Phong

    Phong

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

    The UV2 Layout padding is in UV units. 1.0 is the total width or height of the atlas.

    The "Include colors" means copy vertex colors from the source mesh into the combined mesh. Most meshes and shaders don't use vertex colors so it won't do anything.

    What shader are you using? The Blend non-texture properties depends on having a TextureBlender script that matches your shader. If there isn't a texture blender that matches, then the fallback TextureBlender is used. It looks for a _Color property and if it exists it uses that in the atlas. Of your shader uses a different name for the Color property then you will need to create a modified TextureBlender script for your shader.
     
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Very possible that we are out of synch. Sometimes line breaks can cause different line numbers on different OSs