Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,838
    Ok thanks, that was the issue.

    I have another question regarding the benefit of mesh combine for static objects.
    I am trying to understand when it is worth combining gameObjects together, and when it isn't.
    Let's say i have two cubes. Both use the same material, and both are batching static, and they are very close together. Is it even worth combining the meshes together for this scenario? Or is simply marking the items as static in the inspector and letting unity do the batching sufficient?
    I am trying to figure out when MeshBaker should be used, and when it doesn't need to be used.
    Thanks for your time.
     
  2. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,838
    Hello,
    Question regarding "Include UV1" checkbox:

    When I select this option the meshBaker throws the warning to the console:
    "UV1 was checked but UV1 does not exist in Unity 5+".
    UVerror.png
    According to the unity form, UV1 is reserved for baked lightmapping in Unity 5.0:
    http://forum.unity3d.com/threads/quick-setup-for-starting-enlighten.309609/

    So in meshBaker which UV refers to baked lightMapping coordinates: "UV" or "UV1"?

    Thanks.
     
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087

    This will be tricky. Animating UVs is very difficult with atlases unless you can keep the UVs contained in their little rectangle in the atlas. I think your options are:

    1) If the UV animation is limited to the X axis or the Y axis only then you could hack the atlas so that all the textures it contains are stacked vertically or horizontally. Then the UV animation will probably work. Let me know if this is the case and I can explain further. You will probably need to create the atlas manually if this is the case.

    2) You might be able to write the shader so that it is aware of the UV rect that it needs to live inside. This is probably quite a time consuming and difficult solution. If your UVs need to go out of bounds or wrap then this almost certainly won't work.

    3) If many of the objects you are combining use the same texture, For example if all the petles use one texture and leaves use another texture then you can combine all meshes that use their own texure into separate skinned meshes or into separate submeshes on a single skinned mesh. This way the atlases will each contain a single texture and the UV animation should work.
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    In this case of the two cubes I would let Unity do its static batching. However the objects may use different materials in which case they cannot be batched together. In this case you could use the prefab baker to make them use the same material so they can be batched.
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    In MB lightmapping is handled by the "Lightmapping UVs" dropdown. It corresponds to UV2. Note that in Unity 5 the "preserve existing lightmapping" option is not reliable. The Generate New UV2 layout is the most reliable option.
     
  6. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,838
    Ok. So what is "UV1" in MeshBaker? Do we need to include UV1 if we are generating UV2?
    Thanks.
     
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    You can ignore UV1 in Unity 5 I have read that it is a second reference to UV2 although I have not tested this myself to confirm it.
     
  8. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,838
    ok, thanks.
     
  9. Rabbito

    Rabbito

    Joined:
    Apr 5, 2015
    Posts:
    13
    Hi i have tried to fix the updateproblem but i cant.
    I am using the windows 7 and Unity Version 5.0.2f1.
    I have set the log to debug and it only says:
    UpdateGameObjects called on 1 objects.

    Code (CSharp):
    1.  
    2. UpdateGameObjects called on 1 objects.
    3.  
    4. UnityEngine.Debug:Log(Object)
    5. DigitalOpus.MB.Core.MB3_MeshCombinerSingle:_updateGameObjects(GameObject[], Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean) (at Assets/Extern/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1177)
    6. DigitalOpus.MB.Core.MB3_MeshCombinerSingle:UpdateGameObjects(GameObject[], Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean) (at Assets/Extern/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1171)
    7. DigitalOpus.MB.Core.MB3_MultiMeshCombiner:UpdateGameObjects(GameObject[], Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean) (at Assets/Extern/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:325)
    8. MB3_MeshBakerCommon:UpdateGameObjects(GameObject[], Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean) (at Assets/Extern/MeshBaker/scripts/MB3_MeshBakerCommon.cs:175)
    9. MeshComponentManager:LateUpdateApplyColorMeshBaker() (at Assets/Scripts/World/MeshCompontents/MeshComponentManager.cs:184)
    10. World:LateUpdate() (at Assets/Scripts/World/World.cs:309)
    11.  

    After i have debug the hole process i see that when i call apply he dont update any Meshcombiner.
    Code (CSharp):
    1.  
    2. MB3_MultiMeshCombiner: MB3_MeshCombiner{
    3. ......
    4. public override void Apply(bool triangles,
    5.                       bool vertices,
    6.                       bool normals,
    7.                       bool tangents,
    8.                       bool uvs,
    9.                       bool colors,
    10.                       bool uv1,
    11.                       bool uv2,
    12.                       bool bones=false,
    13.                       MB3_MeshCombiner.GenerateUV2Delegate uv2GenerationMethod=null){
    14.         for (int i = 0; i < meshCombiners.Count; i++){
    15.             if (meshCombiners[i].isDirty){
    16.                 meshCombiners[i].combinedMesh.Apply(triangles,vertices,normals,tangents,uvs,colors,uv1,uv2,bones,uv2GenerationMethod);
    17.                 meshCombiners[i].isDirty = false;
    18.             }
    19.         }
    20.     }
    21.  
    22. ....}
    The isDirty is false for all. I dont know how this all works. But maybe this can help.


    EDIT:
    if I update the Code in the MB3_MultiMeshCombiner


    Code (CSharp):
    1.  
    2.  
    3. public override void UpdateGameObjects(GameObject[] gos, bool recalcBounds = true,
    4.                                          bool updateVertices = true, bool updateNormals = true, bool updateTangents = true,
    5.                                         bool updateUV = false, bool updateUV1 = false, bool updateUV2 = false,
    6.                                         bool updateColors = false, bool updateSkinningInfo = false){  
    7.         if (gos == null){
    8.             Debug.LogError("list of game objects cannot be null");
    9.             return;  
    10.         }
    11.        
    12.         //build gos lists
    13.         for (int i = 0; i < meshCombiners.Count; i++){
    14.             meshCombiners[i].gosToUpdate.Clear();
    15.         }
    16.        
    17.         for (int i = 0; i < gos.Length; i++){
    18.             CombinedMesh cm = null;
    19.             obj2MeshCombinerMap.TryGetValue(gos[i].GetInstanceID(),out cm);
    20.             if (cm != null){
    21.                 cm.gosToUpdate.Add(gos[i]);
    22.             } else {
    23.                 Debug.LogWarning("Object " + gos[i] + " is not in the combined mesh.");  
    24.             }
    25.         }
    26.        
    27.         for (int i = 0; i < meshCombiners.Count; i++){
    28.             if (meshCombiners[i].gosToUpdate.Count > 0){
    29.                 GameObject[] gosToUpdate = meshCombiners[i].gosToUpdate.ToArray();
    30.                 meshCombiners[i].combinedMesh.UpdateGameObjects(gosToUpdate, recalcBounds,updateVertices, updateNormals, updateTangents, updateUV, updateUV1, updateUV2, updateColors, updateSkinningInfo);
    31. //THIS IS ADDED BY ME
    32. meshCombiners[i].isDirty = true;
    33.             }
    34.         }
    35.     }
    Then it is working. But i realy dont want to change your code, because this can only ends bad :)
    I think there is still something i dont see...
     
    Last edited: Jul 11, 2015
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Ahhh, that is correct. Do you have the latest version of Mesh Baker? I my version I do have the isDirty = true although it comes two lines earlier. I think you are working with an older version of Mesh Baker. That would explain why I was having so much trouble reproducing the problem.

    Code (CSharp):
    1.              
    2.                meshCombiners[i].isDirty = true;
    3.                 GameObject[] gosToUpdate = meshCombiners[i].gosToUpdate.ToArray();
    4.                 meshCombiners[i].combinedMesh.UpdateGameObjects(gosToUpdate, recalcBounds,updateVertices, updateNormals, updateTangents, updateUV, updateUV1, updateUV2, updateColors, updateSkinningInfo);
    5.  
     
  11. Rabbito

    Rabbito

    Joined:
    Apr 5, 2015
    Posts:
    13
    ahh now its working, thank you for your support
     
  12. CurtisMcGill

    CurtisMcGill

    Joined:
    Aug 7, 2012
    Posts:
    67
    One thing you might want to check is the color, I found mesh baker sometimes uses a darker color than the original.

     
  13. CurtisMcGill

    CurtisMcGill

    Joined:
    Aug 7, 2012
    Posts:
    67
    Great job on the new youtube videos, I now understand the different features and the latest version works fantastic.

    My question is...

    I have an aircraft with landing gear animation and when I combine mesh, how do I get the animation working and I need to rotate flaps, rudder, etc.

    In other words: I need to combine the 8 different materials, optimize model for draw calls and isolate items that I can animate/rotate.





    In The Fire
     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    I would suggest one of the two options:

    1) Combine everything into a skinnedmesh. This may be wasteful if there are a lot of mesh verts in the fuselage and wings that never move.

    2) If there is a lot of mesh detail (verts) in the non moving parts. Combine all the static part of the plane (fuselage, engines, wings etc...) into a MeshRenderer mesh. Combine all the moving parts into a skinned mesh. This is probably the fastest option. You will have two drawcalls but will save considerable time skinning vertices that don't move.

    You may want to consider combining the landing gear separately if the landing gear will be invisible 99% of the time.

    Regarding the animation, if you just the SkinnedMeshRenderer bounds so it encloses the whole plane then it should just work when you bake Mesh Renderers into skinned meshes.
     
  15. MoonifyPascal

    MoonifyPascal

    Joined:
    Aug 16, 2013
    Posts:
    12
    Hi,

    before buying, i would like to know if :
    -it's possible to generate one texture atlas from several prefabs but without combining their meshes.
    - your tool can deal with nested prefabs
    - it's possible to deal with some prefabs using some textures that are already an atlas dedicated to them.

    Don't know if i'm clear...

    Thanks for your answers?

    Regards
    Pascal
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Hi Pascal

    Yes it is possible to generate an atlas for several prefabs without combining their meshes. Check out this tutorial to see how it works.



    I don't believe Unity supports Nested Prefabs yet. Mesh Baker can handle more than one mesh renderer in a single prefab and can handle these at arbitrary depth in the hierarchy.

    If some textures are already in an atlas, Mesh Baker will copy that entire atlas into the new atlas. It is not smart enough to only extract the part of the atlas used by a specific model.
     
  17. jjobby

    jjobby

    Joined:
    Nov 28, 2009
    Posts:
    161
    Hi, is it possible to change property of material such as color for each mesh that was already combined? For example, if I want player to dye there armor with other color. Can I just change color of armor material? Or do I need to re-bake material again at runtime?
     
  18. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Hi jjobby,

    If there is a color property, that is being used to tint a texture Mesh Baker will set the color property in the combined mesh to the color of the first object in the list of objects to combine. You can't have different objects with different colors keep their different colors in the combined material. The exception is if there is no texture being used at all in which case Mesh Baker makes a small texture using that objects color and puts that into the atlas.
     
  19. zreek17

    zreek17

    Joined:
    Jun 2, 2013
    Posts:
    21
    I did it like U said, but it doesn't work still :(

    This is how my script look like:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class LPSBake : MonoBehaviour {
    5.    
    6.     MB3_MeshBaker mbd;
    7.     GameObject[] gos;
    8.     public string ObjectTag;
    9.     bool showHide = true;
    10.  
    11.    
    12.     IEnumerator Combine()  
    13.     {
    14.         mbd = GetComponentInChildren<MB3_MeshBaker>();
    15.         yield return new WaitForSeconds (0.05f);
    16.         gos = GameObject.FindGameObjectsWithTag(ObjectTag);
    17.        
    18.         mbd.AddDeleteGameObjects(gos, null, true);
    19.         mbd.Apply();
    20.  
    21.     }
    22.  
    23.     void Update ()
    24.     {
    25.         if (Input.GetKeyDown(KeyCode.Q))
    26.         {
    27.             showHide = !showHide;
    28.             print (showHide);
    29.             //MB3_MeshBaker mbd = GetComponentInChildren<MB3_MeshBaker>();
    30.             mbd.EnableDisableSourceObjectRenderers(showHide);
    31.             GameObject.Destroy(mbd.meshCombiner.resultSceneObject);
    32.             foreach (GameObject go in gos)
    33.             go.renderer.enabled = true;
    34.         }
    35.     }
    36.  
    37.     void OnEnable ()
    38.     {
    39.         StartCoroutine (Combine());
    40.     }
    41. }
    42.  
    As U see I use simple foreach loop to enable my source gameobjects.
    But when I need to repeat baking of source gameobjects, there is a mistake:

    NullReferenceException: Object reference not set to an instance of an object
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle._addToCombined (UnityEngine.GameObject[] goToAdd, System.Int32[] goToDelete, Boolean disableRendererInSource) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:641)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle.AddDeleteGameObjectsByID (UnityEngine.GameObject[] gos, System.Int32[] deleteGOinstanceIDs, Boolean disableRendererInSource) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1304)
    DigitalOpus.MB.Core.MB3_MeshCombinerSingle.AddDeleteGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject[] deleteGOs, Boolean disableRendererInSource) (at Assets/MeshBaker/scripts/core/MB3_MeshCombinerSimple.cs:1261)
    MB3_MeshBaker.AddDeleteGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject[] deleteGOs, Boolean disableRendererInSource) (at Assets/MeshBaker/scripts/MB3_MeshBaker.cs:43)
    LPSBake+<Combine>c__Iterator4E.MoveNext () (at Assets/WALLRUN/Platform1Lianas/Bakers/LPSBake.cs:18)

    So it can work only for a 1st time, without any repeats.
    How can I bake it many times?
     
  20. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Hello,

    Are you using the latest version? The line numbers in the exception don't seem to line up with the code in the latest version.

    I think the problem is the Destroy on the Result Scene Object. Mesh Baker needs a game object where it will put the combined mesh. You are destroying it before re-baking. You shouldn't have to destroy the Result Scene Object. Mesh Baker can find the old mesh and update it this has better performance than destroying the old mesh and building up a new one from an empty game object.
     
  21. Ali-Nagori

    Ali-Nagori

    Joined:
    Apr 9, 2010
    Posts:
    151
    is there is a way to bake meshes using their original material and textures. instead of of baking a separate atlas for each baking process.

    if possible please guide
     
  22. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Hi Ali,

    You could do this using the Multiple Materials feature. Map each source material to its own submesh. When you bake Mesh Baker will re-use all the original textures instead of creating an atlas. It will create new materials for each material however you should be able to re-use your source materials and it should work.
     
  23. Ali-Nagori

    Ali-Nagori

    Joined:
    Apr 9, 2010
    Posts:
    151
    thank ian for quick replay,

    by that approach i will end up having more than one combined mesh, which will kill the purpose of combining the meshes in the first place , in my case the model using up to 15-20 materials per actor, and creating atlas for each model is will reduce the quality of the details+ increases the memory load . what i wish for is that the baked mesh points to its original Mats by simply making the SkinnedMeshRenderer including them all in material array list
     
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Hi Ali,

    You are right, using the multiple materials feature creates submeshes which each get their own drawcall. However this is what is happening when there are multiple materials in the material array list. Every time you see an object with multiple materials listed then the mesh that is being used has one submesh for each material. The only way to reduce the number of submeshes used is to use atlases.

    If you are loosing quality combining everything into one atlas could you try combining into several atlases using the multiple materials feature?
     
    Ali-Nagori likes this.
  25. Ali-Nagori

    Ali-Nagori

    Joined:
    Apr 9, 2010
    Posts:
    151
    thanks again ian for your advice , i will work around these options.
     
  26. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,838
    Hello,
    I've used Mesh baker in one scene to combine meshes. When I try to copy the gameObjects with the combined mesh to another scene, the combined mesh does not show up in new scene. The mesh filter reports "Missing (Mesh)". How can I transfer the combined mesh from one scene to another scene? I would rather not have to create Prefabs for this.
    Thanks.
     
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    The easy way is to create a prefab. You can delete the prefab after and keep the combined mesh asset. Other than that you will have to save the Mesh instance somehow. This can be done with a short script.
     
  28. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,932
    Hello, I have the latest version and am using Unity 5.1.2. I do not have a Create Other under the CreateObject tab. I have used your product in earlier versions of Unity without a problem.

    I downloaded, redownloaded, check the version, exited and restarted, and all that jazz but still no Create Other.

    Is it broken or is there another way to create the Mesh Baker Object in the scene?

    Oh, and all I have in this scene is a terrain, Time of Day, a directional light, and models.

    Thanks.
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Hi Telia,

    I have not tested in 5.1.2 yet. The latest I have tried it 5.1.0. It works in 5.1.0. Will download 5.1.2 and test.

    In the meantime you can create the MeshBaker objects easily by hand. The menu items are just for convenience.

    Create an empty GameObject with a child GameObject. Add an MB3_TextureBaker to the parent and an MB3_MeshBaker or MB3_MultiMeshBaker to the child object.

    A BatchPrefabBaker is just a GameObject with three components. MB3_BatchPrefabBaker, MB3_TextureBaker and MB3_MeshBaker.
     
  30. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,932
    Great, thank you. :)
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Hi Telia,

    I tested this and it works for me. There are menu items in Game Object -> Create Other -> Mesh Baker. Do you get any warnings or errors in the console?
     
  32. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    Hello,

    I'm trying to follow the steps in your youtube tutorial about combining meshes with the same material. When I click 'bake' it gives me the following error:

    Materials on Grass(Clone) (UnityEngine.GameObject) in the list of objects to combine were not a subset of the materials on the first object in the list.
    UnityEngine.Debug:LogError(Object)

    I have no idea what this means. Any help would be appreciated :)
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    To use this feature all the objects need to use the same set or subset of materials as the first object. The first object in the list of objects to be combined needs to have all of the materials. Mesh Baker uses this list as the "Master List" of materials. It sounds like there are materials on "Grass (Clone)". That are not on the list of materials used by the first object.
     
  34. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    Thanks for your reply :) That's a little hard to understand as all the objects in the objects to be combined list are the same
     
  35. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    ...so looking a bit closer it seems that when the first object is being transferred over to the new mesh baker mesh, the material name is changed to the material name + the word "instance" in brackets. So the material name changed from "grass" to "grass (Instance)". I noticed that changing some aspect of the material grass had no impact on the material grass (Instance). Could this be why mesh baker says the material is different? If it is, how do you stop mesh baker from changing the material name?

    ...sorry if this question is stupid. I think I'm grasping at straws here.
     
    Last edited: Sep 12, 2015
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Not a stupid question at all. You have uncovered one of the nastier, subtle details of the Unity API. Somewhere in your project there is a script that is assigning materials to the object using:

    myMeshRenderer.material = someMaterial

    You should be using:

    myMeshRenderer.sharedMaterial = someMaterial

    If you use the first version then a new copy or instance of the material is quietly created in memory. It is independent of other copies of that material. If you modify it then the other copies will not be changed. You are now responsible for destroying these materials when your objects are destroyed or you will leak materials.

    Mesh Baker sees all of these materials as being different. Which they are. You can switch the shader on one without affecting any of the others. You almost always want to use the sharedMaterial property instead of the material property. In my opinion it was bad API design of Unity to create a property that instantiates new data like this. This should have been a method that has a name that makes it obvious that something new is being created.
     
  37. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    I'm glad I wasn't just being derpy. I really have no idea what script could be doing that though. It certainly isn't any I've made. I started a new project and only imported the object I want to be mesh baked and the mesh baker. Do you think you could take a look at my project? If so, what's the best way I could send it to you?
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    By any chance are you using Marmoset Skyshop? It creates copies of materials.

    Anther way to fix this would be to set the sharedMaterial property on all of your objects to the same material. Either by hand or using a script.

    If you want to send me the project, package it up using Unity's Export Package and PM me or email me a download link.
     
  39. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    Hi

    I'm very interested in Mesh Baker. Especially in the skinned mesh combination. But I have a question and a feature suggestion.

    Would it be possible to include atlas MIP tile separation in Mesh Baker?

    What I mean is that MIP levels should have different tiles resized as though they were different layers in Photoshop.

    For example an 8192x8192 atlas that consists of 8x8 tiles should construct MIP levels out of the individual 1024x1024 textures. So that they aren't blurred together with other tiles.

    This would make padding completely unnecessary and remove ugly seams when objects are viewed at a distance or at a steep angle.

    As long as the tile divisions are power of two, the seams will be completely eliminated up until the MIP level that is smaller than the tile count. In the example above, a 8x8 tiled atlas would be seamless up until MIP 8x8 pixels.

    One way this can be done is to write textures to a .dds file that can include custom MIP textures. Unity uses .dds files and I have made custom MIP textures with Gimp 2 and the .dds plugin. So I know it is possible to do manually at least.

    If Mesh Baker had this feature, I'm sure even people who make their own mesh combinations and atlases would want to purchase Mesh Baker. Me being one of them.

    I don't have Mesh Baker so I don't know if this feature is already included, but considering you have a padding option I assume that it does not.
     
    Last edited: Sep 13, 2015
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    . Hi Staffan, this is an intriguing idea. I will give it some thought. I would like the same functionality to be available at Runtime as in the Editor. One problem with the .dds files is that would only work for atlases generated by the editor.
     
  41. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    Wouldn't you want them to be for best performance?
     
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    It would be nice to have control over how the MIP maps are created.
     
  43. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Had a look and this should be possible with the Unity API. I haven't tested it but it is possible to write to different mipmap levels. Not making any promises but I will consider adding this.
     
    StaffanEk and hopeful like this.
  45. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,838
    Hello,
    I am generating texture atlases using meshBaker. I am having a hard time getting the texture atlas to include the RGB color assigned in the original material slot.


    rgb.png

    Do you know if it possible to do this in MeshBaker?
    Or do I manually add the color to the image file using Gimp or something before/after using MB to create a texture atlas? Basically I have two materials I want to include in the texture atlas, the only difference between them is the RGB color.

    Thanks
     
    Last edited: Sep 18, 2015
  46. Phong

    Phong

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

    I see that you have both a texture in the Albedo and a color.

    If there is only a color set (no texture) then Mesh Baker will grab the color and use that in the atlas.

    If there is both a color and a texture defined then Mesh Baker ignores the color and just uses the texture. This is because different shaders combine color and texture differently (Additive, Multiply, something else). Mesh Baker does not know how it should combine the two.

    You will need to manually add the color using GIMP or Photoshop to create two different textures and use those.
     
    Last edited: Sep 18, 2015
    ArachnidAnimal likes this.
  47. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    Hi Phong,

    Have you tested the mipmap writing functionality?
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Not yet. I have been busy with other projects and haven't had a chance to look into this. Will try over the next few days. Have you tried? Are you having issues?
     
  49. Dess64

    Dess64

    Joined:
    Oct 6, 2015
    Posts:
    5
    I would like to know : is it possible to use your baking tool during a game, for the regroupement of game objects that are build with instantiation? (and if it is possible, is there a tutorial about this special use of your tool?)
     
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,087
    Yes, it is easy to combine meshes at runtime using mesh baker. I do not have a video tutorial, but there are several example scenes in the project that do this. And some documentation in the manual. I would suggest the following.
    1. Create the atlas assets in the editor at build time. This can be done in a separate scene. Lots of videos showing how to do this part.
    2. In your game scene configure a MeshBaker component with the bake settings you want. Give it the atlas from step 1
    3. At Runtime:
      1. Instantiate your game objects
      2. Add them to the MeshBaker and bake
      3. Hide the renderers on the source game objects
      4. If you want do delete some from the combined mesh then give MeshBaker the instance IDs for the deleted meshes and Bake
      5. If you want to add more objects to the combined mesh then add them and Bake.
    You can also use MeshBaker to create an atlas and modified prefabs that use the atlas materials directly. If you instantiate these in your scene they are very easy to combine because they all use the same material. You can use Mesh.CombineMeshes().