Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Mesh Baker by Digital Opus [RELEASED]

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

  1. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Yes, that's what's happening.

    Code (csharp):
    1. Sidewalk_02_Corner_Out (8) (UnityEngine.GameObject) 1556772 has submeshes which share verticies. Adjusted uvs may not map correctly in combined atlas.
    The UV Maps are tiny when I open them in Blender:
    upload_2023-11-4_11-12-51.png

    Zooming in:
    upload_2023-11-4_11-13-42.png

    So that's pretty tiny indeed.

    What would be the simplest way to encourage MeshBaker to work with this? Can you see any way around this that doesn't require hand-editing UV in Blender, or do I need to manually edit the UVs?

    I'm not certain I understand what you mean here - are you suggesting increasing Atlas Padding in the Material Bake Options? I set it to 2 and re-baked but it didn't seem to make any difference.
     
  2. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Oh well - I managed to hack a solution for now. I deleted the material from the objects in question, then added grey planes underneath to fill in the gaps. Then, I baked the mesh with the hacky planes and that worked for now.
     
    Phong likes this.
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    If it were me, I would edit that model in blender. It is fairly easy to scale the UV for that one mesh and export it as FBX back to Unity.
     
  4. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Yes, makes sense but I don’t know my way around Blender and it would take me too long.
     
  5. nkalinay

    nkalinay

    Joined:
    Aug 9, 2020
    Posts:
    5
    Hi,

    I recently picked up Mesh Baker and I'm having issues with the lighting on a combined mesh. Anyone have any ideas what can be going on with this? The lighting abruptly changes on the combined mesh as I move around the scene. I've posted a video here to show it in action...



    Appreciate any help or pointers you can provide!
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Hi nkalinay, what shader, lighting technique and pipeline are you using. It almost looks like an LODs but doesn't seem right for that.
     
  7. nkalinay

    nkalinay

    Joined:
    Aug 9, 2020
    Posts:
    5
    Hi Phong,

    I'm using standard shader on the materials. The rendering pipeline is the built-in one. The lighting in that scene is basic point lights - realtime, not baked.

    Thanks!

    Nick
     
  8. mehrankan

    mehrankan

    Joined:
    Apr 12, 2015
    Posts:
    63
    is it possible for meshbaker to create fbx files after making atlassed assets?
     
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Hi Nick. Here is my theory: Unity limits the number of point lights used when rendering each object (how many do you have)? When all the objects are separated then each part of the floor is getting lit by a few nearby point lights. When the objects are combined into a single large renderer then there are probably too many lights illuminating the entire object and Unity needs to cull some. This isn't working very well. See:

    https://docs.unity3d.com/ScriptReference/QualitySettings-pixelLightCount.html

    Have you considered a different lighting technique like lightmapping or deferred rendering?
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    There is no built in ability in Mesh Baker to create FBX files. However you can install Unity's "FBX Exporter" package. You can use Mesh Baker to "Bake Into Prefab" and then use the "FBX Exporter" to convert the baked mesh to an FBX.
     
  11. nkalinay

    nkalinay

    Joined:
    Aug 9, 2020
    Posts:
    5
    Thanks Phong...this seems like a reasonable theory. Let me experiment with some different lighting techniques and I'll get back to you!
     
  12. mehrankan

    mehrankan

    Joined:
    Apr 12, 2015
    Posts:
    63
    Hi, I have a similar question, I want to run meshbaker for our character customization system NOT on the main thread. are these features released?
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    No, not yet for the Texture Baker. I have been focusing on speeding up the Mesh Baking side which has been more effort than expected.
     
  14. Sir_patrickl

    Sir_patrickl

    Joined:
    Jun 24, 2013
    Posts:
    62
    Hi, Does Mesh Baker support LODs?
     
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    You can use Mesh Baker with LODs in two ways.

    1) You can use the Batch Prefab Baker to bake prefabs with LODs. The meshes will not combined, but the UV layouts will be adjusted so that all the prefabs share the same atlas material. You can use these prefabs in your scene and enable Unity's static batching. The meshes will be combined by Unity but the LODs and frustum culling still work.

    2) If you have a group of renderers in your scene that are close together and have LODs. The MeshBakerGrouper can group them into bakers by LOD level. This generates one MeshBaker per LOD level. The LOD0s, LOD1s, ... each get combined into separate combined meshes. You can then build a new LOD group from the combined meshes. This feature only works well if the group of meshes has similar scale.
     
    Willbkool_FPCS and Sir_patrickl like this.
  16. morfevs

    morfevs

    Joined:
    Dec 21, 2016
    Posts:
    20
    Hi all.
    I am enjoying MeshBaker very much!
    And I have some simple questions for you experts.

    One of them is...

    What happens with Glass? Is it actually possible to do it with MeshBaker?

    Thanks everybody.
     

    Attached Files:

  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    The best approach for a combined mesh with opaque and transparent materials would be to use the "Multiple Materials" feature. This will create multiple materials (submeshes) on the combined mesh. One submesh would be for all opaque materials. One for all transparent materials. You can make more submeshes as needed. For example it is common to put materials with a lot of tiling on their own submesh.

    See this tutorial video for more information:

     
  18. Sapien_

    Sapien_

    Joined:
    Mar 5, 2018
    Posts:
    102
    Sorry if this sounds dumb or has already been answered but every time I bake using the texture baker on any material using the shadergraph it does not work. Can this not work with the shadergraph?
     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Definitely not a dumb question. Can you describe what is happening? Are there errors or warnings in the console? Is the problem bad atlases? No atlases? Are you setting the shader on the combined material to your shadergraph shader before your texture bake. This is an important step. Mesh Baker looks at this shader to get a list of the texture properties to make atlases for. If it is set to a shader with texture properties that have different names then you could get no atlases. There should be a line in the console that says "report ...". It may have some clues regarding what is happening.
     
  20. a_kovats

    a_kovats

    Joined:
    Sep 25, 2017
    Posts:
    3
    Hi Folks,

    I am using Mesh Baker to combine skinned meshes runtime. Unfortunately, I couldn't find out how to get the combined mesh after baking. Can anyone help me with this issue? It must be a way to access the combined mesh by script.

    Thanks,
     
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    You can access the mesh using a script like this:


    Code (CSharp):
    1.        
    2.        MB3_MeshBaker myMeshBaker;
    3.        
    4.         // ...  do some baking
    5.         Mesh mesh = ((MB3_MeshCombinerSingle) myMeshBaker.meshCombiner).GetMesh();
    6.  
    Also note that if you are baking in the editor and want the mesh to be an asset in the project folder then you need to set the output to "Bake Into Prefab". If you use "Bake Into Scene Object" then the mesh will be saved as part of the scene.
     
  22. a_kovats

    a_kovats

    Joined:
    Sep 25, 2017
    Posts:
    3
    Thank you Phong!

    It was life saving :)
     
    Phong likes this.
  23. jabrail_chumakov

    jabrail_chumakov

    Joined:
    Feb 17, 2020
    Posts:
    20
    Hi everyone!

    I'm using Mesh Baker to merge buildings with many objects into one. However, I faced a small problem. Before baking, each object in the building had a separate script "Mesh Info" with the object ID. For example, table in my office has an ID: e3d56581. The problem is that after baking the "Mesh Info" script disappears. I want to select an object after baking and discover its ID. Is there any way to do it?
     
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    You can leave the source GameObjects in the scene with renderers disabled on removed. Any scripts, colliders, rigidbodies will still be in the scene. You are probably using the physics colliders to "select" your object with a raycast. It is fine for performance to have a lot of separate physics colliders in your scene. The MeshInfo script is probably on the Collider or Rigidbody?

    The only problem is highlighting the selected mesh. If you want to highlight the selected mesh you can use "ShowHide" to hide the triangles in the combined mesh that belong to the selected object and enable the renderer for that object with a "Highlight" shader.
     
  25. jabrail_chumakov

    jabrail_chumakov

    Joined:
    Feb 17, 2020
    Posts:
    20
    No, in my case I don't have any colliders in the scene. Instead I'm using a dynamic raycasting (Dynamic RayCast System). In case I will disable the renderer component of some game object I will not be able to detect the position of that game object, since raycasting works based on the renderer component. Do you have any suggestions on that?
     
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    That will be tricky.

    Does the Dynamic RayCast System RayHit return a triangleIndex that was hit?

    If it does then you could process the combined mesh after MeshBaking it. You could grab the combined mesh triangles and build a data structure that maps: triangleIndex -> source renderer. At runtime you could use this map to quickly lookup the source gameobject that was hit.

    Let me know if the RayHit returns a triangleIndex and I can explain in more detail how to do this. It is a bit tricky.
     
  27. jabrail_chumakov

    jabrail_chumakov

    Joined:
    Feb 17, 2020
    Posts:
    20
    As far as I know, triangleIndex works only for MeshColliders.
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    When you do a "Dynamic Raycast System raycast", what does it return?

    Does it return a RayHit? If it is casting against a renderer then it should be casting against the mesh that is being renderered. That mesh will always have triangles so it might return the triangle index as part of the return.
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    I thought about this overnight and I think that you need the ability to identify which part of the mesh (triangle or vertex) is hit by a raycast. From there you can map that triangle to a source GameObject in the scene. If "Dynamic Raycast System" does not return a triangle index then could you use a static MeshCollider with the combined mesh? Put it on its own layer so it doesn't interfere with anything and raycast against that. It will return a triangle index.

    To map the triangle index to a GameObject I would preprocess the combined mesh after baking it like this:
    • In file MB3_MeshCombinerSingle.cs line 135 make this field public
      • public List<MB_DynamicGameObject> mbDynamicObjectsInCombinedMesh = new List<MB_DynamicGameObject>();
    • Then preprocess the mesh like this:

      Code (CSharp):
      1.             // member variable of script
      2.             // Use this array to lookup which source gameobject a triangle index belongs to
      3.             public GameObject[] triIdx_to_SourceGameObject;
      4.  
      5.         [ContextMenu("Build_triIdx_to_SourceGameObject_Map")]
      6.         public void Build_triIdx_to_SourceGameObject_Map()
      7.         {
      8.             MB3_MeshBaker myMeshBaker = null;
      9.             MB3_MeshCombinerSingle myMeshCombiner = (MB3_MeshCombinerSingle)myMeshBaker.meshCombiner;
      10.             Mesh m = myMeshCombiner.GetMesh();
      11.             int[] tris = m.triangles;
      12.             triIdx_to_SourceGameObject = new GameObject[tris.Length];
      13.             // Visit each triangle in the combined mesh
      14.             for (int triIdx = 0; triIdx < tris.Length; triIdx++)
      15.             {
      16.                 int vertIdx = tris[triIdx];
      17.                 // Find that source mesh that this triangle belongs to
      18.                 foreach (MB_DynamicGameObject dgo in myMeshCombiner.mbDynamicObjectsInCombinedMesh)
      19.                 {
      20.                     if (vertIdx >= dgo.vertIdx &&
      21.                         vertIdx < dgo.vertIdx + dgo.numVerts)
      22.                     {
      23.                         triIdx_to_SourceGameObject[triIdx] = dgo.gameObject;
      24.                         break;
      25.                     }
      26.                 }
      27.             }
      28.         }
     
  30. egleiser

    egleiser

    Joined:
    Aug 9, 2015
    Posts:
    4
    Does this work with polyspatial on VisionOS? Are the shaders required at runtime post batching? If so, I could try converting them to shadergraph.
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Are you asking about Mesh Baker? It works with any shader that uses texture properties that are mapped onto meshes using the UV channel. Most shaders work this way. You should be able to use whatever shaders your project is currently using. It is very common to use Mesh Baker on VR projects. I am 99% certain that it will work with VisionOS. If there are any issues, let me know and I will try to fix them.
     
  32. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Hey @Phong, I'm struggling to understand what is happening in this particular situation - can you please help?

    Here's the situation. There is a mapping from a single source material to a single target:

    upload_2024-2-3_20-4-31.png

    The source material looks like this:

    upload_2024-2-3_20-5-8.png

    When I baked it, I was expecting it to create a base map containing that blue-gray base color. But instead, it ignores it. This is what I get:

    upload_2024-2-3_20-6-15.png

    "Blend Non-Texture Properties" is checked on the Texture Baker.

    Any ideas what's going on? Am I missing a step?
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    I haven't tried to reproduce the issue yet but I suspect this is a bug. The color tint is probalby white because the Blend Non Texture Properties Texture Blender sets the color tint to white and assigns a color atlas. to the BaseMap property. However the color tint atlas is not being generated and assigned because there is only one color. Next week I will look into this case.


    You could manually fix this by assigning the the source material to the combined mesh. I will look into it so that this will be automatically handled in the future.
     
  34. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Oh, that makes sense. There will be multiple color tint materials in this batch - it was my first test.
    I’ll see what happens when there are multiple.
     
    Phong likes this.
  35. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    765
    Is there a way to keep the current pivot point of a mesh after baking? I have a prefab with several child meshes and I want to bake the child meshes such that they keep their pivot point. The only choices are World Origin, Bounds Center, and Custom Location. I don't want the pivot point to be the Bound Center, and I can't choose World Origin because the child meshes have offsets and rotation to parent. So that leaves just "Custom Location", but I don't really know what values to set it at. I was hoping there was an option to just keep the pivot location at it's original location.

    upload_2024-2-4_17-15-6.png
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    You want to use the Batch Prefab Baker. It is designed for exactly this situation. It looks after keeping the original pivots of the meshes.

    I should also mention that you can use: output = 'bake mesh assets in place' if you want more control. The Batch Prefab Baker uses this under the hood. If you place the Renderers at pos=0,0,0 rot=0,0,0 scale=1,1,1 then the pivots will be identical to the original mesh pivots.

     
    Last edited: Feb 7, 2024
  37. yokobe0012

    yokobe0012

    Joined:
    Nov 2, 2021
    Posts:
    16
    I encountered some problems using mesh baker in my project. My project is 2D, but above it is the mesh renderer component. I want to merge multiple hierarchical meshes into one mesh when merging meshes. , like this, how should it be merged?
     

    Attached Files:

  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    That should work. Can you describe the problems are you seeing?
     
  39. yokobe0012

    yokobe0012

    Joined:
    Nov 2, 2021
    Posts:
    16
    To be precise, I converted the Sprite animation into GO of SkinMeshRender and MeshRender components, and then I wanted to merge the meshes on it into one mesh, but because it is 2D, the merged meshes are not sorted one after another.Can I modify the script myself so that the merged mesh has an offset on the z-axis? Or is it already supported but I didn’t find it? If you have any ideas, please let me know.
     
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    I am not sure that I understand what you mean by "are not sorted one after another". The image you posted looks like flat planes that are separated by a distance. When you bake into a combined mesh is this happening?

    Re: offset on the z-axis. Is the pivot of the combined mesh the problem? You can control the pivot for the combined mesh using this feature:
    upload_2024-2-22_8-37-39.png

    You can also control it by setting the pivot to "World Origin" and arranging your objects around the world origin. When you bake, the world origin becomes the pivot of the baked mesh.

    Does this answer your questions?
     
  41. yokobe0012

    yokobe0012

    Joined:
    Nov 2, 2021
    Posts:
    16
    Sorry for not making it clear before. In fact, the effect I want is to merge several 2D plane meshes into a mesh with a z-axis offset. I tried changing the z-axis offset of each mesh of the prefab before baking, and offset from the z-axis, but after merging, they are still classified into one z-axis 0.
    The good news is that I have solved this problem and just need to offset the vertices of each mesh on the z axis to achieve the effect I want.
     

    Attached Files:

    Last edited: Feb 23, 2024
    Phong likes this.
  42. emomartian

    emomartian

    Joined:
    Sep 30, 2013
    Posts:
    5
    Hello!

    I love Mesh Baker and have been using it for years.

    Is there a way to distribute generated meshes in Asset Bundles?

    I am building a game that needs to run on mobile devices, so I am using MeshBaker to bake the geometry of levels. This reduces draw calls significantly, but the combined mesh of cliffs, rocks, and other nature features is very large. To reduce the build size, set the baker to generate Prefabs and then included the meshes + prefabs in an asset bundle.

    However, when I actually build the game, the generated meshes continue to contribute to the build size, implying they are being added.
     
  43. x4000

    x4000

    Joined:
    Mar 17, 2010
    Posts:
    353
    This is just how asset bundles and unity work, it has nothing to do with any particular middleware. If you're referencing anything in a scene, then that goes in the build. To move it out of the build, you need to not have it referenced in the scene, and then load it via custom code -- if you're using asset bundles.

    If you want to use addressables, then that's a new flow built on top of asset bundles, and I have not looked into it yet. My understanding is that might be more friendly to non-programmers.

    In general, to build asset bundles prior to addressables, you can't even build an asset bundle without writing custom code hooks to do it. Nothing about asset bundles prior to addressables "just happens," it's all very specific and explicit code. I think addressables was built to resolve that to an extent, but I honestly haven't looked into it much.
     
    Phong likes this.
  44. emomartian

    emomartian

    Joined:
    Sep 30, 2013
    Posts:
    5
    Hello! Thank you for the reply.

    I'm already using Asset Bundles for my game and they are working as I'd expect them to. All of the meshes that I am feeding into Mesh Baker (as well as the textures) are loaded in Asset Bundles and this drastically reduced my build size prior to baking the scene's rock formations. I don't understand why I had no issues pulling meshes and textures I created myself out of the build using Asset Bundles but am unable to do so with meshes created by Mesh Baker.
     
    x4000 likes this.
  45. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    I think there must be a reference in the scenes and assets included in the initial build executable to the combined meshes. Have you tried using a tool like "Asset Usage Detector" to find the references:

    https://assetstore.unity.com/packages/tools/utilities/asset-usage-detector-112837
     
    x4000 likes this.
  46. emomartian

    emomartian

    Joined:
    Sep 30, 2013
    Posts:
    5
    Phong likes this.
  47. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Did this work out for you? Was there a reference?
     
  48. Volkerku

    Volkerku

    Joined:
    Nov 23, 2016
    Posts:
    115
    Why do I get an error message "Need to set Texture Bake Result on MB (MB3_MeshBaker)". Try to cobine a series of skinned meshes with MB3. I want to keep materials as is and bake ito a new asset. As below:
    upload_2024-4-18_14-16-18.png
     
  49. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    The problem is "output = bake mesh assets in place". This will not create a single combined mesh. Each mesh will remain separate with UVs adjusted for the combined material. If there is no combined material then there is nothing to do. You want to use "bake into prefab" or "bake into scene object"
     
  50. DevCriel

    DevCriel

    Joined:
    Mar 11, 2021
    Posts:
    5
    Hello, Phong,

    I recently purchased your product and am impressed by the significant improvements in batch saving and FPS it offers. However, I have a few questions and suggestions regarding its use:

    • I found the texture-baking process quite demanding, taking up to two hours for a scene with 906 meshes. I attempted to utilize the TextureArray features, but I noticed that the "Build Texture Array Slices From Objects To Be Combined" function triggers numerous calls to AssetImport.SaveAndImport. I believe performance could be enhanced by batching these operations. Although I tried to modify the code myself, I found it challenging due to its complexity and my limited understanding of the MeshBaker Asset. Could you please consider incorporating AssetDatabase.StartAssetEditing and AssetDatabase.StopAssetEditing in the next update to optimize this process? More information on these methods can be found here:

    • https://docs.unity3d.com/ScriptReference/AssetDatabase.StartAssetEditing.html
      https://docs.unity3d.com/ScriptReference/AssetDatabase.StopAssetEditing.html
    Updating the importer only when it has been marked as dirty could be another option for performance:

    • While experimenting with the texture array, I encountered an issue where I could not "bake materials into a combined material," receiving the error: "Combined Material is null please create and assign a result material." I am unsure what "a result material" refers to. Is it in the Texture Bake Result SO, or is it the Combined Materials? I discovered that activating the "Build Source To Combined Mapping From Objects To Be Combined" option seems necessary, but I do not understand why this step is required. This part of the process was not clear in the documentation, and I apologize if I missed it. Could you please explain how to correctly set the Result Materials as a parameter in ConfiguerMultiMaterialsFromObjsToCombine?
    Thank you for considering my feedback. I look forward to your response.

    Best regards,
     
    Last edited: Apr 26, 2024