Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. 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:
    1,862
    One quick thing to check, Are you leaving the MeshBakers in the scene? Do you have "clear buffers after bake" enabled? It should shrink things a lot if you have that checked. You could also try deleting the MeshBaker out after baking to see if that helps.

    The scenes will be larger because previously Unity would have one mesh (eg. a rock) and would draw that 100 times. The memory needed is just the memory for the rock once. When the 100 meshes are combined, the vertices are duplicated 100 times resulting in a large mesh. There isn't a lot you can do to fix this. Static batching has this problem too. Some options:

    1) Do the mesh baking at runtime just after the scene loads. Then you get the small scene for ship, but a large scene in memory after it loads. The large scene never exists on disk.
    2) Check that you aren't baking any more channels than you need in the combined mesh. If you don't have bump maps then you can get rid of tangents.
     
  2. satyaloka

    satyaloka

    Joined:
    Dec 3, 2017
    Posts:
    2
    I did used "Clear Buffers", but now I've redo the baking with less channels and some tweak on the original mesh, I managed to shrink it down to 89MB. I guess there's nothing much left to do, except doing the baking after the game first load.

    Thank you so much for the great tool and help!
     
    Phong likes this.
  3. lzardo2012

    lzardo2012

    Joined:
    Apr 11, 2013
    Posts:
    52
    Hi
    I´m getting this error, trying to build for Android:

    Assets\MeshBaker\Examples\Scripts\MB_MigrateMaterialsToDifferentPipeline.cs(26,32): error CS0103: The name 'EditorUtility' does not exist in the current context
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    Apologies, one of the scripts has editor only code which won't compile when creating builds. I will push up a bug fix version right away, but it can take 2-3 days to go live. In the meantime you can make the following changes to fix it. Add the "if UNITY_EDITOR" and "#endif" in the code bellow. You need to wrap the "using UnityEditor" in #if UNITY_EDITOR... #endif. And wrap the contents of the class MB_MigrateMaterialsToDifferentPipeline in #if UNITY_EDITOR... #endif:

    File: MB_MigrateMaterialsToDifferentPipeline.cs

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. #if UNITY_EDITOR
    5.     using UnityEditor;
    6. #endif
    7. using DigitalOpus.MB.Core;
    8.  
    9. ...
    10. ...
    11. ...
    12.  
    13. [ExecuteInEditMode]
    14. public class MB_MigrateMaterialsToDifferentPipeline : MonoBehaviour
    15. {
    16. #if UNITY_EDITOR
    17.     ...
    18.     ...
    19.     ...
    20. #endif
    21. }
    22.  
     
  5. lzardo2012

    lzardo2012

    Joined:
    Apr 11, 2013
    Posts:
    52
    Hello

    thanks!

    For now, I simply commented all tat script and it worked, guess I´ll wait till the next update to have it fixed.


    By the way, I have another question, probably a silly one, but:

    I have some textures that I want to atlas together, BUT, the objects UVs does not fit inside the UVs, most of them have UVs outside the limits of the map and, it´s necessary there´s no way to get around it easilly

    Is there a way to atlas it correctly?
     
    Phong likes this.
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    Yes, there is a checkbox on the TextureBaker "Consider Mesh UVs". If this is checked then Mesh Baker will look at the UVs of the source meshes and copy exactly enough texture to span the UV layout. This is useful both for your case where the UVs go outside the range 0..1 (tiling). It is also useful if you include a prop that uses a tiny part of a huge texture and you don't want to include the entire giant texture in your project.

    upload_2021-3-8_7-51-20.png
     
  7. lzardo2012

    lzardo2012

    Joined:
    Apr 11, 2013
    Posts:
    52
    Hmm, thanks, gonna try that!
     
  8. GameHourStudio

    GameHourStudio

    Joined:
    Apr 17, 2020
    Posts:
    104
    Hi Phong, I mailed you few of my queries related to mesh baker today. Kindly respond. Also I asked you few questions on Mesh Baker LOD forum two days ago. I think you missed notifications. Kindly respond that as well. Thanks.
     
  9. PhilFaily

    PhilFaily

    Joined:
    Jul 31, 2017
    Posts:
    7
    Feature Request - Get/Update Objects To Be Combined From a Parent (Button in Baker Component)

    In our project whe world is sectioned up in chunks and connected using sectors/portals, we are using a single material for everything.

    Every time we modify a chunks source mesh objects by adding or removing objects, we need to edit the Objects To Be Combined Array.

    The current way we do this is to set the Array Length to 0 to Clear it to ensure it only contains the latest objects, then Click Open Tools for Adding Objects. This automatically fills in the correct mesh baker reference for the Search For Meshes to Add. Then we select the parent object of the chunk and click Add Select Meshes To Target.

    This generally works ok but its a lot of clicks when all we want to do is tell the Baker to just traverse the same Parent again and Update the List.

    A nice feature here would be set the Parent into the Baker component as a container reference and then an Update List button, done in one click. The real benefit of this feature is that it would likely reduce the possibility of mistakes and the tedium of the work flow.

    We are aware its possible to drag the Parent onto the Baker Component but this has no filters and you will get objects that are disabled added into the list.

    I thought about writing my own Editor Window Tool to contain a list of Bakers and their Parent Container objects and manually fill in the Custom List of Objects Array externally but I've looked at the API and I really didn't know where to start.

    One other idea was to have the Baker monitor the Parent Container child count and flag that it has been modified and needs to be updated.
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    Are you using a set of filters? Is it enough to traverse the hierarchy or do you need the Mesh Baker to remember the set of filters that was used too?
     
  11. PhilFaily

    PhilFaily

    Joined:
    Jul 31, 2017
    Posts:
    7
    Hi Phong, firstly thanks for making MB its a god send! :)

    We don't use any shader/material filters, since every mesh renderer under a parent is 'known' to be part of the chunk bake and we are using a single material. The only thing we may leave on is ignore disabled game objects.

    In the section of the Mesh Baker component where it says to drag a parent in:
    • it would be great if it kept the parent as a reference or had a field to drag the source parent into
    • a checkbox to ignore inactive gameobjects
    • a button to 'Refresh' the list. This would make it a single button press after modifying the source parents children.
    As mentioned before a nice QOL feature would be to have the Baker Check the list length and Source Child Count and display a warning or notice that the list is not sync'd with the source list.
     
    Phong likes this.
  12. GameHourStudio

    GameHourStudio

    Joined:
    Apr 17, 2020
    Posts:
    104
    Hi Phong, I have tried this multiple times and get same result. When ever I bake a Skinned Mesh Renderer using MB, and then I try to export that Skin Mesh Renderer using Unity's own FBX Exporter, it gives me the error as shown in the image. upload_2021-3-18_12-25-22.png

    But when I use KellanHiggins exporter available at below link,
    https://github.com/KellanHiggins/UnityFBXExporter
    The object is exported properly as highlighted in the red box (The inspector is not showing that mesh properties instead showing the active element). But this exporter convert Skin Mesh into Mesh Renderer and Also exports in ASCII format. This is fine for me at the moment. But FBX exporter does not exports at all. I don't know if it is related to MB also but I thought to report you. Also I try to bake the Mesh to Skin Mesh. It worked but when I try to REBAKE this skin mesh into mesh renderer, it failed. Is it possible using MB? Thanks.
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    I will take a look. Unity's FBX exporter has some source code so hopefully I can figure out what is going on.
     
    GameHourStudio likes this.
  14. fedorval

    fedorval

    Joined:
    Nov 15, 2019
    Posts:
    17
    Hello!

    I'm currently trying out your asset and I'm trying to work with the Mesh Baker Grouper.

    Now I've seen the "Cluster By LOD Level" setting and ticked it because I was interested in keeping my LODs. Generally I managed to make it work, combining every mesh by their LODs and everything.

    Only thing is, even though I've set a Parent Object, once all the MeshBakers are baked, they just dump their finished mesh right at the root of the scene and the objects aren't sorted by lodgroup. Every single LOD is just laid down everywhere on the root with no grouping per cluster.

    Is there a way to automatically sort them into working LOD Groups so that I don't have to do a whole lot of manual work every time I combine my meshes? Also why don't they get parented to the Parent Scene Object?
     
  15. GameHourStudio

    GameHourStudio

    Joined:
    Apr 17, 2020
    Posts:
    104
    Hi again, Some times it happens that at time of baking meshes, I disable original renderers and then leave the Mesh Baker object in the scene. And when I make build, the build includes texture references to those disabled individual meshes as well causing build size to increase. As per my understanding, if any thing is references any where in inspector, its texture etc will be included in build. So what is the proper way to dont include the data related to individual, disabled meshes? Thanks.
     
  16. GameHourStudio

    GameHourStudio

    Joined:
    Apr 17, 2020
    Posts:
    104
    It is taking me a lot of time to delete original references and creating mesh colliders on the new generated colliders. Because In Memory Profiling I can see the original materials and textures are still being referenced. There should be an option which asks us to destroy the orignal references or atleast an option to generate colliders on newly generated meshes. If there is already kindly let me know. Thanks.
     
  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    Hi Fedorval,

    The Cluster by LOD Level could definitely use more polish. Unfortunately at this time there is not a way to sort them into working LOD groups. Thanks for brining this to my attention. I will take a look to see if this can be improved.

    Regrading the Parent Scene Object issue. This sounds like a bug. I will definitely look into why that is happening as it should be adding this to the parent scene object.
     
    fedorval likes this.
  18. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    There is a button on the Mesh Baker Grouper "Delete Renderers On All Child Mesh Baker Source Objects". This will delete the renderers which should remove the references to the materials & textures. If there are Mesh Colliders on the source objects then these will still exist. I usually leave the original mesh colliders in place because:

    1) It is more efficient for physics to have many small colliders rather than one large one.
    2) Typically the mesh colliders use a low res version of a mesh and re-use the same mesh across many colliders so that the memory impact is not bad.

    Let me know if the Mesh Baker Grouper button doesn't work with your workflow. This feedback is useful for me.
     
  19. GameHourStudio

    GameHourStudio

    Joined:
    Apr 17, 2020
    Posts:
    104
    Hi, I am unable to trace this button though I have updated MB to latest version.
    upload_2021-3-23_23-35-27.png
     
  20. GameHourStudio

    GameHourStudio

    Joined:
    Apr 17, 2020
    Posts:
    104
    Also here is a problem I am facing. I am using Texture Arrays instead of Texture Atlases and what I am seeing, If I use ETC2 RGBA8 CRUNCH COMPRESSION format for texture array material combining, this sort of weird texture is formed and when I use without CRUNCH COMPRESSION i.e. only ETC2 RGBA8 target texture it works fine. Also in both cases the size of the texture array remains same and as per my understanding of crunch compression, for POT textures size should be way lower.
     

    Attached Files:

  21. GameHourStudio

    GameHourStudio

    Joined:
    Apr 17, 2020
    Posts:
    104
    Also as you can see, though I have attached PARENT TRANSFORM but still the newly generated combined meshes are not the children of this parent element. upload_2021-3-23_23-44-32.png
     
  22. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    Hi GameHourStudio

    Re: Deleting the renderers. Yare correct. The button I was thinking of is actually "Disable Renderers On All Child Mesh Baker Source Objects". I don't know what I was thinking. However this would be very easy to implement to delete. This is a method that deletes all source renderers for a single Mesh Baker:


    Code (CSharp):
    1.     [ContextMenu("Delete Renderers On Source Objects")]
    2.     void DeleteSourceRenderers()
    3.     {
    4.         MB3_MeshBaker mb = GetComponent<MB3_MeshBaker>();
    5.         List<GameObject> gos = mb.GetObjectsToCombine();
    6.         for (int i = 0; i < gos.Count; i++)
    7.         {
    8.             Renderer r = gos[i].GetComponent<Renderer>();
    9.             MB_Utility.Destroy(r);
    10.         }
    11.     }
    It could be easily modified to work for a MeshBakerGrouper (add another loop to do this for all mesh baker children).

    Re: The parenting not working. This is a known bug. It will definitely be fixed in the next version.

    Re: The Crunch compression issue. This is something I will need to look into. Will report back. Which version of Unity are you using?
     
  23. GameHourStudio

    GameHourStudio

    Joined:
    Apr 17, 2020
    Posts:
    104
    Hi thanks for responses. I am using Unity 2019.4.20f1 with mesh baker latest version
     
  24. GameHourStudio

    GameHourStudio

    Joined:
    Apr 17, 2020
    Posts:
    104
    Also Unbaked light works on your MeshBakerStandardTextureArray shader. But once light is baked, the result is always same. What I mean is that if I set light intensity to 1 or intesntiy to 100 BEFORE BAKING light, the result is always same once light is baked. Although it should happen like that for 1 intensity, baked lighting should be darker and for 100 intensity lighting should be brighter but this is not the case. Kindly check this also.
     
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    I looked into the Crunched Texture Array issue. It looks like this is a limitation in Unity. It is probably a limitation in the GPU hardware. I couldn't find it documented anywhere but when I try to bake texture arrays in Unity2020 using: ETC2 RGBA8 CRUNCH COMPRESSION then the Unity Editor gives the error:

    Crunched Texture2DArray is not supported.

    The resulting Texture Array is identical to ETC2 RGBA8 compression. I think it is a bug in 2019 that Unity allows the texture array to be created given that the generated result doesn't work.

    Will take a look at the MeshBakerStandardTextureArray shader to see if I can find out why it does not lightmap.

    [Update] Sorry for the delay, still looking into the lightmapping issue. This is a tough nut to crack. Have not been able to discover why it is not lightmapping correctly.
     
    Last edited: Mar 29, 2021
    GameHourStudio likes this.
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    It took a while to track down the problem but it is fixed now. If you use the version on the "Master" branch or the "Unity2019.4_StandardShaderModifiedToUseTextureArrays" it should work. The problem was the "Occlusion Map". Texture array default textures work differently from regular Texture default textures. Instead of defaulting to "white" the texture array defaulted to "grey"
     
    GameHourStudio likes this.
  27. PhilFaily

    PhilFaily

    Joined:
    Jul 31, 2017
    Posts:
    7
    Question - Welding Vertices

    In our project we construct the world from a lot of prefabricated pieces like Walls, Corners etc...

    Despite our best efforts to ensure the vertices on the meshes in 3DSMax are perfectly rounded off we still seem to get some very small error when Grid snapping them in Unity which causes lightmapping seams to become visible.

    If we manually vertex snap the parts together this fixes the issue but its a very laborious task and we want to just work on the grid.

    This got me thinking that its there are lots of duplicated verts in the baked mesh and maybe it would be possible to have a 'Weld Verts' feature added that can specify some small tolerance.

    1 - 2 millimetres is enough to cause lightmap artefacts and visible cracks in the world that can have high contrast when the Skybox becomes visible through them.

    Is this a practical thing that could be added to Mesh Baker, I imagine its probably something has already been considered at one point?
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    Hello,

    I have considered a feature similar to this which would remove hidden interior faces. It is a fairly difficult feature to implement though so it has not yet been implemented.

    In your case it would be fairly easy write a script to process the mesh post-mesh-bake. First run Mesh Baker, then run this script:
    • Grab the mesh
    • Read the verts
    • Collect groups of verts that are within the threshold
    • for each group calc the average and set the value of the verts in this group to the average.
    • Write the modified verts back to the mesh.
    • Save the asset if it is an asset in the project.
    This doesn't eliminated duplicates. Eliminating duplicates is a fair bit more complicated because not all duplicates can be eliminated (they might have different normals, uvs etc.) and the triangles need to be adjusted to use the updated vertex list.

    I will consider adding such a feature but I am nervous about making the complicated UI even more complicated and this would not be appropriate to use at runtime since it would be slow (lots of vertex comparisons).
     
    PhilFaily likes this.
  29. PhilFaily

    PhilFaily

    Joined:
    Jul 31, 2017
    Posts:
    7
    That actually sounds like a great idea!

    Averaging the verts rather than welding them, I can imagine actually welding them is a lot more involved.

    Incidentally I did manage to Weld them by 'Pro Builderizing' the Baked mesh and using the Pro Builder Vert weld but this did create a small amount of problems with some verts welding and messing up Lightmap UV's.

    Is there a straight forward way to subscribe to the Bake Complete event with a custom editor interface?
     
  30. SOIL

    SOIL

    Joined:
    Sep 2, 2011
    Posts:
    213
    Good 30 years I do that now. Working with 3dsmax, zbrush, blender, maya, substance products, unity, whichever software out there - name it....... and you won't believe it - I can't believe it, I was still not able to reproduce a successful atlas & mesh baking (without LOD). I can't tell you more than that. It seems I am too stupid to follow 9 steps.
     
  31. Kalificus

    Kalificus

    Joined:
    Sep 4, 2020
    Posts:
    8
    Hey phong,

    Just got the asset today, it seems pretty straightforward and useful. I might be missing something, but any time I try baking skinned meshes I cant get them to animate. The armature / mesh comes out fine. I've tried it with a few models and I guess I must be missing something. Root motion still works on the animations, but the actual animations dont play (character still in bindpose). Im baking them into prefabs.
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    The problem is most likely the culling setting on the Animator component.

    upload_2021-4-7_15-18-5.png

    Try the Always Animate setting. Most likely the bones are no longer beneath the Animator in the hierarchy. The animator is not detecting that they are moving.

    Also you might need to double check the RenderBounds on the baked Skinned mesh. If you combine several skinned meshes these bounds might not encompass the full range of motion. Your skinned mesh can occasionally vanish if it is near the edge of the camera fustrum and the bounds are not big enough.
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    I don't have an OnBakeComplete delegate for the mesh baking because it is not a coroutine.

    What you can do is have your script call the bake on the baker. This script should do what you want. Attached it to a component with a Mesh Baker on it. You may need to save the mesh if it is an asset.



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class BakeAndWeldVerts : MonoBehaviour
    6. {
    7.     public class Cluster
    8.     {
    9.         public List<int> vertIndexes = new List<int>();
    10.         public Vector3 averagePostion;
    11.  
    12.         public void CalcAverage(Vector3[] vs)
    13.         {
    14.             averagePostion = Vector3.zero;
    15.             for (int i = 0; i < vertIndexes.Count; i++)
    16.             {
    17.                 averagePostion += vs[vertIndexes[i]];
    18.             }
    19.  
    20.             averagePostion /= vertIndexes.Count;
    21.         }
    22.     }
    23.  
    24.     public float threshold = .01f;
    25.  
    26.     [ContextMenu("Bake And Weld Verts")]
    27.     void DoBakeAndWeldVerts()
    28.     {
    29.         // Bake the combined mesh
    30.         MB3_MeshBaker mbd = GetComponent<MB3_MeshBaker>();
    31.         mbd.AddDeleteGameObjects(mbd.GetObjectsToCombine().ToArray(), null, true);
    32.         mbd.Apply();
    33.  
    34.         // Grab the mesh
    35.         MeshRenderer r = (MeshRenderer) mbd.meshCombiner.targetRenderer;
    36.         Mesh m = r.GetComponent<MeshFilter>().sharedMesh;
    37.         Vector3[] vs = m.vertices;
    38.  
    39.         // average the verts
    40.         List<Cluster> groups = new List<Cluster>();
    41.         Cluster[] mapVertToGroup = new Cluster[vs.Length];
    42.         for (int i = 0; i < vs.Length; i++)
    43.         {
    44.             for (int j = i+1; j < vs.Length; j++)
    45.             {
    46.                 if (Vector3.Distance(vs[i], vs[j]) < threshold)
    47.                 {
    48.                     Cluster group;
    49.                     if (mapVertToGroup[i] != null)
    50.                     {
    51.                         group = mapVertToGroup[i];
    52.                     } else
    53.                     {
    54.                         Debug.Log("Creating Group");
    55.                         group = new Cluster();
    56.                         groups.Add(group);
    57.                     }
    58.  
    59.                     if (!group.vertIndexes.Contains(i)) group.vertIndexes.Add(i);
    60.                     if (!group.vertIndexes.Contains(j)) group.vertIndexes.Add(j);
    61.                     mapVertToGroup[i] = group;
    62.                     mapVertToGroup[j] = group;
    63.                     group.CalcAverage(vs);
    64.                 }
    65.             }
    66.         }
    67.  
    68.         Debug.Log("Found " + groups.Count + " groups of verts threshold");
    69.         for (int i = 0; i < groups.Count; i++)
    70.         {
    71.             for (int j = 0; j < groups[i].vertIndexes.Count; j++)
    72.             {
    73.                 vs[groups[i].vertIndexes[j]] = groups[i].averagePostion;
    74.             }
    75.         }
    76.  
    77.         m.vertices = vs;
    78.  
    79.         // TODO save the mesh if it is an asset.
    80.     }
    81. }
     
    PhilFaily likes this.
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    Can you post a photo of what is happening?
     
  35. Kalificus

    Kalificus

    Joined:
    Sep 4, 2020
    Posts:
    8

    Ah, setting the animator to Always animate did the trick. I now have an army of 300 skeletons running at 200 batches 60 fps. Very exciting! Thank you very much.
     
    Phong likes this.
  36. PhilFaily

    PhilFaily

    Joined:
    Jul 31, 2017
    Posts:
    7
    Amazing thankyou so much Phong!

    I had actually went ahead and wrote a very similar Editor Script with an almost exact algorithm. But I like your approach to combining the Bake in the same process. I might enhance this component with a custom editor interface so its just a Button rather than a right click menu selection.

    One thing to add after aligning the verts is to call Unwrapping.GenerateSecondaryUVSet again on the mesh. This totally cleaned up all the cracks and light map seams I was having.

    Thanks again!
     
    Last edited: Apr 8, 2021
    Phong likes this.
  37. gewl

    gewl

    Joined:
    May 19, 2016
    Posts:
    23
    Hi, sorry to ask a very rudimentary question but I can't find an answer in the docs. I'm trying to use this tool to atlas/batch dozens of static objects using a number of different 4k textures. Upon batching I get a big performance boost, but the textures on these objects looks very downrezzed. To prevent the objects looking much worse, would I need to increase the atlas's size to 4096 * [the number of textures the objects use]? Is there any way to automate that process of atlas dimension generation in general? And am I right in thinking that the resulting atlas would prohibitively large, and that this might not be a great use case for this tool?

    The tool seems incredible from my dipping into it today, though, this is great.
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    Your atlas will bump to the next power of two (8K or 16K). You can fit four 4k textures in an 8k texture. You can fit 16 4k textures in a 16K texture.

    8K and even 16K textures are HUGE. They will take a lot of hard drive space. They can be used but it is advisable to only have a few of these if you use them.

    TextureArrays can be used in place of atlases. These are like atlases except they stack textures like a deck of cards instead of combining them into one big texture.

    Major advantages:
    • They can support tiling without needing to bake the tiling
    • Can pack many more textures into an atlas
    Major disadvantages
    • Is a big commitment. You need to modify your shaders to use TextureArrays
    • You need to modify your meshes to encode the slice to use in the UV channel
    • You need a tool like Mesh Baker to create them
     
    gewl likes this.
  39. gewl

    gewl

    Joined:
    May 19, 2016
    Posts:
    23
    Thank you, that's very helpful!
     
    Phong likes this.
  40. unity_zw6QHpcgpJfeDA

    unity_zw6QHpcgpJfeDA

    Joined:
    Mar 23, 2018
    Posts:
    5
    I am creating seperate CombinedSkinnedMeshes for each clothset the character can have and would like to use them in just one prefab and easily activate / deactivate the non-used clothsets. Issue here is that the baked CombinedMeshes do not share the same root model / bones, so that everything is duplicated. Is there a way to change the root model / bones after baking again?
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    I am a little fuzzy about what is happening.

    It is not easy. Mesh Baker sometimes merges bones if the same transform appears more than once in the bones list. You would need to write a script that would grab the combined skinned mesh bones. Figure out which source bones map to the combined mesh bones, Assign all the source transforms to the to the bones array and assign these bones to the SkinnedMeshRenderer.

    Curious why the duplicated bone structure doesn't work for you. Can't you just use the duplicates in place of the originals?
     
  42. unity_zw6QHpcgpJfeDA

    unity_zw6QHpcgpJfeDA

    Joined:
    Mar 23, 2018
    Posts:
    5
    ah I was working with creating a prefab after baking directly, issue here was that for each baked clothset a different copy (of the bones) was constructed. When I bake directly in the scene it seems they are still originated to the same bone structure and I am able to create one model with multiple baked clothsets but only one bone structure (hooray!!). I have a quite complex setup for each different clothset, any easy way / examples to automate the mesh baking process?
     
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    Are you using the output = "Bake into prefab" feature? That should smooth out the workflow a bit. If you "bake into a scene object", the mesh is not saved as an asset. If you make the result into a prefab you will need to save the mesh as an asset via a script or you will loose the reference to the mesh in the prefab.

    Regarding automation. There are a lot of different workflows for Mesh Baker. Which do you want to automate? There are some included tools for automation

    1) The "Tools For Adding Objects" can can create an configure many Mesh Bakers in a scene quickly
    2) The "Mesh Baker Grouper" can create, configure and bake Many Mesh Bakers in a scene quickly
    3) The "Batch Prefab Baker" can bake many prefabs quickly and has a tool for replacing prefab instances in a scene.

    All of these require some manual work but you can work with many prefabs at once.
     
  44. unity_zw6QHpcgpJfeDA

    unity_zw6QHpcgpJfeDA

    Joined:
    Mar 23, 2018
    Posts:
    5
    Everything fine now :) thanks for your feedback!
    Regarding automation I have tried to find a way to automate the process by not interacting with the editor / inspector views at all but by setting up the Texture and Mesh Bakers via script directly. As your software architecture is defined in a good manner this was possible quite easily!

    Great tool, great code! Thanks a lot :)
     
    Phong likes this.
  45. Kalificus

    Kalificus

    Joined:
    Sep 4, 2020
    Posts:
    8
    Sorry to bother you again Phong;

    I am learning the runtime bake functionality, but I cant seem to wrap my head around it. Here is the code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MB_Example : MonoBehaviour {
    5.    
    6.     public MB3_MeshBaker meshBaker;
    7.     public GameObject[] objsToCombine;
    8.  
    9.     void Start()
    10.     {
    11.         meshBaker.AddDeleteGameObjects(objsToCombine, null, true);
    12.         meshBaker.Apply();
    13.     }
    14.    
    15.     void LateUpdate(){
    16.        
    17.         meshBaker.AddDeleteGameObjects(objsToCombine, null, true);
    18.  
    19.         meshBaker.UpdateGameObjects(objsToCombine);
    20.  
    21.         meshBaker.Apply(true, true, true, true, true, false, false, false, false);
    22.     }
    23. }
    This correctly bakes the meshes at Start(), but I cant modify the array of objsToCombine or it throws an error. My goal is to bake additional meshes onto the already baked mesh. Not sure if Im going about this correctly. Any help would be appreciated
     
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    This looks close. I think you don't need the call to "meshBaker.UpdateGameObjects". Remove that line.

    The call to "AddDeleteGameObjects" should only include the new objects you want to add. Objects that are already in the mesh should not be in this array.

    Also it looks like you are adding objects every frame. That is a very heavy operation. You probably only want to add objects when necessary.

    I would recommend looking at the example scene "SceneDynamicAddingDelete". It adds and deletes some meshes from a combined mesh. The script is fairly simple.
     
  47. Lorrak

    Lorrak

    Joined:
    Sep 17, 2019
    Posts:
    15
    Hello, does it support Bakery - GPU Lightmapper ?
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    You should be able to lightmap the combined meshes no problem. The combined meshes are regular Unity meshes. If you bake with one of the options:
    • generate new UV2 layout
    • copy UV2 to separate rects
    Then the combined mesh will have a valid UV2 layout for lightmapping.
     
    Lorrak likes this.
  49. LaCorbiere

    LaCorbiere

    Joined:
    Nov 11, 2018
    Posts:
    29
    Howdy. I've been trying to bake a fairly small and compact scene from the Asset store with Mesh Baker and retain the quality of the lightmapping of the original un baked scene. Is this possible? I find the results that I'm getting with 'Copy_UV2_unchanged_to_seperate_rects' as outlined in a earlier thread is not giving accurate lightmapping. Note the keyboard in the lower picture and the brightness and accuracy of the top image in comparison. Could it be bad mapping of the original scene? Also looks like the main light isn't being included in the lightmapping bake. Any suggestions would be great thanks.
     

    Attached Files:

  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,862
    Hi LaCorbiere,

    I think the problem is the lightmap resolution/ texels are too large relative to the UV2 islands. The large texels are spanning the gap (being shared) between the UV islands. You should be able to confirm if this is happening by using the "baked lightmap" debug mode in the scene view. If you look at the scene after lightmapping and zoom in on that keyboard, you will probably see that the texels are fairly large relative to the size of the keys. You should be able to fix it by increasing the lightmap resolution. If you have meshes with very very small parts like the keyboard you might want to leave them out of the bake and let them lightmap as their own object or even light them using lightprobes.
    upload_2021-4-28_13-24-10.png

    Let me know if this fixes your issue.
     
unityunity