Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Mesh Baker by Digital Opus [RELEASED]

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

  1. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Sorry for the long delay responding, I was travelling yesterday.

    I have just released a new version of MeshBakerLOD to the asset store that uses the MB3_ components instead of the MB2_ components. It should be live in a day or two.

    There should be a legacy folder in the Mesh Baker package that includes the MB2_ versions of the scripts. I have also uploaded a new version of MeshBaker to ensure that this is the case.
     
  2. celaeno

    celaeno

    Joined:
    Jan 31, 2013
    Posts:
    54
    Hello,

    I can't manage to bake meshes with lightmaps. When I Add selected meshes, it gives some warnings:


    "Object Box10 uses uvs that are outside the range (0,1)this object can only be combined with other objects that use the exact same set of source textures (one image in each atlas) unless fix out of bounds UVs is used"
    "Added 0 objects. Make sure some or all objects are selected in the hierarchy view. Also check ths 'Only Static Objects', 'Using Material' and 'Using Shader' settings".


    So it won't add the meshes.

    When I set Using Lightmap Index to "don;t filter on lightmapping", it will select the meshes. Then I set Lightmapping UV's to "preserve current lightmapping", but the baked mesh has strange colors on it.

    Without lightmaps I;m able to select the meshed and bake them, but... when I use "generate_new_UV2_layout" Unity3d crashes.

    Is there a way to solve this, or am I doing something wrong?

    Thanks
     
    Last edited: Jun 1, 2014
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    It sounds like the source meshes use different lightmaps. When the scene was lightmapped it rendered into multiple lightmaps. Some objects in the scene use one lightmap. Some objects use a different one. These objects cannot be combined into a single mesh with lightmapping preserved because the combined mesh can only be associated with a single lightmap. If you run the report it has a column that shows which lightmap index the source meshes use.

    This is the first report of generate new UV2 layout crashing I have heard of. Generating a new UV2 layout can duplicate vertices in the mesh. This can result in the mesh going over 64k which could cause the crash. Are you very close to the 64k mark? Does it work if you remove a few meshes?
     
  4. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    375
    Hello, I am using the latest version mesh baker. But whenever i create meshbaker gameobject, i receive this error(without doing anything else);

    NullReferenceException: Object reference not set to an instance of an object
    DigitalOpus.MB.Core.MB3_MeshBakerEditorInternal.DrawGUI (.MB3_MeshBakerCommon target, System.Type editorWindowType) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorInternal.cs:172)
    DigitalOpus.MB.Core.MB3_MeshBakerEditorInternal.OnInspectorGUI (.MB3_MeshBakerCommon target, System.Type editorWindowType) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorInternal.cs:69)
    MB3_MeshBakerEditor.OnInspectorGUI () (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditor.cs:50)
    UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at C:/BuildAgent/work/aeedb04a1292f85a/Editor/Mono/Inspector/InspectorWindow.cs:1124)
    UnityEditor.DockArea:OnGUI()

    And when i try to bake mesh into prefab, it gives error, failed to add/delete objects.

    What should i do? I am on android build.
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    There is.

    Click the "Open Tools For Adding Objects" button. It opens a window with tools for adding objects in bulk. You select one or more parent objects in the hierarchy and click "Add Selected Meshes". The feature will add all child objects with Mesh Renderers attached. There are a bunch of filters that can be set to control what gets added.
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Odd, that I am not able to reproduce the first error. However you should be able to fix it by changing line 172 and 173 in MB3_MeshBakerEditorInternal.cs to. I will make sure this change gets into the next version:

    if (mom.GetObjectsToCombine().Count > 0){
    Renderer r = MB_Utility.GetRenderer(mom.GetObjectsToCombine()[0]);

    Regarding the second error, is that the entire console output? Were there any previous warnings or errors? If so could you post them? I just tried it on a siimple scene and it worked.
     
  7. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    375
    Is there anything different from this video in current version? (after 3.30)



    Bake into scene works, but baking into prefab gives error.

    I have tested in two computers, different objects (even simple planes with default material) But bake into prefab doesn't work.

    I will edit this post and add error's that i receive. One that i remember is something like: Render output not set. And everytime it gives failed to add/delete objects error.

    By the way, there is a "Mesh" slot right below "Combined Mesh Prefab" slot. What should i do with it?
    When it gives error, a mesh is set there, it has some name that has numbers. But clicking on it doesn't get me to the mesh. (there is no mesh generated)
     
  8. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    375
    It suprisingly worked this time while editing some urban construction pack sidewalks.

    But after prefab is created, both prefab and meshes pivot point is far away from their center. Am i doing something wrong?
     
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Mesh Baker will bake the position, rotation and scale of the source objects into the vertices of the combined mesh. This is necessary if you are baking a grove of trees together then each mesh needs its vertices offset scaled and rotated in the combined mesh. This feature can be useful for adjusting the scale, rotation or pivot point on imported meshes. The origin will become the pivot point of the combined mesh. You need to position your source objects accordingly before baking

    The "mesh" field is exposed in the inspector so that you can control which mesh asset a combined mesh is baked to. The previous version of Mesh Baker would often create a new mesh asset each time a prefab was baked. You can ignore it most of the time. The number beside the field is the InstanceID of the mesh. It is useful to know sometimes to when troubleshooting. I wish Unity displayed these in the inspector.
     
  10. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    375
    Receiving error again, making same setup same settings but receiving error.
    Here is an error that occurs when i click bake on mb3 mesh baker

    Target Renderer was not set.
    UnityEngine.Debug:LogError(Object)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:ValidateTargRendererAndMeshAndResultSceneObj() (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1463)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:_addToCombined(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:339)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:AddDeleteGameObjectsByID(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1317)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1275)
    MB3_MeshBaker:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/MB3_MeshBaker.cs:44)
    MB3_MeshBakerEditorFunctions:BakeIntoCombined(MB3_MeshBakerCommon) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorFunctions.cs:41)
    DigitalOpus.MB.Core.MB3_MeshBakerEditorInternal:bake(MB3_MeshBakerCommon) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorInternal.cs:198)
    DigitalOpus.MB.Core.MB3_MeshBakerEditorInternal:DrawGUI(MB3_MeshBakerCommon, Type) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorInternal.cs:167)
    DigitalOpus.MB.Core.MB3_MeshBakerEditorInternal:OnInspectorGUI(MB3_MeshBakerCommon, Type) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorInternal.cs:69)
    MB3_MeshBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditor.cs:50)
    UnityEditor.DockArea:OnGUI()

    Here is another error;

    Target Renderer game object is not a child of Result Scene Object was not set.
    UnityEngine.Debug:LogError(Object)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:ValidateTargRendererAndMeshAndResultSceneObj() (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1467)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:_addToCombined(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:339)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:AddDeleteGameObjectsByID(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1317)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1275)
    MB3_MeshBaker:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/MB3_MeshBaker.cs:44)
    MB3_MeshBakerEditorFunctions:BakeIntoCombined(MB3_MeshBakerCommon) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorFunctions.cs:41)
    DigitalOpus.MB.Core.MB3_MeshBakerEditorInternal:bake(MB3_MeshBakerCommon) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorInternal.cs:198)
    DigitalOpus.MB.Core.MB3_MeshBakerEditorInternal:DrawGUI(MB3_MeshBakerCommon, Type) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorInternal.cs:167)
    DigitalOpus.MB.Core.MB3_MeshBakerEditorInternal:OnInspectorGUI(MB3_MeshBakerCommon, Type) (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorInternal.cs:69)
    MB3_MeshBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditor.cs:50)
    UnityEditor.DockArea:OnGUI()
     
  11. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    375
    It is working again, i don't understand. But maybe you can use these errors on a future bugfix.

    How can i import generated mesh on 3ds max?

    Thanks in response.
     
  12. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    375
    I got it now, this one isn't explained in documentation. (maybe a bug?)

    I need to generate mesh with "bakeIntoSceneObject" first, and after that bakeIntoPrefab. Otherwise it doesn't work.
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    O.K. that makes. It explains why it worked for me when I tested it. I will try to get a fix for this out today or tomorrow.
     
  14. youest

    youest

    Joined:
    Dec 3, 2013
    Posts:
    4
    Hi there,
    I bought the mesh baker yesterday, it works well with simple example, but when I try to use it on complex cities I am in trouble.

    Maybe I don't understand something... :)
    The big issue is when I use the texture baker with the "Build Source To Combined Mapping From Objects To Be Combined" option, that builds the sub-meshes with duplicates throwing me this error: "Each source material must be unique" "appears more than once in the list of source material" when I press bake button.
    After this I don't know how to continue with editor, I have tried to remove duplicate setting the source material array to 0 and it seams work, but is it the right choice? or should I remove the duplicate sub-meshes?
    Why does the script create duplicates?

    PS:sub-meshes cannot be removed in a simple mode, I should modify the editor to do this
     
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    This is tricky to explain.

    With the multiple materials feature. Mesh Baker tries to map one or more source materials to each combined mesh material. Image you have two trees each with two submeshes:

    TreeRedMaple
    Mat_A maps to Combined_Mat_Leaves
    Mat_B maps to Combined_Mat_Trunk
    TreeGreenMaple
    Mat_C maps to Combined_Mat_Leaves
    Mat_D maps to Combined_Mat_Trunk
    The above setup works. The result will be two combined material atlases, one for the leaf materials one for the bark materials.

    A conflict will arise if a material is re-used in the the list of source materials because it could map to a different combined material eg.

    TreeRedMaple
    Mat_A maps to Combined_Mat_Leaves
    Mat_B maps to Combined_Mat_Trunk
    TreeGreenMaple
    Mat_C maps to Combined_Mat_Leaves
    Mat_B maps to Combined_Mat_Trunk1

    The Mat_B material is being mapped to two different combined material atlases. One way to fix this is to duplicate material Mat_B so that it is distinct and use that on one of the source meshes.

    It is probably a bug if the script is generating these. I will see if I can reproduce the problem and fix it. I have not been able to reproduce the problem but I think it can be fixed by making the following change.

    File MB3_TextureBakerEditorInternal.cs there is a "for" loop approximately line 230. Split this for loop into two as follows:

    Code (csharp):
    1.  
    2.                 //first pass put any meshes with obUVs on their own submesh
    3.                 for (int j = 0; j < r.sharedMaterials.Length; j++){
    4.                     if (MB_Utility.hasOutOfBoundsUVs(m, ref dummy, j)){
    5.                         if (!obUVobject2material_map.ContainsKey(r.sharedMaterials[j])){
    6.                             Debug.LogWarning("Object " + go + " submesh " + j + " uses UVs outside the range 0,0..1,1 to generate tiling. This object has been mapped to its own submesh in the combined mesh. It can share a submesh with other objects that use different materials if you use the fix out of bounds UVs feature which will bake the tiling");
    7.                             obUVobject2material_map.Add(r.sharedMaterials[j],m);
    8.                         }
    9.                     }
    10.                 }
    11.                
    12.                 //second pass  put other materials without OB uvs in a shader to material map
    13.                 for (int j = 0; j < r.sharedMaterials.Length; j++){
    14.                     if (!obUVobject2material_map.ContainsKey(r.sharedMaterials[j])) {
    15.                         if (r.sharedMaterials[j] == null) continue;
    16.                         List<Material> matsThatUseShader = null;;
    17.                         if (!shader2Material_map.TryGetValue(r.sharedMaterials[j].shader, out matsThatUseShader)){
    18.                             matsThatUseShader = new List<Material>();
    19.                             shader2Material_map.Add(r.sharedMaterials[j].shader, matsThatUseShader);
    20.                         }
    21.                         if (!matsThatUseShader.Contains(r.sharedMaterials[j])) matsThatUseShader.Add(r.sharedMaterials[j]);
    22.                     }
    23.                 }
    24.  
     
    Last edited: Jun 13, 2014
  16. youest

    youest

    Joined:
    Dec 3, 2013
    Posts:
    4
    Thank you,
    splitting the loop seams do not resolve the problem, I got the same error.

    Looking around the class to understand what happens there,
    I found the bug, if there are 2 or more objects that share material and the first has not out of bounds the UVs and the second has correct UVs , you add this material in both lists.

    It can be fixed in 2 ways, remove the already inserted material from the list or move out the second "for", I have chosen the second.
    Code (CSharp):
    1. for (int i = 0; i < mom.objsToMesh.Count; i++){
    2.                 GameObject go = mom.objsToMesh[i];
    3.                 if (go == null) {
    4.                     Debug.LogError("Null object in list of objects to combine at position " + i);
    5.                     return;
    6.                 }
    7.                 Renderer r = go.GetComponent<Renderer>();
    8.                 if (r == null || (!(r is MeshRenderer) && !(r is SkinnedMeshRenderer))){
    9.                     Debug.LogError("GameObject at position " + i + " in list of objects to combine did not have a renderer");
    10.                     return;
    11.                 }
    12.                 if (r.sharedMaterial == null){
    13.                     Debug.LogError("GameObject at position " + i + " in list of objects to combine has a null material");
    14.                     return;                      
    15.                 }
    16.                                 if (mom.fixOutOfBoundsUVs) {
    17.                                         Mesh m = MB_Utility.GetMesh(go);
    18.                         Rect dummy = new Rect();
    19.                         for (int j = 0; j < r.sharedMaterials.Length; j++){
    20.                             if (MB_Utility.hasOutOfBoundsUVs(m, ref dummy, j)){
    21.                                 if (!obUVobject2material_map.ContainsKey(r.sharedMaterials[j])){
    22.                                     Debug.LogWarning("Object " + go + " submesh " + j + " uses UVs outside the range 0,0..1,1 to generate tiling. This object has been mapped to its own submesh in the combined mesh. It can share a submesh with other objects that use different materials if you use the fix out of bounds UVs feature which will bake the tiling");
    23.                                     obUVobject2material_map.Add(r.sharedMaterials[j],m);
    24.                                 }
    25.                             }
    26.                                                
    27.                         }
    28.                                 }
    29.                         }
    Code (CSharp):
    1. for (int i = 0; i < mom.objsToMesh.Count; i++){
    2.                                 GameObject go = mom.objsToMesh[i];
    3.                                 Renderer r = go.GetComponent<Renderer>();
    4.                                 for (int j = 0; j < r.sharedMaterials.Length; j++){
    5.                                         if (!obUVobject2material_map.ContainsKey(r.sharedMaterials[j])) {
    6.                                                 if (r.sharedMaterials[j] == null) continue;
    7.                                                 List<Material> matsThatUseShader = null;;
    8.                                                 if (!shader2Material_map.TryGetValue(r.sharedMaterials[j].shader, out matsThatUseShader)){
    9.                                                         matsThatUseShader = new List<Material>();
    10.                                                         shader2Material_map.Add(r.sharedMaterials[j].shader, matsThatUseShader);
    11.                                                 }
    12.                                                 if (!matsThatUseShader.Contains(r.sharedMaterials[j])) matsThatUseShader.Add(r.sharedMaterials[j]);
    13.                                         }
    14.                                 }
    15.             }
    I have removed the checks which are made in the previous for ;)
    and added the check for out of bounds variable so that if i don't want correct them, the combined material is only one, can I assume that it is correct?
     
    Last edited: Jun 14, 2014
  17. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    8,471
    Does this work on moving objects, or objects with physics ?

    Also can it dynamically add objects to a group that has the same material ?

    Example: I have a spell that casts 50 gameobjects, all same material, can the tool disable/enable physics and combine their meshes while they are inactive ? And re-enable physics and split the mesh back to parts locally when something to interact with is near ? (or at least globally)

    thanks

    EDIT: Just read that it includes "Runtime API for baking on the fly"

    So, the above should be possible with this ? Also what would be the performance for the dynamic splitting/combining ? In the scenario described above for example
     
    Last edited: Jun 14, 2014
  18. XMachinaX

    XMachinaX

    Joined:
    Dec 29, 2012
    Posts:
    152
    Hi, I tried the free trial of Mesh Baker and it works briliantly, such a useful tool. I just want to check though is there any way of combining materials that use detail maps/shaders. It seems that when combining materials that use different sized maps it resizes them all to the size of the main texture, meaning I cant use this for our project as almost all of our stuff uses detail shaders.

    I noticed that you mentioned on the webpage for mesh baker that this is currently Mesh Baker's main limitation. Is there any way of working around this or will you be implementing a fix for this in a future update?

    Please get back to me asap (I would like to still purchase Mesh Baker today in time for the 24-hour special, if a workaround/solution to our problem can be attained that is). Thanks in advance for any help.
     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Thanks for the post. Yes, this should fix the problem. I will update Mesh Baker with this fix. I thought that splitting the loop should have fixed it.
     
  20. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Yes this is definitely possible. Moving objects and objects with physics are no problem. The original objects are left in the scene (with renderer's inactive). You can bake the 50 objects into a skinned mesh even if they are mesh renderer objects. The source objects are affected by physics, animations, scripts just as they normally would be. Each source object becomes a bone and the skinned mesh is animated as the source object tumbles through the scene. This would result in one drawcall.

    If your 50 objects spend a lot of time without moving relative to each other, such as a pile of blocks. You could bake them into a MeshRenderer and avoid the overhead of a skinned mesh. You would need to write a script that would be added to the colliders on each of the blocks that would detect an impact and re-enable the renderers on each block and hide the combined mesh.

    Combining inactive meshes is not problem.

    Mesh Baker doesn't do anything with physics. Whatever is happening with the source objects will happen with the combined mesh (if using the skinned mesh approach).

    The performance for the bake is very good. You would not want to bake every frame, but a single bake resulting in a 12k combined mesh takes about 1/60th of a second on mobile.
     
    Last edited: Jun 14, 2014
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    If Mesh Baker is building multiple atlases (one for maintex, one for bump, one for spec). Then the corresponding textures in each atlas must be in the same place. Mesh Baker will re-size them to fit the rectangle in the atlas where the need to go. It analyses the textures and tries to scale them up to the largest size.

    I am not familiar with detail mapping but my understanding of detail textures is that they make extensive use of tiling. Tiling and atlases don't play well together. There are a few limited things that can be done:
    • Only bake together objects that use the same material.
    • Baking the tiling (works if a texture is only tiled a few times).
    • If tiling happens only in one direction then the atlas can be arranged so all textures are side by side.
    • Putting the tiled material on its own submesh in a combined mesh
    I don't believe there is anything more that can be done beyond these things so I doubt a future version of Mesh Baker will have a solution for this. The package does include full source so you could try to modify the texture packing to suit your own needs.
     
  22. XMachinaX

    XMachinaX

    Joined:
    Dec 29, 2012
    Posts:
    152
    Thanks for the reply Phong. Hmm, this worries me a bit. I also see that the non-texture properties arent retained in the combined material and all of the materials will ahve the same non-texture data. I'm geussing a work around for this would also be to just use objects of the same material, but then I wouldnt benefit from combined materials.

    I think I will discuss this with the rest of the team and ask their opinion, but I think we might need to pass on Mesh Baker (which is a shame as its really a fantastic plugin). Apologies, our budget is quite tight so we have to buy plugins only if they are completely necessary and usable with our project.

    Thanks again for the amazing advice and the fast reply.
     
  23. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    8,471
    Nice, the bone approach is probably what i could use since the objects will move very often

    BTW, if i destroy one of these source objects, will the skinned mesh auto update accordingly ?

    Also can i dynamically add objects to the skinned mesh group ? Like if i have two casts of 50 objects in a row, can the 2ond 50 objects be attached to one pool skinnedmesh and then be deleted one by one by some rule ?
     
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Not automatically. You need to remove it from the combined mesh before you destroy it (2-3 lines of code).
    Sometimes it is better to move the mesh very far away so it effectively is gone from the scene without needing to re-bake.

    Yes you can add and remove objects from an existing combined mesh. This example youtube video shows objects being added and removed from a skinned mesh (last few seconds). This is one of the example scenes in the project.

     
  25. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    8,471
    Just bought it :)

    Thanks for all the answers, i cant wait to implement it, will be crucial for one of my systems (and the rest of the game in general i guess :) )
     
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Enjoy! Feel free to contact me if you have any questions.
     
  27. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    8,471
    Thanks, i will probably have to since i am trying something rather complex :)
     
  28. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    8,471



    Hi,

    I have come across an issue. I try to instantiate a 4x4 array of your real time test scene cube (Cube2PF). I stop when i reach 20K Vertices. When i stop instantiating, i do the standard update and apply for all gameobjects. There is nothing else running besides the demo code.

    void LateUpdate(){

    meshbaker.UpdateGameObjects(objsToCombine.ToArray());
    meshbaker.Apply(false,true,true,true,false,false,false,false,true);
    }

    This scheme leads to 25-35ms for the main thread and 4 draw calls.

    When i just copy the same 4x4 cube array in the scene until i reach 20k vertices, i get 13-15ms at the end

    Also the physics dusring the copy and the settle performance hit is much bigger with the script on that native Unity.

    Some pics above. Any ideas what i am doing wrong ?

    Thanks

    EDIT: The 4 draw calls is probably because i have a GUI on when using the script to do the cast (instantiation) of the array, so is irrelevant

    EDIT2: When i disable the script i get 12-14ms, of course objects stop being interactive

    EDIT 3: There is an extra layer of shiness without the script, this is probably some material property overriden by another material in the combined version ?


    Also another question, Unity will batch dynamic objects below 300 vertices, does Mesh Baker batch objects with more than 300 ?
     
    Last edited: Jun 15, 2014
  29. willrsnds

    willrsnds

    Joined:
    Jul 29, 2012
    Posts:
    13
    Has there been any progress on supporting substances? Either internally or with a tested workflow?
     
  30. youest

    youest

    Joined:
    Dec 3, 2013
    Posts:
    4
    Hi phong,
    I would use some store assets, but I get some strange behavior with them.
    If I bake texture with UVs out of bounds checked I get this(left backed, right original):


    otherwise if i bake all on the same shader without fixing bounds I get this(left backed, right original)

    Can you help me to understand where is the mistake?
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    I think you are correct that the drawcalls are probably caused by the GUI.
    It looks like you are updating and applying every frame. This is definitely an expensive approach similar to dynamic batching.

    I would recommend baking into a skinned mesh. You don't need the script. Switch the render type on the baker to "skinned mesh" and bake. Then "disable renderers on source objects".

    This should result in a skinned mesh with one draw call.
    Switch the shader on the the combined mesh material to match the shader on the source materials
    The script you are using (baking every frame) is equivalent to dynamic batching except there is no limit to the number of meshes that can be baked. It is not cheap though. There is a reason that Unity's dynamic batching is limited to 300 verts. In most cases the gain of few drawcalls is not worth the cost of combining meshes above 300 verts.

    Mesh Baker has the advantage that you don't have to bake every frame (unlike dynamic batching). You can bake only when you want the baking to happen.
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    First, I should say that meshes that have been combined can have substance materials applied to them. This will work.

    Unfortunately I have not had time to get to this. My effort lately has been on cleaning up the API and workflow and Mesh Baker LOD.

    The only way I see this working is by converting the procedural material generated textures to regular textures and then combining these into an atlas. Of course in this process the textures will become non-procedural. and you won't be able to apply a procedural texture to the combined mesh unless all source meshes used the same material. There are methods in the ProceduralTexture API for GetTexture and GetTextures. It would not be hard to:

    • Write a script to grab the procedural textures on a source object and save them as regular .png files
    • switch the material on the source object to a regular material
    • use the saved .png textures in the regular material
    • Use mesh baker to build atlases and combine meshes
     
  33. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    8,471
    Thanks for the answers, getting back to optimizing :)

    EDIT: Maybe i need to apply a skinnedmesh to the script, since i need to add objects on the fly. The objects on the scene are not all at once, they are instantiate in groups of 4
     
    Last edited: Jun 15, 2014
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    There is definitely submeshes and tiling happening here. This is a complex situation. I would recommend looking at this video
    . It does the best job of explaining how to combine meshes that use tiling. Also look through the console messages carefully and run the "list shaders in scene" report to see what it says about these meshes. Have you tried using the "Build Source To Combined Mapping From Objects To Be Combined" button? I notice that in the first example you have two submeshes and the second example you have one. Have your tried both configurations with and without the "fix-out-of-bounds-uvs"?

    You may need to resort to baking meshes that all use the same source material.

    Let me know if this helps.
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    The advantage of the skinned mesh is that you don't need to update every frame. The skinned mesh renderer takes care of that. You only need to call AddDeleteSceneObjects and Apply every time a new group of objects needs to be added.
     
  36. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    8,471
    Indeed, got it working without the update !!!! with minimal changes (actually no changes besides erasing the update code)

    Thanks a lot for the help :), works great
     
  37. willrsnds

    willrsnds

    Joined:
    Jul 29, 2012
    Posts:
    13
    I will have to dig into this. Also I purchased mesh baker last night :)
     
  38. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    581
    Hi, I used MB3 and LOD for a while with good results, but now I need to code my own specific LOD system.

    I'm adding objects dynamically in to the scene and I need to bake them in different groups.

    At the moment I'm able to setup and use a MB3_MeshBaker instance to add some objects and to bake them.

    But I don't know how to do it again with different objects without destroying the first baked one.

    Also how can I get a reference to the newly baked mesh? The Apply method return void and the MeshBaker class doesn't expose any property.

    Thanks
     
  39. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    581
    Ok, I resolved instantiating a MeshCombinerSimple for each group.

    My objects currently use a single texture, but from the profiler I see that the method _copyAndAdjustUVsFromMesh is taking a lot of time. It loop between submeshes to recalculate the UV coordinates. But in case of a single texture the UV should be just copied without any calculation. Do you think that is easy to implement this check?
     
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Regarding your earlier question about how to bake again with different objects without destroying the first ones. Mesh Baker remembers what it contains. Think of it as a container like the "List" class. When you call:

    AddDeleteGameObjects( arrayOfToAdd, arrayOfToDelete )

    It is like adding everything in the "toAdd" list and removing everything in the "toDelete" list.

    Regarding the "_copyAndAdjustUVsFromMesh" performance. The optimization you mention would be a good one. It should be easy to implement. I will try to include it in my next version, hopefully submitted today. All you should need to do is look in the TextureBakeResults.PrefabUVRects. If there is only one rect and it is 0,0..1,1 and "fix out of bounds" is false, then there is only one texture in the atlas and it should not be necessary to adjust the UVs (will still need to copy them).
     
  41. youest

    youest

    Joined:
    Dec 3, 2013
    Posts:
    4
    Hi Phong,
    I solved the above problem;
    in my previous code, as said I have added the check ok mom.fixOutOfBoundsUVs, that was incorrect, removing that the baker works well.

    Now I have encountered a new problem, a null pointer error on realtime MeshBaking at line 641 of MB3_MeshCombinerSingle class:
    Matrix4x4l2wMat = go.transform.localToWorldMatrix;

    NullReferenceException: Object reference not set to an instance of an object
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle._addToCombined (UnityEngine.GameObject[] goToAdd, System.Int32[] goToDelete, Boolean disableRendererInSource) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:641)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle.AddDeleteGameObjectsByID (UnityEngine.GameObject[] gos, System.Int32[] deleteGOinstanceIDs, Boolean disableRendererInSource) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1317)
    DigitalOpus.MB.Core.MB3_MultiMeshCombiner._bakeStep1 (UnityEngine.GameObject[] gos, System.Int32[] deleteGOinstanceIDs, Boolean disableRendererInSource) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:472)
    DigitalOpus.MB.Core.MB3_MultiMeshCombiner.AddDeleteGameObjectsByID (UnityEngine.GameObject[] gos, System.Int32[] deleteGOinstanceIDs, Boolean disableRendererInSource) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:353)
    DigitalOpus.MB.Core.MB3_MultiMeshCombiner.AddDeleteGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject[] deleteGOs, Boolean disableRendererInSource) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:342)
    MB3_MultiMeshBaker.AddDeleteGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject[] deleteGOs, Boolean disableRendererInSource) (at Assets/MeshBaker/scripts/MB3_MultiMeshBaker.cs:36)



    and before this null pointer there are some error logs that say:
    Object door_plank_01 has an unknown material door (Instance) (UnityEngine.Material). Try baking textures
    UnityEngine.Debug:LogError(Object)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:_addToCombined(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:440)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle:AddDeleteGameObjectsByID(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1317)
    DigitalOpus.MB.Core.MB3_MultiMeshCombiner:_bakeStep1(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:472)
    DigitalOpus.MB.Core.MB3_MultiMeshCombiner:AddDeleteGameObjectsByID(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:353)
    DigitalOpus.MB.Core.MB3_MultiMeshCombiner:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:342)
    MB3_MultiMeshBaker:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/MB3_MultiMeshBaker.cs:36)

    With the same objects and baking mesh on editor, that does not happen.
    I use the same already baked texture result.
    my simple code below
    Code (CSharp):
    1.  
    2.                 baker.ClearMesh ();
    3.                 baker.textureBakeResults = atlas;
    4.                 var allToMesh = getAllChildren (baker, toMesh);
    5.                 baker.AddDeleteGameObjects (allToMesh, null, false);
    6.                 baker.Apply ();
    7.  
    Are there some known issues?
     
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Hello,

    It looks like the material on one of your objects has been "instanced". This happens when a script accesses renderer.material (either read or write). If you pause your game and look at the objects in your scene you will see that the material property in the inspector has "(instance)" appended to the name. This means it has been duplicated and you are now working with a copy (compare the ID using GetInstanceID()). The script should almost certainly be accessing renderer.sharedMaterial. Accessing a renderer's material through .sharedMaterial does not create a new instance of the material.

    There is probably another script in you scene that assigns to or reads from the renderer.material field.

    Mesh Baker can only handle switching materials to other materials that have been baked into the atlas. The new material instance (even though it is identical to another material) is not in the textureBakeResult and Mesh Baker will not know how to map it to part of the atlas.

    I will have a look and try to make Mesh Baker crash more gracefully when this happens.
     
  43. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    581
    Thank for your fast prompt :) I'll check the new update.

    Anyway another big improvement in term of performance could be to distribute the baking process in multiple frame, or, even better, to move big part of the code on a second thread.
    Now I still have a heavy lag every 2 or 3 second when baking on mobile around 16000 vertices. The game goes over 60 fps, and of course the full baking process can't be so fast (1/60 of second).
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Thanks for the suggestions. I will try to incorporate some of these in a future release.
     
  45. Anand M

    Anand M

    Joined:
    Nov 2, 2012
    Posts:
    2
    Hi,

    I just bought the package and its contains some of the new features included which are not shown the video tutorial.
    I would like to ask you one, sorry if this was already been asked / answered, If an object contains 2 or more materials how its can be baked into one material...when I am trying to do such process, the console shows a error message that the materials are excluded the moment it added.
    Requesting for a small tutorial on this....

    Regards
    Anand
     
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Hi Anand,

    I have been meaning to re-do some of the tutorials. It is hard to keep up with everything though.

    If you want to collapse all the submeshes, then the easiest way is to NOT use the "multiple materials" feature. By default mesh baker will map all the submeshes into a single submesh.

    If you use the "Build Source To Combined Mapping From Objects To Be Combined". You can edit what it generates. You can modify the mapping so that all materials map the the same combined material. However there was probably a reason that Mesh Baker put this material on its own layer. What did the error message say?
     
  47. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,072
    Hi Phong,

    I have Unity Pro and I'm porting to Windows Phone. My project uses MichaelD's Mobile top down dungeon for all static background objects and I have them light mapped. The Top Down Mobile asset has all meshes use a single material (with a texture and normal map). Is there any performance benefit for me to use Mesh Baker on this setup? Would using it affect the light maps I've already created? I wouldn't really want to redo light map baking for all the levels as that takes a long time.
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    The benefits would be:

    1) Static batching will build the combined meshes at build time which can result in large meshes included in the build. Sometimes these meshes are large enough to be an issue. With Mesh Baker you could defer the combining until level load.
    2) With mesh baker you could add content dynamically to the combined meshes.

    If you don't want to do either of these things then there would probably be no benefit.

    You should be able to bake the meshes with Mesh Baker and preserve lightmapping. You need to be careful to group meshes together that all use the same lightmap.
     
  49. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,726
    Blend Shape Support In Mesh Baker

    I have received numerous requests to add blend shape support to Mesh Baker.

    Unfortunately it is not possible to write or directly read the blend shape information in a Mesh using the Unity API. It will not be possible to add this to Mesh Baker until Unity exposes this data. If you would like to see this feature added, consider voting up this feature request:

    http://feedback.unity3d.com/suggestions/expose-blend-shape-vertex-data
     
  50. alexman

    alexman

    Joined:
    Jul 11, 2012
    Posts:
    17
    Just bought Mesh Baker, I can use the basic functionality to combine mesh and textures, although i had experienced some distorted colour in the combined texture, but good work!

    I am using it for static scene objects at this stage, houses, trees, rocks, etc. Does mesh baker baked object use less memory on iOS then original objects?
     
unityunity