Search Unity

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:
    2,085
    OK, so I tried the following and this workflow does work although it feels very sketchy.
    • In edit mode, create a prefab containing an empty game object for each character
    • Enter play mode and navigate to a scene that has some characters you want to bake.
      • It is probably best if the characters have an animation that plays the "T pose" playing
    • Do this for each character you want to bake (while still in play mode)
      • Create a TextureBaker and MeshBaker
      • TextureBaker
        • Create Empty Assets For Combined Material. This will create Project Folder assets.
        • Configure bake settings
        • You may need to use "Mesh Baker Texture Packer Fast", you can only use "Mesh Baker Texture Packer" if all the source textures are readable, uncompressed, true color. You may be able to find the source images in the project and set them to this before entering playmode if you want to use "Mesh Baker Texture Packer".
        • Bake the textures
      • Mesh Baker
        • Output -> Bake into Prefab
        • Assign one of the empty prefabs you created earlier
        • renderer = skinned mesh renderer
        • Configure Bake Settings
        • Bake
    • Exit playmode. You should have a prefab and atlas for each character.
     
    shyamarama likes this.
  2. trojant

    trojant

    Joined:
    May 8, 2015
    Posts:
    89
    Thank you for your reply. Using your method, I tried to merge three AIcharacters,But it is not generating bake textures, and the animation of the characters is still. I feel that meshbaker can't work with UMA.
     

    Attached Files:

  3. CJA_888

    CJA_888

    Joined:
    Sep 12, 2019
    Posts:
    15
    Hi,phong
     
    Phong likes this.
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Regarding the animation, you may need to set the Animator culling settings to "Always Animate".
    Regarding the baking. Were there error messages? Did you try the Texture Packer Fast?

    It may be that you are right and it is not possible. It may be that character controller is also being assembled at runtime which may also need to be saved as an asset.
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Did you have a question or query?
     
  6. CJA_888

    CJA_888

    Joined:
    Sep 12, 2019
    Posts:
    15
    I bought and used Mesh Baker, which is a great tool.But I had a little problem using it.When I bake some trees, I choose to use multiple combined materials.But Baker couldn't read all the maps when I combined them.

    I also used the Custom Shader Propert Name option in Baker, but still didn't recognize all the maps.

    I used Unity2020 and made shader with the Amplify Shader Editor tool.
     
  7. CJA_888

    CJA_888

    Joined:
    Sep 12, 2019
    Posts:
    15
    I have sent the general questions to your email by screenshot, and my email address is hannqi@live.com.
    If you have time, please help me with this problem. Thank you very much.
     
  8. CJA_888

    CJA_888

    Joined:
    Sep 12, 2019
    Posts:
    15
  9. Phong

    Phong

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

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    upload_2020-11-21_10-42-37.png

    To clarify, when you select the shader in the project, this is the name that you need, with correct capitalization.
     
  11. CJA_888

    CJA_888

    Joined:
    Sep 12, 2019
    Posts:
    15
    Hi, Phong.I changed the name of Properties according to what you said and I succeeded. Thank you very much.

    But Now I have a new problem, I hope you can help me again.

    please look at the picture.
    The picture:https://drive.google.com/file/d/1ViK5wlGEylzPQUlk-avXCrx84nULx7xx/view?usp=sharing

    I successfully combined all the texture, and then I used the Bakery tool to bake the lightmap, but the baked result showed some black blocks.Since the baking tool calculates the lighting information based on the ASE Shader on the right of the image.

    I wonder if it's because the bakery tool in the top left of the image use a textual-packing and unpacking feature called XAtlas inside of it.Here is xatals website: https://github.com/jpcy/xatlas.
    Do you have any solution to this problem?pls help me,Thank you so much.
     
  12. AndrewCzarnietzki

    AndrewCzarnietzki

    Joined:
    Jul 23, 2013
    Posts:
    189
    Hey, I just purchased mesh baker, but I'm getting a lot of warnings in Unity 2020.1.8f1:

    Assets\MeshBaker\Editor\core\MB_BatchPrefabBakerEditorFunctions.cs(649,13): warning CS0618: 'PrefabUtility.ReplacePrefab(GameObject, Object, ReplacePrefabOptions)' is obsolete: 'Use SaveAsPrefabAsset or SaveAsPrefabAssetAndConnect with a path instead.'

    How critical are these? Is there a newer version, and or what's the update path?
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hello, mentioned that you combined the textures, I presume you also combine the meshes and this picture is the lightmapping on the combined meshes? The problem is probably overlapping UV islands on the UV2 channel. When you baked the meshes what Lightmap UV settings did you use?

    You probably need to bake the meshes with one of these two Lightmap UV settings:
    • Generate new UV2 layout
    • Copy UV2 to separate rects
    These settings will generate UV2 channels with no overlapping islands. Then it should work.
     
  14. Phong

    Phong

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

    I just coded up fixes for these last week. The fixes will be in the next version which should come out mid-late December. The warnings are not harmful. I have tested up to Unity 2020.1 and the code that uses these works in all versions. Thanks for mentioning this.
     
  15. CJA_888

    CJA_888

    Joined:
    Sep 12, 2019
    Posts:
    15
    Picture (It worked!!But there's one small problem):https://drive.google.com/file/d/1miUmn-Yc7VJTzSY2C_hUm_zwzc655OEX/view?usp=sharing

    Yeah, we did it.Thank you phong. Almost all the problems have been solved, but there is still one small problem.The two trees combine to share one texture altas, so they also share all of their properties.So the problem is, when I adjust the properties, one tree looks great, but the other looks ugly.Very vexed.Do you need to adjust the attributes in shader and export their maps before combining them?
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    This is a hard problem to solve.

    Mesh Baker does have a "Blend Non-Texture Properties" feature that tries to blend the properties as textures are added to the atlas. However it requires "TextureBlender" scripts that contain knowledge of how the shader uses the properties internally. Mesh Baker includes some TextureBlender scripts for shaders similar to the Standard shader, but your shaders are unusual. Writing the TextureBlender script would probably be hard.

    Another solution could be modify the shader so that instead of using the slider properties it has one more Texture property.
    • AO Power = red channel * 100
    • Meatiliness = green channel * 100
    • Normal Power = blue channel * 10
    Then you could assign a small texture to each material and bake one more atlas.

    I am not sure if this is more work than it is worth. Are you using this shader in a lot of places.
     
  17. Toby31

    Toby31

    Joined:
    Jul 7, 2014
    Posts:
    70
    Hi,

    looking to purchase mesh baker and was wondering if it was compatible with sectr complete 2019? from my limited knowledge the two seem a little counter intuitive. Just wanted to check before I made the purchase as I'm currently researching optimisation. has anybody had any experience of using the two together?
     
  18. Phong

    Phong

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

    Regarding compatibility, I don't have sectR so I cannot guarantee complete compatibility. However I think it depends on how you want to use Mesh Baker (there are a lot of different ways to use it). Mesh Baker can create prop prefabs that share materials. These are ordinary Unity prefabs using ordinary Unity meshes. I am 99.9% certain that these prefabs would work with Sectr. Mesh Baker can also be used to create customizable skinned mesh characters which should work fine with Sectr.

    There are some workflows that would likely interfere with each other. The most likely problematic bit is the "MeshBakerGrouper" which helps collect objects in the scene that are close together so they can be baked into one or more combined meshes. I think it would be important that all these meshes be in the same "Sectr-Sector". I am not sure if the Sectr workflow would play nicely with the MeshBakerGrouper workflow. Note that you can still combine meshes without the MeshBakerGrouper, it is just more work to collect them into a list.
     
    Toby31 likes this.
  19. mindravelinteractive

    mindravelinteractive

    Joined:
    Jun 26, 2018
    Posts:
    15
    Hi,
    Can i use this to atlas textures but not meshes? I have 30 different meshes using different textures, I need them to use one single texture but I don't want to combine the mesh. How is it possible?
     
  20. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    You want to use the Batch Prefab Baker. This will create a combined material and duplicate your prefabs to use the combined material. You can use these duplicated prefab in your scenes in place of the originals. Mesh Baker includes a tool for switching prefabs in the scene.

     
    mindravelinteractive likes this.
  21. aler_buffon

    aler_buffon

    Joined:
    Dec 9, 2015
    Posts:
    22
    Hi Ian. On the project in which I participate, we are dealing with a large number of tiles and trim textures, cutting the geometry into squares for further packaging takes too much time. Therefore, we use manual assembly, which also takes quite a lot of time, and also not as flexible as if it was baked through a mesh Baker. Our textures have different sizes, as an example, I made a quick scene with 3 buildings, it has a vertical atlas of 4096 by 512 pixels, but depending on the destination, the atlas may be different, 2048x515\1024x512. The entire layout extends beyond the border of the texture canvas.
    My question is, do you plan to continue supporting horizontal and vertical atlases with upokovkaya beyond the boundaries of the Atlas?
    Sorry for my English)
     

    Attached Files:

  22. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    193
    Hi, I've already reached you through email, feel free to answer where you prefer :)

    I've been really enjoying Mesh Baker but I'm having some trouble in a specific use case.

    I have a robot that is split into many meshes and each mesh uses a different texture+material.

    Therefore I wanted to merge all the textures into a single atlas, and have the uv's in the sub-meshes changed so that they correctly point to the new material and texture atlas.

    The problem is that I can't manage to do this without baking all the meshes of the robot into a single mesh... Which is very useful in many cases but not in this one :(

    Is there any way of creating a texture atlas + material and auto swapping the original meshes by a new mesh that points to the correct uv's of the new atlas?

    So, can I bake the textures and still have the robot split into many sub meshes that use the new baked material?
    If the robot is baked into a single mesh I can't animate it any longer :(
     
    Last edited: Dec 2, 2020
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    You can use the Batch Prefab Baker to bake each part separately. The Batch Prefab Baker bakes the prefab-meshes but keeps each body part (mesh) separate. You may need to make each body part into a temporary prefab to do this. After doing this you can switch the meshes and materials on your original robot to those generated by the Batch Prefab Baker or you use the generated prefabs in place of your parts.

    Note that it is possible to use MeshBakers directly to do this using output -> "Bake Meshes In Place". But I would recommend using the Batch Prefab Baker instead. It is a much more efficient workflow.

    Something you may want to consider is baking all the body parts into a skinned mesh (MeshRenderers can be baked into Skinned Meshes). If the body parts are low poly then this is a good idea as the skinned mesh will have one drawcall vs. one per body part.
     
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Yes, I do intend to continue supporting this. I would love to hear about peoples experiences with this feature. Is it working for you?
     
  25. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    193
    I don't quite follow unfortunately. I'm trying to do the "Bake Meshes In Place" approach since I have a ton of subobjects with a ton of custom logic and cross references among the parts. So it would be ideal if the meshes and material got adjusted without affecting anything else (I know that I'll still have 1 draw call for every different sub-mesh but I'll still save a ton of drawcals).

    Anyways, after creating the texture atlas and having the shared material when I use a Mesh Baker with the Bake In Place option new meshes get created that indeed have the correct UV's of the shared material but:
    1.They don't get swapped by the original meshes
    2.The pivot point of said meshes is really far away and is not the pivot point of the original mesh (I need a correct pivot point)
    3. Since the new meshes don't get swapped in the shared material stays unused too
     
  26. aler_buffon

    aler_buffon

    Joined:
    Dec 9, 2015
    Posts:
    22
    This does not work as expected, I am using the latest available version of the mesh baker. as well as Unity2020.1.2f1. Baking of atlases is possible only with the ConsiderUV checkbox is on, it does not work without it. I recorded a short video in which I showed the difference between how a baker bakes and, ideally, how it should look))) I will also attach a package with a scene and resources from it. Thanks for the answer, maybe this will help you)
    https://drive.google.com/file/d/1y31g5qm8N7w3yjWYvydslByuiHKEha47/view?usp=sharing
     

    Attached Files:

    Phong likes this.
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    These are the reasons that I suggested the Batch Prefab Baker. The pivots will be correct if the source MeshRenderer has transform: position = 0,0,0 rotation = 0,0,0 scale = 1,1,1 before baking. This workflow is tedious and not realistically practical with a lot of source meshes. The Batch Prefab Baker looks after managing the pivots and switching the meshes and materials. You should be able to do it with this hacky workflow.

    1) Generate a prefab for each robot part. The easiest way to do this is to drag them from the scene to the project folder.
    2) Duplicate these prefabs.
    3) Set up a Batch Prefab Baker and use the duplicates as source and the orginals as target.
    4) Do the Batch Bake
    5) Select each object in your scene and "unpack prefab"
    6) Delete the prefabs in the project folder.
     
    GeriB likes this.
  28. luxregina

    luxregina

    Joined:
    Mar 3, 2015
    Posts:
    22
    Hello!
    I've tried the free version to see if it could help me optimize my game, and so far I've been impressed with the result.
    I however have one question before I switch to the full version: my textures are very small, my game is a mix of 3D and pixel-art textures. When baking them into an atlas, I saw that they were all resized to "pack" the Atlas.
    Is there a way to prevent the texture resizing, even if it leads to empty space on the atlas?
    (Resizing blurs the pixel, and cannot guarantee the same pixel density, so that would be a big no-no in my case)
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    If you disable (on the TextureBaker):
    • Resize Power Of Two
    • Force Power Of Two
    Then it should copy textures to the atlas without any resizing (Unless the atlas packing exceeds the max atlas size). With these settings your atlas will probably not be a power of two. Unity likes textures to be Powers of two and may scale your atlas to the next largest power of two. You may need to fiddle with the image importer settings on the atlas after import to get the result you want.
     
  30. luxregina

    luxregina

    Joined:
    Mar 3, 2015
    Posts:
    22
    Thanks! I checked, it works indeed!
    Knowing that those textures are not mip-mapped and not compressed (because of the pixel art), do you foresee any mobile performance issue?
    Also, in the free version, I cannot seem to be able to target the new mesh created to optimize UVs, which leads to artifacts when I'm baking the lights. Can you confirm it's not an issue I will run into once I purchase the full version?
    Here is a quick video of the game I'm working on (it's a VR game, btw), so that you get an idea of why I need the textures to be non-compressed, non-scaled, non-mipmapped >


    I appreciate your time answering! :)
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    If the textures are small then performance should not be a problem.

    Regarding mip-mapping. Mip-maps are important for rendering distant objects. Not for performance, but for jitteriness/stability of the rendered image. If you imagine a distant triangle that takes up only a few pixels on screen (eg 3x3). When UVs are sampled, if there are are no mip-maps and the source texture is largish, then completely different pixels can get sampled if there is a tiny change in camera angle. Distant objects will twinkle. Mip-maps fix this issue. If your textures will always be viewed at the same distance and always roughly the same size on screen, then you should be fine.

    Regarding lightmapping. When you bake the mesh, there is a setting for Lightmapping UVs. If you set these to:
    • generate new UV2 layout or copy UV2 to separate rects
    Then you should be able to bake lightmapping on the combined mesh.

    You might have noticed that you can't adjust the import settings of the combined mesh assets. This is because they are saved as Unity Meshes, not .fbx or .blend files which can then be imported. One option is to install the "Unity FBX Exporter" package. you can use this to save the combined mesh assets as .fbx files, which can then be "imported". You can also edit the combine meshes in Max or Blender.
     
  32. pdinklag

    pdinklag

    Joined:
    Jan 24, 2017
    Posts:
    154
    Hey!
    I'm having a small issue with normal maps baking at runtime. I am using the code below code to combine several skinned meshes into one. Basically, it all works fine: MeshBaker builds an atlas with the combined textures and I get a correctly bound combined skinned mesh.

    However, the atlas' normal map is not "activated" automatically. It looks like there is no normal map at all on the mesh after the code below has finished. To debug this, I inspected the generated skinned mesh and its material to see if a normal atlas has been generated at all. It turns out it that there is indeed a normal atlas, and as soon as the material inspector opens up, the normal map also appears on the mesh just fine.

    Now, I wonder how I can get this to work at runtime, without opening an Inspector? Is there some additional activation or update function I need to invoke on the material? I tried looking at the material inspector source code, but could not find what exactly causes the normal map to pop up.

    I am in Unity 2020.1.11. This is my code:
    Code (CSharp):
    1. private void Bake()
    2. {
    3.     // setup texture baker
    4.     _baker = new GameObject("_Bake");
    5.     _texBaker = _baker.AddComponent<MB3_TextureBaker>();
    6.     _texBaker.objsToMesh = new List<GameObject>();
    7.     _texBaker.textureBakeResults = ScriptableObject.CreateInstance<MB2_TextureBakeResults>();
    8.     _texBaker.resultMaterial = new Material(Shader.Find("Universal Render Pipeline/Lit"));
    9.     _texBaker.packingAlgorithm = MB2_PackingAlgorithmEnum.MeshBakerTexturePacker_Fast;
    10.     _texBaker.maxAtlasSize = 2048; // TODO: how to pick intelligently?
    11.     _texBaker.LOG_LEVEL = MB2_LogLevel.warn;
    12.  
    13.     // add renderers
    14.     var objs = _texBaker.GetObjectsToCombine();
    15.     var smrs = gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
    16.     foreach (var smr in smrs)
    17.     {
    18.         objs.Add(smr.gameObject);
    19.     }
    20.  
    21.     // create atlases
    22.     _texBaker.onBuiltAtlasesSuccess += OnAtlasesBuilt;
    23.     var coroutineResult = new MB3_TextureCombiner.CreateAtlasesCoroutineResult();
    24.     StartCoroutine(_texBaker.CreateAtlasesCoroutine(null, coroutineResult, false, null, 0.01f));
    25. }
    26.  
    27. private void OnAtlasesBuilt()
    28. {
    29.     // setup mesh baker
    30.     var meshBaker = _baker.AddComponent<MB3_MeshBaker>();
    31.     meshBaker.textureBakeResults = _texBaker.textureBakeResults;
    32.     meshBaker.parentSceneObject = transform;
    33.     meshBaker.meshCombiner.renderType = MB_RenderType.skinnedMeshRenderer;
    34.  
    35.     // combine meshes
    36.     meshBaker.BuildSceneMeshObject();
    37.     meshBaker.AddDeleteGameObjects(_texBaker.GetObjectsToCombine().ToArray(), null, true);
    38.     meshBaker.Apply();
    39. }
     
    Last edited: Dec 13, 2020
  33. pdinklag

    pdinklag

    Joined:
    Jan 24, 2017
    Posts:
    154
    I have two more questions I couldn't find answers for. Sorry for the double-post, but things are popping up as I'm trying to implement MeshBaker into my game. :)

    Maybe some context: I have a character creation system in my game and I'd like to combine all the attire into one mesh to boost performance.
    1. I make heavy use of color tinting, partially also without any textures, and found the considerNonTextureProperties setting. Using it does not apply any tints at all, though. Instead, I get hundreds of errors logged by this line in TextureBlenderURPLit:
      Code (csharp):
      1. Debug.LogError("TODO end " + m_smoothness + "  " + sourceMat + "  " + shaderTexturePropertyName);
      Is the texture blender not yet implemented for URP?
    2. I see that I can combine BlendShapes by activating doBlendShapes, but is there a way to just "bake" them like SkinnedMeshRenderer.BakeMesh does? My skinned meshes have many BlendShapes for customization, but they are not needed ingame, only during character creation, so I'd like to bake them to save memory.
     
    Last edited: Dec 14, 2020
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Regarding the "TODO..." line you can definitely remove that. I just checked and there are two of those lines in the file. Sorry that those debug lines were left in the latest version. My unit testing usually catches these but I am finding that it is challenging trying to support three pipelines. I Don't have a good system in place yet. The TextureBlender should work. Which version of Unity are you using and which shader?

    Regarding the Blend Shapes. There is no way to Bake them like SkinnedMeshRenderer.BakeMesh currently. You could probably do it by writing your own script:
    • Position the skinned mesh at 0,0,0, rot 0,0,0 scale 1,1,1
    • Pose the skinned mesh in its bind pose
    • Apply the Bind Pose
    • SkinnedMeshRenderer.BakeMesh
    • Copy the vertices, norms, and tangents from the baked mesh to the source mesh.

    This would probably work.

    Regarding the normal map not showing up when baking it at runtime. A few things to check:
    • Check that the result material does indeed have a normal map applied in the bump map property slot.
    • Check that texture is flagged as a "normal map".
    If there is indeed a normal map then it is probably a "shader/material keyword problem". The URP shader is actually a collection of many, many shader variations. This is done for performance so the shaders don't run the code for unused features. The shader is implemented so that chunks of functionality can be removed if a feature is not being used. For example if there is no normalmap then all the normal map code is stripped out (making the shader significantly faster). There are variants for all the possible permutations of the features. These variants are enabled and disabled by Shader.EnableKeyword, Shader.DisableKeyword and Material.EnableKeyword, Material.DisableKeyword. The editor inspector is invoking the keyword enable/disable when you focus on the material. At runtime you will need to do this manually depending on which textures are assigned. You also may need to enable/disable the keywords for fog, shadows, lightmaps or lightprobes, reflection probes etc...
     
  35. etchthaboss

    etchthaboss

    Joined:
    Jun 13, 2016
    Posts:
    12
    Hey there,

    I'm looking to bake textures and mesh at run time to reduce drawcalls. I've been able to do this in editor/inspector at runtime and all works properly. I'm trying to write a script to do this. Im struggling with adding objects to combine to the Texture Baker. How can I do this with the Runtime API?
     
  36. pdinklag

    pdinklag

    Joined:
    Jan 24, 2017
    Posts:
    154
    Thanks for the quick reply!

    No worries about the TODOs, it's good to know.

    I'm in Unity 2020.1.11, all materials are set up with the URP's Lit shader, specular workflow.
    All materials of my meshes can be tinted. Some have textures, some have no texture and just the tint.

    The baked material atlas is looking fine, just no tints are applied at all, not even on those materials with textures. I did some basic debugging and found that TintTextureWithTextureCombiner of TextureBlenderURPLit is never called even once (but yes, I did make sure that considerNonTextureProperties is set to true), so something must be preventing it from happening.

    OK, fair enough. I'm doing quite some mesh magic here and there for various reasons already, so I'm sure I can do that. Just wondered if I could maybe save that work. :)

    That's all fine.

    If the inspector does those things, that explains why opening the inspector magically fixes the problem. I'll have a look at this, thanks for pointing me in this direction!
     
  37. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    The texture baker has a field "objsToMesh". This is a list of GameObjects. Each of these GameObjects should have a Renderer. You can look at the example script BakeTexturesAtRuntime.cs. It shows and example of runtime texture baking although it doesn't collect and add objects to combine.


    Code (CSharp):
    1. List<GameObject> objsToMesh = textureBaker.objsToMesh;
    2. ...
    3. objsToMesh.Add(myGameObjectWithRenderer);
    4. ...
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I will take a look at the URP texture blender to see if I can discover why it is not working for you.
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I think I know the problem with the "non-texture properties" not working. I presume you are using the Texture Blender Fast? This feature doesn't work with the Texture blender fast texture packer. The feature relies on copying pixel-by-pixel which is what the Mesh Baker texture packer does. The texture packer fast copies entire blocks of pixels at once. I should add an error message when using this feature with texture packers that don't support it.
     
  40. pdinklag

    pdinklag

    Joined:
    Jan 24, 2017
    Posts:
    154
    Yes, you are right, I used the fast packer. I just tried it with the standard packer and that worked. There is also already a warning that "non-texture properties" have limited support in the fast packer, it's maybe just not too clear that color tinting is affected, but that may be just me.

    Now, the downside is that the standard packer is slower by an order of magnitude and requires textures to be uncompressed AND have r/w enabled, which is both extremely heavy on memory. I just looked into things and it seems really easy to add color tinting support to the fast packer. I'll contact you via PM.
     
  41. Imillionaire

    Imillionaire

    Joined:
    Dec 14, 2012
    Posts:
    60
    So im having this issue with mesh baker where when combining a bunch of meshes (these here have already been combined out of 10's of individual smaller pieces) it will make meshes that sort of cut into each other, ive posted the settings i used as well. any idea why this is happening and how i can prevent it? i'd rather it combine all these into one mesh, or at least not take a chunk right out of the middle of one and add it to another. MeshBaker01.png
     
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hello, the images are a bit small and I can't really see what is happening. Can you post a pick that zooms in on a problematic bit? From your description I can think of a few possibilities.

    1) Are you using a transparent/translucent shader? This could be an "order independent transparency" problem. It works when the objects are separate because they can be sorted then separately rendered back to front. When combined it doesn't work because the triangles are rendered in the order that the graphics card visits them and you can get background tris on top of foreground tris.
    2) Another possibility is shader vertex displacement or tessellation.

    Can you describe the shader you are using and post a zoomed in pic (Ideally with the scene set to render wireframe & shaded)?
     
  43. etchthaboss

    etchthaboss

    Joined:
    Jun 13, 2016
    Posts:
    12

    Awesome got that all working! Reduced my draw calls 30x which is fantastic (runtime avatars with 8 skinned meshes....)

    Now the only problem I have is that it takes about 15 seconds when I startup to do the baking. I have it on the coroutine as the texture baking example but it seems to hang and freeze up the thread. I could potentially even live with that for now, but is there a way I could cache the mesh baker result so I have it saved between scene switches.
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Unity as a method "Object.DontDestroyOnLoad" I think you can call this on the root "combined mesh" and it will survive until the next scene. Note that you will need the bones and animator to survive too so you might want to put everything under a single game object and call Object.DontDestroyOnLoad on the root.
     
  45. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    Hi Phong, I have been using your tool since last few months and it really helps me in reducing my drawcalls. But now I am facing the problem in optimizing my new game scene. The scene is a city scene which uses modular pieces and very little props. Currently there are 18000 meshes in the scene with 130+ materials. The major problem is the whole hirarichy is messed up. All the meshes are under single parent object. Currently I am getting 1100+ draw calls and when I combine all of them using another grid based tool I get 150 to 200 draw calls. But the other tool does not combine materials. But it really detects and combines meshes falling in a grid with very little manual work. You might be already familiar with the tool. But your tool combine materials as well. But does not do grid based combining (Or may be I do not know). What I wish I could input the parent element and define grid size with some search conditions and your tool not only find and combine the meshes based on grid but also combine and create new materials. Also it should automatically discard the objects with procedurally generated meshes or renderers which are not able to combine. May be I am demanding too much but I do not know how am I going to combine meshes and materials for this. Or as last resort, Can you tool combine the COMBINED MESHES combined by other tool? I tried but results were very weird so I want your proposed method to sort my problem before proceeding. Thanks.
     
  46. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    Just after posting this question, I came across your TOOLS FOR ADDING OBJECTS and CLUSTER GROUPING. And I came across you youtube channel where I found a tutorial. I am using that and it is such a big sigh of relief. Only I request you to highlight this feature and add relevant videos in Asset store as well as on your website page a detail about this asset. Also still you can advice me about speeding up workflow for large scattered scenes. Thanks.
     
  47. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Glad you found that video.

    I am hiring an assistant to create updated tutorial videos in the spring. We will be sure to add them to the asset store page. There will be a few additional videos added.

    Do you have specific questions about the workflow? Which parts are taking a long time for you?

    One think I would consider it the Agglomerative clustering option. I prefer it to the grid cluster because it groups the meshes where they are most concentrated.
     
  48. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    For the time being I am going through the process and it is not taking so long as I thought. I will update my feedback soon. The feature I would like to have at the moment is option to shift original materials and relevant textures of baked elements to a specified folder (Only if I wish to otherwise leave the material in original place). I know I have this option if I create a new material and set destination folder but incase I only bake meshes based on original materials I do not have this option. This really helps in arranging scattered scene. The other feature I would like to have is to set Render ques through meshbaker windows of the original materials in case I bake with original material or for new materials If I create new material. For the time being, after combining mashes, I have to shift all materials to a folder myself and then I have to assign render ques there. These extra two steps force me reselect materials though I already selected them during mesh baking whereas I could shift and assign the render ques during meshbaking without requiring these extra steps if I had above two features. I do not know if this is something worthy to consider but at the moment I feel it important. Regards,

    Update : Plus after combining materials when I see the build report, it includes all the old materials and textures in the build though after combining I do not require any of them. So there should be option to remove original meshes and materials from the transforms so that there is nothing referring original materials and meshes and they are not included in the build reducing build size.
     
  49. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    So here is where I need you expert opinion. Unity static batching reduces draw calls to minimum if shared materials are used. Unity static batching also performs frustum culling on the vertices of combined mesh which are not visible to the camera. But all this at the cost of increased build size, (upto double or more even because it duplicated the static meshes). Your tool replaces original meshes instead of duplicating meshes. This way we can have reduced draw calls without increasing build size. But the meshes combined by you does not offer frustum culling and tris cound/ verts count per frame rises significantly because even a corner of combined mesh is going to fall in frustum, it is going to render whole mesh. This happens even if I use cluster groups and I have very little far clipping plan (150 to 200). I understand I have to chose whether frustum culling or reduced size. But I need your suggestion. What is your recommended strategy for such cases. I can not increase build size more but I want only those vertices or objects belonging to larger mesh to be visible which are actually in camera. Is this even possible? My heart says to me its not.
     
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Thanks for the feedback about the workflow. Mesh Baker has a button "Select Objects In Scene". Do you think a button "Select Source Material Assets" would do what you want? It sounds like most of the pain is in selecting all the materials.

    Regarding static batching vs mesh combining:
    • Note that both these techniques will bloat the build about the same amount since they are both generating combined meshes.
    • I find that combined meshes are usually a bit faster than static batching (if there is not a lot of out of frustum triangles being rendered). I think this is because there is still some runtime overhead with static batching. Unity needs to cull and generate triangle lists every frame.
    • I like to combine meshes when:
      • There are no LODs
      • When meshes can be grouped into reasonable clusters. I usually use agglomerative clustering.
      • When occlusion culling would not be extremely effective.
    • I like to use static batching when:
      • There are LODs
      • When geometry is widely scattered
      • When occlusion culling doesn't work well