Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. TheDemiurge

    TheDemiurge

    Joined:
    Jul 26, 2010
    Posts:
    42
    Just a quick FYI:
    My update function has been calling that method, and the Apply method with no parameters. I tried with and without Apply, in either order, in Update and LateUpdate, with no difference. I'm working on making a smaller scene to reproduce it, as it is right now it's got a ton of dependencies.
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Thanks, I appreciate this.
     
  3. jomeier

    jomeier

    Joined:
    Jun 5, 2010
    Posts:
    45
    @Phong:
    I prepared a unity package with two animated models where the left one disappears at a certain camera angle.

    Can you PM me a mail address please where I can send it to (13 MBytes big) ?
     
  4. jomeier

    jomeier

    Joined:
    Jun 5, 2010
    Posts:
    45
    @Phong:
    The animated models seem to disappear, if a group of models was baked and after the bake the original model is moved away (cause in my final scene the baked models run through the scene independent from each other).

    But thats just an assumption. I have a scene where two animated models where baked and after that not moved away from each other. In this scene, the models dont disappear ... Strange :)
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Thanks for sending the package jomeier. I am able to reproduce the problem.

    It is definitely a bug with Unity's SkinnedMeshRenderer. It appears that updating the bounds on the SkinnedMeshRenderer has no effect. The mesh vanishes at exactly the moment that the original bounds goes out of the camera frustum.

    Setting "updateWhileOffscreen" works but is very expensive. However if you turn on "updateWhileOffscreen" and then turn it off again immediately, then updating the bounds manually works afterward. Please let me know if this works for you.

    Not a very satisfying solution but it appears to work. Here is the modified UpdateBounds class:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.      
    5.  
    6. public class UpdateBounds : MonoBehaviour {
    7.     MB2_MeshBaker mb;
    8.      
    9.     void Start () {
    10.             mb = GetComponent<MB2_MeshBaker>();
    11.             SkinnedMeshRenderer r = mb.resultSceneObject.GetComponentInChildren<SkinnedMeshRenderer>();
    12.             //the following lines are needed or updating the skinned mesh bounds in Update has no effect.
    13.             r.updateWhenOffscreen = true;
    14.             r.updateWhenOffscreen = false;
    15.         }
    16.    
    17.     void Update () {
    18.         mb.UpdateSkinnedMeshApproximateBounds();
    19.     }  
    20. }
     
  6. jomeier

    jomeier

    Joined:
    Jun 5, 2010
    Posts:
    45

    Hi Phong. It seems to work now with MeshBaker. I created a big scene with 200 animated models (Vertices > 64k) and was in need for the Multi Meshbaker tool. During the compilation I got errors.

    The MultiMeshBaker component seems not to have a UpdateSkinnedMeshApproximateBounds method.

    Can you provide that?
     
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Jomier. how did I miss that. Add this to MB2_MultiMeshCombiner:

    Code (csharp):
    1.  
    2.     public void UpdateSkinnedMeshApproximateBounds(){
    3.         for (int i = 0; i < meshCombiners.Count; i++){
    4.             meshCombiners[i].combinedMesh.UpdateSkinnedMeshApproximateBounds();        
    5.         }
    6.     }
    7.  
    And this to MB2_MultiMeshBaker

    Code (csharp):
    1.  
    2.     public void UpdateSkinnedMeshApproximateBounds(){
    3.         meshCombiner.UpdateSkinnedMeshApproximateBounds();
    4.     }
    5.  
    I will add these changes in the next update.
     
  8. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    I have a 2 questions before i purchase. I am not sure if they have been answered yet since the thread is many pages and i have not read them all.

    1.) Lets say im using a custom shader like marmoset skyshop for instance. It has a seperate texture for different things such as one for spec/gloss.. another for color... another for a normal map. Would it create textures for each of these when baked including their alpha channels?

    2.) How would I go about handling LODs. Lets say i want to make seperate LOD models and my scene is filled with prefabs that have the LODs set up as invidividual models. Is there a good way to make seperate bakes for each of these? Or Do I have to manually drag each model in the correct position to set it up for baking?
     
  9. jomeier

    jomeier

    Joined:
    Jun 5, 2010
    Posts:
    45
    Great! It works now :)

    Thanks a lot for your help. You made a rather cool tool :) !
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Yes, before baking the texture(s) you create a new material for storing the bake result. You set the shader on that material. MeshBaker will create one atlas texture for every texture slot in that material. MB temporarily converts all textures to ARGB32 before baking so alphas will come through. Check out the basic usage tutorial video.
    I am glad you asked!! I am literally hours away from releasing Mesh Baker LOD which does exactly what you describe! It will be a separate asset in the asset store that needs to be purchased in addition to MeshBaker. I have submitted it to the Asset Store and am waiting for approval. It will be for sale on digitalopus.ca later today. I am uploading tutorial videos to youtube as we speak (79% uploaded).

    I am very excited about this asset! It is an absolutely essential part of huge environments.
     
  11. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    Very awesome!

    3 more question actually :)

    1.)Does mesh baker also bake uvset 2 for the models.. the lightmapping uvset. And obviously the lightmaps...

    2.) Marmoset skyshop has a shader that uses uvset 2 to do occlusion for one of its texture slots. Guess the obvious question is will those textures be baked as well? And will they be baked according to the correct uv set since that particular texture goes off uv set 2.

    3.) is there a way to export the models out to a 3d package to further tinker with once exported. Or do i need to rely on a seperate tool for that?
     
    Last edited: Oct 23, 2013
  12. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Yes and no. You can include uvset2 in the bake and MeshBaker adjusts this if that UV set is used for lightmaps. However the source models must all use the same lightmap. This is because the lightmap index is stored in the Renderer and the renderer on the combined mesh can only have one index. The lightmaps themselves are not combined.
    You can enter a list of custom property names in the inspector. If those properties exist in the shader then the textures for those will be baked. If you include UV set 2 in the bake it should work, although I am not sure if the UV2s would need to be adjusted. I am not sure if this would work or not.
    This functionality is not built into Mesh Baker but there are some tools on the wiki that will export to obj format and I believe there are some assets in the asset store that will do this as well.
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
  14. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    wow very impressive. Here are some more questions for you :)

    1.) The LOD thing.. i noticed u used like "areas" in a grid set up... can you control the size of these areas? or even the position? Like a tight city scene might be cool to bake back alley stuff vs interior stuff vs street stuff... if u can control that. And can i then save these generated LODs into prefabs so they can be used in another scene.. even combined into other LODs?

    2.) I didnt know unity static batching did not effect LOD objects. are you sure about this? Im talking static unmoving objects that have lods... not dynamic ones.

    3.) Might be a little off topic but in a way its not because i want to fit your products into my pipe line. I guess im curious if its possible,in terms of light map generating, to select which objects will be on which lightmap atlas. Since beast will generate multiple lightmaps for the scene based on the size and resolution. I plan on painting on lightmaps with another tool to replace the need for decals and transparency to get less over draw... u know .. painting in cracks and stuff. Plus I would liek to know abotu if i can choose which objects are on which lightmap since doing that will allow objects to be static batched better since, i think, they only get static batched if they are on the same material and on the same lightmap.

    4.) Is there a way to select the importance of a texture... size wise when baking... do i just select the resolution in unity or something on import, and then bake it and the size should work like that? for example 512x512 shows up as 512x512 on the atlas and 128x128 shows up as 128 x128 on the atlas.
     
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    You can control the size of the clusters but not the offset. Yes you can generate prefabs of the LODs and use them in other scenes once you are done. I demonstrate this in the tutorial videos at http://digitalopus.ca/site/mesh-baker-lod/.
    I have not been able to confirm that Unity prevents the two from being used together, however there are good reasons why you might not want to. The meshes generated by Unity's static batching are generated at build time. The only possible way it could do LOD is to bake all the possible LOD levels for all the objects into the static mesh(s) and switch which triangles are being shown. This appears to be confirmed by Unity's documentation where they warn that static batching would not be a good idea for a dense forest environment:

    Using static batching will require additional memory for storing the combined geometry. If several objects shared the same geometry before static batching, then a copy of geometry will be created for each object, either in the Editor or at runtime. This might not always be a good idea - sometimes you will have to sacrifice rendering performance by avoiding static batching for some objects to keep a smaller memory footprint. For example, marking trees as static in a dense forest level can have serious memory impact.

    This is confirmed by this story of a developer who turned static batching off because his build size grew too big:

    http://antonyblackett.wordpress.com...ing-the-roller-coaster-you-dont-want-to-ride/

    This I do not know. There is not much in the API for lightmaping since most of it happens in the editor.
    Mesh Baker tries to bake the textures in the atlas so they are the same size as the original source images. It ignores the Unity size setting. If your source image is 1024x1024 then in the atlas it will also be 1024x1024. Unless the atlas will exceed the maximum size for the build target platform in which case the entire atlas is scaled uniformly down to the maximum atlas size.
     
    Last edited: Oct 25, 2013
  16. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    I'm having an issue with run-time generation of assets. I'm creating the TextureBakeResults based on what the user has selected as character options. I then bake that, along with the character, to a skinned mesh. And it works great - the character and their accessories renders as one, skinned, animated mesh.

    So the problem isn't the fact that it does or doesn't work, as it works great. The problem is I get neverending errors while the game is running after the mesh is generated.

    First, my code for generating the baked assets. I use a coroutine to ensure baking elements have finished before moving on to other things:

    Code (csharp):
    1.  
    2.     IEnumerator initSteveCoroutine()
    3.     {
    4.         // Generate the player's hat if they have one
    5.         string savedHatName = SaveGameController.getSaveGameDataStringValue("CurrentSelectedHat");
    6.         if(savedHatName != "NONE")
    7.         {
    8.             ClothingType targetHat = ClothingLibraryController.getClothingTypeByName(savedHatName);
    9.             hatObject = (GameObject)Instantiate(targetHat.clothingPrefab);
    10.            
    11.             hatObject.transform.parent = GameObject.Find(targetHat.boneToAttachTo).transform;
    12.             hatObject.transform.localPosition = targetHat.offsetFromBone;
    13.             hatObject.transform.localEulerAngles = targetHat.rotationAtBone;
    14.         }
    15.        
    16.         yield return new WaitForEndOfFrame();
    17.        
    18.         // Generate the player's glasses if they have one
    19.         string savedGlassesName = SaveGameController.getSaveGameDataStringValue("CurrentSelectedGlasses");
    20.         if(savedGlassesName != "NONE")
    21.         {
    22.             ClothingType targetGlasses = ClothingLibraryController.getClothingTypeByName(savedGlassesName);
    23.             shadesObject = (GameObject)Instantiate(targetGlasses.clothingPrefab);
    24.            
    25.             shadesObject.transform.parent = GameObject.Find(targetGlasses.boneToAttachTo).transform;
    26.             shadesObject.transform.localPosition = targetGlasses.offsetFromBone;
    27.             shadesObject.transform.localEulerAngles = targetGlasses.rotationAtBone;
    28.         }
    29.        
    30.         yield return new WaitForEndOfFrame();
    31.        
    32.         // Update Steve's hair color
    33.         string savedHairDyeEntry = SaveGameController.getSaveGameDataStringValue("CurrentSelectedHairDye");
    34.         HairDyeOption activeDye = HairDyeLibraryController.getHairDyeOptionById(savedHairDyeEntry);
    35.        
    36.         GameObject steveHairObj = GameObject.Find("SteveHairMesh");
    37.         steveHairObj.renderer.sharedMaterial = activeDye.colorMaterial;
    38.        
    39.         GameObject steveFacialHairObj = GameObject.Find("SteveFacialHair");
    40.         steveFacialHairObj.renderer.sharedMaterial = activeDye.colorMaterial;
    41.        
    42.         yield return new WaitForEndOfFrame();
    43.  
    44.         // Need a new texture bake result
    45.         MB2_TextureBakeResults texBakeResult = ScriptableObject.CreateInstance<MB2_TextureBakeResults>();
    46.        
    47.         yield return new WaitForEndOfFrame();
    48.        
    49.         myTextureBaker.textureBakeResults = texBakeResult;
    50.         myTextureBaker.resultMaterial = gameplayMaterial;
    51.                
    52.         if(savedHatName != "NONE")
    53.             myTextureBaker.objsToMesh.Add(hatObject);
    54.        
    55.         if(savedGlassesName != "NONE")
    56.             myTextureBaker.objsToMesh.Add(shadesObject);
    57.        
    58.         myTextureBaker.objsToMesh.Add(steveMeshObject);
    59.         myTextureBaker.CreateAtlases();
    60.        
    61.         yield return new WaitForEndOfFrame();
    62.        
    63.         myMeshBaker.ClearMesh();
    64.         myMeshBaker.textureBakeResults = myTextureBaker.textureBakeResults;
    65.         myMeshBaker.AddDeleteGameObjects( myTextureBaker.GetObjectsToCombine().ToArray(), null);
    66.        
    67.         yield return new WaitForEndOfFrame();
    68.        
    69.         myMeshBaker.Apply();
    70.        
    71.         yield return new WaitForEndOfFrame();
    72.        
    73.         // Clear the now unneeded objects and their textures from memory.
    74.         if(savedHatName != "NONE")
    75.             hatObject.renderer.material = null;
    76.        
    77.         if(savedGlassesName != "NONE")
    78.             shadesObject.renderer.material = null;
    79.        
    80.         steveMeshObject.renderer.material = null;
    81.     }
    82.  
    So at this point I have a fully skinned, baked, animated character, and it works great and does what I need. But then I receive errors:

    SkinnedMeshRenderer requires a mesh with skinning or blendshape information. UnityEditor.DockArea:OnGUI()
    Number of bind poses doesn't match number of bones in skinned mesh.
    SkinnedMeshRenderer requires a mesh with skinning or blendshape information.

    And that last error message then repeats forever. The object they are saying is the problem is the new SkinnedMeshRenderer object that was the result of the mesh baking. From what I can tell, it looks like this SHOULD mean that the mesh in the SkinnedMeshRenderer doesn't have blendshape info... however it clearly does, or else it wouldn't be animating.

    So at that point I'm a bit stuck... any thoughts on why I'm receiving those unending errors?
     
  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    It does seem strange. Here is what I would do.

    1) Check that myMeshBaker has its renderType setting set to skinned mesh.

    2) Verify which skinned mesh is causing the problem by disabling objects in the running scene and clearing the log to see if the errors stop.

    3) If neither of those things provide a clue then I would put some Debug.Log statements in the methods _getBones _getBindPoses in MB2_MeshCombiner printing out the number of bones and bind poses in the bake. Hopefully this would provide a clue where the problem is. Let me know if this helps.
     
  18. Phong

    Phong

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

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    There is a new version of Mesh Baker available with some significant improvements:

    • Mesh Baker internally uses instance IDs instead of the GameObject references to identify objects being Deleted from the combined mesh. This has the benefit of allowing objects that have been destroyed to be removed from the combined mesh without needing a reference to them.
    • Added a flag to make validation optional when combining meshes. Speeds up adding and updating when you are certain what you are adding and removing is safe.
    • Fixed bug in UpdateApproximateBounds.
    • Added two UpdateApproximateBounds scripts that can be added to a SkinnedMeshRenderer to keep the bounds updated.
    • Improved the logging.
    • Fixed errors switching the output if meshes had already been baked.
     
    Last edited: Nov 7, 2013
  20. chiapet1021

    chiapet1021

    Joined:
    Jun 5, 2013
    Posts:
    605
    Hi there! I'm extremely interested in Mesh Baker and Mesh Baker LOD for my game projects! I had a question on the texture atlasing I was hoping you could answer for me:

    I'd like to use a set of modular building meshes to create multiple prefabs that represent building structures. For example, my mesh set includes structure pieces like walls, towers, windows, etc. Let's say I would like to take a wall mesh and a tower mesh, use four instances of each and join them like a castle (i.e., a tower at each corner with walls along the sides).

    My question is this: When I go to bake the textures in this scenario, will Mesh Baker add the texture of each mesh instance separately to the final atlas, even though they would essentially be four copies of the same thing? Would there be any atlas optimization if I baked the towers and walls separately? I'm concerned about loss of texture quality/resolution if I get too ambitious with the mesh combining.

    Thanks in advance!
     
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Mesh Baker tries very hard to ensure that the minimum number of textures in the atlas is needed.

    If you have 4 towers that use the same material, or even the same set of textures with the same tiling, then these textures will appear in the atlas once. If you use the same texture on two different models with different tiling then these will appear in the atlas twice. If you use UV tiling instead of specifying the tiling in the Texture inspector then you can have one copy of the texture in the atlas used by models with different tiling parameters.

    If you are using a lot of tiling on your buildings then a good way to combine them would be to group all the similar wall sections in the entire city together so that there is only one texture in the atlas and the tiling doesn't need to be baked. This approach is even more effective if you use out of bounds UV tiling instead of specifying the tiling in the Texture inspector because you can combine different meshes with different tiling parameters together.

    Also note that the list of objects to be combined in the Texture Baker can be different from the list of objects in the Mesh Baker. This is useful for making master atlases that can be used by different bakers that use a subset of the textures in the atlas.
     
  22. chiapet1021

    chiapet1021

    Joined:
    Jun 5, 2013
    Posts:
    605
    Fantastic. Thanks so much for the response and tips. This asset is definitely on my to-buy list.
     
  23. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    Do I have to use an atlas texture? I don't get the point. I already have an atlas texture and I'm doing a multi-mesh multi-material bake yet it still wants to generate and use an atlas texture. Can't I just bake the meshes and maintain UVs so I can use my existing materials and textures? This is especially a problem for me as I'm using substances. If not this doesn't really provide me much benefit over using gamedraw to combine child meshes. Also a cool feature to have would be to export to mesh and export to .obj.

    Edit: Looks like I can assign the original material after baking. This is a problem for some bakes though. For example I have a spike log with 3 materials on it. 2 of the materials have the same texture, but completely different properties yet it wants to combine the 2, which results in my spike log looking like crap. The only way I could work around this was by ensuring all 3 materials have a separate shader so it didn't try to combine the first two. Once done I change the shader back then assign the original materials and it works, but this seams like a completely unnecessary and absurd step to do.

    Edit: The below is reported to the console on Unity 4.2.

    Code (csharp):
    1.  
    2. Assets/MeshBaker/scripts/core/MB2_MeshCombiner.cs(1018,33): warning CS0168: The variable `max' is declared but never used
    3. Assets/MeshBaker/scripts/core/MB2_MeshCombiner.cs(1018,38): warning CS0168: The variable `min' is declared but never used
    4. Assets/MeshBaker/scripts/core/MB2_MeshCombiner.cs(1056,35): warning CS0219: The variable `w2l' is assigned but its value is never used
    5. Assets/MeshBaker/scripts/core/MB2_MeshCombiner.cs(1420,113): warning CS0472: The result of comparing value type `int' with null is `true'
    6. Assets/MeshBaker/scripts/core/MB2_MultiMeshCombiner.cs(382,85): warning CS0472: The result of comparing value type `int' with null is `true'
    7.  
     
    Last edited: Nov 11, 2013
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    At this time a Material Bake Result is required in order bake meshes together. It makes scene when combining meshes with different materials however you are correct in that if all your meshes use the same material then it is a required step that is not really necessary. A few users have requested being able to bake meshes with the same material without baking an atlas first. I will try to add this in the next version.

    Regarding the Obj export. I agree it would be nice but there are some free scripts on the wiki and other assets in the store that do mesh export so I haven't added this. It is a lot of work. One issue with Obj format is that it doesn't handle skinned meshes bones and animations so I would prefer to do Fbx if I were to do this.

    Hmmm, I am surprised this worked. Even if the source materials have different shaders Mesh Baker will combine the their texture properties into the atlases needed by the result shader. I can think of two ways of handling this problem:

    1. Use the multiple materials feature to map the materials that use the same texture to different submeshes in the combined material. You will end up with more drawcalls but this is the only way to have a combined mesh with maltiple materials that have different simple properties if you want to preserve the simple properties.
    2. Duplicate your original texture asset. Mesh Baker will think they are different and they will both appear in the atlas. However they will both share the same set of properties in the result material.


    Sorry about these warnings. I didn't notice them before submitting the last version. It is on my release checklist to check that there are no warnings but somehow it was missed this time. Will effeminately fix these in the next version. You can remove the first three lines if you wish and remove the "int with null" part of the comparison to get rid of the other two.
     
  25. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    *** I answered most of my questions already. I'm gonna play around with it a little bit more, but this looks like it could be a huge performance saver for me :D If all goes well, I will be purchasing this, and i'm pretty excited about it.


    Hi Phong,

    I think I might be really interested in your asset. I downloaded the free trial version, and I followed the video tutorial on "Combining Skinned Meshes". I have 3 main questions, and some of them are kind of noobish, so please don't get mad :)

    I have a warrior model that is 7 separate skinned mesh renderers under one parent game-object. For instance, shoes, pants, shoulders, hands, body, head, etc are all separate (but they make up one model). So I used the free trial version, and it combined and made a texture atlas just fine (I think). And then I baked all of the meshes into one scene object successfully (I think lol).

    Here is my question, in my scene, when I go to move the created scene object (the combined scene object that Mesh Baker created), the transform pivot moves, but the mesh/object does not move with it. Is this because it's a free trial version? I'm assuming that somehow it can't be manipulated because it's the free version. Is this correct?

    Secondly, the created scene object looks perfectly fine, and it even has the "idle" animation on it, but I don't see an animation component on the scene object -- so how is the created scene object playing the "idle" animation without an animation component?

    Thirdly, does Mesh Baker 2 work with Unity free version? Specifically, will combining skinned meshes/textures work just fine in Unity free version? (I think the trial just told me "yes" it does, but I need to be sure).

    Overall, it "looks" like everything is working like it's supposed to, but I can't be sure. I need to make sure my model's animations are preserved correctly. As far as I know, everything else is working as intended. I get 1 skinned mesh renderer as output, but I don't know if the animations work.
     
    Last edited: Nov 11, 2013
  26. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    Awesome, would be really cool to basically just have a "multi-mesh bake" and it maintain existing materials. Regardless this is still very cool and helpful tool. I find so far in my tests it combines much better than gamedraws so that is a huge plus for me.

    Ah, that makes sense. What about being able to save the mesh as a .asset so you can use mesh import settings?

    I was surprised my self. I discovered it by reviewing mesh baker code and found it combined based off shader. So assigned a different shader per material so it didn't bother combining. This basically allowed me to skip the combine step. I then assigned my original materials to the baked mesh and works flawlessly. So I really think mesh baker can already do combine with original materials; maybe easier than expected to implement? I'll try it out with a few more meshes, but so far this approach has worked for 3 meshes perfectly fine thus far.

    Not a problem. Was just letting you know. :)

    With all things aside this is a wonderful asset. 5 star rated for sure, thank you for all your hard work.
     
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    With skinned meshes you need to move the bones. If you combined MeshRenderers then the bones will be the transforms on the source MeshRenderer objects. This will preserve any animations you have on the source objects. Moving the transform of the combined mesh won't do anything.
    See comment above.
    Every part of Mesh Baker works in the Free Version of Unity.

    Yes the animations will work with two caveats:
    • You may need to change the culling settings on the animation component. Cull Based On Renderers does not work well because the rederers the animation component finds are usually disabled. You need to use animate based on clip bounds or always animate.
    • You may need to add a script to keep updating the render bounds of the SkinnedMeshRenderer. This is especially important if you combine several skinned characters that can wander some random distance from each other. You mesh may suddenly vanish. Mesh Baker includes two scripts for doing this.
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    If you use the "bakeIntoPrefab" feature it saves the combined mesh as an asset but it is already a Unity mesh so you don't get any import settings if you click on it. :(
     
  29. Alcyone

    Alcyone

    Joined:
    Nov 15, 2013
    Posts:
    13
    Hi Phong,

    I have purchased your Mesh Baker 2 today, and I have spent some minutes merging one model, IT WORKED perfectly, but... after that I have tried with another two different models and there isn't any way to bake it...

    I get this when I try to bake materials:

    All materials are Diffuse, and the combined mesh material too.

    Please help me, I have lost like 3 night-hours trying to advance, maybe I'm missing something?

    Thanks a lot!

    Here it is an image about the error:
    $img.jpg


    If you, or anyone in the forum want to test it and help me, I have uploaded the model in fbx here:
    http://www.asierarranz.com/a380.fbx [33.5Mb]
     
    Last edited: Nov 15, 2013
  30. Phong

    Phong

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

    Replace line 831 in file MB2_TextureCombiner with this one:

    Code (csharp):
    1. sb.AppendFormat("Object {0} has submeshes that share vertices. This is a problem because each vertex can have only one UV coordinate and may be required to map to different positions in the various atlases that are generated. Possible treatments:", objsToMesh[i]);
    I will submit this fix immediately to the asset store. I added a new feature which offers advice about what can be done to combine meshes and it looks like I missed this bug. Sorry :(

    I downloaded your model and have been playing with it. It is always interesting to see what people are trying to use. I didn't look at everything but here are some problems I see right off the top.

    • The scale on the root of the model is -1,-1,-1 for some reason. This is a problem because mesh maker inverts the normals when it tries to bake the scaling. Set it to 1,1,1.
    • The chasis has 8 submeshes with eight different materials and textures. Six of these textures are almost identical. You should pick one as a master and use that on your model.Then you will have an atlas with three textures instead of eight. Some of UV Texture usage is very inefficient most of the texture is empty sapce.
    • Some of the submeshes share vertices. This is usually a mistake.
    • Many of the materials have empty texture slots. You are using the color property of the material to set the color. This doesn't work when materials are combined unless everything can have the same color. Try adding a 2x2 solid color texture.
     
    Last edited: Nov 15, 2013
  31. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    I have a question:

    Can Mesh Baker be used to combine Meshes and Materials ?

    Does that work for Meshes that move in relation to each other, like a car and its wheels?


    Cheers

    Gian-Reto
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Yes. combining meshes and materials is exactly what Mesh Baker is designed to do. Not all meshes are combinable but if they can be combined then it is almost certain that mesh baker can do it. There are obvious limitations. For example when combining a transparent material with an opaque material you are forced to choose whether the result will be transparent or opaque.
    You have a few choices if you want to combine meshes that move relative to each other:

    1) Use MeshBaker to make copies of the meshes that can share a material. Now Unity's dynamic batching can combined the objects.
    2) Combine the Meshes into a skinned mesh. The parts can still move independently but the result will have one drawcall.
    3) Use the MeshBaker API to update the vertices in the combined mesh every frame. I wouldn't recommend this one. Number 2 is a better choice if things need to be updated every frame.
     
  33. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    Doh, Captain Obvious at work again... I wanted to ask if it is possible to combine it at runtime. Sorry for asking an incomplete question :)


    Number 2 does sound interesting. Can I do this at runtime with Mesh Baker? Because the Parts will be selected at runtime, so the combine should also take part at runtime.
    How does the skinning work with a Model made up of rigid parts? Are the parts still accessible from script (I animate them in script, as I want the wheels to be animated with the values from the suspension, and the turret to react to the input of the player).


    thanks for the answers!


    Gian-Reto
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    You can both combine materials and meshes at runtime. A lot of work has been put into making this very efficient. The mesh combining is awesome. Look at the videos for Mesh Baker LOD to see how frequently you can bake. You can't save meshes as assets at runtime but you can generate new meshes in memory. Baking skinned meshes etc.. can all be done at runtime.

    There are example scenes/scripts in the package showing runtime baking of meshes, materials, combining skinned meshes and adding MeshRenderer objects to skinned meshes.

    Baking materials at runtime has significant limitations:

    • Source textures must be in ARGB format. These take up a lot of space.
    • It generally takes between 5 - 30 seconds to combine textures into an atlas depending on how many textures and how big the atlas is.
     
    Last edited: Nov 20, 2013
  35. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    Thats good news... will definitly look into your asset in the next few days.

    I don't think the size of the textures will be a big problem. I assume the resulting Atlas can be compressed after creation. As the Atlas Creation could be done before running the game in the main scene (in some kind of vehicle selection menu), VRAM should not be an issue.

    The Time it takes to combine could be a little bit of a pain. But with a clever menu, that somehow detracts from the wait time (animated "part replacement" visible, while the mesh gets baked in the background), the player most probably will not notice.

    Question is: will it run faster if I combine all the non-replacable parts in the editor, so only 1-2 parts that should be replacable will be replaced ingame? So the system only needs to add 2 parts to the skinned mesh, and their textures to the atlas?
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Baking atlases in the editor is a good idea. Yes they can be compressed after being baked.
    It is only the texture baking that is slow. Mesh baking is very fast. A 64k mesh bakes in perhaps .06 sec on a PC .3 sec on a mobile. There is almost no gain if you are baking a few parts of a combined mesh vs. baking all the parts. The reason is that most of the time is spent copying old arrays to new arrays and the entire source array needs to be copied regardless of how many source meshes change. Another slow point is assigning the arrays to the mesh. This takes about .3 of the total bake time. It is also unaffected by how many meshes are being changed.

    Mesh baking is fast enough that it can be done multiple times per second in game in most cases.
     
  37. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    Crazy idea:

    How about keeping the mesh parts separate and baking them at runtime, but combining all the textures to a single atlas in the editor? So that, when the player picks the parts he wants to use, the mesh gets baked, but the same atlas is used for texture (just with different UV Coordinates for the variable parts)?

    As the swappable parts will most probably use less than 20% of the total texture size, the overhead in VRAM usage should be okay for use in a PC / Mac / Linux Standalone game, right?
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Not a crazy idea at all. What you describe is exactly the use case that Mesh Baker was designed for. The idea is to build a master atlas in the editor that has all possible textures. After this has been done then ANY mesh that uses those textures can be combined quickly at runtime with ANY combination of other meshes that use those textures. You can't always use this technique because there may be too many textures but if you can it is awesome. This approach has been battle tested and works very well.

    The architecture of Mesh Baker is designed so that the Material baking and Mesh Baking components are loosely coupled. The output of the material bake is a special asset that contains the material -> UV rectangle map. This special asset is the only input that the mesh baking component needs. This way you can bake your atlases in a simple atlas-generating-only-scene. You don't even need to use your source objects. You can can use placeholder cubes as long as they have the same materials that your source objects use. After the atlases are baked you can use the generated atlases and this special asset in your other scenes to combine the meshes without the need to bake the materials again.
     
    Last edited: Nov 21, 2013
  39. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    Great news. I bought Mesh Baker, and will give it a spin over the weekend.

    Thanks for all the useful information and I am looking forward to using your tool.

    Cheers

    Gian-Reto
     
  40. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Hello I'm new to Unity and I have a question about optimizing on mobile, so please bear with me.

    I don't have Unity Pro. I was wondering if your system will work with any of the off-the-shelf asset store occlusion culling systems like InstantOC, which shoots out raycasts from the current camera view and turns off the renderer of any object that isn't hit.

    I'm trying to understand the advantages of drawcall reduction vs occlusion culling.

    Let's say I have 1000 mesh rocks in my scene, your system can combine them all into one giant mesh at runtime right? That would reduce the drawcalls from 1000 to 1? But now if the current camera view sees just one rock, it will now render all 1000 rocks, correct? So now even though the drawcalls have been reduced dramatically, the amount of vertices always being rendered will be way higher than using a culling system.

    I assume a culling system will only make drawcalls for the amount of rocks currently seen by the camera...so for example if there are currently 10 rocks in view, that will be 10 drawcalls, but with much much fewer vertices. Can you tell me what performance will be better? 1 drawcall with lots of vertices, or 10 drawcalls with much fewer vertices?

    Or maybe I could combine both strategies...maybe I could use your system to bake out groups of rocks that are clumped close together, so instead of one large mesh I could have maybe ten groups of 100 rocks each. Then I could feed those groups into an occlusion culling system and cull any group not seen by the camera. So it would be sort of a compromise between drawcalls and vertices rendered.

    Please let me know what is possible for the best performance using your system possibly together with culling, with Unity Free. Thank you!
     
    Last edited: Nov 23, 2013
  41. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    Hi Phong

    I spent an hour with your system to just try a simple in editor bake. Impressive Results, Drawcalls reduced to 10% of non-combined mesh!

    However, I have a problem with the Resulting Texture Atlas I could not fix, and a big question you might be able to point me in the right direction.

    The Problem:

    $meshbaker_source.png
    This is the source mesh. You see the Normal Map is clearly visible. The meshes (as in heat outlet mesh) in the back are a single Poly with some further one along the edges.

    $meshbaker_problem.png
    This is the generated mesh. The normal map seems to be somehow weird. The Texture File is 2048x2048 in the original, and gets compressed to a smaller size in the atlas even though there is plenty of space available (I set the max size to 4096, and the resulting texture size is 4096x2048, only using over 2/3 of the space in there even).

    Any idea what I can do to make sure the textures keep their original size? Any idea how I improve the quality of the packed texture if the size can't be fixed?

    EDIT: I found the option to make it keep its original size.... but the problem stays the same even when the problematic Texture gets the original 2048x2048 in the resulting atlas.


    The question would be: I now have a skinned mesh without bones... what do I do now with it? I am a total noob when it comes to skinning and bone animation, but I would guess I need bones to for example turn the turret.
    Is there another way to adress the mesh parts in script? Can I somehow inject the bones after the bake? is there any good tutorial on these topics?


    Thanks for any help

    Gian-Reto
     
    Last edited: Nov 23, 2013
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    This is pretty much correct.
    Almost certainly 1 drawcall will be faster. Drawcalls in Unity seem to have a big cost beyond just shipping the vertices to the graphics card. Reducing drawcalls is probably the single most effective thing you can do to improve performance. Obviously sending fewer vertices is faster but it is less effective than you would think.
    You should check out Mesh Baker LOD. It doesn't do occlusion culling but it does bake your meshes into clusters automatically for you. It also does LOD so you can have low poly versions of your rock in the distance and higher poly up close. It could probably be made to work with an occlusion culling system but I haven't tested this.
    For an outdoor scene you should look at LOD before looking at Occlusion culling. Occlusion culling is awesome for indoor environments where the player is in one room at a time and 95+% or your scene can be culled, but not so good for outdoor scenes where most of the scene may be in view. LOD is a much better approach for reducing vertices for outdoor scenes.
     
    Last edited: Nov 25, 2013
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Is there tiling or submeshes or both involved these can cause this sort of problem. Were there any messages or warnings in the console? Mesh Baker is fairly good about identifying problems with meshes.
    I presume what you have done is baked several MeshRenderer meshes into a SkinnedMeshRenderer using Mesh Baker. If this is the case then the bones will be the transforms on the source Game Objects. You can move the vertices in the Skinned Mesh by moving the source objects around in the scene. It does not matter what moves the transforms animation, physics, script.

     
  44. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    No tiling, no submeshes for the body of the vehicle. I did not see any errors, but I will check again.

    I think there is only one Meshrenderer component on the main object containing all the submeshes. that might be the problem in the second case.... I will add MeshRenderers to all submeshes and see if that changes anything.
    I do understand that correct: I'll have the new skinnedRenderer active, but deactivate all Meshrenders on the source object. I keep both the new object with the skinned mesh and the old source, the second one just with deactivated Renderers. If I move one of the objects containing the old submeshes, the bones in teh skinned Mesh move?
     
    Last edited: Nov 25, 2013
  45. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Thanks for all the info. I think I have a little better understanding now. However, can you tell me the difference between Mesh Baker and Mesh Baker LOD?

    As far as I know, Mesh Baker combines the meshes and textures to achieve reduced drawcalls, but does not reduce the polycount in any way. Does Mesh Baker LOD automatically reduce the polycount in the baked Mesh Baker meshes at runtime to create levels of LOD? Or is it simply a straightforward LOD system that works with LOD meshes that I still have to create by hand?

    Also, are the colliders for the combined meshes still intact and fully operational? Thanks again!
     
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Mesh Baker is the combining tool and combining API. It creates atlases and combines meshes. It is very full featured in that it handles submeshes, skinned meshes lightmapping etc...

    Mesh Baker LOD uses the Mesh Combining API in meshbaker to do LOD. It does NOT create your LOD meshes for you. You need to do that yourself. It does straightforward LOD but it bakes the LOD meshes together into clusters for you. A lot of work has been put into the scheduler to make this process very efficient and handle overloading gracefully.

    The second.
    The recommenced way to use Mesh Baker is to disable the renderer component on the source game object but leave the collider enabled. There is no performance benefit to baking colliders together.
     
  47. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I don't think your understanding of submeshes is correct. Multiple materials and submeshes are the same thing. Submeshes are part of a mesh. They are nothing more than an extra list of triangles in a mesh so that you can apply more than one material to a single mesh. You can't add different mesh renderers to each submesh. What I should have asked is "do any of the renderers you are combining use multiple materials?".

    Regarding the skinned meshes: yes your understanding is correct. I would recommend opening the example scene "scene basic". Then switch the render type to "skinned mesh", bake, disable renderers in source. Now try moving/rotating the source objects (with disabled renderers). This is the simplest way to see how it works.
     
  48. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    Okay, I checked again, you where right, I was wrong: every submesh has its own meshrenderer. And after checking, everything works fine after just disabling the meshrenderers on the source object... turning the source object itself will turn the relevant part in the skinned mesh, just like before, but without the draw call overhead. Call me mighty impressed :)

    That leaves the problem with the Normal map. I redid the texture baking, no errors, some messages about missing textures being created as 2x2, but that was mainly missing specs and illum ones on other parts of the car (which do get correctly created as non-illuminated and fully spec'ed... does not look good in my case, but its my fault, easy to fix, and will not be a problem when the model is fully textured).
    The Body part though should not be affected, it has all the textures (diffuse, spec, normals, self-illum), they are all of the same size (2048x2048 ), and on the source object I see no problem.

    any suggestions what I could try?


    Thanks in advance

    Gian-Reto
     
  49. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I would check the settings on the generated atlas texture itself for the bumpmap. Try increasing the Maximum size. Make sure that the normal map settings are set.
     
    Last edited: Nov 26, 2013
  50. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    575
    Assets/MeshBaker/scripts/core/MB2_BakeInPlace.cs(23,25): error CS0246: The type or namespace name `MB2_EditorMethods' could not be found. Are you missing a using directive or an assembly reference?

    what console error is this and how can i fix it? Thank you