Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. hoyoyo80

    hoyoyo80

    Joined:
    Jan 31, 2018
    Posts:
    27
    Play with batch prefab baker but get this error "Row 0 source prefab is the same as row 0 result prefab". What wrong? Thanks

    EDIT:Success bake the prefabs, now i got combined material,LOD and occlusion working together. But i notice some texture get darker a lot. Any tips for combining material?
     
    Last edited: Oct 18, 2019
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    It is important to only combine meshes that will usually be visible at the same time. Unity will cull non-visible meshes. It does this by testing the bounds of each renderer against the camera fustrum (volume). If you combine meshes that are far apart, then the bounds of the combined mesh becomes very large. It is likely that this mesh will be always (or very often) not-culled. If you see an increase in tris it means that meshes that were being culled are now not being culled. Suggestions:

    • Only combine meshes that are close together. The Mesh Baker Grouper can help with this.
    • Use the batch prefab baker and static batching. Props can still be culled but are also "combined". You should see fewer batches because more objects are sharing a material, but no increase in tris.
     
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Regarding darker textures. What do the textures look like in the atlas compared to the source textures? Could it be that one of the source materials was using a color tint?

    Here are possible causes I can think of:
    • A source material had a color tint. Blend non-texture properties might help.
    • There is something different about the source texture and atlas texture. Atlas may have added an alpha channel (try setting format of atlas to something that has only RGB). Source texture might have used a different compression format.
    • Compare the properties of the combined material and source material. Did the source material have emmision and result does not?
    • Was the source object lightmapped?
    • Are the render settings different for the combined mesh vs the source mesh? Perhaps the source mesh is getting lighting that the combined mesh does not.
     
  4. CamRule

    CamRule

    Joined:
    Mar 19, 2019
    Posts:
    5
    Hey Ian,

    Thanks for creating mesh baker, absolutely loving it already and just picked it up today.

    I had a question on a unity discord group and was given your details to message you regarding my specific problem.

    Currently, I use Standard Plus in the unity asset store as it allows me to import pre-baked lightmaps from 3ds max corona. However, I cannot seem to get mesh baker to register the lightmap texture and texture atlas them. It really would be amazing if you could help me here, any advice would be amazing! I have tried adding them in the extras slot to type in the new texture layer with 0 luck.

    Cheers,
    Cam
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    I am not familiar with Standard Plus?

    How does it work? Is the lightmap added as a texture to the material? Does it use UV2?

    If so, you should be able to combine materials that use the same lightmap using "lightmap UVs = Copy Unchanged".

    If you want to combine the lightmaps into an atlas of lightmaps, that will be tricky. At this time mesh baker only really packs UV0 into atlases. I hope to add functionality in the future so that different UV channels and some of the texture properties can be packed into different sets of atlases.

    There is a very hacky way to pack an atlas for another UV channel currently. Write a script that swaps UV <-> UV2 just before baking. Then bake (putting the property name of the atlas texture property into the custom property names). Then switch the UV channels back after baking.
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    I am excited to announce that Mesh Baker 3.29.0 has just been released!

    This is a huge update. The big new feature is Texture Arrays. Mesh Baker now includes a set of tools to bake Texture Arrays and modify meshes to use them!

     
    hopeful and JBR-games like this.
  7. Leniaal

    Leniaal

    Joined:
    Nov 7, 2012
    Posts:
    55
    Hi, I have na issue baking the building you see in the screenshot. The one on the right is the original. As you notice the baked mesh on the left is all black (it's not the material).

    I have successfully baked quite a few meshes, but this one has given me some trouble. I already tried splitting it up in more parts but its the same result. I should add that the total vert count is quite high, around half a million.

    upload_2019-10-24_18-18-19.png
     
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Buildings are tricky because they typically have multiple materials and extensive tiling. I would suggest watching this video that explains how to handle this. Usually you want to use "consider UVs" and sometimes put materials on their own submesh using the Multiple Materials feature.


     
  9. CamRule

    CamRule

    Joined:
    Mar 19, 2019
    Posts:
    5
    Hey there, thanks for the earlier response regarding my question. I don't have the skills to write a script so I'm just trying to get decent light bakes after meshbaking, but in running into problems.

    I'm bringing in my own uv2 unwraps for lightbaking but I can't seem to mesh bake and retain the uvs. How do I go about this? I've tried retaining uv2 but my mesh won't generate and I've also tried the top option but it says (won't work for unity 5) and I also get 0 output when I use that.

    If I create new uv2 channel and light bake. I'm getting weird light leaks/bleeds at the uv seems. Is their a solution to this? I am fine generating new uvs as long as I can fix this issue.

    My lightbakes are perfect before meshbaking so I'm rather confused as to what is going on after merging meshes.

    Cheers
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    If your source meshes have their own UV2 channel you should use:

    Lightmapping UVs -> Copy UV2 To Separate Rects

    After that you should be able to bake the combined mesh. Re: The light leaks when you generate a new UV2 channel. This can happen if there is insufficient padding between the UV2 islands. If any texels span the gap between the UV islands then the light of an object can be affected by the random objects that are beside it in the lightmap.
     
  11. CamRule

    CamRule

    Joined:
    Mar 19, 2019
    Posts:
    5
    Thanks so much for that. When I go to bake the mesh with: Lightmapping UVs -> Copy UV2 To Separate Rects

    It works when I apply mesh bake alone, however, when I apply texture bake and mesh bake together I get this error:

    System.IndexOutOfRangeException: Index was outside the bounds of the array.
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle._copyUV2unchangedToSeparateRects () [0x00151] in M:\Unity\Projects\Oculus Quest test stability\Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:2821
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle._addToCombined (UnityEngine.GameObject[] goToAdd, System.Int32[] goToDelete, System.Boolean disableRendererInSource) [0x01f21] in M:\Unity\Projects\Oculus Quest test stability\Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:1112
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.AddDeleteGameObjectsByID (UnityEngine.GameObject[] gos, System.Int32[] deleteGOinstanceIDs, System.Boolean disableRendererInSource) [0x001de] in M:\Unity\Projects\Oculus Quest test stability\Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:2067
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.AddDeleteGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject[] deleteGOs, System.Boolean disableRendererInSource) [0x00065] in M:\Unity\Projects\Oculus Quest test stability\Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:2001
    at MB3_MeshBaker.AddDeleteGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject[] deleteGOs, System.Boolean disableRendererInSource) [0x0001d] in M:\Unity\Projects\Oculus Quest test stability\Assets\MeshBaker\scripts\MB3_MeshBaker.cs:43
    at MB3_MeshBakerEditorFunctions.BakeIntoCombined (MB3_MeshBakerCommon mom, System.Boolean& createdDummyTextureBakeResults, UnityEditor.SerializedObject& so) [0x001fc] in M:\Unity\Projects\Oculus Quest test stability\Assets\MeshBaker\Editor\core\MB3_MeshBakerEditorFunctions.cs:94
    at DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal.bake (MB3_MeshBakerCommon mom, UnityEditor.SerializedObject& so) [0x00029] in M:\Unity\Projects\Oculus Quest test stability\Assets\MeshBaker\Editor\MB3_MeshBakerEditorInternal.cs:447
    UnityEngine.Debug:LogError(Object)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:bake(MB3_MeshBakerCommon, SerializedObject&) (at Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:476)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:DrawGUI(SerializedObject, MB3_MeshBakerCommon, Type) (at Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:393)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:OnInspectorGUI(SerializedObject, MB3_MeshBakerCommon, Type) (at Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:151)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/Editor/MB3_MeshBakerEditor.cs:99)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    Is there anything I can do to fix this?

    Thanks again
     
  12. thehen2

    thehen2

    Joined:
    Apr 1, 2014
    Posts:
    43
    Is there any way to set lightmap scale for generated meshes? Currently I'm manually having to set it after every bake.
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Which version of Mesh Baker are you using? (Should be in the release notes). The latest version has different line numbers so I can't see what is throwing the error.
     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Currently no, I will add that to the todo list since it should be fairly easy to add.
     
  15. CamRule

    CamRule

    Joined:
    Mar 19, 2019
    Posts:
    5
    Says this is my assets:
    Version: 3.29.0 • Oct 23, 2019
    Version 3.29.0 Oct 20, 2019 Added Beta support for Texture

    I also noticed these when I opened unity this morning. Could they be related? is there a good method to debug this? The objects I am merging have UV2 already set, so it should be working use the last option you mentioned right? I really need this to work

    Attached are the errors that occurred this morning

    Cheers
     

    Attached Files:

  16. CamRule

    CamRule

    Joined:
    Mar 19, 2019
    Posts:
    5
    Regarding my earlier posts:

    I tried a clean install and this was the error I got. Might be good to note this?

    Image attached with the error log

    Thanks again.

    Edit. I then tried skinnned mesh renderer and got:
    System.IndexOutOfRangeException: Index was outside the bounds of the array.
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle._copyUV2unchangedToSeparateRects () [0x00151] in M:\Unity\Projects\light test\Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:2821
     

    Attached Files:

  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593

    I think I know what is going on. I see that you have "Clear buffers after bake" unchecked. Usually this is only unchecked if you are going to bake, then Update the bake. What is happening is:

    • The first bake is done with a certain set of channels. Mesh Baker creates data for these channels. Other channels are empty.
    • A new channel is added "UV2".
    • The next bake tries to "Update" the previous bake. However there is no data in the UV2 buffer which causes the error.
    The error about blendShapes is the same. I think this was checked after the first bake.

    The cleanest thing to do would be to would be to start with a clean MeshBaker component, clear it, and leave the "Clear Buffers After Bake" checked. You might be able to continue using the existing MeshBaker component, but check the "Clear Buffers After Bake" and bake twice.

    Note that you shouldn't use the "blend shapes" channel with non-skinned meshes. It is only useful with skinned meshes.
     
  18. LumoKvin

    LumoKvin

    Joined:
    Sep 28, 2019
    Posts:
    122
    Why is Mesh Baker more expensive than other mesh combiners? What can it do that the others can't?
     
  19. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    279
    I tried the free version to see if it would benefit me, but I cant get it to work, even with following tutorials. it seems to bake the material fine, but just throws errors on mesh baking.
     
  20. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Can you tell me version of Unity you are using?
    Also what errors you are getting?

    I am planning on updating the free version(it is overdue) over the next few weeks.
     
  21. TonismoGames

    TonismoGames

    Joined:
    Jun 12, 2018
    Posts:
    38
    Hi, I am trying to run TextureBaker and MeshBaker on gameobjects that are instantiared at runtime.I keep getting this error. upload_2019-11-13_16-14-53.png
    The Mesh Baker works with these materials. Is there a way around this? upload_2019-11-13_16-17-24.png
     
  22. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    148
    Hi there,
    I need a workflow and I can't get my head about how to setup MeshBaker to get what I want.
    • I use Mesh Baker Grouper to generate a LOT of mesh bakers
    • I don't use any texture baker as I don't need to bake materials (I've got an empty and unused one on the mesh baker grouper otherwise it was complaining)
    What I would like to obtain at the end is a single prefab, with all the combined mesh from all my mesh bakers (generated by the mesh baker grouper). And a folder with all mesh data in there.

    Right now I've tried several solutions:
    • use mesh baker grouper out of the box with "Bake Into Scene": it works and I can have a prefab with all combined meshes, but can't use it in other scenes since the mesh data is in the original scene
    • use mesh baker grouper with "bake into prefab" for all the mesh bakers. But I need to create a single prefab for each combined mesh (which I don't want, it's a pain to setup and update when you have dozens of mesh bakers).
    • I've looked into the batch prefab baker, not sure what it does, not sure if it's for me, but it requires a texture baker which I don't use
    • use mesh baker grouper with "Bake mesh asset in place" also require a texture baker
    @Phong any idea? Thanks a lot for this awesome plugin btw :)
     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    The error may be a false positive. The reason the error is there is that MeshBaker maps the material on the source meshes to rectangles in the atlas. The problem with "Instanced" materials is that they are usually not the original materials (the ones baked into the map). They are clones of those materials and they won't be recognized when trying to map the clones to rectangles in the atlas.

    If you are creating the textures at runtime, it may be that you are indeed baking the instanced materials. If this is the case then you could remove this error message from the sourcecode and things should work. Or you could rename the materials so that the word "Instance" is not in the name.

    Do you know why the materials are "Instances"? Usually when objects are created at runtime, materials are not duplicated (cloned prefab instances share a material with the original). The typical way that the materials get turned into instances is by accessing:

    myMeshRenderer.material

    Instead of:

    myMeshRenderer.sharedMaterial

    Accessing MeshRenderer.material has the nasty side effect of quietly duplicating it and replacing the renderer's material with the duplicate. 99% of the time you should be accessing MeshRenderer.sharedMaterial instead. Have you searched the source to see if you are using MeshRenderer.material anywhere?
     
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Hmmm, I see your problem and I can't think of a way to do exactly what you want other than a custom script. It would be fairly easy to write a custom script to do this. How is your scripting?

    The psudocode would be:

    • Collect all the MeshBaker components that are children of the MeshBakerGrouper
    • Get the meshes for each of these: myMeshBaker.meshCombiner.GetMesh()
    • Save these as an asset in the project: AssetDatabase.CreateAsset
      • AssetDatabase.CreateAsset( [mesh object here], [path to asset] );
      • AssetDatabase.SaveAssets();
    Another hacky way that might work, is to create mesh assets in the project and assign these meshes to the "Mesh" field in the MeshBakers. The only problem is that the MeshBaker doesn't know that it needs to mark the assets as dirty for saving. You might need to change something else in the scene and save the scene to get the changes to stick.
     
    ph_ likes this.
  25. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    148
    Ok I get it; then once I've got the meshes saved as asset in my project, I can use those with the combined mesh in my high level prefab.
    I'm a programmer and scripted a bit with MeshBaker already so it should be fine; I'll try this and report back thanks!
     
    Phong likes this.
  26. TonismoGames

    TonismoGames

    Joined:
    Jun 12, 2018
    Posts:
    38
    Hi Phong,
    Thank You for the reply. The reason for the materials getting instanced is that they get modified during runtime .The shaders have CPU Instancing checked. What I do during runtime is copy the materials from the original MeshRender.materials, modify it,colo,metallic. I then apply it back to the MeshRenderer. I want to be able to bake the materials in the background. A lot of the things in my project are instanced at runtime. So it is not possible to baked instanced materials at runtime?Is it because it doesnt contain the needed data?
     
  27. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    148
    @Phong An other issue that I have is that in the complex hierarchy that I'm trying to bake, some meshes are set to "Cast Shadows ON" and other to "Cast shadows OFF".
    When baking everything with mesh baker, it looses this information.
    What would be nice:
    1. If all meshes have a common "Cast Shadow" flag, mesh baker could set the correct one on the generated mesh (right now it default to ON).
    2. Then one of the two options:
      1. Either the ability in "Analyse Scene" and "Search for Meshes To Add" to filter by cast shadow flag value.
      2. Either have a checkbox in the MB component to say "Split meshes if flag conflicts", and it could generate two (or more) meshes if they have different flags
    I believe it could be the same thing for various flags (receive shadows...).
    Adding 2.1 is probably easier, but I think 2.2 would be best :)

    Note that it's only a suggestion, I am adding 2.1 right now in my solution so I am not blocked at all :)
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    It will work as long as the materials that are on your source objects when baking the meshes are the same instances of the materials that were used when baking the materials.

    Although you will need to remove or disable that error in the sourcecode. (Or remove the word "Instanced" from the name of the materials. You are the unusual circumstance where what you are doing is not an error.
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Thanks for the suggestion. This is a good point. I will add it to the todo list.
     
  30. ferspec

    ferspec

    Joined:
    Jun 27, 2019
    Posts:
    2
    Hi, is there a way to combine meshes to generate a single SkinnedMeshRenderer at runtime without having to initially create all the individual skinned mesh renderers? i.e., so to input an array of just raw mesh data?

    I have the following:
    - 16 body part meshes, which combined is the base character mesh
    - 200+ swappable clothing meshes
    - all meshes stored separately as individual ScriptableObjects
    - all meshes are originally modeled under the same rig, thus all have same number of bone weights
    - not concerned about textures or materials at this point

    I would like to allow dynamic character customization at runtime (similar to the example CustomizeCharacterGame scene), but it would seem inefficient (memory-wise) to have to:
    1. generate them as prefabs to create skinned mesh renderer components for all 200+ meshes
    2. temporarily instantiate each one as they're swapped in/out and then destroy

    Thanks
     
    Last edited: Nov 22, 2019
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593

    The hard part about what you want to do is that the list of bones in each source mesh is usually in a different order from other source meshes (even if they share the same ring) and will usually have a different number of bones from each source meshes (shirts will only have arm, chest, torso bones in the bones array. Then the bone-indexes in the source bone-weights will be wrong and need to be re-mapped when the adding the bone-weights the combined mesh.

    Also, the normals in the source meshes need to be tweaked at the seams so you don't get hard edges at the seams.

    Also, the bindpose for each bone in the mesh needs to be exactly the same for each source mesh. This is always true if all source meshes came from the same .fbx and use the same bones, but if you used different .fbx for each source mesh then you can't rely on this.

    For these reasons you can't just append all the channel data from the source meshes and have a functioning combined mesh.

    You might be able to do what you want by pre-processing your meshes and saving them as assets in the project. You would pre-process them in the editor to ensure that:

    1) Every pre-processed mesh uses the same number of bones and the bones are in the same order. With bone weights adjusted.
    2) Every pre-processed mesh uses the same channels.
    3) Every pre-precessed mesh has adjusted normals at the seams.

    The way I would do this is to use MeshBaker in the Editor to create one big combined mesh with one instance of every source mesh. Then I would extract the channel data for each source mesh from the combined mesh channels and save these as my pre-processed mesh assets. These pre-processed meshes could be combined at runtime (fairly easily) without instantiating the skinned mesh renderers.

    This is not a trivial project. I can provide some more advice on how to extract the channel data for each source mesh if you want to pursue this.
     
  32. ferspec

    ferspec

    Joined:
    Jun 27, 2019
    Posts:
    2
    Appreciate the reply.

    Each mesh is indeed imported from separate .fbx files. However each .fbx file also contains a complete duplicated hierarchy of the entire armature and all of its bones. I’m assuming this would check off #1?

    e.g. In the Unity Project this would translate to:
    window_project.png
    Where each “Armature” contains the same full list of bones, so if dragging Arms into the Scene Hierarchy we’ll also have all the unrelated bones as well:
    window_hierarchy.png

    For more context, every mesh is modeled within a single master .blend file, and then exported individually (while also making sure that the entire armature is always included in each export).

    The plan would be to include the initial ~200 meshes in the actual game build, and then introduce new meshes (clothing items) later on via rolling DLC’s.

    Would this mean that if a DLC introduces only 1 new clothing item, it would have to bundle in an updated "master mesh" that combines all the original 200 meshes plus the 1 new mesh? Or does MeshBaker expose an API that would allow downloading just the 1 mesh (which would also contain its own reference to the entire armature) and then updating its internal copy of the "master mesh"?

    I’m targeting mobile so performance and memory usage is of high concern. Would definitely appreciate some advice on how to best approach this. Thanks.
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Unity will consider the armatures in each .FBX file to be independent, not "the-same". This means that if you combined these with MeshBaker, you will end up with two copies of the armature/bones in the combined mesh that need to be animated in sync (terrible for performance). To fix this you will need to do the following.

    • Package each of your meshes as a separate DLC bundle (eg. a single shirt)
    • The game clients will download the bundle and load them
    • In memory you now have an instance of your shirt skinned mesh
    • Before you combine this body part with other body parts you need to do the following on the client with a script
      • Designate one of the armatures to be the "master armature"
      • Visit each skinned mesh body part that you want to combine
        • Get the bones array from the SkinnedMeshRenderer
        • Replace each bone in that array with its corresponding bone in the "master armature". You won't be able to trust the order. You need to check the names of the bones.
        • Assign this updated bones array back to the SkinnedMeshRenderer
    • Now that all the body parts use the same bones, you can use mesh baker to combine them. This can be done at runtime on the client. There will be a single armature in the combined mesh.
    Note that you will still have the problem with normals at the seams of your meshes that I describe in my tutorial video. You will need to use the BoneWeightCopier to fix this at some point. I would suggest doing this in the editor and packaging the fixed mesh instead of the original.
     
  34. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    148
    @Phong Just wanted to come back and say thanks, the suggested solution worked. I've got a workflow that work with baking in a single prefab. Thanks!
     
    Phong likes this.
  35. stevenkeaykrid

    stevenkeaykrid

    Joined:
    Jan 23, 2019
    Posts:
    3
    Hi @Phong,

    I'm working on a project where we import a bunch of models at runtime that always use the same three texture maps (albedo, normal, specular) but that often use an additional unique texture. (For each model, the additional texture is imported as a separate material). The number of possible models and unique textures are in the hundreds. Because of this, it doesn't seem viable to create a texture atlas containing all possible textures before running. I have some questions regarding our workflow that this asset may be able to help with:

    We are developing for VR so performance is a top-priority.

    1. Does creating a texture atlas at runtime with multiple materials per model work? (They share the same shader).

    2. Since each model shares the same three texture maps, would it be beneficial in any way to create this texture atlas before running and to combine it with the additional unique textures at runtime? (To reduce runtime combining time).

    3. Each model needs to be able to move independently and will have visual effects applied to them based on the mesh of each model. It is essential that each individual model retains its original pivot point as well. Will combining the meshes disrupt this in any way?

    Apologies if these questions have been answered previously.

    Thanks.
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
     
  37. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Hi Stevenkeaykrid,

    Re: the huge number of combinations. I am a little fuzzy on what your setup is. It sounds like your models have two materials each. The first material has three texture slots (albedo, normal, specular). The second material has a single texture slot. If this is the case then you would be baking two sets of atlases and two combined materials:
    • A = first would have albedo, normal speclar atlas textures
    • B = second would have your extra textures (if there are many textures you could split this into multiple atlases)
    The two combined materials will be assigned to the combined mesh separately. As long as A can hold all the albedo textures and B can hold all the extra textures, you could pre-bake these atlases. You could even split B into multiple atlases/materials if there are too many and assign the correct one at runtime.

    1) Yes, creating texture atlases for models with multiple materials at runtime does work, but it takes a lot of memory and it slow. I only recommend doing this as part of a "loading" phase, not during intense gameplay.

    2) Yes, if you can it is beneficial to combine textures at built time.

    3) Combining meshes will change the pivots and ability to move the meshes independently (unless the combined mesh is a skinned mesh). You can choose to combine the materials but leave the meshes not-combined. This makes your meshes eligible for dynamic batching. Another option that works if your meshes don't have too many vertices is to bake the MeshRenderers into a skinned mesh. This way you get one drawcall, but add the overhead of an extra skinned mesh. If the mesh does not have a large number of vertices, it is usually worth it.
     
  38. stevenkeaykrid

    stevenkeaykrid

    Joined:
    Jan 23, 2019
    Posts:
    3
    Yes, exactly. The models have two materials each with the setup you described. I see, appreciate the insight.

    Thank you for your response to the questions. Sound like it would, at the very least, be a good idea to combine the materials in our case even if it may not be viable to combine the meshes.

    Following this:

    Our models are quite complex so a skinned mesh would probably not be possible - but is it possible to enable/disable the MeshRenderer for each individual model in the combined mesh after baking? The project is set up in a fairly linear way so that the user may only interact with one model at a time until that model has "reached its goal". I'm wondering if we could at least improve performance by enabling the "real" version of each model when it needs to be interacted with and disabling the renderer for the combined copy of that model.

    Thanks.
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    It is generally a good idea to have as few materials as possible as it enables a lot of batching possibilities.

    Yes, you can update the combined mesh to show and hide various meshes. If the player can only move one mesh at a time, then you could do as you say. Have one big static mesh and show/hide them as needed and enable only the mesh that the player is interacting with.
     
  40. stevenkeaykrid

    stevenkeaykrid

    Joined:
    Jan 23, 2019
    Posts:
    3
    Okay awesome! Thanks for all your help. Looking forward to using the tool :)
     
  41. sekever-n00b

    sekever-n00b

    Joined:
    Nov 4, 2017
    Posts:
    56
    Hi!
    I'm using 60 materials across a lot of objects and each object share from 5 to 20 of these materials. I haven't get much luck baking with BM grouper.
    I'm trying to bake an enormous amount of stuff that definitely requires more prefabs(MB baked result prefabs). Currently I have to manually select all objects in scene and mesh bake them and so on and on and then bake mesh bakers.
    Is it possible that this can be done automatically?
    instead of to give MB only one empty prefab to output, give multiple empty prefabs and let MB divide all of listed scene objects in it and deal with them one by one<(MB baked result prefabs)
     
    Last edited: Nov 30, 2019
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    I am not sure how important it is to control how the meshes are grouped. I can think of two options:

    1) Use the Batch Prefab Baker. This would preserve everything about your original prefabs, except it would switch the mesh and material(s) to the combined version. These "baked" prefabs are very easy to combine since they all have the same channels and use the same set of materials.

    2) You could use a MultiMeshBaker instead of a MeshBaker with the "Bake Into Prefab" option. The MultiMeshBaker will split your source mesh into multiple meshes if the combined mesh would be too big. When using the "Bake Into Prefab" option, it saves all these meshes as assets and creates a single prefab with all these MeshRenderers as children. It would be easy to Unpack this prefab and make each of the children into its own prefab.
     
  43. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,613
    Is there some kind of "auto mode", that would just combine what ever it can, without manually selecting things?
    (say, for and selected mesh and all of its child meshes?)

    also is 64k vertices limit already fixed in new unity versions?
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Re: Auto-mode. Not at this time. You can use a MeshBaker component by itself (without combining textures first).
    • Add a MeshBaker to the scene.
    • Drag some meshes to it.
    • Click Bake
    It is on my todo list to add this to the MeshBaker window.

    Re: 64k limit. Yes, Mesh baker does support meshes larger than 64k.
     
    mgear likes this.
  45. sekever-n00b

    sekever-n00b

    Joined:
    Nov 4, 2017
    Posts:
    56
    I can't combine materials (except mesh) because they already are altases actually. (well its a city my trying to mesh bake here, so in a first round there are over 1000 prefabs (buildings) in scene...and at the end i plan to apply occlusion culling,..) When trying multi mesh baker my 16 gb pc ram goes out of course and unity crushes. Any help is appreciate
     
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Two things to check:

    Is MaxVertsInMesh something reasonable? (64k ish is a good number)
    Have you tried with "Clear Buffers After Bake" checked

    The second one is probably the problem. The MultiMeshBaker is trying to hold a copy of all the baked data. If you clear buffers after each bake it should work.
     
  47. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    410
    Hey, I think I found a bug or at least something that's not documented as far as I can see and is very annoying.

    When preparing a Texture Baker and selecting "Bake Materials into Combined Material", it seems you're not only setting the necessary textures to read-only (which would make sense) but instead every single texture in the project. This is crazy slow on large projects and totally unnecessary. I just had to wait through a 3-hour reimport because of that, and luckily I was not on Android build target / ASTC textures, then it would have been a 24-hour reimport.

    Is there an option for that? Am I missing something?

    EDIT: Actually, is there an option to skip making textures readable altogether? I assume you have to blit them to GPU at least once anyways, so why not just blit the original texture into temp and read that (which would not require isReadable)? That would speed the process up considerably.

    BUG: Baking into prefab with "Bounds Center" method does not set the transform properties of the prefab. Dragging the prefab into the scene should make it appear where the bake has happened, not in (0,0,0). This makes it unnecessarily hard to position correctly.

    BUG: Selecting multiple objects with MB3_MeshBaker on them seems to support multi selection, but actually pressing "Bake" will bake a random one (first selected probably). Please make sure if you set your Inspectors to support multi-object editing that buttons etc. also support it.
     
    Last edited: Dec 4, 2019
  48. sekever-n00b

    sekever-n00b

    Joined:
    Nov 4, 2017
    Posts:
    56
    I did try few things, after crushings there are some unfinished MB left overs results, i think ill leave it for my next PC gen with 64gb ram perhaps
     
  49. PeteMichaud

    PeteMichaud

    Joined:
    Jul 11, 2015
    Posts:
    25
    I'm thinking about buying Mesh Baker and MB LOD, but I want to verify that it'll work for my use case:

    I am making a game that involves base building (like Ark, Fallout 4, Rust, etc). If you're not familiar with the genre, structures are made out of modular parts that the player can place in the environment, so they might place 4 "foundations" down on the ground, and snap walls around them, and a roof on top, making a small house they can go inside of. Technically, it means the environments can get quite complex, and since they are runtime dynamic and editable, they sort of defy normal build-time level optimizations.

    One consequence of this is that when the player is distant from their buildings, they can't see them, and as they approach the location of their buildings, the parts in many of these games can be seen loading into the environment piecewise, and any player-placed lights are especially late to the loading party.

    I'm hoping to use your tools to make it possible to view the buildings at a far distance. What I have in mind is that when the player exits build mode, a background process collects all the building parts for that area and combines them into a single mesh. I'll then show the single mesh and hide the collection of individual parts until the player gets close enough to the area, when I'll swap them back.

    Ideally I'd be able to generate a few LOD levels for viewing at greater distances.

    I am not planning to use the combined mesh up close because 1) players will likely want to edit the parts while they are close, and 2) many of the parts actually dynamic (eg. doors that open, plants that grow). So your tool would only need to make a single mesh that looked right at a distance. On the other hand, if the swap is seamless enough I could imagine selectively combining the "static" building parts (like walls) and just not combining the dynamic parts, so that the buildings were at least partially optimized, but the interactive parts would still work.

    Does this use case seem workable to you?
     
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,593
    Thanks for the heads up. Regarding the first bug you mention. I am not sure why you are seeing that behavior. I use Mesh Baker all the time and it normally only sets the textures to read only for the textures that it is about to bake. It does not do this at all when using the GPU. Can you send me more information about your setup?
    • Version of Unity
    • Platform
    • Build platform
    • Do you have "Texture Compression" override in the the Build Settings