Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. Augis1980

    Augis1980

    Joined:
    Sep 23, 2014
    Posts:
    33
    Hi, I'm getting errors in Unity2017.4 when trying to publish WebGL.

    Assets/Plugins/MeshBaker/scripts/core/MB3_TextureCombiner.cs(2661,56): error CS0234: The type or namespace name `ProceduralMaterial' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference?

    Assets/Plugins/MeshBaker/scripts/core/MB3_TextureCombiner.cs(673,32): error CS0234: The type or namespace name `ProceduralMaterial' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference?


    Any solutions?
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Are you using the most recent version? I thought I had removed all references to ProceduralMaterial.
     
  3. Augis1980

    Augis1980

    Joined:
    Sep 23, 2014
    Posts:
    33
    Yes you are right, I had earlier version. Thank you. All good now
     
  4. indieDoroid

    indieDoroid

    Joined:
    Jan 25, 2016
    Posts:
    186
    Hi,

    I'm just trying out mesh baker Free to see if it works for my project.

    I'm getting this Missing error in the "Texture bake Result". I only pressed "Bake".

    In the youtube videos, I didn't see this error. It said "none" instead.



    Any idea what I'm doing wrong?

    Thanks,

    Unity ver 2018.1.7f1
     

    Attached Files:

  5. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    30
    I have been using Mesh Baker with great success for quite some time now. Seemingly out of the blue I have been getting the following error on executing AddDeleteGameObjects:

    Object CanopyGlass-0-8-15 Mesh Importer has read/write flag set to 'false'. This needs to be set to 'true' in order to read data from this mesh.
    UnityEngine.Debug:LogError(Object)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:_addToCombined(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1190)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:AddDeleteGameObjectsByID(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:2377)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:2311)
    MB3_MeshBaker:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/MB3_MeshBaker.cs:43)

    I have been using the same mesh that is on that object for 6 months with Mesh Baker without a problem. The only change is that this time the AddDeleteGameObjects call happens in a coroutine. Elsewhere in the project I am calling the same function on different objects in a coroutine and that works fine.
    I use the same process for importing meshes into Unity and they always say that Read/Write is enabled on the import settings.

    Any idea what is happening?
    Thanks,
    -mat
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    The "Texture Bake Result" is an asset generated by the MB3_TextureBaker component. It combines the textures used by different materials into a single giant texture. This helps with performance.

    If it is left as "Missing", your meshes will still be combined but they will not share a material (if the source meshes used different material). To get most of the performance benefit the combined mesh should use as few materials a possible.

    To generate an atlas use an MB3_TextureBaker to create the atlas (Texture bake Result). Then bake the meshes.
     
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548


    You should be able to fix this by setting the read/write flag to "true" on the Importer for that model. It sounds like that got set to false somehow.

    If you do this and the problem persists, please let me know.
     
  8. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    30
    It looks like that flag is set to true on the importer, see screenshot. I have tried unchecking it and rechecking it. I have tried reimporting it.
     

    Attached Files:

  9. indieDoroid

    indieDoroid

    Joined:
    Jan 25, 2016
    Posts:
    186
    Ok thanks for the explanation. I bought the pro version yesterday and that one doesn't seem to show the error anymore.

    Thanks for the help
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Did you click 'Apply' after c
    Did you click "apply" after rechecking the box? I looked in the code and the only way that error can happen is if the Application is playing and mesh.isReadable is false. That is the only reference in the code to that flag. Mesh Baker does not try to set that flag anywhere in the code. Also I don't think that flag can be set or unset at runtime so I don't think that it can be Mesh Baker setting it. Is this the only mesh exhibiting the problem?
     
  11. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    30
    Yeah, i hit apply and i also created a new game object in the scene with that mesh, same problem. I also removed and created a new meshbaker object just in case. I have tons of imported meshes throughout the project that i use with meshbaker at runtime and i don't have this problem.

    I am going to re-export the mesh from CAD and re-import it into unity. It is very strange that it just started happening.

    I also looked through the MB3 code and found the part where it checks that flag. I tried commented out the check and it was unable to actually use the mesh later and crashed, so i agree that it is probably not something with MeshBaker, and it is probably something that happened to the mesh itself, despite it working in unity directly and everywhere else except in the MB AddDelete function.

    Thanks.
    -mat
     
  12. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    30
    I figured it out. At some point Static batching got turned on for some groups of imported meshes. So when the objects load they all get combined into one mesh by unity. Then when I try to combine them with MB at run-time, it cannot because the combined mesh that is set to each individual game object apparently has the read/write flag turned off.

    I am not sure exactly when this happened, but in case anyone else can't combine meshes at runtime with MB, check the static batching on the source objects. If the source objects use the same mesh and static batching is turned on, unity will replace the individual meshes with a combined mesh that cannot be read by scripts including Mesh Baker and it appears as if the imported mesh is the one without read/write enabled.
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Glad to hear you found a solution to the issue.
     
  14. Eiseno

    Eiseno

    Joined:
    Nov 1, 2015
    Posts:
    79
    @Phong Did u test 2018.2 ? i got some error about tizen

    Assets/MeshBaker/scripts/Editor/core/MB3_TextureCombinerEditorFunctions.cs(45,41): error CS0117: `UnityEditor.EditorUserBuildSettings' does not contain a definition for `tizenBuildSubtarget'
    Assets/MeshBaker/scripts/Editor/core/MB3_TextureCombinerEditorFunctions.cs(58,41): error CS0117: `UnityEditor.EditorUserBuildSettings' does not contain a definition for `tizenBuildSubtarget'
    Assets/MeshBaker/scripts/Editor/core/MB3_TextureCombinerEditorFunctions.cs(44,77): error CS0117: `UnityEditor.EditorUserBuildSettings' does not contain a definition for `tizenBuildSubtarget'
    Assets/MeshBaker/scripts/Editor/core/MB3_TextureCombinerEditorFunctions.cs(42,41): error CS0117: `UnityEditor.EditorUserBuildSettings' does not contain a definition for `tizenBuildSubtarget'
     
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Hi Eiseno, I am aware of this issue and have a fix that will get pushed out in the next release. Hopefully early next week. You can fix it in the meantime by replacing the first few function in MB3_TextureCombinerEditorFunctions.cs:

    Code (CSharp):
    1.         enum saveTextureFormat {
    2.             png,
    3.             tga,
    4.         }
    5.  
    6.         private saveTextureFormat SAVE_FORMAT = saveTextureFormat.png;
    7.  
    8.         private List<Texture2D> _texturesWithReadWriteFlagSet = new List<Texture2D>();
    9.         private Dictionary<Texture2D,TextureFormatInfo> _textureFormatMap = new Dictionary<Texture2D, TextureFormatInfo>();
    10.  
    11.         public MobileTextureSubtarget AndroidBuildTexCompressionSubtarget;
    12. #if UNITY_TIZEN
    13.         //public MobileTextureSubtarget TizenBuildTexCompressionSubtarget;
    14. #endif
    15.         public void Clear(){
    16.             _texturesWithReadWriteFlagSet.Clear();
    17.             _textureFormatMap.Clear();
    18.         }
    19.  
    20.         public void OnPreTextureBake()
    21.         {
    22.             AndroidBuildTexCompressionSubtarget = MobileTextureSubtarget.Generic;
    23.  
    24.             // the texture override in build settings for some platforms causes poor quality
    25.             if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android &&
    26.                 EditorUserBuildSettings.androidBuildSubtarget != MobileTextureSubtarget.Generic)
    27.             {
    28.                 AndroidBuildTexCompressionSubtarget = EditorUserBuildSettings.androidBuildSubtarget; //remember so we can restore later
    29.                 EditorUserBuildSettings.androidBuildSubtarget = MobileTextureSubtarget.Generic;
    30.             }
    31. #if UNITY_TIZEN
    32.             TizenBuildTexCompressionSubtarget = MobileTextureSubtarget.Generic;
    33.             if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Tizen &&
    34.                 EditorUserBuildSettings.tizenBuildSubtarget != MobileTextureSubtarget.Generic)
    35.             {
    36.                 TizenBuildTexCompressionSubtarget = EditorUserBuildSettings.tizenBuildSubtarget; //remember so we can restore later
    37.                 EditorUserBuildSettings.tizenBuildSubtarget = MobileTextureSubtarget.Generic;
    38.             }
    39. #endif
    40.         }
    41.  
    42.         public void OnPostTextureBake()
    43.         {
    44.             if (AndroidBuildTexCompressionSubtarget != MobileTextureSubtarget.Generic)
    45.             {
    46.                 EditorUserBuildSettings.androidBuildSubtarget = AndroidBuildTexCompressionSubtarget;
    47.                 AndroidBuildTexCompressionSubtarget = MobileTextureSubtarget.Generic;
    48.             }
    49. #if UNITY_TIZEN
    50.             if (TizenBuildTexCompressionSubtarget != MobileTextureSubtarget.Generic)
    51.             {
    52.                 EditorUserBuildSettings.tizenBuildSubtarget = TizenBuildTexCompressionSubtarget;
    53.                 TizenBuildTexCompressionSubtarget = MobileTextureSubtarget.Generic;
    54.             }
    55. #endif
    56.         }
     
  16. LabInno

    LabInno

    Joined:
    May 19, 2016
    Posts:
    6
    Hi,

    I am trying to bake a very big object with a MultiMeshBaker. It is working well for the first output meshes, but at some point I get the error :

    Code (Console):
    1. Cannot add objects. Resulting mesh will have more than 64k vertices. Try using a Multi-MeshBaker component. This will split the combined mesh into several meshes. You don't have to re-configure the MB2_TextureBaker. Just remove the MB2_MeshBaker component and add a MB2_MultiMeshBaker component.
    2. UnityEngine.Debug:LogError(Object)
    3. DigitalOpus.MB.Core.MB3_MeshCombinerSingle:_addToCombined(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1338)
    4. DigitalOpus.MB.Core.MB3_MeshCombinerSingle:AddDeleteGameObjectsByID(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:2441)
    5. DigitalOpus.MB.Core.MB3_MultiMeshCombiner:_bakeStep1(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:422)
    6. DigitalOpus.MB.Core.MB3_MultiMeshCombiner:AddDeleteGameObjectsByID(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:303)
    7. DigitalOpus.MB.Core.MB3_MultiMeshCombiner:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:279)
    8. MB3_MultiMeshBaker:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/MB3_MultiMeshBaker.cs:37)
    9. MB3_MeshBakerEditorFunctions:BakeIntoCombined(MB3_MeshBakerCommon, Boolean&) (at Assets/MeshBaker/scripts/Editor/core/MB3_MeshBakerEditorFunctions.cs:77)
    10. DigitalOpus.MB.Core.MB3_MeshBakerEditorInternal:bake(MB3_MeshBakerCommon) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorInternal.cs:297)
    11. DigitalOpus.MB.Core.MB3_MeshBakerEditorInternal:DrawGUI(SerializedObject, MB3_MeshBakerCommon, Type) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorInternal.cs:263)
    12. DigitalOpus.MB.Core.MB3_MeshBakerEditorInternal:OnInspectorGUI(SerializedObject, MB3_MeshBakerCommon, Type) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorInternal.cs:115)
    13. MB3_MultiMeshBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB3_MultiMeshBakerEditor.cs:58)
    14. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    Am I missing something ? Is there some conditions on the source meshes that prevent it to be processed by the baker ?
     
  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Do you know which version of Mesh Baker you are using and which version of Unity? The line numbers do not correspond to the latest version. That could be the problem. Recent versions of Unity allow meshes larger than 64k. There are a few operations like generating UV2 which can add vertices to a mesh. It is not known before generating how many verts may get added. This can bump the mesh over the 64k limit. A workaround is to set the max verts per mesh to something below 64k (e.g. 60k) This will leave some buffer room for the extra verts.
     
  18. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    219
    Texture Issues with Meshbaker Pro

    Greetings!
    So I have been playing around with mesh baker pro for my mobile VR /android game. And it's saved me. I figured out that I can "bake" my individual dungeon room into one mesh and it's dropped my drawcalls from around 60 to 15 and has greatly sped up my performance.

    However, I am getting odd texture quality on some of the bakes. Sometimes when I bake a "room" the textures degrade and look very pixelated, yet the next room over, when I bake in the same level, the textures look great! I'm wondering if anyone has seen this and knows a quick fix (before I spend a bunch of time/days sleuthing through forums and doing trial and error withe the program)
    I am suspicious that maybe I am trying to bake to many objects int he room (walls, floor, ceilings, a few crates and support pillars, maybe 15-20 objects in all) that it may be too much for the texture compressor, but this is just a huntch I have....

    Here is an screen shot example. The good is a room, that baked perfectly, the Bad is the next room over, where the textures pixelated out. Has anyone seen this type of behavoir before? Any advice or suggestions on how to fix?

    Cheers!

     
  19. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    30
    It looks like something in Mesh Baker is preventing the Auto API Updater from running after updating to the latest Unity version 2018.2.0f2.

    After the update, when the API Updater is ran, it fails with this message:
    Internal error: Recursion detected while updating scripts (assembly name: Assembly-CSharp-Editor.dll)

    The warning right before it fails is:
    [MY PROJECT]/Assets/MeshBaker/scripts/Editor/MB3_BatchPrefabBakerEditor.cs(129,38): warning CS0618: 'PrefabUtility.GetPrefabParent(Object)' is obsolete: 'GetPrefabParent() has been deprecated. Use GetCorrespondingObjectFromSource() instead (UnityUpgradable) -> GetCorrespondingObjectFromSource(*)'

    (Filename: [MY PROJECT]\Assets\MeshBaker\scripts\Editor\MB3_BatchPrefabBakerEditor.cs Line: 129)

    If I go into that file and make the change from the warning:
    //UnityEngine.Object obj = PrefabUtility.GetPrefabParent(go);
    UnityEngine.Object obj = PrefabUtility.GetCorrespondingObjectFromSource(go);

    The API updater works as expected and it all seems good. This might just be a heads up for your next version. I don't think I use this feature of MB, but it aborted the whole API updater execution for the project. There is also GetPrefabObject that might be the function needed.

    Best.
     
  20. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    That looks like a tiling issue. I think what is happening is that the floor has a UV rectangle larger than 1..1. This will tile the material. To fix it you need to use the consider UVs feature. Mesh Baker can bake the tiling mesh to its own submesh where it is free to tile as much as it wants.

    This video explains what is happening and various ways of dealing with it.

     
    jons190 likes this.
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Thanks for letting me know. I am hoping to release a new version this week so I will take a look at this.
     
  22. zornor90

    zornor90

    Joined:
    Sep 16, 2015
    Posts:
    163
    Hello, I am interested in purchasing this asset. Our game is procedural and we generate a map of prefabs at runtime - I was wondering if this asset would allow me to basically combine all the meshes on the prefab into a single gameobject and then re-save the prefab to be loaded / instantiated at runtime, or does it require things to be baked into the scene?
     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Hi zorno90,

    The tool is very flexible.
    • Meshes can be combined to a mesh instance in a scene
    • Meshes can be combined and saved a an asset
    • Meshes can be combined at runtime
    • Prefabs can be modified with adjusted UVs so that they share an atlas material. These meshes are very quick and easy to combine at runtime. They can be combined using Unity's Mesh.CombineMeshes, Mesh Baker or Unity's Static batching utility.
     
    zornor90 likes this.
  24. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    219
    Awsome. I also noticed that "generated new lightmapping UVs" (i think thats what the radio button was called) seemed to help. I had "ignore UV" checked.....
     
  25. zornor90

    zornor90

    Joined:
    Sep 16, 2015
    Posts:
    163
    Awesome thanks so much, I went ahead and picked it up! I do have another question. It looks like when I combine textures, the max size generated is 4096. My question is, is it possible to keep all my original texture sizes? We use a lot of 4k maps and I don't want to lose the graphical fidelity in our scene
     
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    You can type a different number in the max atlas size box. Different platforms support different max texture sizes in Unity. For mobile the usable max size is 2k or 4k for newer devices. For desktop you can use 8k. I am not sure what the limit is for other platforms.
     
  27. sekever-n00b

    sekever-n00b

    Joined:
    Nov 4, 2017
    Posts:
    41
    Hello!
    How to bake objects that doesnt seems that they wanna be baked that easley? The moment I press Bake button it just stays that way.
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Do you mean that Unity hangs?

    Are they compressed in PVRTC compression? There is a bug that causes these textures to display warnings which can slow baking down a lot. I am releasing a fix that will be available in a few days. For the time being you will need to make sure the textures are uncompressed.
     
  29. sekever-n00b

    sekever-n00b

    Joined:
    Nov 4, 2017
    Posts:
    41
    Ups my bad, It seems that it worked before, it just needed one night. It baked 3552216 faces + bunch of stuff in it. To me its better to see that it worked out then working fast and crash.
     
  30. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Were you baking meshes or textures or both? I am very curious as that sounds like it is taking far longer than it should. Were those faces baked into a single mesh? That is a very big mesh. You might want to try using a multi mesh baker to bake that into several smaller meshes.

    Were there many repeated errors or warnings in the console? Sometimes an operation generates an error. If there are many of these (one per pixel or vertex). That can slow Mesh Baker to a crawl. Please let me know if this is happening so I can try to reproduce it an fix it.
     
  31. sekever-n00b

    sekever-n00b

    Joined:
    Nov 4, 2017
    Posts:
    41
    I was baking just meshes using only mesh baker, no warnings, one model has texure the othe has not . Can I send you those models through email ? Is this the right email contact.digitalopus@gmail.com ?
     
    Last edited: Jul 19, 2018
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Yes please, baking meshes is normally fast enough to do at runtime in a single frame. Taking several hours to bake a single mesh seems crazy. Also let me know what the bake settings were.
     
  33. TechTools

    TechTools

    Joined:
    Nov 21, 2013
    Posts:
    20
    Hi again, thanks for this excellent asset there's nothing else like it. I'm still amazed by what is possible with it!

    However I do have a couple more questions if you don't mind:

    In the skinned mesh example, the 'ConstructionDudeOrangePrefab' has it's skinned mesh renderer on the rig (specifically 'Bip001 Pelvis') and not on the empty 'construction_worker' GameObject. I would have expected it to be on the empty GameObject, and all my characters have their skinned mesh renderers there. Will this be a problem when I bake? Did you move the skinned mesh renderer there to allow the baking? The structure seems unusual.

    Also, in the runtime example you are combining meshes not skinned meshes, so is there an example of doing the same for skinned meshes? I expect to have 10 characters in my game and they depend on the user selection so I'm thinking I'll have to bake at runtime.

    Another potential issue is that some of them have a separate head, if this (2 skinned meshes) is a problem I can always join them in my 3d modelling package and create new fbx's, so less of a concern than the other two issues above.

    I hope that these are straightforward questions and that I've not asked something I've overlooked in the demos, as I'm really looking forward to using this properly and optimising my game to a much better level.Thanks in advance of any help :)
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    The construction worker is an old Unity Standard Assets model from Unity 3.x which probably explains its strange setup. The location of the Skinned Mesh Renderer game object relative to the children does not affect anything. The location of the Skinned Mesh Renderer game object relative to the Animation or Animator component does affect the culling settings. For "CullUpdateTransforms" or "CullCompletely" to work the SkinneMeshRenderer must be a child of the Animator component.
    The "SkinnedMesh" example is both an editor example and a runtime example. If you push play then buttons will appear and you can add and remove meshes from the skinned mesh. An extra skinned mesh character is added when the scene starts. Also the Character Customization scene adds and removes skinned mesh body parts. (each of these is a skinned mesh).
    This should not be a problem. If you combine the materials then when the meshes are combined you will have a single (1 draw call) skinned mesh.
     
  35. TechTools

    TechTools

    Joined:
    Nov 21, 2013
    Posts:
    20
    Thanks for clarifying the requirement of having the skinned mesh renderer as a child of the animation/animator component. My models have an animator (they are using mecanim). Also I appreciate you explaining the reason for the unusual structure of the construction worker.

    I didn't notice that the skinned mesh renderer demo adds another skinned mesh character, my bad. I'll take a look at the code that adds it to the combined skinned mesh.

    Things are coming on quite well with my demo scene. While recreating my animation setup I remembered that 'always animate' needs to be selected for culling mode on the animator when using animation controllers, and now I can update both of the blend trees for the two characters by adjusting some of the variables during run time. I've also got collision working ok following your advice in an earlier comment regarding leaving the colliders switched on in the source mesh.

    I do have a couple more questions though if you don't mind, before I fully adapt the existing structure I have to make use of Mesh Baker.

    I remember you mentioning that the bounds of the baked mesh needs to be updated in real-time. Forgive my naivety, and sorry if I've missed the answer to this already, but couldn't you simply make the bounds the size of the map to begin with, if so are there any overheads with doing it this way, and if not what is the best way to manage this?

    Also, since the specific models aren't known until the game starts due to the multiplayer element of my game and character selection, is it possible to create an empty baked mesh (if such a thing exists) and then add to it at runtime? Another issue is that I will not use all the characters if more than one player chooses the same character (which is possible) so can textures be baked at runtime, if not is there any problem/what is the best practise with only using a subset of the baked materials?

    On another note, I am planning to use some dynamic occlusion culling, are there any significant implications of using Mesh Baker in conjunction with such a system, bearing in mind I'll also be using Mesh Baker for my static/non-skinned meshes?
     
    Last edited: Jul 25, 2018
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Rendering skinned meshes is expensive so you only want it done when necessary. If your skinned meshes are always on screen then this is a perfectly usable solution. Also if you know what the bounds will be, (.eg two skinned mesh monsters that always hang out in the same area). You can set the bounds to be the size of the area that the two meshes wander around in.
    Unfortunately the latest versions of Unity don't like empty skinned meshes. The Console generates errors (Mesh assigned to SkinnedMeshRenderer doesn't have skinning information).

    Texture atlases can be baked at runtime, but there are some serious drawbacks:
    • It is slow.
    • Source textures cannot be uncompressed so you may be baking textures with compression artifacts
    • The new atlas cannot be compressed once it has been created.
    If you do want to do this I would recommend using the Mesh Baker Fast texture packer.
    You will need to be careful to only combine meshes that are close together. If you combine meshes that are far apart in the scene, then the Bounds of the combined mesh may be very large and difficult to cull.
     
  37. TechTools

    TechTools

    Joined:
    Nov 21, 2013
    Posts:
    20
    Thanks for clarifying the best use cases for baking/combining skinned meshes. If I'm not mistaken I think my scene doesn't fit the scenario you mentioned of multiple skinned meshes always being visible.

    Each map has multiple buildings, hills, trees and mountains (around 10 to 15 of each) that often obscure the other players as everyone changes position, therefore would you suggest I don't bake my skinned meshes? I could use some kind of occlusion culling on the obscured meshes instead as they aren't always visible? If that's seems correct (due to them not always being visible) can I still leverage texture packer atlases for my skinned meshes even though they're not baked?

    Also hearing what you said above about occlusion culling makes me unsure now what group sizes I should use for the static geometry (non-skinned meshes such as buildings).

    I realise that this is a balancing act that needs to benchmarked for specific use cases, and with baking geometry whether skinned or not the main optimisation is reducing draw calls, but I'd appreciate some guidelines on how to balance this with other optimisation efforts such as culling and perhaps some rules of thumb depending on scene size and mesh density (mine are all very low poly, relatively small maps), particularly on mobile which is my current platform.

    I apologise in advance if this has already been covered and thank you for the help so far.

    I just want to get it right, and I know this tool can help me get the best performance possible. Although the examples have helped hugely with understanding the different types and processes of baking possible at an atomic level, due to their relative emptiness I'm finding it difficult to know how to apply all the individual features together in a larger Unity scene.
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Combining material is almost always helpful. There are different kinds of drawcalls (from most expensive to least expensive) Setpass calls, Batches, Drawcalls. Setpass are the most expensive. They require the shader and textures to be switched in the GPU. The GPU needs to wait until the previous call is completely finished before it can do this. Having as few materials as possible in the scene means Setpass calls are less frequent.

    Regarding occlusion culling. You will need to do some testing to see. In my experience I have not found occlusion culling to provide much benefit with outdoor scenes. It is amazing for dungeons and building interiors where 90% of the geometry or more can easily be occluded. Calculating what is occluded takes some work so this reduces the benefit.

    One thing to take advantage of is Unity's Static Batching. The Batch Prefab baker is great for this. Get as many objects as possible sharing a material, then make them static let Unity's Static Batching combine them and cull them when they are outside the camera fustrum. It even works with LOD.

    Even with static batching it is still useful to combine any objects that will always be together (a pile of crates or cannonballs or rocks).

    Regarding, you want to get it right: Optimizing is very complex and varies a lot depending on platform, number of meshes, materials, how many transparent vs. opaque so it is hard to give advice. I would recommend the following.
    • Read Unity's guides for optimizing. The first step is doing some testing to see if you are CPU bound or GPU bound.
    • Pay attention to how much overdraw you have to see if you are bound by fillrate.
    • Experiment with different setups. On our project we created a project that would fill a scene with different numbers of meshes and fill the screen with different numbers of layers of transparent materials. This allowed us to measure how much geometry we can expect to have in a scene, the expense of various shaders. How many layers of full screen transparency etc...
     
  39. TechTools

    TechTools

    Joined:
    Nov 21, 2013
    Posts:
    20
    Thanks again for this excellent advice, and I will refer to this throughout the benchmarking that I'll be doing over the next few weeks.

    I was aware of the need to combine textures to avoid draw calls, as then all the data can be sent to the gpu in one. Although I still have significant gaps in my knowledge, I have read the Orange Book a few times now and started my OpenGL coding in 1997 at University. As you say though this topic is very complex, and of course a lot of traditional OpenGL topics don't translate directly into the context of Unity. I especially appreciate the breakdown of different draw call types, and what to watch out for when optimizing.

    One thing I'm still not clear on, and this is probably because I've not looked at the examples as much as I should is whether a texture baker atlas can be used without a mesh baker. As you hinted at I may not need to combine geometry as the characters are often offscreen, but I still want to combine the textures. I'll take another look at the examples.

    I've read Unity's optimization guide a number of times as well but as you say it's very complex and I do need to create some more test scenes which coincidentally I'd already started today. I need to read up on overdraw, but my instinct is that Unity frustrum/occlusion culling can help as even on an outdoor scene we should be able to avoid drawing things outside of the frustrum or out of sight. I believe Unity's built-in system disables any mesh or skinned mesh renderers it finds on culled GameObjects.

    This would provide an alternative to baking my skinned meshes, but this is based on your comment of avoiding drawing skinned meshes unless necessary. I need to test both approaches and benchmark. Even though I have no opacity, the simplest textures and shaders that provide light-mapping, around 20 low-density meshes and somewhat empty map topologies, it's still difficult to guess which would yield better results. I wouldn't say I'm either CPU or GPU bound currently as my game is inherently low-poly and low-detail, but I'm striving for a golden ratio to support more devices, and will then get an additional VFX effect or two

    In terms of Unity's performance I'm still unclear on how marking meshes as static impacts the occlusion culling as it implies they are batched not grouped, so if I do go down that path I still have a lot of research and experimentation to do.
     
    Last edited: Jul 27, 2018
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    To use the atlas materials the UVs of a mesh must be modified. So the meshes must be baked. However they can be baked for each mesh and the meshes not combined. This can help make many more meshes eligible for static and dynamic batching.
    It does not disable the renderers but it doesn't render them.
    [QOUTE]
    This would provide an alternative to baking my skinned meshes, but this is based on your comment of avoiding drawing skinned meshes unless necessary. I need to test both approaches and benchmark. Even though I have no opacity, the simplest textures and shaders that provide light-mapping, around 20 low-density meshes and somewhat empty map topologies, it's still difficult to guess which would yield better results. I wouldn't say I'm either CPU or GPU bound currently as my game is inherently low-poly and low-detail, but I'm striving for a golden ratio to support more devices, and will then get an additional VFX effect or two

    In terms of Unity's performance I'm still unclear on how marking meshes as static impacts the occlusion culling as it implies they are batched not grouped, so if I do go down that path I still have a lot of research and experimentation to do.[/QUOTE]
    Static batching is powerful. Unity creates a giant vertex buffer (basically a combined mesh). Then when draw calls happen it only draws the triangles needed by the object being drawn. Each object still gets its own drawcall but these drawcalls are very cheap. This way objects can still be culled based on occlusion, fustrum culling and LOD can still work.
     
  41. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,138
    Hello, I've just discovered this asset and it looks awesome. :) I've got a scene composed of a bunch of (static) rocks. They all use the same shader, but they use about a half-dozen different materials that differ only in their texture. So they seem like a good candidate for baking (but there are some difficulties).

    I'll confess I haven't read through all 44 pages of this thread, so apologies if these questions have been answered before.
    1. There are a lot of occluded faces that can never be seen. That wastes memory and probably causes overdraw at runtime. Can Mesh Baker detect and eliminate these?
    2. The other (perhaps bigger) problem is that the current materials use tiling, with repeat counts up to 32: upload_2018-7-28_7-23-51.png
    I'm watching the tutorial above on dealing with tiling now, but I think I haven't gotten to the good part yet. :) Is this something that can be dealt with via submeshes? And in that case, will it still be a single draw call? (I confess I don't really understand how submeshes work.)
     
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Hi, thanks for the interest.

    Mesh baker is not able to detect internal faces and remove them.
    Tiling be either:
    • Baked (This can use a lot of space in the atlas)
    • The tiling material can be put on its own submesh. This is a lot like using a separate mesh. It does not save a drawcall. However often meshes are combined with many materials only one of which has extensive tiling. In this case the extensive tiling can be left on its own submesh and everything else combined.
     
    JoeStrout likes this.
  43. OasisFirewall

    OasisFirewall

    Joined:
    May 26, 2018
    Posts:
    4
    Hi there,

    This asset is fantastic! I primarily use it to generate a texture for objects that only have solid colour materials with no texture, by checking the 'Blend Non-Texture Properties'. However the generated png texture always changes the colours a bit (hue/saturation/brightness). I cant figure out how to get the texture baker to match the colours in the material exactly, which means I always have to open the png in photoshop and manually fix the colours one by one. Its a lengthy fix process of 'guess which colour belongs where' in a grid of 20x20 randomized little colour squares... It was a funny game to begin with but it slows progress down a lot.

    Is there a setting in the texture baker that I have not configured properly that might fix this?
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    Hi Oasis,

    The final color depends on the code in the shader being used. What shader are you using? The "Blend Non-Texture Properties" feature uses the TextureBlender scripts. These scripts are written to reverse engineer the code in the shader to get the texture color that should match the color property. These scripts need to be hand written unfortunately, this process is not automatic. Mesh Baker ships with scripts for the Standard shader variants and the Diffuse shader. There is a fallback that is used for all other shaders. You can add a TextureBlender script for your own shader. It is easiest to copy and existing TextureBlender script and just change what you need to. Mesh Baker should be able to find the script anywhere in the project.
     
  45. OasisFirewall

    OasisFirewall

    Joined:
    May 26, 2018
    Posts:
    4

    Hi Phong,

    I'm using Unity's unlit color shader. Iv'e tried the standard shader but the colors still dont match up. Anything else I might be doing wrong?

    Cheers :)

    Edit: I think I might have figured it out. Using the fast Mesh Baker Texture Packer_Fast keeps the colors correct. What exactly is the difference between it and the non fast packer?
     
    Last edited: Aug 16, 2018
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    The Mesh Baker Texture Packer Fast copies the textures to the atlas using Render Textures this is much faster than copying them by reading the pixels into an array and copying them to another array which is what the regular texture packer does. The Render Texture approach is faster but offers less control and different hardware and graphics APIs can produce subtly different results.

    One thing I forgot to ask. When you do this are you using the Blend Non Texture Properties feature. If this is disabled then the color in the source textures should be copied exactly to the target, but only one of the color tint values can be used which can cause the combined material to look different. If Blend Non Texture Properties is enabled then the color tints will be blended into the color copied to the atlas.
     
  47. OasisFirewall

    OasisFirewall

    Joined:
    May 26, 2018
    Posts:
    4
    Interesting, I couldn't find any description on it in the documentation, but I'm glad it works now :)

    I am enabling the Blend Non Texture Properties option, however there was no texture on the material, only a color tint. I was trying to bake all the color tints into a texture atlas. Thats why I was a bit confused when the color tints were wrong after baking because it had nothing to blend with but itself.

    I have two more question to do with the mesh baker component. When adding more objects to a prefab baker that has already been used, clicking on Populate Prefab Rows from Texture Baker resets all the existing Source and Result prefabs. Is there any way to Populate from Texture Baker without resetting all the previously populated items?

    Secondly, the Populate from Texture Baker donest seem to have any consistent order when populating. Is there a way to populate the Source prefabs in alphabetical order?
     
    Last edited: Aug 20, 2018
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    At this time that is not how this works, but it would be logical to make this work as you describe. I will try to set this up to work that way in a future version.

    Currently there is no way to change the order of the prefabs to be alphabetical. However I don't think this would be too hard to add.

    In file MB3_BatchPrefabBakerEditor.cs

    There is a method:

    PopulatePrefabRowsFromTextureBaker

    At the end of this method, before converting newRows to an array. Sort it something like this should work (untested):

    newRows = newRows.OrderBy(x => x.sourcePrefab).ToList();
     
  49. lolclol

    lolclol

    Joined:
    Jan 24, 2013
    Posts:
    177
    Hi,

    Thanks for this amazing free tool. However i combined a large scene with approx 1759 objects and tested the scene in mobile with 30fps at a constant rate without the colliders but when i add mesh collider and re build the scene and installed it on android the fps dropped to 11 fps. Any suggestion of how can i cap this scene at 30 or 60 fps with colliders ?

    Thanks
     
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,548
    It sounds like the problem is probably one of physics rather than rendering (which is what Mesh Baker helps with. This is a big topic and I don't know anything about your scene so it is hard to advise. have you looked at the Unity Manual for information about optimizing physics? By any chance do you have 1759 rigid bodies in your scene?