Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mesh Baker by Digital Opus [RELEASED]

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

  1. PhoenixRising1

    PhoenixRising1

    Joined:
    Sep 12, 2015
    Posts:
    488
    Hey.
    How can I bake "locked" meshes like the following:



    in the above picture the bracelet is locked, and as you can see the new combined mesh has the bracelet out of position.
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Sebastien,

    I think the problem is that there is another plugin assembly in the project that reflection cannot read the types for. Perhaps there is a .Net 4.5 plugin or a sealed plugin might do this. Try replacing the first foreach loop in drawTabAnalyseScene with this one. It catches the exception and continues to execute. It should print out the name of the assembly that it can't read the types for. Please let me know what the assembly is so I can look into this further.

    Code (csharp):
    1.  
    2.             foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies())
    3.             {
    4.                 System.Collections.IEnumerable typesIterator = null;
    5.                 try
    6.                 {
    7.                     typesIterator = ass.GetTypes();
    8.                 } catch(Exception e)
    9.                 {
    10.                     Debug.Log("The assembly that I could not read types for was: " + ass.GetName());
    11.                     //suppress error
    12.                 }
    13.                 if (typesIterator != null)
    14.                 {
    15.                     foreach (Type ty in ass.GetTypes())
    16.                     {
    17.                         var myInterfaces = ty.FindInterfaces(interfaceFilter, qualifiedInterfaceName);
    18.                         if (myInterfaces.Length > 0)
    19.                         {
    20.                             types.Add(ty);
    21.                         }
    22.                     }
    23.                 }
    24.             }
    25.  
     
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Ephemeral life, has the bracelet been baked into the skinned mesh, or is it a separate MeshRenderer that has been baked and added as a child to one of the bones? I am not sure what you mean by "locked" mesh.

    The problem might be that a translation/rotation was baked into the bracelet. This can happen when baking a prefab if the source prefab is not at location 0,0,0 rotation 0,0,0 scale 1,1,1 when baked.
     
  4. PhoenixRising1

    PhoenixRising1

    Joined:
    Sep 12, 2015
    Posts:
    488
    I thought I couldn't move the submesh, but I just saw that there are a bunch of bones I will have to move manually instead (that's what I meant with locked). Never experienced this before...

    In the first pic the meshes all have these grey boxes to them which disables me from moving them that way:



    and I'm forced to move the bones only:



    I tried resetting the transform but still get the following:



    and I have no clue how to move the bracelet cause I can't move it directly. Maybe this is one of those models where it's simply not worth the effort.
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Ephemeral,

    If you want to PM me a link to the model I wouldn't mind taking a look at it. It sounds like the troll_bracelet and troll_weapon are separate skinned meshes. It should be possible to bake these together. What components are on the troll, troll_bracelet and troll_weapon game objects?
     
    PhoenixRising1 likes this.
  6. PhoenixRising1

    PhoenixRising1

    Joined:
    Sep 12, 2015
    Posts:
    488
    Thanks. Gonna send you a PM.
     
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Ephemeral,

    I noticed that the game objects "troll", "troll_bracelet" and "troll_weapon" which have SkinnedMeshRenderers have rotations and translations. I reset these transforms as well as the transform on "troll_anim_Prefab" to location 0,0,0 rotation 0,0,0 scale 1,1,1. Then baked and it worked.
     
    PhoenixRising1 and hopeful like this.
  8. PhoenixRising1

    PhoenixRising1

    Joined:
    Sep 12, 2015
    Posts:
    488
    Thanks a lot for the help.

    Edit: I noticed that it's the same thing I tried yesterday but I couldn't get it to work. Dunno what I'm doing wrong. Gonna try a new project and see if the problem persists.

    So I created a new project and only imported the troll and mesh baker, reset the transforms, and the same result. The pics below are from the previous project.




     
    Last edited: Jan 20, 2016
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Ephemeral,

    The three source meshes are all skinned meshes, so make sure you are baking into a skinned mesh, not a MeshRenderer mesh (set the "renderer" field on the Mesh Baker to "skinned mesh").

    Also you probably want to bake this into a prefab. This is a bit tricky with skinned meshes since you need to include the original bones in the prefab. There are step by step instructions in the Mesh Baker FAQ for this:

    http://www.digitalopus.ca/site/mesh-baker-2-faq/
     
  10. PhoenixRising1

    PhoenixRising1

    Joined:
    Sep 12, 2015
    Posts:
    488
    That was a facepalm moment for me, sorry about that. I even baked another char successfully into a prefab earlier today.. Dunno what to say :).
     
  11. betalulu

    betalulu

    Joined:
    Apr 9, 2014
    Posts:
    10
    Hello! i just purchased this tool and is very satisfied with it's output. thank you for the great work.
    however i encountered an issue on source materials that have tiling and offset settings.
    this is the original roof material look like, the meshes of the roof have out of bound uv on them:
    original_roof.JPG
    original material settings:
    roof_source_material.JPG

    baker settings:

    baker_settings.JPG

    and the result:
    baked_roof.JPG

    as you can see
    1. the scale of the roof texture is wrong
    2. normal/occlusion maps offset and tiling don't match the diffuse map(a bug?)

    for comparison, the red-brick material below doesn't have tiling and offset seems to be baked correctly(the mesh of the red brick material also has out of bound uv).

    can this be fixed or is there any setting i missed to correct this issue?
     
  12. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hello, sorry for the late response. I didn't notice an alert for this post and don't always check the forum.

    Does the source mesh have multiple materials? If so I suspect the submeshes are being collapsed together. You probably need to set up multiple materials for this case. Were there any warnings about the meshes in the console? Also when baking the textures there is a "suggested treatment" message that is written to the console. Was this printed out? What did it suggest?
     
  13. betalulu

    betalulu

    Joined:
    Apr 9, 2014
    Posts:
    10
    Thanks for responding! I did setup multiple materials output but still had this tiling issue, i'll send you a simplified scene for test.
     
  14. Muralidaran

    Muralidaran

    Joined:
    May 2, 2014
    Posts:
    93
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Mura,

    I have not tested MB with speed trees. I would try it out in a test scene just with Mesh Baker. If it works with Mesh Baker then it should work with Mesh Baker LOD. I will give it a try too.
     
  16. Muralidaran

    Muralidaran

    Joined:
    May 2, 2014
    Posts:
    93
    Hi Phong,

    I haven't had time to check on the Speed trees yet because I am running into another issue. I am trying to Mesh bake and LOD my buildings. I follow the steps in the tutorial as best I can, set up the atlases, the mesh and the LOD. On the surface everything seems to work great. My drawcalls are way down, the meshes change levels when you get closer. It all looks good until you look at the error log. I don't know if you can read all of those but it is telling me that the meshes have unknown materials on them.

    Any idea what's causing this. Is it an actual problem or should I just ignore it and move forward.(Don't like that idea)

    Thanks for the help,
    Mura

    Oh and if I use the normal Unity LOD component I do not get the errors.

    MBProb1.png
     
  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Maralidaran,

    From the errors it looks like one of your LODs has a baker label set which forces it to be baked by a particular baker, but the mesh baker on that baker doesn't have its Material Bake Result set up to handle the materials on that LOD. Can you check if this is the case?
     
  18. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    334
    Hello I wasn't sure how to contact you about a problem so I will post here.
    I have a player character model that has meshes for each piece of armor, faces, beards, etc...
    I have purchased Mesh baker to try to reduce my draw calls.

    The problem that I am finding is if I bake all the skinned meshes together(over 150 of them) I can't toggle each armor/face part on and off.
    Each mesh is a skinned mesh attached to the parent.
    I also tried baking them in place but I didn't notice a difference (the saved by batching remained 0).

    What is the best way to go about this?
     
  19. Muralidaran

    Muralidaran

    Joined:
    May 2, 2014
    Posts:
    93
    Hi Phong,

    I know it's Valentines day and more importantly The Walking Dead is coming on in about an hour(who needs love when you have zombies, right?!?), but I wanted to update you on where I am at.

    I checked what you recommended and everything was setup right. I tried a fresh start, again, and still got the same results and I think I know why. I am using the Post Apocalyptic pack for my buildings. Each building is made of Layers so you can make them as tall or short as you want(see pic). And each segment has 2 LODs with separate materials for each. To make the LOD0 look good I have to make 2 separate atlases, one for each level. If I try to combine the two it ends up looking blurry and has some really odd tiling issues. This creates a problem because I can only put one label in and 2 atlases can't share a label.

    As far as I can figure I have only 1 option and that is to bake them and use the Unity LOD system for the buildings. Then I can use Mesh Baker LOD for everything else. Do you agree or do you know of another way to handle this?

    Thanks again for the help.
    Mura

    MBProb3.png
     
  20. Muralidaran

    Muralidaran

    Joined:
    May 2, 2014
    Posts:
    93
    Hi again. So while I am waiting for a response i decided I would check out the speed trees and I don't think it will work/help. The speed trees use a 4 LOD system. For each LOD there are 5 materials(2 bark and 3 leaves). Same with the buildings tiling them made it look bad and I got the same error as with the building when I tried an atlas for each level. The fourth level of the LOD is a Billboard renderer which meshbaker doesn't seem to accept.

    Any thoughts on that. The speed trees are already a huge improvement over the other trees I have so Mesh baking them may not even be necessary/worth the time and effort. Let me know what you think and thanks again.
    Mura
     
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Kastasteel,

    If you want to toggle the body parts on and off at runtime, then you will either need to write a script to rebake the skinned mesh, or hide the body parts you don't want by moving them off screen (behind the camera for example.

    There is an example script included with Mesh Baker. The "SkinnedMeshRenderer" scene shows how to add and remove by baking at runtime.
     
  22. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Muralidaran,

    Hmmm, Mesh Baker LOD is limited in that the different source LOD levels must use the same material for it to work. It sounds like this won't be an option in your case.
     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Sorry, for being so late replying, I typed this yesterday but for some reason it didn't take.

    Hi Mura,

    I looked into the speed trees and was able to get it to work for one kind of tree at least.

    1) You will need to use the multiple materials feature. I was able to do this by:
    Created a Mesh And Material Baker
    Added all the different LODs for one of the trees (omitted the billboard)
    Checked the multiple materials
    Clicked build source to combined maping from objects to combine
    2) I then set Mesh Baker LOD with that that Baker.

    3) I set the Billboard Renderer to "Bake Into Combined" = unchecked. This initially produced some errors. I had to make some tweeks to the code to get this to work. I can send you these changes if you want. Will push an update up to the store. This would probably work for your buildings which have different materials on the different levels.

    4) You might be able to get your buildings to work if you use the Multiple Materials feature.

    You might want to consider using Unity's Static Batching for handling some of your LOD work. Unity's LOD and Mesh Baker LOD approach the problem differently and should be used in different situations:

    Unity's LOD:

    Bakes all the meshes that share a material together into one giant mesh in the editor. Non visible meshes are hidden but still exist in memory:
    Advantages:
    • Very fast at runtime. No Baking.
    • Simpler to setup

    Disadvantages
    • Can use a lot of memory if you have a big scene. All LODs exist in memory all the time.
    • Only works with static content where content is known at build time. (Procedural content is out)
    • Doesn't work with skinned meshes
    You can help the static batching by "Prefab Baking" your prefabs so that as many objects as possible share materials.
    Mesh Baker LOD:
    Does all baking at runtime. Combined meshes are constantly adjusted as the player moves around the scene.
    Advantages:
    • Uses less memory. Only the meshes needed by the scene are in memory.
    • Can be used on content generated at runtime.
    • Can be used with Skinned Meshes
    Disadvantages
    • Not as fast because of all the baking
    • More work to set up
    If you want me to send the example scene PM me.
     
  24. upwardstudios

    upwardstudios

    Joined:
    Jun 7, 2015
    Posts:
    6
    Hello,

    Just purchased the mesh baker- is there a way to mass import or drag over objects into the elements drop down in the "objects to be combined", we have hundreds of objects per scene and want to know if there is a quick way to place them all over there. Thank you
     
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Yes, on the MB3_MaterialBaker inspector there should be a "tools for adding objects" button. This opens a window with two tabs. One tab helps group objects and can create bakers for these groups. The other tab has search filters for adding objects in bulk.

    This video shows how to use these tools:

     
  26. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    334
    I tried your suggestion of following the example for "Skinned mesh renderer".

    Your example only combines mesh renderers with skinned mesh renders.
    I am combining skinned with skinned to add the body/armor parts.

    I was able to get a body part to combine at runtime but the animations don't work.
    Not sure if I need to set a root bone or something.

    Well let me clarify: For example I am adding the chest to the body.
    While the body moves the arms of the chest don't.

    Here is my code:
    Code (CSharp):
    1.     public void AddMeshes()
    2.     {
    3.         if (chest == null)
    4.         {
    5.             chest = (GameObject)Instantiate(chestPrefab);
    6.  
    7.             chest.transform.parent = character.transform;
    8.             chest.transform.localPosition = Vector3.zero;
    9.             chest.transform.localRotation = Quaternion.identity;
    10.             chest.transform.localScale = Vector3.one;
    11.  
    12.             GameObject[] objsToAdd = new GameObject[1] {chest};
    13.  
    14.             skinnedMeshBaker.AddDeleteGameObjects(objsToAdd, null, true);
    15.             skinnedMeshBaker.Apply();
    16.         }
    17.         else if (skinnedMeshBaker.CombinedMeshContains(chest))
    18.         {
    19.             GameObject[] objsToDelete = new GameObject[1] {chest};
    20.  
    21.             skinnedMeshBaker.AddDeleteGameObjects(null, objsToDelete, true);
    22.             skinnedMeshBaker.Apply();
    23.             //Destroy(chest);
    24.             chest = null;
    25.         }
    26.     }
     
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    If animations have stopped the problem is almost always the culling settings on the animator component. You have to set the culling settings to "always animate". Also if you are combining two skinned meshes then make sure the render bounds on the combined SkinnedMeshRenderer component is fixed to something big enough to always contain the meshes or you are using one of the scripts that updates the render bounds.

    There is a good list of things to check when baking skinned meshes together in the manual and there is this tutorial video that has lots of info on skinned meshes.

     
  28. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    334
    Wow this is much harder than I thought it would be.

    OK, now the problem I have is that when I try to add the "chest" prefab (from a prefab) it errors out.

    Error:
    NullReferenceException: Object reference not set to an instance of an object
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle+BoneAndBindpose.GetHashCode () (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:91)

    on method:

    publicoverrideint GetHashCode() {

    //OK if don't check bindPose well because bp should be the same

    return (bone.GetInstanceID() %2147483647) ^ (int) bindPose[0,0];

    }

    but if I use an instance of the model it's self it works.

    It seems the problem has something to do with the bones.

    This is problematic because I would need references to all the body parts(over 150) stored in variables.
    And I also can't remove the skinned mesh renderers from them(only disable them).

    It would be much better it I could use a saved prefab(like in the skinned mesh renderer demo).

    What options do I have to make this work?

    I can send you an example if you want.

    P.S. I added the "MB2_UpdateSkinnedMeshBoundsFromBones" script but it does not seem to be updating the bounds.
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Kasteel,

    It would be great if you could send an example. I added that code a few months ago so it would be good to know if there is a case that breaks something.
     
  30. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    334
    I sent it to you.
    Let me know your findings.
     
    Last edited: Feb 18, 2016
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Kasteel,

    I downloaded your project and understand what you are trying to do now. This won't work. The problem is that with skinned meshes you can't bake an uninstantiated prefab into a combined mesh. The reason is that skinned meshes have a list of "bones" which are really scene Transforms. Unity uses the position, rotation, scale of these transforms to deform the mesh. An uninstatiated prefab is not in the scene hierarchy, so Unity doesn't know where these bones are and thus can't know how to deform the mesh. Unity sets the bones to "null" for uninstantiated transforms which will break the mesh combine operation and the combined skinned mesh.

    You will need to use the instances instead of prefabs to combine. If you want to delete a part out of the combined mesh in the future all you need is the InstanceID of the original game object. There is an API call AddDeleteGameObjectsByID You don't need to keep the game object around. You will need to keep the backpack's bones around though since these are used to move and deform the backpack.
     
    hopeful likes this.
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Kasteel,

    I am not sure if it was clear from my previous comment, but you will need make sure that after you have positioned the backpack correctly in the scene, you will need to move the bone gameobjects of the backpack instance in the hierarchy so they are the children of the correct bone(s) on the characters skeleton (probably spine, shoulders, pelvis). This will ensure that the backpack will remain attached to the character as they move around the scene.
     
  33. Muralidaran

    Muralidaran

    Joined:
    May 2, 2014
    Posts:
    93
    Awesome, Thanks Phong. I will check it out and let you know how it goes. If I can get those code changes that would be great.
     
  34. mcbauer

    mcbauer

    Joined:
    Oct 10, 2015
    Posts:
    496
    Works great. but I need someway of accessing the combined mesh. I have a large scene that I combine, and I need to be able to now add that combined mesh in other scenes.

    Any ideas? Sorry if you have posted this response somewhere prior.
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    I assume you are using Output: Bake Into Scene Object. You need to use Output: Bake Into Prefab. This will save the baked mesh as an asset in your project. You can then use the prefab in other scenes.
     
  36. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    334
    Still having problems.

    Ok so I took your advice and I am using instances of game objects to bake a mesh at runtime.

    When the game first loads it is taking all the default parts and baking them into the mesh.
    This seems to work fine, here is a pic and the code for that:

    https://www.dropbox.com/sc/uswi3auwij3wsnn/AADtCdfVdJ2ZHvwgomArESE9a

    Code (CSharp):
    1.         public void Init()
    2.         {
    3.             objsToAdd.Clear();
    4.  
    5.             if(helm == -1)
    6.                 helmInstance = ObjectPooler.instance.GetPooledObject(PlayerObjects.instance.defaultHelm);
    7.             else
    8.                 helmInstance = PlayerObjects.instance.GetObject(DataManager.armorMeshInfo[helm].defaultId);
    9.  
    10.             if(chest == -1)
    11.                 chestInstance = ObjectPooler.instance.GetPooledObject(PlayerObjects.instance.defaultChest);
    12.             else
    13.                 chestInstance = PlayerObjects.instance.GetObject(DataManager.armorMeshInfo[chest].GetMeshId(gloves));
    14.  
    15.             if (gloves == - 1)
    16.                 glovesInstance = ObjectPooler.instance.GetPooledObject(PlayerObjects.instance.defaultGloves);
    17.             else
    18.                 glovesInstance = PlayerObjects.instance.GetObject(DataManager.armorMeshInfo[gloves].defaultId);
    19.  
    20.             if(legs == -1)
    21.                 legsInstance = ObjectPooler.instance.GetPooledObject(PlayerObjects.instance.defaultLegs);
    22.             else
    23.                 legsInstance = PlayerObjects.instance.GetObject(DataManager.armorMeshInfo[legs].GetMeshId(chest, boots));
    24.  
    25.             if(boots == -1)
    26.                 bootsInstance = ObjectPooler.instance.GetPooledObject(PlayerObjects.instance.defaultBoots);
    27.             else
    28.                 bootsInstance = PlayerObjects.instance.GetObject(DataManager.armorMeshInfo[boots].defaultId);
    29.  
    30.             objsToAdd.Add(ObjectPooler.instance.GetPooledObject(PlayerObjects.instance.baseObject));
    31.             objsToAdd.Add(helmInstance);
    32.             objsToAdd.Add(chestInstance);
    33.             objsToAdd.Add(glovesInstance);
    34.             objsToAdd.Add(legsInstance);
    35.             objsToAdd.Add(bootsInstance);
    36.  
    37.             GameManager.instance.CombineMeshes(objsToAdd.ToArray(), null);
    38.         }
    Code (CSharp):
    1.         public void CombineMeshes(GameObject[] objsToAdd, GameObject[] objsToDelete)
    2.         {
    3.             if (objsToAdd != null && objsToAdd.Length > 0)
    4.             {
    5.                 skinnedMeshBaker.AddDeleteGameObjects(objsToAdd, objsToDelete, true);
    6.                 skinnedMeshBaker.Apply();
    7.             }
    8.         }
    Then if I try to remove the current chest(skin) and replace it with a different one(cloth armor) in game(runtime baking) I get this:

    https://www.dropbox.com/sc/8r8byhqdw7ptqzs/AACNHQNPMLov6CZXLrBdsMhYa

    And the strange part if I just start with the cloth armor as the default it works.

    https://www.dropbox.com/sc/is2civh9k7cthp5/AAD385s7ekSXod4VeGkNPIvla

    I must be doing something wrong when adding/removing the chest.
    Here is the code for that:
    Code (CSharp):
    1.         public void EquipMesh(SocketType socketType, int armorMeshInfoId)
    2.         {
    3.             objsToAdd.Clear();
    4.             objsToDelete.Clear();
    5.  
    6.             chestHold = null;
    7.  
    8.             if (socketType == SocketType.Chest && armorMeshInfoId != chest)
    9.             {
    10.                 chestHold = ObjectPooler.instance.GetPooledObject(chestPrefabInstance);
    11.                 chest = armorMeshInfoId;
    12.              
    13.                 if (chestHold != chestInstance)
    14.                 {
    15.                     objsToDelete.Add(chestInstance);
    16.                     objsToAdd.Add(chestHold);
    17.                 }
    18.             }
    19.  
    20.             if ((objsToAdd.Count + objsToDelete.Count) > 0)
    21.             {
    22.                 GameManager.instance.CombineMeshes(objsToAdd.Count > 0 ? objsToAdd.ToArray() : null, objsToDelete.Count > 0 ? objsToDelete.ToArray() : null);
    23.  
    24.                 if (chestHold != null && chestHold != chestInstance)
    25.                     chestInstance = chestHold;
    26.             }
    27.         }
    Update: I found the problem is coming during the delete.
    I just commented out the add code so when I try to equip the new chest it should remove the default chest mesh. But that is when it becomes distorted.

    Any ideas?
     
    Last edited: Feb 25, 2016
  37. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    334
    I sent you a pm with a project showing you the problem.
    Just run it then click the toggle chest button to see the issue.
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    O.K. taking a look
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi Kasteel,

    I think the problem is that the Mesh Baker is configured to clear the buffers after the first bake (in the editor). In the mesh baker inspector there is a "clear buffers after bake" checkbox just above the "bake" button. Toggle this off. It is set to on by default because the MeshBaker internal buffers can use a lot of memory which is only ever needed for the unusual situation you are in. (Bake initial mesh in editor then swap parts at runtime).
     
  40. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    334
    I updated the code I sent you showing the problem persists even with the "clear buffers after bake" checkbox unchecked.
    Been working on this problem for about a week now, it's killing me.
     
  41. crushforth

    crushforth

    Joined:
    Jul 22, 2010
    Posts:
    113
    I haven't purchased this yet as I'm still trying to determine if it would be suitable for our needs. Does this support the ability to have all the meshes and textures not combined in the editor and only perform the combining during the build/deploy process?

    I'm curious about the artist workflow. What happens if the artists are continually modifying the meshes and textures, do you have to perform the 'combine' process manually after each change or can they all remain as individual assets in the database and be 'flagged' to be combined during deployment?
     
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    It does not work this way out of the box. To make this a non-destructive pipeline would be tricky. It could possibly be scripted to do this but there I are some issues I can see with this process. When the textures are combined into an atlas, the meshes need to have their UVs modified to use the atlas. Although this could be scripted to be part of the build, once the UVs have been modified, it is hard to un-modifiy them so the artists can continue working with the original textures in the editor. Also there are a lot of options involved in the baking, It generally takes a fair bit of tweaking to get the desired result. To make this a non-destructive pipeline I think a lot of assets would need to be swapped out with modified copies and maintaining all the references would be hard.

    One good approach is to use the "Batch Prefab Baker". With this tool you assign a bunch of input prefabs and the tool generates output prefabs that share a material. These output prefabs should be used in the scene. One nice thing about using these prefabs is that it is very easy to combine these prefabs once they have been created. They can be combined using Unity's Mesh.CombineMeshes API call, no texture baking is necessary. You probably could do the combine as part of the build process or even at level startup at runtime. If an artist modifies a texture or a mesh, then then you re-open the batch baking scene and re-bake. The textures (can take 15sec to 2 minutes) depending on number of textures. And the prefabs need to be rebaked which takes about 30 seconds. The time consuming part is configuring the original bake. Once that is done it can be re-used.
     
  43. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    I'm using the MeshBaker. I'm trying to figure out why it is when I bake a mesh, mesh baker creates a combined mesh whose pivot point is at global position 0,0,0.
    I am baking a single mesh that has a pivot point at (190.3, 8.5, 582.5) but yet the combined mesh has the pivot point at 0,0,0. Do you know if this is expected to happen?
    Thanks.
     
    Last edited: Feb 27, 2016
  44. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    334
    Phong,

    I used the "Bake into scene object" and now it is working.
    Thanks!

    I do have another problem and I was wondering how people have been handling it.

    A lot of my materials have a detail mask and a detail color.
    I see that mesh baker baked all the masks into one mask and that is good.
    The problem is because everything uses the same material.
    If one of my armor parts should use red color detail all the other parts change color to red as well.

    What is the best way around this?
     
  45. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi TTTTTa,

    This is expected. Mesh Baker bakes the world space positions of the vertices into the combined mesh. Imagine if you were baking three crates into a single combined mesh. In order for the crates to maintain their offsets in the combined mesh then the world space positions need to be baked into the vertex positions. If you want the combined mesh to have the same pivot and rotation as the source mesh then set the source mesh transform to position: 0,0,0, rotation: 0,0,0, scale 1,1,1 before baking.

    This can be used to create variations of your mesh that have different scales or fix the rotation or pivot on imported meshes.
     
    ArachnidAnimal likes this.
  46. RobertEspinoza

    RobertEspinoza

    Joined:
    Aug 18, 2014
    Posts:
    10
    So if you were combining multiple meshes, you would have to move them together to 0,0,0 to where you would want the group to contain it's pivot?

    Thanks
     
  47. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Yes, the pivot of the combined mesh will be at 0,0,0.
     
  48. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    334
    I'm not following.
    How would that help with the detail mask/colors?
     
  49. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,068
    Hi katasteel, I was replying to the other question from oz about pivots.

    Regarding detail masks. If the detail mask uses UV0 and is not tiled, then you should be able to use an atlas for the detail color. If you add "_DetailAlbedoMap", to the list of custom property names then Mesh Baker should try to create this atlas.

    I don't believe there is any way to get the detail mask to work if it using UV1.
     
  50. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    334
    OK thanks, I think what I am trying to ask is to get this to work I would still need multiple materials.

    One for each color correct?
    If the gloves have a green detail and the chest has a red detail I would need at least 2 materials/shader combos to make it work.
    One with the green detail color and the other with the red detail correct?

    There is no way to "bake in" the colors so I can only use one material/shader combo correct?