Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mesh Baker by Digital Opus [RELEASED]

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

  1. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Are you using the MultiMeshBaker or the MeshBaker component?

    If you are using the MultiMeshBaker component, it has a "Max Mesh Size" field. The combined mesh will always be less than this. If the combined mesh exceeds this limit then extra combined mesh(es) are created as needed.

    If you are using the MeshBaker component then it will just keep stuffing verticies into the combined mesh. I have a Unit test that has this working. If you PM me I can send you a Unity package.
     
    roundyyy likes this.
  2. CWatsonT2

    CWatsonT2

    Joined:
    Jan 9, 2019
    Posts:
    114
    I am using the URP shader in 2019.3. That would make me very happy if it works Monday. Thank you!
     
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    It usually takes a few days for unity to review an approve so it probably won't be "live" until Tuesday or Wednesday.
     
  4. FinsworksInteractive

    FinsworksInteractive

    Joined:
    Jul 8, 2018
    Posts:
    8
    Hi! I'm having some problem trying to figure out how to properly combine something like this school of skinned mesh renders where it's not individual skinned mesh renders that's animated but a clump of them.
    I tried every option and followed the video tutorial but the animation doesn't seem to be preserved. So the baked mesh is static.
    The assets in question:
    https://assetstore.unity.com/packages/3d/characters/animals/school-of-fish-155320

    thank you in advance.
     
  5. shefermichael

    shefermichael

    Joined:
    Mar 7, 2019
    Posts:
    1
    Hey @Phong, I've been following the workflows from the manual and everything seems to work well until I reach the final step of Baking with the MeshBaker. When baking into scene object I do get a gameobject but with no meshes or assets

    I'm consistently getting this error and I'm not sure what to do about it

    Code (CSharp):
    1. Texture Bake Results has no materials in material to sourceUVRect map. Try baking materials. Can't combine meshes. If you are trying to combine meshes without combining materials, try removing the Texture Bake Result.
    2. UnityEngine.Debug:LogError(Object)
    3. DigitalOpus.MB.Core.MB3_MeshCombinerSingle:_validateTextureBakeResults()
    4. DigitalOpus.MB.Core.MB3_MeshCombinerSingle:_addToCombined(GameObject[], Int32[], Boolean)
    5. DigitalOpus.MB.Core.MB3_MeshCombinerSingle:AddDeleteGameObjectsByID(GameObject[], Int32[], Boolean)
    6. DigitalOpus.MB.Core.MB3_MeshCombinerSingle:AddDeleteGameObjects(GameObject[], GameObject[], Boolean)
    7. MB3_MeshBaker:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/MB3_MeshBaker.cs:43)
    8. MB3_MeshBakerEditorFunctions:BakeIntoCombined(MB3_MeshBakerCommon, Boolean&, SerializedObject&)
    9. DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:bake(MB3_MeshBakerCommon, SerializedObject&) (at Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:459)
    10. DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:DrawGUI(SerializedObject, MB3_MeshBakerCommon, Type) (at Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:405)
    11. DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:OnInspectorGUI(SerializedObject, MB3_MeshBakerCommon, Type) (at Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:151)
    12. DigitalOpus.MB.MBEditor.MB3_MeshBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/Editor/MB3_MeshBakerEditor.cs:99)
    13. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    There could be a few things going on.

    If you are baking into a prefab:

    1) The source animators/skinned meshes should be duplicated and copied into the prefab. You should be able to create a prefab instance and see these.
    • Are they configured to "always animate" this could be the problem.
    • Are they missing? If so you may have run into a bug that will be fixed in the next release where bones/animations are not copied correctly if the sources are not instances of a prefab. A workaround is to create a temporary prefab and use instances of that prefab as your source objects.
    If you are not baking into a prefab:

    • After baking check the source animators and make sure the culling settings are "Always Animate"
    • Can you move the bones of the source mesh manually by dragging the transforms around in the scene. This should deform the combined mesh. Is this happening?
    Let me know if this does NOT fix the issue.
     
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Are you trying to bake Textures first into atlases, then bake meshes so that they use these atlases? If so then you want to first do the Texture Bake and make sure it was successful.
    • After pressing the button "Bake Materials Into Combined Material", the console should say "Created Atlases"
    • The TextureBaker component should have a box that lists the materials that were baked, something like: upload_2020-6-15_13-30-36.png
    • Once the textures have been baked, make sure that the MeshBaker Component is either:
      • A child of the TextureBaker in the heirarchy and has "Texture Bake Result" = null
      • Or has the same "Texture Bake Result" asset assigned that the Texture Baker used. The list of Shaders and Materials should match the TextureBaker's.
      • upload_2020-6-15_13-33-32.png

    If you are trying to combine meshes without baking textures first, try making sure that the Mesh Baker component is NOT a child of a Texture Baker component in the hierarchy.

    Let me know if these do NOT fix your problem.
     
  8. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Phong likes this.
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
  10. FinsworksInteractive

    FinsworksInteractive

    Joined:
    Jul 8, 2018
    Posts:
    8

    Thank you! the 1st solution worked. Though another possible issue arises?
    now the generated combined school of fish has weird "culling" depending on where the camera are, they keep disappearing in random if you get close enough. No Occullision culling is active, or any flag for it of any short.

    https://thumbs.gfycat.com/TotalHospitableChimpanzee-mobile.mp4
    what could possibly cause this?
     
  11. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    This problem is almost certainly the "render bounds" of the SkinnedMeshRenderer component. You can set this on the component. If these bounds do not intersect the camera fustrum then the skinned mesh is not renderered (becomes invisible). This can be problematic when combining multiple SkinnedMeshRenderers because they can move arbitrarily far apart. You have a few choices.
    • Set this to something large, and add a script so that SkinnedMeshRenderer transform follows the center of the school of fish.
    • Use one of the MeshBaker scripts to update the render bounds dynamically there is one that updates based on the bones and one that updates based on the source render bounds.
    • Write your own custom script that updates the SkinnedMeshRender bounds if you know something about how the fish are going to move.
    BTW: I just released a new version of Mesh Baker which should fix the "baking skinned meshes that arn't instances of a prefab" problem.
     
  12. CWatsonT2

    CWatsonT2

    Joined:
    Jan 9, 2019
    Posts:
    114
    I want to thank you. The URP shader is applying the colors to the atlas perfectly now. I'm still having a quality issue that I can't get sorted out. The quality of the textures is really degraded compared to the original even though it's a 4k atlas. You can see it in the attached image. The shelf in the back is the original and the front shelf is mesh combined with a texture atlas. The original wood texture is 1024x1024 and ends up being the same size on the 4k texture atlas but the quality looks worse. What am I missing here?
     

    Attached Files:

  13. UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    Joined:
    Jan 9, 2017
    Posts:
    151
    Hi Phong! So I attempted running the baking process on runtime (when the game is playing) and it works beautifully! But I have a slight concern. What is the reason in having my textures to be true colour (no compression) / RGBA 32Bit formats? Because this blows up my texture size from 2mb to 21+mb and I have 100 over textures... </3

    Edit: I'm suddenly having an issue. I can't combine an instanced (clone) material?
    So what is happening is that I have 1 material (shared material reference) which I will duplicate and apply player's custom skins in the texture map. Because if I don't do that, all the players will be seeing the same skin. I'm using Photon Pun2.
    Code (csharp):
    1. The sharedMaterial on object combined has been 'Instanced'. This was probably caused by a script accessing the meshRender.material property in the editor.  The material to UV Rectangle mapping will be incorrect. To fix this recreate the object from its prefab or re-assign its material from the correct asset.
    2. UnityEngine.Debug:LogError(Object)
    3. DigitalOpus.MB.Core.<__Step1_CollectDistinctMatTexturesAndUsedObjects>d__9:MoveNext() (at Assets/Settings/Asset Store Packages/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombinerPipeline.cs:333)
    4. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32) (at Assets/Settings/Asset Store Packages/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:284)
    5. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32) (at Assets/Settings/Asset Store Packages/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:297)
    6. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32) (at Assets/Settings/Asset Store Packages/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:297)
    7. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32) (at Assets/Settings/Asset Store Packages/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:297)
    8. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32) (at Assets/Settings/Asset Store Packages/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:297)
    9. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32) (at Assets/Settings/Asset Store Packages/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:297)
    10. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause(IEnumerator, Int32) (at Assets/Settings/Asset Store Packages/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:297)
    11. MB3_TextureBaker:CreateAtlases(ProgressUpdateDelegate, Boolean, MB2_EditorMethodsInterface) (at Assets/Settings/Asset Store Packages/MeshBaker/scripts/MB3_TextureBaker.cs:530)
    12. MB3_TextureBaker:CreateAtlases() (at Assets/Settings/Asset Store Packages/MeshBaker/scripts/MB3_TextureBaker.cs:226)
    13. RuntimeMeshBakerCombiner:Combine() (at Assets/Scripts/Photon Networking/RuntimeMeshBakerCombiner.cs:49)
    14. System.Reflection.MethodBase:Invoke(Object, Object[])
    15. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    16.  
     
    Last edited: Jun 18, 2020
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    What does the atlas look like? My guess is that the wood is being tiled. This tiling needs to be baked into the atlas unless. There should be messages in the console if this is the case:
    • The wood is on its own submesh.
    • You are using TextureArrays in which case the wood can be on its own slice.
    • You might be able to fix the issue using edge to edge texture baking if the tiling only happens in one direction.
     
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Regarding runtime baking and using ARGB formats:

    If you are using the "Mesh Baker Texture Packer", then you need the source textures to be in ARGB32 format because these are the only formats for which it is possible to read and write pixels. The Mesh Baker Texture Packer uses the Unity Texture2D API to read pixel data.

    If you are using the "Mesh Baker Texture Packer Fast", then you don't need the source textures to be in ARGB32 format, because this texture packer uses the GPU to copy pixel data. This is much faster but there are a few downsides. Compression artifacts are copied if the source textures are compressed. You can't use some features like "Blend Non-Texture Properties".

    Regarding the material "Instancing" problem:

    The reason for this error is that when textures are baked, Mesh Baker creates a "map" that maps source-materials to atlas-rectangles. The "key" for this map is the source-material. When the meshes are baked, this key is used to look up the atlas-rectangle that the mesh UVs need to resized to fit into.

    Most of the time when materials are duplicated into an instance it is a mistake. It is very easy to duplicated a material by mistake in Unity. All you need to do is have a script that accesses "myRenderer.material". When this happens to users it creates hard to track down bugs, because they think they are baking a material into the atlas, but when they try to bake a different mesh that has what they think is the same material assigned, then Mesh Baker complains that it doesn't know about this material. It is very confusing because all the materials look the same but the user is not aware that they are using multiple duplicates.

    The easiest fix/workaround is to change the name of the material so that it doesn't have the word "Instance" in it. That is what Mesh Baker is using to detect if the material has been duplicated.
     
  16. UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    Joined:
    Jan 9, 2017
    Posts:
    151
    Thanks for getting back! Took me a while to get everything sorted.

    I wasn't aware of "Mesh Baker Texture Packer Fast" but now I'm using that and I'm getting superb speed (less than 0.5s) on both desktop testing and mobile build :)

    Also, renaming and removing the word "Instance" works like a charm :)

    But I have a small warning. On the desktop, there is no warning. But on mobile I have this:
    "Mesh <xxx> (UnityEngine.Mesh) didn't have tangents. Generating tangents."
    So on mobile, I can't be sure if the mesh was in fact combined properly because I'm not able to go into the inspector to see what is going on and whether disabling the newly generated mesh actually hides everything I wanted to combine. Any idea what this warning is about?
     
  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    The problem is probably due to: Player Settings -> Optimize Mesh Data*

    What this setting does is try to detect which mesh channels your shaders are using, and removes channels from meshes that are not used by your shaders. This optimization happens when a build is created. This could be removing your "Tangents" channels from your meshes. You should be able to fix it by either:

    • Unchecking the "tangents" channel on the Mesh Baker. Do this if your shaders truly do not need tangents.
    • Unchecking the "Optimize Mesh Data" on the Player Settings.
     
  18. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    Hi, I did not tried your asset but before buying I want to ask few questions.

    1. Does your tool support tiled textures? I mean in my game I have cubes where top face have different material with different X and Y tiling and on side faces I have different material with Different X and Y tiling. Both materials are of same shader type. Can your asset combine both in terms of meshes and in terms of materials?

    2. In my game, I setup all things. All static meshes, some vehicles, some animated characters. Now I come to know it needs optimization. But every thing is set and I can not go back to 3D modeling software. I want to combine mesh and materials in unity without disturbing my game setup at all. I would like to combine any static mesh with any other mesh with the only limitation that all meshes which I want to combine belong to same shader. Similarly I want to combine all Skinned meshes belonging to same skeleton rig but containing different materials and different meshes together. Some times the character has hats, swords etc and they are not merged correctly with some free scripts I have.

    3. Can you please compare your asset with ProDrawCall Optimizer, Poly Few, Skinned Mesh Combiner MT?

    I might be asking some more questions but I want to buy the best tool out of 3 other tools I am comparing yours with.

    Regards,
     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    1) Regarding tiling:
    There are a few ways to handle this:
    • Mesh Baker can bake the tiling (both tiling from material scale and offset, and tiling from UVs outside 0..1 range). This works well as long as there is not a lot of tiling. If there is a lot of tiling then it uses a lot of space in the atlas and my not fit without downsizing.
    • If your object has a lot of materials but only a few of them have extensive tiling, they can be mapped to a separate submesh where the original material is re-used. The other materials are baked into atlases. Often with sketchup houses that have 20-30 materials, the number of materials can be reduced to 2-3.
    • If you tiling is done using UVs outside the range 0..1, then you can bake texture arrays. Texture arrays are like a stack of textures. Each slice in the stack is free to tile. Warning, switching to texture arrays is a big commitment and technically advanced. It usually requires creating duplicate, modified, shaders and all meshes that use them need to be baked to have the slice index inserted.
    2) Regarding how to combine things:
    Mesh Baker is a very flexible tool, there are a lot if different ways to use it (workflows).
    • It has tools for quickly selecting and grouping all props in the scene by a wide variety of criteria (shader, material, how close they are together, static flags, lightmap index, render type, location in scene hierarchy). Once props have been grouped you can work with that set of props (bake textures and meshes together).
    • It has a workflow for working with prop prefabs. You can create atlases from your prefabs and create duplicate prefabs with adjusted meshes that use a combined material. There is a tool for switching the prefab instances in your scene with the duplicates. This is great if you want to let static/dynamic batching do your mesh combining.
    • It has tools for grouping meshes that are close together in a scene.
    • It supports baking skinned meshes and MeshRenderers (sword, armour, etc..) into a combined skinned mesh. It is very full featured, including support for blend shapes, and smoothing normals at seams.
    3) Regarding differences with other assets:

    • I would suggest watching some of the tutorial videos for each of the assets to get a sense of how they work. IMO comparing a list of features is not all that useful. You really want to get a sense of what the workflows are like.
     
  20. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    Hi,
    Thanks for replying. After your comments, I thought to give your tool a try before making final choice. So i tried Free version of Mesh baker. I have made up my mind to buy the tool as soon as I get your reply. Below are some of my comments.

    1) I have vehicles in my game. I was needed to have 4 wheels as separate to assign to Realistic Car Controller Asset. So i converted the car mesh into Skinned Mesh Renderer using your asset and your asset converted it into skinned mesh and still RCC is able to detect the separate tyres but the whole vehicle is now in 1 draw call instead of 5. This is really great as I have some times 10 vehicles also in the scene along with drivers having skinned mesh renderers.

    2) I have some passengers sittings in vehicles. When I combine passengers with same material, they are combined perfectly. But when I combine passengers with different material, they are just invisible if I chose to combine them as skinned mesh through TEXTURE BAKER AND MESH BAKER TOOL. See Image 1 below. But If I don't bake it from there but instead I bake it from MESH BAKER tool and assign combined material element there and then bake, it works just fine. But there arises an issue. Before baking the color of character is different before and after baking it. This is not the case however for other meshes and with this specific mesh. The others are using proper textures and this one is using color pallete( very small colored boxed and mesh UVs are inside those boxes with very low UV resolution.) can this be the problem? See image 2 and 3 for this problem.

    3) In my games there are many roads, embankments, cliffs etc all using different materials with different tiling values. I tried to combine the road and embankmenet of my road piece and it combined nicely but here I see some of black artifacts which I could not get rid of even after changing padding values. Can you please through a light over it how to do that? As I make driving simulation games combining roads, embankements, cliffs etc is must for me. See image 4 and 5.
     

    Attached Files:

  21. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    4) When I combine any of skinned meshes, then the meshes are not the child of the parent object I attached script to. This should be automatic to make the object the child of some parent element we want to. Also when i combine skinned meshes, the mesh is in the place of individual meshes but what disturbs me, the BOUNDS CENTER value. the bounds represent the world position of the mesh transform and the TRANSFORM value is 0,0,0. I thought it would be reverse. The mesh bounds center should be 0,0,0, or some such smaller value wherase the transform should be getting the world position. This creates problem when I assign the rig to the combined meshes. See image 6.

    5) Also I could not understand how this is going to work. I have two characters with two different rig hierarchy and two different avatars. Can they both be combined together? If yes then which Rig Root bone would be controlling animations? For single character what I think there is a rig with bone weights. Then the unity creates humanoid avatar where mapping is done between character bones and skin. Then this rigged bone hierarchy can control the character to aniamte. But in combined skinned mesh renderers, how will this work?

    Thanks for your time to read this all.
     

    Attached Files:

  22. UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    Joined:
    Jan 9, 2017
    Posts:
    151
    Ahh I see. I did a quick google search and it appears that tangents are related to bump maps. Do normal maps use tangents too?

    I have another question. Sorry
    Here's the scenario:
    - Players join a game room (up to 6) and only the host can start the game.
    - The host starts the game (button click), a remote call is sent to all client to start the game.
    - In the start game method, the runtime baking is done. So far, with your help, everything is great!
    Issues coming in hot now...
    - If anyone of the clients loses connection and disconnects from the game room (using Photon Pun2 for networking), Photon will remove that player's game object from the scene. If you have used Photon before, this game object is Photon-instantiated. So if the connection drops, Photon automatically removes the game object.
    - When this happens, the mesh of this disconnected player which is part of the runtime baked mesh snaps to world 0,0,0, which is right smack in the centre of the battleground... Lol. What can I do about this?
    - All players have a TTL (time to live) timer which means that they can rejoin the game if disconnected. But on rejoining, Photon will Photon-instantiate the players game object again and this is not part of the runtime baked mesh. So now, we're seeing the remnants of the disconnected player in the middle of the battleground and the new player's unbaked mesh moving around freely. I can control Photon to not instantiate the player's game object on rejoining but is there a way to sort of "link back" to the mesh inside of the baked skinned mesh?
     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Regarding normal maps and bump maps, they are treated exactly the same way inside the shader. They both need tangents to do dynamic lighting calculations.

    Regarding the Photon problem.I think what is happening is this. In the heirarchy you have:
    • Photon game object
      • Source skinned mesh(es) (disabled)
        • Bones of skinned mesh
    • Baked Combined Skinned Mesh (uses bones from source skinned mesh)
    When the "Photon game object" is deleted, the "bones of skinned mesh" are deleted. These bones are used by the Combined Skinned Mesh. When the Combined Skinned Mesh looses its bones, it cannot be deformed so you see the mesh as it was modeled (at 0,0,0).

    Solutions:

    1) If you want the combined skinned mesh to be deleted too then move it so that it is a child of the Photon Game Object. When a play re-connects you could bake at that time.
    2) You could move the "Source Skinned Mesh(es)" out from under the photon object in the hierarchy. Then when the Photon Game Object is disconnected it will survive. You could disable it, then when/if they reconnect, you could enable it and reattach it to the photon game object.
     
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Re: Character using a color tint. The easiest thing to do would be to create a small solid color texture for that slot. Don't make it too small or it can get blended with neighboring textures in the mip-maps I would recommend 64 pix or 128 pix. Or you can enable "blend non-texture properties". This feature tires to blend color tints into the textures as they are baked. It requires knowledge of the shader being used, if you are using "Standard" shaders or "Diffuse" shaders then it should work, if you are using a custom shader then it might work.

    Re: Invisible characters: There is a section in the manual on special considerations when baking skinned meshes. I would check that. It is likely that the problem is related to Skinned Mesh Render Bounds. Are there any error messages in the console? You might also want to check out this video:



    Re: Tiling roads/trees. I would suggest checking out this video on baking tiling meshes. Quick summary:
    • For meshes with a small amount of tiling, turn on "consider mesh UVs"
    • For meshes with a lot of tiling, map the material to a separate submesh (combined material)
    • If you are adventurous and have a lot of time consider using Texture Arrays

     
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Regarding why the combined skinned mesh is a separate game object: This is because most of the time there is more than one source skinned mesh (your question 5). There is no way to choose which source game object the combined skinned mesh should be a child of. You can combine multiple skinned meshes (with separate animator's and rigs). The combined skinned mesh uses the bones from those multiple-source-animated-rigs. See the skinned mesh tutorial video I mentioned in the previous post. It shows how to combine two rigs.

    Regarding bounds center and and location. of the combined mesh transform. For Skinned meshes, the transform position of the skinned mesh renderer is ignored because the mesh is deformed by the source bones, which could move around in the scene. You are right however that the SkinnedMeshRenderer.Bounds does matter. This needs to be dynamically updated (Mesh Baker includes some scripts that do this), or it needs to be large enough to contain all possible movement and move with the animated characters. You may need to write a custom script to move it or position it as a child of something that is moving with the center of the cluster of animated source bones.

    Regarding multiple source skinned meshes. There are two parts to a skinned mesh setup that are loosely coupled through an array of transforms called the "bones". The "bones" is nothing more than an array of Transforms:

    • The animated rig. The ultimate job of the animated rig is to move the bone Transforms. All of the root bone/animation rig stuff you are asking about applies only to this part.
    • The SkinnedMeshRenderer. This takes the array of bone transforms as input. It does not care how the bones are moved. They could be animated using an Animator, they could be moved by physics, they could be moved by a script.
    The combined mesh works because it doesn't care how the bone transforms are moved. These get moved by the source renderers, that are animated by the source animators and scripts.
     
  26. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    Thanks for so much details. I will check out tutorials and I must say, your support is excellent.
     
  27. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    So, I read your tutorial about the Texture Arrays and this is working as I expected. The only problem I am facing now is that the combined mesh is UNLIT. I used UNLIT TEXTURE ARRAY SHADER from your github repository and after baking I changed its type to STANDRD TEXTURE ARRAY shader but still it is unaffected by light. You can see in image. Is it because of free version? I want the unlit road as brighter as the enlighten road.

    EDIT : I just bought your asset today and tried STANDARD TEXTURE SHADER provided by you in github repository and still the road is not bright. I can see the lighting is baked as you can see in the attached image 2 as well. But in Standard Texture Array Shader (provided by you) it is not working. lighting difference in textured array.PNG image 2.PNG
     
    Last edited: Jun 28, 2020
  28. Quantumstorey

    Quantumstorey

    Joined:
    Jun 1, 2017
    Posts:
    9
    I can't seem to bake into prefabs since upgrading to Unity 2019.3.15f

    I have a baked model that I'm switching form scene to prefab baking. I create an empty game object and then drag it into the project view to create the prefab. I assign that prefab as the bake target in the mesh bake. When I click bake, I get this error:

    Any suggestions?

    Code (CSharp):
    1. System.InvalidOperationException: Destroying a GameObject inside a Prefab instance is not allowed.
    2.   at (wrapper managed-to-native) UnityEngine.Object.DestroyImmediate(UnityEngine.Object,bool)
    3.   at DigitalOpus.MB.Core.MB_Utility.Destroy (UnityEngine.Object o) [0x00016] in C:\D_Drive\trolls\Assets\MeshBaker\scripts\core\MB_Utility.cs:403
    4.   at DigitalOpus.MB.Core.MB3_MultiMeshCombiner.DestroyMesh () [0x00027] in C:\D_Drive\trolls\Assets\MeshBaker\scripts\core\MB3_MultiMeshCombiner.cs:655
    5.   at DigitalOpus.MB.Core.MB3_MultiMeshCombiner.ClearMesh () [0x00001] in C:\D_Drive\trolls\Assets\MeshBaker\scripts\core\MB3_MultiMeshCombiner.cs:632
    6.   at MB3_MeshBakerCommon.ClearMesh () [0x00001] in C:\D_Drive\trolls\Assets\MeshBaker\scripts\MB3_MeshBakerCommon.cs:166
    7.   at MB3_MeshBakerEditorFunctions.BakeIntoCombined (MB3_MeshBakerCommon mom, System.Boolean& createdDummyTextureBakeResults, UnityEditor.SerializedObject& so) [0x001f5] in C:\D_Drive\trolls\Assets\MeshBaker\Editor\core\MB3_MeshBakerEditorFunctions.cs:93
    8.   at DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal.bake (MB3_MeshBakerCommon mom, UnityEditor.SerializedObject& so) [0x00029] in C:\D_Drive\trolls\Assets\MeshBaker\Editor\MB3_MeshBakerEditorInternal.cs:447
    9. 0x00007FF7639B1C9C (Unity) StackWalker::GetCurrentCallstack
    10. 0x00007FF7639B5C51 (Unity) StackWalker::ShowCallstack
    11. 0x00007FF7620C1F45 (Unity) GetStacktrace
    12. 0x00007FF7646252EE (Unity) DebugStringToFile
    13. 0x00007FF763A10345 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    14. 0x000001747FA1806B (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
    15. 0x000001747FA17EEB (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    16. 0x000001747FA1736E (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
    17. 0x00000171F76DF22A (Mono JIT Code) UnityEngine.Debug:LogError (object)
    18. 0x00000171E05D5F7B (Mono JIT Code) [MB3_MeshBakerEditorInternal.cs:476] DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:bake (MB3_MeshBakerCommon,UnityEditor.SerializedObject&)
    19. 0x00000171E00C751B (Mono JIT Code) [MB3_MeshBakerEditorInternal.cs:393] DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:DrawGUI (UnityEditor.SerializedObject,MB3_MeshBakerCommon,System.Type)
    20. 0x00000171E00C273B (Mono JIT Code) [MB3_MeshBakerEditorInternal.cs:151] DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:OnInspectorGUI (UnityEditor.SerializedObject,MB3_MeshBakerCommon,System.Type)
    21. 0x00000171E00C25F3 (Mono JIT Code) [MB3_MultiMeshBakerEditor.cs:70] DigitalOpus.MB.MBEditor.MB3_MultiMeshBakerEditor:OnInspectorGUI ()
    22. 0x000001747E83AD00 (Mono JIT Code) UnityEditor.UIElements.InspectorElement/<>c__DisplayClass58_0:<CreateIMGUIInspectorFromEditor>b__0 ()
    23. 0x00000174463C169A (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:DoOnGUI (UnityEngine.Event,UnityEngine.Matrix4x4,UnityEngine.Rect,bool,UnityEngine.Rect,System.Action,bool)
    24. 0x00000174463AF433 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,UnityEngine.Matrix4x4,UnityEngine.Rect,System.Action,bool)
    25. 0x000001747E8628DB (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,System.Action,bool)
    26. 0x000001747E863C23 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,bool)
    27. 0x000001747E8637E3 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUI (UnityEngine.UIElements.EventBase,bool)
    28. 0x00000173B9A00453 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleEvent (UnityEngine.UIElements.EventBase)
    29. 0x00000173B99B8496 (Mono JIT Code) UnityEngine.UIElements.CallbackEventHandler:HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase)
    30. 0x000001747E853E03 (Mono JIT Code) UnityEngine.UIElements.MouseCaptureDispatchingStrategy:DispatchEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
    31. 0x00000173B99B26D6 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel,bool)
    32. 0x00000173B99B1323 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ProcessEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
    33. 0x00000173B99B05BB (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ProcessEventQueue ()
    34. 0x00000173B99B01EB (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:OpenGate ()
    35. 0x00000173B99AFD1B (Mono JIT Code) UnityEngine.UIElements.EventDispatcherGate:Dispose ()
    36. 0x00000173B99B1C2B (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ProcessEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
    37. 0x00000173B99AAB83 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:Dispatch (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel,UnityEngine.UIElements.DispatchMode)
    38. 0x00000173B99AA6EB (Mono JIT Code) UnityEngine.UIElements.BaseVisualElementPanel:SendEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.DispatchMode)
    39. 0x0000017446354D63 (Mono JIT Code) UnityEngine.UIElements.UIElementsUtility:DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel)
    40. 0x000001744635410B (Mono JIT Code) UnityEngine.UIElements.UIElementsUtility:ProcessEvent (int,intptr)
    41. 0x0000017446353973 (Mono JIT Code) UnityEngine.GUIUtility:ProcessEvent (int,intptr)
    42. 0x0000017446353BF3 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_bool_int_intptr (object,intptr,intptr,intptr)
    43. 0x00007FFEC283CBA0 (mono-2.0-bdwgc) [mini-runtime.c:2809] mono_jit_runtime_invoke
    44. 0x00007FFEC27C2112 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke
    45. 0x00007FFEC27CB10F (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke
    46. 0x00007FF763925BDE (Unity) scripting_method_invoke
    47. 0x00007FF76391F94D (Unity) ScriptingInvocation::Invoke
    48. 0x00007FF76391995A (Unity) ScriptingInvocation::Invoke<bool>
    49. 0x00007FF760CA70D5 (Unity) Scripting::UnityEngine::GUIUtilityProxy::ProcessEvent
    50. 0x00007FF7616ADB44 (Unity) GUIView::ProcessRetainedMode
    51. 0x00007FF7620E80E9 (Unity) GUIView::OnInputEvent
    52. 0x00007FF7616ADA3C (Unity) GUIView::ProcessInputEvent
    53. 0x00007FF7620E9AB5 (Unity) GUIView::ProcessEventMessages
    54. 0x00007FF7620E27F6 (Unity) GUIView::GUIViewWndProc
    55. 0x00007FFF2D315C0D (USER32) CallWindowProcW
    56. 0x00007FFF2D315602 (USER32) DispatchMessageW
    57. 0x00007FF7620E6D14 (Unity) MainMessageLoop
    58. 0x00007FF7620F0F18 (Unity) WinMain
    59. 0x00007FF7650C2692 (Unity) __scrt_common_main_seh
    60. 0x00007FFF2CAF7BD4 (KERNEL32) BaseThreadInitThunk
    61. 0x00007FFF2E94CE51 (ntdll) RtlUserThreadStart
    d
     
  29. FictiveDev

    FictiveDev

    Joined:
    Aug 14, 2019
    Posts:
    6
    Hi!
    I have a scene with a lot of objects which uses solid color (standard shader with no textures). How should I go about to optimize this using mesh baker? I've tried already with the "standard" approach but the thing is that Mesh Baker only deals with the texture properties of the combined material shader. It would be great if MB could create (for each single object) a small texture with the right color and place all those in an atlas. Is it possible?
     
  30. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    What version of Unity and rendering pipeline are you using? The shader in github is based on Unity 2018.4. It is likely that it doesn't work properly in 2019.4. I should update it with a 2019 version.
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    When you say "switching form scene to prefab baking" I presume that you are inside the prefab-baking-staging-scene?

    I don't think that will work. I think you need to do the bake from inside the regular Unity scene.
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Yes, this is possible. Enable the "Blend Non-Texture Properties". Be sure to use the "Texture Packer => Mesh Baker" When you do this Mesh Baker will attempt to create small solid color textures and use these in the atlas. It should work well if you are using the Standard Shader. If you are using a custom shader you may need to write your own Texture Blender to get it to work correctly.
     
  33. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    I am using unity 2018.4.10f1 with built in render pipe line. (I am not using HDR).
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I will give it a test later today to see if I can see what is happening.
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I tested in 2018.4 with the github texture array shader and it appears to be lighting for me. (One set of cubes use StandardTextureArrayShader, the other uses Standard).

    Low light intensity
    upload_2020-6-29_13-47-30.png
    High light intenstity
    upload_2020-6-29_13-48-22.png

    Some thoughts. Are the MeshRenderer settings and static flags for the combined mesh the same as for the source? Is is baked lighting (if so you will need to bake the combined mesh)? Does the combined mesh have the same channels as the original?
     
  36. amynox

    amynox

    Joined:
    Oct 23, 2016
    Posts:
    177
    Is mesh baker work with URP?
     
  37. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    I am for the time being concluding my game without using texture arrays. After this game, I will test the problem in detail and will report you back. I am enjoying your tool so far. It helped me in reducing draw calls upto 50%. Also since in my games, there I use a lot of vehicles and prior each vehicle was using 5 draw calls and I have converted them to skinned meshes and now the whole vehicle along with tyres using 1 draw call and still I can animate the tyres separately. This is really good!
     
    Phong likes this.
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Yes, it works with URP. The examples will be pink when you first install the package. There is a UnityPackage in the project (Examples_URP.UnityPackage). If you import this package then the examples will be updated to use the URP/Lit shader. I am working on a script to detect the pipeline and do this automatically but it is not in the current version.
     
    amynox likes this.
  39. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    I'm having an issue that I just recently tracked down to my MeshBaker meshes. I'm trying to combine textures of several houses into one texture for all of them, they each have 10 materials (background houses). I then generate new meshes for each....and they look good. The issue comes in when I try to use ProBuilder to edit the meshes. Some UVs tend to be really small, so small that they look black in the editor and game. I'm also noticing some meshes that get baked have very small UV's for certain materials.

    Do you know a solution to this?
     

    Attached Files:

    Last edited: Jul 5, 2020
  40. Fernando-Pain

    Fernando-Pain

    Joined:
    Jun 20, 2016
    Posts:
    6
    Hi, I'm trying to combine several materials from a given skinned mesh (coming from character creator 3), all is fine but the normal map, which is somehow corrupted and presented in pink color in the inspector.

    Original model
    upload_2020-7-6_12-28-46.png



    Texture and mesh baking result

    upload_2020-7-6_12-18-41.png


    normal map atlas result

    upload_2020-7-6_12-29-54.png


    I mainly bough Mesh Baker to optimize CC3 Characters, I hope they are compatible with Mesh baker and this normal map issue can be fixed. Help please.
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Here is what I think is happening. Some of your source materials don't have textures. They are using color tints. Mesh Baker is creating a small 16x16 texture to use in the atlas for these materials. This 16x16 is much smaller than some of your other textures, (probably 512, 1024 or 2048). As a result the meshes that use the 16x16 textures are getting their UVs squashed very, very small.

    Some thoughts:
    • Is this a problem? Does it matter that they are so small?
    • If you want them to be larger you could assign a solid color texture to the source material that is bigger. Then it will use a larger rectangle in the atlas and the UVs will be bigger.
     
  42. roundyyy

    roundyyy

    Joined:
    Dec 23, 2019
    Posts:
    112
    Hi, I have scene with 100s combined meshes and their atlases. Is there any quick way to generate UV2_layout on them?
     
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hmmm, which version of Unity, render pipline, build target, Color space and shader are you using? If it is a custom shader what is the name of the normal map channel in the shader? You might need to add the name of the normal map channel to the list of "Custom Shader Property Names" and check the "normal map" box, otherwise Mesh Baker won't know it's a normal map channel (normal maps require slightly different processing than regular textures).

    If the issue is not "Custom Shader property Names" If it is possible to create a simple case (put two of your materials on a couple of cubes) and send the package to me, I will take a look to see if I can deduce what is going on.
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    You will need to rebake the Meshes, (not the Texture Atlases). If you still have the Mesh Bakers you can configure the settings to "Lightmap UVs = generate UV2 layout". Note that Mesh Bakers can share settings, so once you have configrued the settings once you can assign the settings to all the other Mesh Bakers. Baking the meshes is very quick, you can multi select them and click bake, or make them all a child of a GameObject with a Mesh Baker Grouper and click "Bake All Child Mesh Bakers".
     
  45. roundyyy

    roundyyy

    Joined:
    Dec 23, 2019
    Posts:
    112
    Unfortunately Mesh Bakers are removed :(
    Can I somehow do it in bulk on generated meshes (in editor), without combining, just adding UV2?
     
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    There is a method in the Unity API for generating UV2 channels. You could write a script that:

    • Finds all MeshRenderers in the scene. Collect a distinct set of meshes. Store these in a list
    If the list of meshes looks good then visit each mesh and
    • Retrieve the UV2 channel from each of these. If it has length 0 then you need to generate one.
    • Calls Unwrapping.GenerateSecondaryUVSet() on each mesh to generate a UV2 channel.
     
    roundyyy likes this.
  47. roundyyy

    roundyyy

    Joined:
    Dec 23, 2019
    Posts:
    112
    One more question. How can I set Max Verts in Mesh in Mesh Baker Grouper? Or are we limited to 65k there? I would like to combine meshes in cells bigger than 65k. Only option I see is to use MultiMeshBaker, but it doesn't have grouping/cluster. Sorry if these are stupid questions, but I'm bit lost. Thank you for your help
     
  48. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    I noticed that one of the textures I want to combine has an Occlusion Map and Height Map, but none are using color tints. I'll try baking it without those maps to see the results.

    Its a problem because any place where there are very small UV's it causes artifacts when there are transparent objects between it and the camera. They look like large black boxes.
     
  49. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    The regular MeshBaker can bake meshes with greater than 65k verts. It will automatically set the correct mesh flags if the combined mesh has more than 65k verts. If you want to split the mesh on number of verts you need to use the MultiMeshBaker. You can set the "Max Verts In Mesh" to greater than 65k.

    Also when you use MeshBakerGrouper -> Generate Mesh Bakers, it will generate

    • an MB3_MeshBaker component if the total verts in source meshes is less than 65 k
    • an MB3_MultiMeshBaker component if the total verts in source meshes is more than 65 k
    You can then configure the "Max Verts In Mesh" on the MultiMeshBaker component.
     
    roundyyy likes this.
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Another reason that you might be getting such a big difference in texture size in the atlas is tiling. It is very common for buildings to have some textures with a lot of tiling. If a few of your textures have massive tiling you can map these to a separate submesh (material). This can reduce atlas usage a lot.

    This tutorial describes this technique.

     
    FiveFingerStudios likes this.