Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. Brenton

    Brenton

    Joined:
    Apr 4, 2013
    Posts:
    18
    Thank you for the quick reply.

    This still seems to show prebuilding the objects in the editor before running (dragging, dropping, etc.). I am looking for a completely runtime solution to solve my example. There is no foreknowledge as to which options the player will choose, therefore the combining needs to happen during level loading/setup phase from a script. Is that a possibility with this tool? Are there any examples? I have watched the latest tutorials and they don't seem to cover doing this steps at runtime.
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    There is an example scene in the project that customized the character at runtime. You can press a button to switch between "bare chest", "hoodie", "broken arm" body parts at runtime. The separate body part meshes are prepared using the workflow shown in the video in a modeler and the editor. They can be combined at runtime once prepared.
     
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    The example scene includes the script and rig for runtime character creation
     
    Brenton likes this.
  4. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    Ah, that's disappointing. I would love to see in the future an option to cull faces from a cube volume.
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I will try to make this a priority.
     
    dock likes this.
  6. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    I just want to create a texture atlas for a character because it's arms, legs, eyes, feet, etc all have separate materials. However, I don't want to combine the meshes. Is that possible?

    I went through the tutorial and was able to generate an atlas, however, I'm not sure how to make the original meshes use the atlas instead of the individual materials.

    upload_2022-8-17_23-56-17.png
     
    Last edited: Aug 18, 2022
  7. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    Did you ever figure that error out?

    "SkinnedMesh (eye (UnityEngine.GameObject)) in the list of objects to combine has no bones. Check that 'optimize game object' is not checked in the 'Rig' tab of the asset importer. Mesh Baker cannot combine optimized skinned meshes because the bones are not available."

    I have 'optimize game object' unchecked and I'm getting this error as well.
     
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    You can do this with the Batch Prefab Baker.

     
    Last edited: Aug 18, 2022
    lclemens likes this.
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    There are two reasons I can think of for this happening.
    1) "optimize game object'
    2) The skinned mesh is a prefab that was created from a "Model Importer Prefab". When the prefab was created, the "eye" transform(s) were deleted or not copied to the prefab. This "bone" is missing.

    If you are willing to share the model I could take a look at it to see if I can discover what is going on. You can contact me using my support email: contact.digitalopus@gmail.com
     
  10. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    I was able to get it working by re-exporting it from blender.
    Thanks, that did the trick!
     
    Phong likes this.
  11. Amentag

    Amentag

    Joined:
    Mar 8, 2020
    Posts:
    3
    Hello.

    Thank you for this asset. I watched all the videos but now iam a little bit lost trying to use it to optimize an environment that is way too heavy for mobile.

    lets say that i have the following environment composed with containers of different colors and i have splitted them into different groups/clusters:
    upload_2022-8-22_20-9-31.png

    I have followed the video called "Batch Prefab Baker" and i have now a scene with Containers sharing the same Atlas.

    Now i would like to combine the meshes of each clusters, how can i easily achieve this please?

    Do i need to duplicate my combined material and apply it to each of my clusters as said in the video?
     
    Last edited: Aug 23, 2022
  12. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    You don't need to duplicate the combined-material/atlas. You can have multiple MeshBaker components sharing the same combined-material/atlas.

    Usually you want to combine meshes that are close together so that off-screen geometry can be culled. However,
    it looks like the containers are very low poly (24 verts per container?). This means that the culling cost of processing the extra-off screen vertices is fairly low. I would try combining everything in one big mesh, or three combined meshes (The middle quad-cluster, outer-ring boxes split into two).
     
  14. Amentag

    Amentag

    Joined:
    Mar 8, 2020
    Posts:
    3
    Thanks for the answer.

    Is there an easy way to combine meshes of different cluster in an environment?
    I did it, but i created 1 mesh baker per cluster and i combined them 1 by 1:
    upload_2022-8-23_21-49-3.png

    Iam not an expert but the containers seems to be heavy. My scene cant even load on mobile even after combinning meshes and textures:
    upload_2022-8-23_21-52-30.png
     
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hmmm, those containers do look heavy. I had thought they were simple cubes. 17k * 40 meshes is .5 Meg Verts. That is a lot for mobile. You are probably GPU bound. Your bottleneck is not the drawcalls, it is that the GPU is not able to process that many vertices and triangles.

    You probably want to simplify the model so that it is a convex box on the outside and concave box on the inside with a missing wall. Then, in a modeling program like blender, generate a normalMap by projecting the high poly geometry onto the low poly crate. Then use directional lightmaps in your scene. With this technique you should be able to get the verts down to less than 100 verts per crate. You can bake them together into one or three clusters to get the drawcalls down. A scene set up that way should look great and render very fast on mobile devices.
     
  16. hjupter2

    hjupter2

    Joined:
    Dec 3, 2013
    Posts:
    15
    hey @Phong I'm having problems when using "multiple combined materials" I've tried everything but when I try to bake (at runtime) I'm always getting that error even if there is a material with that name in the Texture Bake Result file, I had to rename materials and remove (Instance) since I'm doing this at runtime.
    These characters has multiple skin meshes with multiple materials and at run time and colors can be customized.
    Any ideas?
     

    Attached Files:

  17. Phong

    Phong

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

    I presume that the atlas is being generated in the editor? I think that what is happening is that one (or more) of your materials is being duplicated on your mesh before baking. When your try to bake, Mesh Baker doesn't recognize the duplicated material even though it has the same name.

    The most likely cause is that you have a runtime script that accesses:

    Code (CSharp):
    1. Material  myMaterial = mySkinnedMeshRenderer.material;
    When the "SkinnedMeshRenderer.material" property is accessed, Unity quietly duplicates the material on the mesh, applies it to the mesh and returns a reference to the duplicate (see https://docs.unity3d.com/ScriptReference/Renderer-material.html). Then, if you decide to use that mesh later with Mesh Baker, the duplicate material is not recognized as one that was baked. The easiest solution is to use:

    Code (CSharp):
    1. Material  myMaterial = mySkinnedMeshRenderer.sharedMaterial;
    This does not duplicate the material. Let me know if this is not the problem.
     
    Last edited: Aug 26, 2022
  18. hjupter2

    hjupter2

    Joined:
    Dec 3, 2013
    Posts:
    15
    Thanks that fixed the problem but now I need to be able to rebake the character with different configurations so I was trying to remove previous game objects but I'm getting this error and after trying to add gos and bake again it doesn't work.

    upload_2022-8-29_13-52-0.png
     
  19. hjupter2

    hjupter2

    Joined:
    Dec 3, 2013
    Posts:
    15
    Actually I got it working but there is a remaining problem, colors should be different but right now they are always the same.
    I thought it was something with mesh baker but I think the problem here is that I'm using sharedMaterials instead.
    upload_2022-8-29_14-12-44.png
     
  20. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hmmm, may need more information about your setup. It looks like there are two source characters that you are baking together. Do the source characters use different source-materials? Have both of these source-materials been texture baked into an atlas-material? (Look at the atlas texture after baking to see that both source materials have been baked in.)

    If so then, at runtime, you should be able to bake the two characters into a combined mesh that uses the atlas-material. Each character will need to be using its original source-material at the time of baking. If both characters are using the same green-source-material at the time of baking then they will use the same "green" part of the atlas material and look green like in your picture. If they are using different source materials then they should look different.
     
  21. hjupter2

    hjupter2

    Joined:
    Dec 3, 2013
    Posts:
    15
    They all use the same materials and yes textures are baked into the atlas as well but the materials that needs different colors doesn't have any textures.

    The problem is after changing it to use sharedMaterial it keeps the same color for all before the bake.
    What should I do make it use different materials just instantiate them?
    I was trying with property block but still unable to make it work.
     
  22. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I presume the material is using color tints? You could try the Blend Non-Texture Properties feature. It will create a separate rectangle in the atlas for each color tint.



    If you try it and get the wrong tint color let me know. I have an unreleased bug fix for the feature (currently testing). You can contact me directly at contact.digitalopus@gmail.com.
     
  23. hjupter2

    hjupter2

    Joined:
    Dec 3, 2013
    Posts:
    15
    So I managed to make this work, I had to generate a material per color and all the variations with the different colors then bake the texture with all that.
    Thanks!
     
    Phong likes this.
  24. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Mesh Baker does work with URP. Most of my users are VR and Mobile developers.

    Regarding Mesh Baker vs. Mesh Combine Studio.

    Disclaimer: I do not own Mesh Combine Studio and I have not tried to use it. My comments here are based on the asset store description.

    I did not see anything on Mesh Combine Studio's info page about creating atlases. Mesh Baker is all about creating atlases. If you have several props that use similar shaders but different materials then these props cannot be combined or batched together. Mesh Baker can combine these materials into a single combined-material using atlases. When most of your props share the same material it is much easier to combine meshes together to reduce drawcalls. Here is a quick overview video explaining how this works with Mesh Baker.

     
  26. Ceylan12

    Ceylan12

    Joined:
    Dec 24, 2016
    Posts:
    113
    Hello, I'm using the Mesh Baker and loving it but one of the things that I can not understand is that the build size increase after bake which is caused by "levels" size in BuildReportLog.txt. I think the mesh data's are taking this space. Is there a way to decrease this size? Maybe a mesh stripping?
     
  27. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    Dies this work for oculus VR URP?
     
  28. Phong

    Phong

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

    One thing that can cause the increase in Scene size is converting Mesh "instances" to one large mesh. When you have one prop that is used many times in a scene, Unity only has one copy of the Mesh in memory and uses that Mesh many times. When meshes are combined then each "instance" gets copied into the combined mesh with its vertices transformed. This happens with Mesh Baking and with Static Batching. If you have a lot of props copies in your scene then this can really boost scene size. A few quick things to check:
    • Make sure that if you have any Mesh Bakers in your scene that they are configured to "clean up after bake"
    • For your combined meshes ensure that static batching is disabled. These are very likely very large meshes. Static batching will just make a duplicate of the mesh.
    Another solution is to bake the meshes art runtime (during level load). This solution will ship the levels with small Mesh instances and only generate the large combined meshes on the players device.
     
    Ceylan12 likes this.
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Yes, Mesh Baker works with URP. VR and mobile developers are my core user base.
     
  30. Ceylan12

    Ceylan12

    Joined:
    Dec 24, 2016
    Posts:
    113
    Hello, thank you for an answer. The sizes of the meshes are same as before, since I'm using MeshBaker to decrease the material count.

    All the mesh bakers are configured to "clean up after bake" and also the static batching is disabled on entire project.
    It might be much better to bake on runtime but can I still use baked light map while doing that, is there an any workaround. Thank you.
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I believe that using a baked lightmap will work. Make sure that auto generate lightmaps is off. In the editor, generate the combined mesh, lightmap it, for the combined mesh grab and store the:
    • combinedMeshRenderer.lightmapIndex
    • combinedMeshRenderer.lightmapScaleOffset
    then delete the combined mesh.

    Then... at runtime, bake the meshes and assign the lightmapIndex and lightmapScaleOffset to the new combined mesh.
     
    Ceylan12 likes this.
  32. moriyer

    moriyer

    Joined:
    Jan 21, 2019
    Posts:
    1
    Hello~
    I love MeshBake very much!
    I have a question that:
    could MeshBaker bake mesh acorrding to lightmap uv---------generate uv2 acorrding to lightmap offsetscale, replace uv with uv2. result of altas is like way rather than block tiles
    upload_2022-9-11_3-9-45.png
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Mesh Baker can do some of what you want.

    If you use the "lightmap UVs -> Copy UV2 To Separate Rects", setting then a new UV2 layout will be generated considering each object's lightmapScaleAndOffset. I think this is the UV2 layout that you want. However Mesh Baker does not provide a way to move the UV2 channel of the combined mesh to the UV channel. You would need write a script to do that. It is fairly easy to write such a script. Let me know if you need help with that script.
     
  34. Bagazi

    Bagazi

    Joined:
    Apr 18, 2018
    Posts:
    611
    Hi here,
    I am new to Mesh baker, In my case ,I got many exactly same adjacent blocks which make a floor in Unity(All of them are static objects). Maybe Unity will batched them cause they are static, but it looks invalid when made a oculussion baking. I expected them to combine into an entire floor that could bring a good oculussion effect. But I failed. So will it useful by baking the mesh into one using mesh baker? And the textures can remain the original single one?(Cause all the materials are the same,the texture is just a 512*512 png file )..
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Static batching is complex. You won't see a "combined static mesh" renderer in your scene. You can tell if it is working by pushing "play", pausing the game and checking one of your static renderers. It should have a MeshFilter where the mesh field says "combined mesh". Note that with static batching, renderers that are included in the batch can still be culled by LODGroups, Occlusion culling, and disabling the object. You can also see a high number of drawcalls with static batching this is deceiving because these "static-batch" drawcalls are very cheap. It is setpass calls you should be paying attention to.

    You can use Mesh Baker to create a single combined mesh. If all your props use the same material then then this is easy using the MeshBaker component. If your objects used different materials then you can use the TextureBaker to create a combined material then use MeshBaker to combine them. I would suggest looking at my youtube tutorials to see the different workflows.
     
  36. EPS_TA

    EPS_TA

    Joined:
    Sep 27, 2021
    Posts:
    1
    Hi!
    We are trying to implement custom texture blenders for some of our custom shaders (for texture and non-texture based values). In the Blend Non-Texture Properties video, a secondary video is mentioned "advanced tutorial on creating custom texture blenders" with more information on this subject. However we were unable to find it.

    Does it have an alternative name? Or maybe its still in the works?
     
  37. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Sadly that video is still being planned. Sorry.
     
    EPS_TA likes this.
  38. ARVRtech

    ARVRtech

    Joined:
    Aug 21, 2012
    Posts:
    16
    Hi there, thank you for this amazing tool!

    Does anyone know how to fix this error:
    [PathTracer] Failed to add geometry for mesh ''; mesh contains non-finite values.

    This error appears when I start the light baking process in unity Lighting settings.
    I already used Mesh Baker to bake texture atlases and meshes for various different assets in the same scene without any problem. All except the walls and shelves in the images below.

    The Generate Light (for light baking) process will not start until I remove the problematic meshes from the scene.
    Here's a scene preview:
    image.png

    These are the settings in the baker:
    image (1).png
    Baked the texture atlas and I use Diffuse, Metalic-Roughness and Normal Atlases for the baked material for those meshes.

    Used only simple models to create prefabs for this scene.
    image (2).png
    The meshes are really simple and clean. No floating vertices, overlapped edges, faces, etc.
    I generate lightmap UVs in Unity Editor during import and later when baking with Mesh Baker.

    And this is how the texture atlas for diffuse looks like:
    Room_Atlas_01a-mat-_MainTex-atlas-0.png

    I already managed to texture and mesh bake many other assets using Mesh Bake in the same scene, but the walls, shelves and these light assets always report error and block light baking.

    Does anyone know what's causing this issue?

    Thanks a milion!
    Boris
     
    Last edited: Oct 3, 2022
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Boris, it looks like the problematic meshes contains values that exceed the floating point range (too large or too small). Or possibly numbers that have divide by zero errors. These are encoded in a floating point number as Infinity, negative infinity or not-a-number. Are these problem meshes the combined meshes or do the source meshes cause this issue too? If it is the source meshes then these will need to be fixed. You will need to get the verticies, normals, UVs etc... from the mesh, find the INF-values and replace them with something reasonable. Or you could export these meshes to a modeling program. Fix the values there and re-import them to Unity.

    If the source meshes are fine, but the combined mesh has INF and NAN values then I would like to take a look at this. Is it possible to export a simple Unity package with a scene that reproduces these errors that I can look at (you can contact me directly)?
     
  40. ARVRtech

    ARVRtech

    Joined:
    Aug 21, 2012
    Posts:
    16
    Hi, thanks for such a quick reply!

    I managed to track down the problematic mesh.
    It was the TextPlus object from 3DS Max:
    image (3).png

    Mesh should probably be remeshed before export. Something like in the image below but I just deleted the damn thing from the scene it costed me too much time before a deadline :D
    image (4).png

    The Mesh Baker worked like the charm after that! I managed to texture, mesh and light bake the whole scene in a couple of minutes.

    Cheers and all the best!
     
  41. jirimotejlek

    jirimotejlek

    Joined:
    Nov 8, 2016
    Posts:
    20
    Hi, I'm trying to use Batch Prefab Baker to create a Texture Array and write the slice index to my prefabs. I can create the texture array with a number of slices, that part works.
    But I can't write the slice IDs in the UVs. It appears that the Mesh Customizer script is never run when pressing "Batch Bake Prefabs", even though I assigned it in the Mesh Baker script. Is that an intended behaviour? Does Batch Prefab Baker not work with Mesh Customizer script
    (Mesh Baker 3.35.1, Unity 2021.1.28f)
     
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hello, this should work. I have used the Batch Prefab Baker with Texture Arrays. Just to be clear, you assigned the mesh customizer to the Mesh Baker that is on the same GameObject as the Batch Prefab Baker?

    Also how are you verifying that the slice index is not in the UVs?

    I will look into this. I may not get back to you until tomorrow because I have commitments today.

    [UPDATE] I am able to reproduce the issue. I will look into this, although I am not able to work on it until tomorrow.

    [UPDATE] It now seems to be working and I am not able to reproduce the issue anymore.

    I assigned the MeshBaker/Examples/SceneBasicTextureArrayAssets/MeshAssignCustomizerPutSliceIdxInUV0_z

    To the BatchPrefabBaker0->MeshBaker Settings: "Assign To Mesh Customizer"

    I added a line to the file CustomizerPutSliceIndexInUV0_z.cs that prints a debug.Log if the resultType is not 'atlas'. This message is appearing in the console.

    Also when I use the example texture array shader included with MeshBaker, the textures display correctly on the mesh which could only happen if there are valid UV values in the mesh.

    How are you checking that the mesh doesn't have slice index in uv.z component?
     
    Last edited: Oct 5, 2022
  43. jirimotejlek

    jirimotejlek

    Joined:
    Nov 8, 2016
    Posts:
    20
    Thank you for the quick relply and for looking in to it!
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I updated my reply, When I started working on this today it was working.
     
  45. jirimotejlek

    jirimotejlek

    Joined:
    Nov 8, 2016
    Posts:
    20
    Upon reviewing the code I think I see where the problem is now. The Mesh Customiser is only supposed to work when you click "Bake" in Mesh Baker. I expected it to work when clicking "Batch Bake Prefabs" in Batch Prefab Baker. My apologies, I didn't notice initially because all my meshes have the same name so when I click "Bake" in Mesh Baker it results in one result only as the meshes keep overwriting each other.
     
  46. Phong

    Phong

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

    The Mesh Customizer does work for me when I click "Batch Bake Prefabs". I will take another look at this to see if I can discover why it is not firing in some cases.
     
  47. Paspartout

    Paspartout

    Joined:
    Apr 21, 2020
    Posts:
    2
    Hello there.

    I have a scene with a lot of materials(70) and want to use MeshBaker to reduce the number of SetPass calls and batches without creating new meshes using the Batch Prefab Baker. It works nicely but I had the problem that it is pretty slow. For around 300 Meshes in a single prefab it takes 5-10 Minutes. For each replaced mesh it seems that Unity reimports the target prefab and redraws the preview of the mesh which makes everything slow from what I can see in the profiler:



    My use case might be a different than usual. All I want is converting a single prefab with a lot of meshes and materials to a copy where the meshes and materials are replaced with the batched variants.
    Alternatively I guess I could try splitting the big prefab up into multiple ones but I am not sure if that will help in the end when I wanna replace a single texture for example.

    I tried to improve the performance a little bit by not saving the generated meshes on each prefab at the end of the whole process and using `AssetDatabase.DisallowAutoRefresh` but Unity still wants to reimport the modified saved prefab with each modified mesh it seems. Might investigate further in the future.
    Have you considered this use case? I would really appreciate an improvement in performance there but I can see Unity and its Asset Pipeline being confusing.

    I am using the most recent version of MeshBaker together with Unity 2019.4.31f. Thanks!
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hello, I will keep this in mind although I consider this to be an unusual use case. Usually the separate props are put each in their own prefab.

    Is your prefab used in one or more scenes? I know that modifying a prefab that is used in many places takes a long time to update. Modifying a prefab that is not used anywhere updates very quickly. You might be able speed this up by making a duplicate of your prefab, Batch Baking that, and then replacing the original prefab with the baked duplicate. However with this strategy, if there are references in your scene to GameObjects and components inside the prefab instance then these references will break.
     
  49. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hello,

    I spent some more time looking into this and am not able to reproduce the problem. When the AssignToMeshCustomizer asset is assigned to the MeshBaker that is attached to the BatchPrefabBaker, then the UVs are modified for me when I press: "Batch Bake Prefabs". I am not sure why this is not working for you.
     
  50. qqepijackxu

    qqepijackxu

    Joined:
    Jun 14, 2019
    Posts:
    26
    Hi and thanks for this great asset! Question: I have 6 textures: 3 x 1024 and 3 x 2048. I would like to bake them into on 4096 x 4096 atlas (just like in the image). I've tried multiple settings without luck. For some reason it shrinks 2048 textures into 1024 even though i've set the maximum atlas size 4096. It does work when 1k and 2k materials are separated but combining these into 4k is also problematic. Any suggestions?

    Thanks!
     

    Attached Files:

    • 2048.png
      2048.png
      File size:
      47.2 KB
      Views:
      129