Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. LunaTrap

    LunaTrap

    Joined:
    Apr 10, 2015
    Posts:
    120
    Nevermind, here is the solution, Set to generate new UV2

     
    hopeful likes this.
  2. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    @LunaTrap

    You may want to use "Lightmap UV" in Meshbaker and select "Generate new Lightmap UVs" (I can't remember the exact name). That solved the problem for me.

    Edit: LOL...you posted right before I did!
     
  3. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    I am getting an array index out of range error when combining lots of objects at runtime.

    This code generates the error:
    Code (CSharp):
    1. combineObjects = cbTexturebakerOverhead.GetObjectsToCombine();
    2. GameObject[] combineObjectsArray = combineObjects.ToArray();
    3. cbMeshbakerOverhead.AddDeleteGameObjects(combineObjectsArray, null, true);
    4. cbMeshbakerOverhead.Apply();
    Error:
    Any idea how to fix this?

    Edit: even if I add only two objects via a drag and drop array on the Inspector (not using GetObjectsToCombine(), it still generates the error.
     
    Last edited: Jul 15, 2017
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    You will need to bake the lightmap using the combined mesh. When you generate the combined mesh, you need to set the 'lightmapping uvs' to either 'Copy UV2 to separate rects' or 'generate new UV2 layout'.
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084

    Hi LunaTrap,

    Are the source textures very small? This can happen when textures that are very small are combined into an atlas. The UV sampling can easily pick up neighboring colors when the pixels are interpolated. There are a few things that can help.

    1) More padding
    2) Make the source textures larger and a power of two. I would recommend at least 16x16 or 32x32. This will help the mipmaps behave better.
    2) Set the atlas texture filter mode to "point". This may not work well if the textures vary in color.

    Let me know if these do not fix the problem.
     
  6. Polemus

    Polemus

    Joined:
    Nov 14, 2016
    Posts:
    28
    I would like to know if meshbaker will help in the following scenario:

    I have a shipyard, one of the sections of the shipyard have containers sitting around, the containers are all instantiated runtime and positions/stacking of containers are randomly generated, I also randomly select one of the 13 container variation prefabs i have. Is there any way i can combine the result of the generated "container yard" for both mesh and materials using meshbaker?

    I had a look at the demo scenes, but i cant seem to see how dynamically added objects are combined.
     
  7. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    I'm getting distinct lines at the seams between gameobjects of my road.

    I've been changing the Atlas Padding in an effort to remove them (I've tried 0, 1, 2, 6, 8 10 & 20).
    Is this the correct approach and the padding number is just not correct?

    If not, what is the correct solution to eliminate the lines at the seams? Thanks!


    BTW, I'm already using "Generate Lightmap UV's."
     

    Attached Files:

    Last edited: Jul 18, 2017
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    Yes, Mesh Baker can be used at runtime. There are a few example scenes included that show both runtime baking of meshes and textures. You can examine these in the free version. I would only recommend combining textures at runtime in scene setup, not during gameplay. Combining meshes should not be a problem. You can prepare the prefabs in adavance so they already share a material.
     
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    Are you using the 'consider UVs' feature? The problem could be UVs outside the range 0..1. Are there any warnings or messages about these meshes in the inspector? Can you post the inspector settings for the TextureBaker
     
  10. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Yes, I'm using the 'Consider UV' feature. I'll check for warnings now and post inspector settings.
     
  11. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Ok...it looks like there are warnings about the UV's.

    What can be done about it?
     

    Attached Files:

  12. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    I am getting an array index out of range error when combining lots of objects at runtime.

    This code generates the error:
    Code (CSharp):
    1. combineObjects = cbTexturebakerOverhead.GetObjectsToCombine();
    2. GameObject[] combineObjectsArray = combineObjects.ToArray();
    3. cbMeshbakerOverhead.AddDeleteGameObjects(combineObjectsArray, null, true);
    4. cbMeshbakerOverhead.Apply();
    Error:
    Any idea how to fix this?

    Edit: even if I add only two objects via a drag and drop array on the Inspector (not using GetObjectsToCombine(), it still generates the error.
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    Hi, it looks from the inspector that the road and sidewalk both use out of bounds UVs and it appears that there are multiple materials. In this case it is often necessary to use multiple materials. This video should explain what is going on.

     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    Hi Elecman, are you using the latest version (Free Version or Full Version)? This is an odd error. Is it a fresh baker or have you added or deleted any objects previously. If so then "Clear buffers after bake" may be the issue. Are there any previous warnings? Are the meshes readable (there is a setting in the importer for that)?
     
  15. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    It is the full version (3.21). It is not a fresh baker. First I added a texture baker with a mesh baker, baked it and added some code so I could change the transform of objects at runtime. This worked fine, but I found out that if I copy my project and place it onto another machine, the runtime changes wouldn't work until re-baking the initial meshes. So I decided to bake the meshes at runtime instead. I deleted all previously baked meshes (combined mesh object and Mesh on mesh baker script), and tried to bake it at runtime. This is when I got the index out of range.

    I tried with and without "clear buffers after bake", but it makes no difference. There are no previous warnings. All meshes have read/write enabled.
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    Hi Elecman,

    I am not able to reproduce the error.

    I would suggest calling cbMeshbakerOverhead.ClearBuffers(); before AddDeleteGameObjects(); Please let me know whether or not this works. This shouldn't be necessary but there could be some bad data in the baker.

    If it does not work, would it be possible for you to send me a unity package with a scene reproducing the error? My support email is contact.digitalopus@gmail.com.
     
  17. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    Thanks, that did the trick. But it should be
    Code (CSharp):
    1. cbMeshbakerOverhead.meshCombiner.ClearBuffers();
    not
    Code (CSharp):
    1. cbMeshbakerOverhead.ClearBuffers();
     
    Last edited: Jul 21, 2017
  18. lzardo2012

    lzardo2012

    Joined:
    Apr 11, 2013
    Posts:
    80
    Hi...

    I just wanted to know if mesh Baker is working in Unity 2017?

    I can´t bake anything anymore.
     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    Thanks for the heads up. The texture compression is handled completely differently in Unity2017 and it is possible to read pixels from compressed textures now. You should be able to fix the problem by removing line: 1165 and 1166 in file MB3_TextureCombiner. I will push a version to the asset store with this fix soon.
     
  20. lzardo2012

    lzardo2012

    Joined:
    Apr 11, 2013
    Posts:
    80
    Thanks for the quick reply!
     
  21. Weblox

    Weblox

    Joined:
    Apr 11, 2016
    Posts:
    277
    @Phong

    Hi, I just watched some of the nice Tutorial videos and I am slowly getting my head around the workflow.

    - Is it possible to output "bake into prefab" with renderer "skinned mesh" ?
    - Is it possible to have the Texture Baker delete the original Textures from the Project after baking the Texture Atlas ?
     
  22. kuight

    kuight

    Joined:
    Dec 8, 2014
    Posts:
    7

    Same here!

    Setting texture format for veh_fire_texture0 (UnityEngine.Texture2D) to ARGB32 setting platform override format for iPhone to AutomaticTruecolor
    UnityEngine.Debug:Log(Object)
    DigitalOpus.MB.Core.MB3_EditorMethods:SetTextureFormat(Texture2D, TextureFormatInfo, Boolean, Boolean)
    DigitalOpus.MB.Core.MB3_EditorMethods:AddTextureFormat(Texture2D, Boolean)
    DigitalOpus.MB.Core.<__Step2_CalculateIdealSizesForTexturesInAtlasAndPadding>d__69:MoveNext()
    DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32)
    DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32)
    DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32)
    DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32)
    DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32)
    MB3_TextureBaker:CreateAtlases(ProgressUpdateDelegate, Boolean, MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/MB3_TextureBaker.cs:359)
    DigitalOpus.MB.Core.MB3_TextureBakerEditorInternal:DrawGUI(SerializedObject, MB3_TextureBaker, Type) (at Assets/MeshBaker/scripts/Editor/MB3_TextureBakerEditorInternal.cs:332)
    MB3_TextureBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB3_TextureBakerEditor.cs:33)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    TextureFormat is invalid!
    UnityEditor.AssetDatabase:ImportAsset(String, ImportAssetOptions)
    DigitalOpus.MB.Core.MB3_EditorMethods:SetTextureFormat(Texture2D, TextureFormatInfo, Boolean, Boolean)
    DigitalOpus.MB.Core.MB3_EditorMethods:AddTextureFormat(Texture2D, Boolean)
    DigitalOpus.MB.Core.<__Step2_CalculateIdealSizesForTexturesInAtlasAndPadding>d__69:MoveNext()
    DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32)
    DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32)
    DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32)
    DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32)
    DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32)
    MB3_TextureBaker:CreateAtlases(ProgressUpdateDelegate, Boolean, MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/MB3_TextureBaker.cs:359)
    DigitalOpus.MB.Core.MB3_TextureBakerEditorInternal:DrawGUI(SerializedObject, MB3_TextureBaker, Type) (at Assets/MeshBaker/scripts/Editor/MB3_TextureBakerEditorInternal.cs:332)
    MB3_TextureBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB3_TextureBakerEditor.cs:33)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  23. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    This fixes errors but the normal map is baked in the wrong base color.

    rear CB lowest-mat-_BumpMap-atlas1.png
     
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    Yes, this works for prefabs but an extra step is necessary. The procedure is described in the FAQ. The bones and animator from the source game objects are used so it is necessary to include these in the combined prefab. Mesh Baker does not automate this part because there are many possible configurations.
    You would need to do this manually or use the API to do this. Mesh Baker is designed to be non-destructive so that you can re-bake if something changes.
     
    Weblox likes this.
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    Looking into the issue.
     
  26. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    On another note, it would be nice if there is a checkbox for each map (albedo, normal, roughness, etc.) to indicate that all objects have the same map. In my case, all maps but the albedo map of all objects to be merged are the same. But this is not taken into account, resulting in redundant information in the combined texture. You can see this happen in the normal map example I just posted.
     
  27. thomasctobin

    thomasctobin

    Joined:
    Dec 5, 2016
    Posts:
    3
    I am running into multiple problems trying to bake my textures into a texture atlas. Combining two objects with the same mobile bumped diffuse shader, results in texture format is invalid, and corrupts my texture file. All my objects then turn white and when the atlas is created it is simply white. I have no invalid uv's, and my uvs are inside the U1V1 Space. Not sure what I'm doing wrong but can not get your tool to work with multiple objects. Works for multiples of the same but not on different objects. Using 2017.1.0f3.
     

    Attached Files:

    kuight likes this.
  28. kuight

    kuight

    Joined:
    Dec 8, 2014
    Posts:
    7
    Same here
     
  29. thomasctobin

    thomasctobin

    Joined:
    Dec 5, 2016
    Posts:
    3
    Update: tested it on texture packer fast - it builds an atlas now, except some of the materials are coming out blue.
     
  30. thomasctobin

    thomasctobin

    Joined:
    Dec 5, 2016
    Posts:
    3
    FIXED: Reverted back to unity 5.6, Unity 2017 NOT SUPPORTED.
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    I have just submitted a new version to the asset store with fixes for Unity 2017. It ususally takes 2-4 days for the submissions to be reviewed.
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    I just submitted a version to the asset store that fixes this issue. It usually takes 2-4 days to become live. Contact me at contact.digitalopus@gmail.com if you are in a hurry and I will send you the changed scripts.
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    I will be dropping support for Unity 4 with the next release now that Unity 2017 has been released.
     
  34. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    Can I just re-bake the textures? Usually when I do this, it won't work and I have to delete the baking asset, before re-baking.
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    You can normally re-bake as many times as you like. However the previous version corrupted source textures. You may need to switch the compression to something different for the source textures and re-import them before you are able to use them again. Then you can re-bake as many times as necessary.
     
  36. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    Ok, thanks. Looking forward to the new version. Really happy with MeshBaker so far :)
     
  37. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    New version is now available. Let me know if you have any issues.
     
  38. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    Thanks. Updated and re-baked. Worked perfectly.
     
  39. CDUnityDev

    CDUnityDev

    Joined:
    Jan 31, 2017
    Posts:
    25
    Can this extension be used to bake a material that uses a splatmap shader into one that just has a diffuse or something like that?
     
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    No, it won't do that.
     
    CDUnityDev likes this.
  41. Ghullie

    Ghullie

    Joined:
    Jun 13, 2016
    Posts:
    2
    Hi,
    I'm having an error popup whenever i try to Bake a "multimesh" with tiling textures that are out of bounds.

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

    The result is empty gameobjects under "CombinedMesh-Meshbaker".

    This only happens when "Consider mesh UV" is checked on. Otherwise it bakes the meshes normally - but obviously the texture is messed up.

    Using Unity 2017 and latest version of MeshBaker

    Any solutions?
     
    Last edited: Aug 3, 2017
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    Hi Ghullie, if you use the "Consider mesh UV" option then Mesh Baker only takes the part of the source textures covered by the UVs of the source meshes used to bake the texture. If the UVs are larger than the source atlas then the texture may be tiled multiple times in the atlas.

    Consider an example where you have a texture for a wooden crate, and three meshes that use it.
    1. A crate mesh that uses the entire texture
    2. A wooden board mesh that uses only part of the texture
    3. A wooden wall that tiles the crate texture
    If you baked the atlas using only mesh 2 then you could not use that atlas to combine 1,3 because parts of the source texture needed by the meshes would be missing. If you baked the source atlas using 3 then you could use the atlas with 1,2 because the parts of the texture they needed would be included.

    To fix the issue the atlas must be baked with a mesh that has a UV layout that encompasses all the UV layouts of the meshes you want to use, or you need to include all the meshes you want to use in the texture bake.
     
  43. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    hello @Phong , i have a question,, what's the downside of settings these textures as read/write enabled for runtime baking? and if am targeting mobile, is there some things i have to worry about?

    thanks
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    As I understand it, if a texture is read/write disabled then the texture does not need to exist in the CPU memory. It can be stored in the GPU memory only. If a texture read/write enabled then a copy of the texture needs to exist in CPU memory. To be honest I am not sure how this applies to mobile because on most mobile devices GPU and CPU share memory. It is hidden in the inner workings of Unity.

    A more serious issue is the compression. In order to read the pixels, the texture needs to be in an uncompressed format. The format of a texture cannot be changed at runtime so it needs to be stored uncompressed which takes up a lot of space but also is considerably slower for the GPU than uncompressed textures. Also the generated atlas cannot be compressed at runtime after it has been generated.

    For these reasons I recommend generating the atlases in the editor if possible.
     
  45. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    When I bake textures with Mesh Baker, source textures are included in the android build. Is it normal ?
     
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,084
    They will be included if they are referenced somewhere. If the source objects are in your scene they will be included. If the 'Material Bake Result' is referenced in your scene (by a texture baker or a mesh baker) they will be included.
     
  47. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    Thanks for the replay @Phong

    i found in unity documentation when using unity texture2d you can compress it in run time to DX1 or DX5, also you can flag it as "makeNoLongerReadable" then the texture will be marked as no longer readable and memory will be freed after uploading to the GPU. as documentation claims..

    i dunno if it works on the actual device..but on editor and on android target build.. it made a 5+ mb texture into 1.2mb at runtime compression...(dunno how to check texture on GPU part)

    wouldn't be awesome if meshbaker would handle entire scenes on runtime :D
     
  48. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    So is there anyway just use atlas texture in Mesh Baker ? Actually same material for multiple objects and don't use source textures.
     
  49. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    i think you could.. if you generate new mesh in prefabs that uses the texture atlas..

    to avoid seeing your old textures in build:
    1- do not put them in Resource folder
    2- do not reference the texture in any scene included in build, or any asset (scripts/materials/etc) in resource folder.
     
  50. Urishizu

    Urishizu

    Joined:
    Sep 24, 2016
    Posts:
    158
    Edit: Wow, I just saw the MeshBakerGrouper component. Incredible, that's exactly what I was looking for. It can generate multiple groupings based on distance which can then be set to static and culled by Unity properly. Very nice! This tool is fantastic!
     
    Last edited: Aug 5, 2017