Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    Mesh Baker is really a Great Asset!
    but there one thing i dislike so far in the product, which is the way it handles and fixes out bound uv meshes..
    i think there is a simple more efficient way to handle this functionality. sometimes having uv out of bound is unavoidable for long bridges and such models. or while working with tools such as probuilder..

    Here is my suggestion to improve this functionality without generating huge duplicated textures:
    imagine this image of multiple meshes using same texture and extending outside uv as shown in the image>
    uv meshes.png

    all meshes as you can see.. extend (almost) one additional tile on the "U" direction.
    my idea is simply mesh baker should realise that all these meshes extending need only one more additional tile added to contain them all when generating atlas. so.. total is two tiles only on atlas for this texture!

    then simply put all these meshes uv in their original "place" in the new generated texture placed inside the new atlas.. that's it! now the atlas more clean and job is done. no resize or too many copies of same texture.

    is it possible to implement such a thing in future update? i don't think it's that hard?

    of course this is the basic idea. but you can add cropping and such for unused parts of texture. but i am fine with this simple solution.
    with this solution i will be able to work on uvs manually in meshes (like extending number of tiles in u or v direction) and expecting consistence results from mesh baker based on how much i go outside uv bounds. right now it's unpredictable.
     
    Last edited: Oct 7, 2015
  2. Dess64

    Dess64

    Joined:
    Oct 6, 2015
    Posts:
    5
    Thanks a lot, Phong, for your interest... I'll try your suggestion as soon as possible...
    Do you think it is possible to test all that with the free version of "Mesh Baker"?
     
  3. Phong

    Phong

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

    Thanks for taking the time to write this. This input is valuable for helping me improve the asset. I have read your description about how you would like this feature to work carefully, but I am not sure I understand. I believe that what you are describing is the way that MeshBaker currently works. In your picture it looks like the UVs extend from 0 to approximately 1.7 in the U direction and 0 to 1 in the V direction. In this case MeshBaker would create a new texture that would contain one tile in the V direction and 1.7 tiles in the U direction. Then the UVs would be scaled in the U direction to match the new texture. Have I misunderstood what you have described?

    BTW there is another approach to tiling textures that I have thought about trying to implement. Often textures tile primarily in one direction. For example a tree trunk or a long bridge. In these cases the out of bounds UVs could be fixed to be in bounds on the short axis only. UVs on the long tiling axis would be left out of bounds. The texture could still be used in an atlas as long as the long tiling axis extends from one edge of the atlas to the other in the tiliing direction. In many cases this can be accomplished currently by hacking the atlas.
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Yes you should be able to test this in the free version. There is a scene called "SceneDynamicAddDelete" that shows how to add and delete objects using a script at runtime. Here is the entire script that instantiates the objects, bakes them into the mesh. Then deletes or adds one third of the objects every 1.5 seconds.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class MB_DynamicAddDeleteExample : MonoBehaviour {
    6.     public GameObject prefab;
    7.     List<GameObject> objsInCombined = new List<GameObject>();
    8.     MB3_MeshBaker mbd;
    9.     GameObject[] objs;
    10.     void Start(){
    11.         mbd = GetComponentInChildren<MB3_MeshBaker>();
    12.    
    13.         // instantiate game objects
    14.         int dim = 25;
    15.         GameObject[] gos = new GameObject[dim * dim];
    16.         for (int i = 0; i < dim; i++){
    17.             for (int j = 0; j < dim; j++){
    18.                 GameObject go = (GameObject) Instantiate(prefab);
    19.                 gos[i*dim + j] = go.GetComponentInChildren<MeshRenderer>().gameObject;
    20.                 go.transform.position = (new Vector3(9f*i,0,9f * j));
    21.                 //put every third object in a list so we can add and delete it later
    22.                 if ((i*dim + j) % 3 == 0){
    23.                     objsInCombined.Add(gos[i*dim + j]);
    24.                 }
    25.             }
    26.         }
    27.         //add objects to combined mesh
    28.         mbd.AddDeleteGameObjects(gos, null, true);
    29.         mbd.Apply();
    30.    
    31.         objs = objsInCombined.ToArray();
    32.         //start routine which will periodically add and delete objects
    33.         StartCoroutine(largeNumber());
    34.     }
    35.  
    36.     IEnumerator largeNumber() {
    37.         while(true){
    38.             yield return new WaitForSeconds(1.5f);
    39.             //Delete every third object
    40.             mbd.AddDeleteGameObjects(null, objs, true);
    41.             mbd.Apply();
    42.          
    43.             yield return new WaitForSeconds(1.5f);
    44.             //Add objects back
    45.             mbd.AddDeleteGameObjects(objs, null, true);
    46.             mbd.Apply();
    47.         }
    48.     }
    49. }
    The scene "SkinnedMeshRenderer" also does runtime adding and deleting but it is a bit more complicated because it uses a GUI and is baking objects into a combined skinned mesh.
     
  5. Dess64

    Dess64

    Joined:
    Oct 6, 2015
    Posts:
    5
    Thanks a à lot Phong for all your support,
    I must recognize that I'm not à specialist at all in this area and so your help is all the more precious to me...
    I will test all that shortly!
     
  6. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    Thanks for following up, here is screen shots and details of the issue. click on images to expand..

    the first screen shows the first senario:
    MBIssue01.jpg

    am using multiple basic platforms with material of grass texture on top, and another material for wall texture on the other sides.... as you can see, once i selected these 3 gameobjects and gave them to meshbaker, then check the option to fix out of bound.. this is result after the atlas is generated.

    you will notice that meshbaker decided to make multiple copies of same texture around atlas, and they are resized and so on! i dunno why this happens but it creates a larger texture atlas than expected.. But Pay attention to the uvs in the screen and memorize it for a moment! now check second screen.

    the second screen shows a more acceptable cleaner results:
    MBissue02.jpg

    these are the same exact platforms.. same settings. everything..
    except i only merged those 3 platforms together into single mesh using other tools not through mesh baker.. uvs still intact in same place.. i didn't change anything else..
    so now i only supplied one gameobject for mesh baker.. but as you can see now mesh baker decided to make a more cleaner atlas, using only both textures no duplicated no re-sizing etc..

    This is the Kind of baking i was hinting at.. second result simply is as you stated in how mesh baker should work , more compact organized results..but on first scenario.. i dunno what mesh baker is doing..


    another thing i noticed which effects the texture quality..
    even while using the workaround with padding set to zero... i still notice some generated texture atlas are re-sized a bit..
    (its the same squeeze you see on first screen i given in the atlas atlas,, the top left part texture, check how it is resized a bit!)
    i tried to set max tiling bake size to larger value but it gives me error whenever i put something larger than 4096>>
    Invalid value for max tiling bake size.
    is there away to override this?

    thanks
     
    Last edited: Oct 8, 2015
  7. Phong

    Phong

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

    Thanks for sending the more screen shots. I understand what you are after now. In the second case you sent with an atlas built using other tools, the tiling has been baked only once using the largest tiling x and tiling y values. Each object's UVs are adjusted to use that texture. Mesh Baker creates a separate tiled texture for each object (because they are all tiled with different tiling values). What you propose would be a good way to do this. I will see if I can modify MB to use this approach.

    On a side note, I would recommend using the multiple materials feature for these objects. You could map the grass to one submesh and the dirt to another submesh. You would end up with an extra drawcall, but MUCH smaller atlases since there would be no need to tile at all (original textures could be re-used).

    Regarding the resizing of textures. The problem might be "resize power of two textures" or "force power of two textures". Try setting both of these to off. Regarding the MaxTilingBakeSize limit. You should be able to find this warning in MB3_TextureCombiner.cs line 266. You can edit the code to put whatever value you want. Do a search in this file for the error message if it is a different line.
     
  8. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    yep exactly,

    btw mesh baker is the tool that baked the second scenario texture atlas!
    but i only got this good result when i merged these meshes as a single large mesh before baking it in mesh baker. (which is something i discovered by luck when i was preparing screenshot).
    i can merge my scenes or prepare them for meshbaker as one mesh, but it creates additional steps in the work flow on something that mesh baker could achieve easily.

    it's funny that i found a temproary solution while trying to show you my point :)
     
    Last edited: Oct 9, 2015
  9. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    btw regarding your side note... thanks!

    am targeting mobile platform and try to have good visual game in terms of lighting and shadows, and drawcalls obviously going to accumulate up so easily and frame rate will drop...submeshes with standard shader + shadows.. gives me 10+ draw calls without counting props and other related stuff on screen which can go beyond 40 draw calls .. and am aiming for something less than 40 draw calls to keep fps high...

    i have two choices here.. should i use baked lightmaps? or bake atlas to reduce drawcalls and use real time lighting?

    for both cases, getting additional build size is unavoidable...but at least with atlas i get far more better and nicer look than baked lightmaps + more control + less fighting with unity.. and sometimes.. smaller build sizes.

    with baked atlas + realtime lights and shadow, am achieving now almost 60 fps on mobile. which is amazing :)
     
    Last edited: Oct 9, 2015
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Thats amazing! What you are doing sounds great. I am very surprised to here that the dynamic lighting looks better. Thats great if it does because you can animate the lights which usually makes games look even better. Do you have a link to website or videos of your project? I would like to check it out.
     
  11. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    Thanks phong!
    actually i don't have my project set to public yet, this is something am planning to do after couple of months.
    but am sure ill hang around here later (maybe more notes or suggestions)

    on side note, i also propose another improvment to make atlas for outbound uvs, complementing the previous stated idea.
    in following screen shot, atlas can be arranged this way to. these are environment platform atlas + vegetation props.

    mesh baker could detect if environment extend long enough in horizontal direction, meshbaker could sort smaller atlases on top so height and width calculated and rest let it up get tiled normally and save alot of space :)

    Enviroment.png

    i might pushing many ideas :) , but am working alone so time is very important for me. and mesh baker is the best around.
     
  12. fabsther

    fabsther

    Joined:
    Jul 13, 2011
    Posts:
    3
    Hi,

    Can i optimize texture with your tools :
    I've got mesh textured with large texture and wasted space.
    I'm looking for a tool that refactor mesh uv in order to make his texture smaller.

    Can you be my savior ?
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Mesh Baker is probably not the tool for this job. Sounds like you need to take your mesh into a modeling program and move the UVs around.
     
  14. deV11

    deV11

    Joined:
    Oct 19, 2015
    Posts:
    5
    I'm interessted too ! It could be done if we could edit the atlas while keeping mesh updated following UV changes...
    No way you could develop that ? Mush 3d modelers hate optimize their textures...
     
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hmm,

    I will consider adding this feature. My understanding of what you are after is something like an "un-atlaser". When the texture is copied from the source, only the rectangle that is actually used will be brought over. So if you are baking a few crates that use a tiny piece of a huge atlas then only the crate rectangle will be copied from the old atlas to the new atlas.

    Is this correct?
     
  16. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,835
    Hello,
    I was wondering about the "Copy UVs unchanged" vs "Generate new UV2s" options. Your manual says it is recommended to choose "Generate new UVs". But I am having an issue with lightbaking (See below pic). Then I ran across this thread from someone suggesting to select "Copy UVs unchaged" instead of "Generate new UV2s".
    http://forum.unity3d.com/threads/so-many-lightmapping-problems-unity-5.321033/
    (near the bottom of the page)
    When would you suggest choosing "Copy UVs unchanged"? And could it help with the issue below?
    Thanks

    shadows.png
     
  17. Phong

    Phong

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

    You could try Copy UVs 2s unchanged but I think it would only work by colossal coincidence. I provide that option for people that are using the UV2 channel for something other than lightmapping. It copies the UVs verbaitum from the source mesh to the target lightmap. This should break lightmapping.

    Generate new UV2 layout should be your best option. However it is critical that you do it before you bake the lightmaps. If you are baking the lightmaps on the source objects then baking the combined mesh this will not work.

    The "preserve existing lightmapping" works in Unity 4 (provided all your source meshes use the same lightmap). It might work in Unity 5. In some of my test scenes this has worked. In others it has not. I haven't tracked down why yet. But you could give it a try.
     
    ArachnidAnimal likes this.
  18. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,835
    Ok, thanks. Issue seems to be my baked resolution and scale in the lightmap is too low for this particular mesh.
     
  19. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    I have multiple character models each with separate texture...I only want to make texture atlas out of it without combining meshes...is that possible with mesh baker? I tried material baker ,but it only bakes atlas, does not assign uvs ..
     
  20. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    You want to use the Batch Prefab Baker or a mesh baker with "Bake Meshes In Place". These will create copies of your meshes (assets) that have adjusted UVs that can use the atlas. See this tutorial video:

     
    idurvesh likes this.
  21. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Worked like charm for 6 characters out of 7..one character is messing around with completely wrong texture...I thought its problem of large texture so tried that character with only one more character but unfortunately result is same
     
  22. Phong

    Phong

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

    Hard to know what the problem is without more information. Mesh Baker is very good about printing detailed information to the console. Especially if the Log Level is set higher than "info". Was there any information about this mesh in the console when baking the textures?

    My guess is there is tiling and or submeshes involved which can get complicated. See the console for suggestions. You probably need a multiple materials setup to map the problem submeshes or submeshes with tiling to their own submeshes. See this video for information on how this works.

     
    idurvesh likes this.
  23. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    That did work thanks,

    I am now baking large scene into seprate chunks with Mesh baker's "Grid" option...It used to work properly few hours back but now with same scene its giving me following error.


    Code (CSharp):
    1. The list of objects to combine contains duplicates.
    2. UnityEngine.Debug:LogError(Object)
    3. MB3_MeshBakerRoot:DoCombinedValidate(MB3_MeshBakerRoot, MB_ObjsToCombineTypes, MB2_EditorMethodsInterface, MB2_ValidationLevel) (at Assets/MeshBaker/scripts/MB3_MeshBakerRoot.cs:53)
    4. MB3_MeshBakerEditorFunctions:BakeIntoCombined(MB3_MeshBakerCommon) (at Assets/MeshBaker/scripts/Editor/core/MB3_MeshBakerEditorFunctions.cs:27)
    5. MB3_MeshBakerGrouperEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerGrouperEditor.cs:72)
    6. UnityEditor.DockArea:OnGUI()
     
  24. Phong

    Phong

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

    Check the list of "Objects To Combine" at least one of the objects in that list appears twice.
     
  25. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    There are around 750+ objects, how can I check it? Is there any way mesh baker will let us know which objects are appearing twice? Also Objects are same but they are in different prefabs, it used to work previously ,but its not working now.
     
  26. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Ok, changing following line of code in MeshBakerRoot.cs did provided me names of same objects ,


    Code (CSharp):
    1.     for (int j = i + 1; j < objsToMesh.Count; j++){
    2.                 if (objsToMesh[i] == objsToMesh[j]){
    3.                     Debug.Log("Same Obje " + objsToMesh[i].name + " " + objsToMesh[j].name);
    4.                     Debug.LogError("The list of objects to combine contains duplicates.");
    5.                     return false;  
    6.                 }
    7.             }
    But question remain same, the above items are separate in each prefab.It should work ? or I am missing something?
     
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hmm, did you upgrade MeshBaker?

    I would suggest double clicking the error in the console to launch the code editor. I modified the error message to read:

    Debug.LogError("The list of objects to combine contains duplicates at " + i + " and " + j);

    Now it will print the indexes of the duplicated objects.

    BTW you may not be aware but to delete a row in a list in the inspector you need to [shift] delete.
     
    idurvesh likes this.
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Are these prefab project assets or scene objects? If there are scene objects, (instances of a prefab) I don't see how they could be the same if they are instances unless somehow one is the same object. If you know the indexes of the objects that are duplicated can you click on one to select the object, change the name and see if the other object's name changes too? If so then these are the same object. If not then I would like to find out more about what is happening.
     
    idurvesh likes this.
  29. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    I found the exact problem.The problem is which I do not know if universal but in my case here is the problem,

    My object hierachy is like,
    -Parent (with no mesh renderer)
    -Child (with mesh renderer)
    -Grand Child (With mesh renderer)
    -Child(WIth no mesh render)
    -GrandCHild (With mesh renderer)



    In above scenario, the child object which has mesh rendered and its immediate child too has mesh render so its throwing an error of duplicate, whereas child with no mesh render and grand child with mesh render works as expected.

    So changing hierarchy structure worked for me, though I think its an bug to fix.

    I tried to fix it by added following validation in Root file,
    Code (CSharp):
    1.     for (int j = i + 1; j < objsToMesh.Count; j++){
    2.                 if (objsToMesh[i].GetInstanceID() == objsToMesh[j].GetInstanceID()){
    3.                     Debug.Log( i + "Same Obje " + objsToMesh[i].GetInstanceID() + " " + j+" " + objsToMesh[j].GetInstanceID());
    4.                     Debug.LogError("The list of objects to combine contains duplicates.");
    5.                     return false;  
    6.                 }
    7.             }
    But its still giving me same error with same instance id on both object.When I checked both object's ID by going into inspector's "Debug" mode its showing diff id for both objects but in mesh baker log its showing same id.

    PS: Changing name did not changed name in any instance of other objects.
     
    Last edited: Nov 24, 2015
  30. Phong

    Phong

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

    This is very interesting to me. I would like to see what is going on. I will try to reproduce this on my end. Is there any chance you could send me the offending prefab? Please PM me if this is a possibility.
     
  31. Phong

    Phong

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

    I am not able to reproduce this problem. I cannot get this error to happen. Is there any way you could PM me the problem prefab?

    Thanks.
     
  32. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Yes sending you in a moment
     
  33. mBeierl

    mBeierl

    Joined:
    Dec 7, 2012
    Posts:
    9
    Hey, we are thinking about getting this product but are not quite sure if our use case is covered. Maybe you can help me.

    We can't use Unity's terrain tools to place detail meshes. So we place a lot of them individually as normal GameObjects. We want to reduce draw calls, but still need to be able to put our custom shader on the objects and remove objects during runtime.
    Is it possible to combine those detail objects to a skinned mesh renderer using mesh baker and still be able to delete single objects and use our custom shader?

    Any help is highly appreciated :)
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Yes, this should be quite easy with MeshBaker. You can to create a combined mesh with exactly the same channels as your source meshes. If you put your source material on this it should display exactly like the original. Adding and removing meshes from a combined mesh at runtime is easy.
     
  35. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,835
    Hello,
    I am still a bit confused between UV1 vs UV2.

    According to Unity employees, the UV channels are used as follows:

    Texture coordinates for albedo, normal maps etc. is UV0.
    Texture coordinates for baked lightmap is UV1.
    Texture coordinates for realtime lightmap is UV2.

    You can see the explanation at http://forum.unity3d.com/threads/quick-setup-for-starting-enlighten.309609/

    However if I understand MeshBaker, it considers the UV2 to be used for baked lightmapping.

    Could you please explain what MeshBaker does with the UV1 and UV2 channels after a MeshBake, and which channel is used for the baked lightmaps by Unity?

    Thank You for your time
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Don't blame yourself for being confused. Unity 5 lightmapping is a poorly documented black box. It requires a fair bit of experimental research to discover how it works. Unfortunately I do not know much more than you. That thread you pointed out is a gold mine of information. I was actually not aware that Unity uses UV1 for baked and UV2 for realtime lightmaps. That actually explains much of the strange phenomena I have been seeing. In Unity 4 UV1 was an alias for UV.

    I believe your explanation of the uses of UV, UV1 and UV2 are correct.

    Mesh Baker does nothing with the UV1 channel because UV1 is not readable or writable in the unity API which makes the "preserve existing lightmapping" impossible for baked lightmaps in Unity 5. The existence of the UV1 channel is not mentioned in any official Unity documentation as far as I have been able to discover.

    Now that I have read the information in that forum thread I realize that "preserve existing lightmapping" might be usable for realtime GI (UV2) with some very minor code changes on my part.

    The UV2 channel is readable and writable. However if the user chooses "Generate new UV2 layout" then mesh baker calls the Unity Editor function Unwrapping.GenerateSecondaryUVSet on the combined mesh after it has been generated. Although the documentation only says that this generates a UV2 layout, I suspect that this also generates a UV1 layout, because these meshes can be lightmap baked after this has been done. I suspect that Unwrapping.GenerateSecondaryUVSet is what the Model Importer uses when the user checks the Generate Lightmap UVs box.

    The "Copy UV2 Unchanged" copies the UV2 channel without modifying anything. This is useful if the UV2 channel is being used for something other than lightmapping.

    I notice that in the documentation Unity says that if no UV2 channel exists then Unity uses UV for the lightmap charts (even if the UV has overlapping charts). So in theory, if all the source meshes:
    • do NOT have lightmapping UVs
    • and "Generate Lightmap UVs" is NOT checked in the Model importer
    • and source meshes do not use out of bounds UVs to tile
    Then the combined mesh should be usable for baked an realtime GI without using "Generate new UV2 layout" and might preserve existing lightmapping. I stress the "might" because Unity says that enlighten ALWAYS alters the UV charts before using them.

    I hope this enlightens you.
     
    hopeful and ArachnidAnimal like this.
  37. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,835
    Ok, thanks for taking the time to look into this and the explaniation
     
  38. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Thanks for your help through PM ,my problem got solved :)
     
  39. Phong

    Phong

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

    I have leaned a lot more about this over the past day and some of what I said was wrong. Apparently this is the correct set of UVs. In the forum thread you mentioned the Unity Employees were referring to shader UV0,UV1,UV2 which corresponds to mesh.uv, mesh.uv2, mesh.uv3.


    The UVs that are actually used by the GI for lightmapping are not stored in the mesh. They are stored in MeshRenderer.additionalVertexStreams. This way the same mesh can be shared by many Renderers each of which has lightmapping unique to that renderer.

    The UVs in the mesh are repacked for each MeshRenderer using it. The UV channel that is chosen for repacking is:

    use mesh.uv3 if present
    else mesh.uv2 if present
    else mesh.uv

    (for baked lightmapping it starts at mesh.uv2)

    If you read mesh.uv2 or mesh.uv3 you will read your original data back from those channels. If you read UV1 or UV2 in shader code you will read the data out of the MeshRender.additionalVertexStreams.

    mesh.uv1 is a depricated field that is an alias for mesh.uv2
     
    Last edited: Dec 1, 2015
    hopeful and ArachnidAnimal like this.
  40. JBacal

    JBacal

    Joined:
    Jun 6, 2015
    Posts:
    59
    Hello,

    I am repeatedly getting the error listed below when trying to "list shaders in scene". Any thoughts?

    Thanks,
    Jay

    at MB3_MeshBakerEditorWindow.sortIntoBakeGroups3 (System.Collections.Generic.List`1 gameObjects, System.Collections.Generic.Dictionary`2 gs2bakeGroupMap, System.Collections.Generic.List`1 objsNotAddedToBaker) [0x00029] in /Users/admin/Desktop/Unity Projects/SkyForest/Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorWindow.cs:597
    at MB3_MeshBakerEditorWindow.listMaterialsInScene () [0x00365] in /Users/admin/Desktop/Unity Projects/SkyForest/Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorWindow.cs:508
    at MB3_MeshBakerEditorWindow.drawTabAnalyseScene () [0x00363] in /Users/admin/Desktop/Unity Projects/SkyForest/Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorWindow.cs:144
    UnityEngine.Debug:LogError(Object)
    MB3_MeshBakerEditorWindow:drawTabAnalyseScene() (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorWindow.cs:146)
    MB3_MeshBakerEditorWindow:OnGUI() (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorWindow.cs:62)
    UnityEditor.DockArea:OnGUI()
     
  41. Phong

    Phong

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

    Looks like you included the stack trace but not the actual error itself. Is it an IndexOutOfBoundsException or a NullPointerException? I am looking at that line of code but it would help to know what the error is.
     
  42. JBacal

    JBacal

    Joined:
    Jun 6, 2015
    Posts:
    59
    Sorry, I rebooted Unity and everything is currently working. If the error reappears I will let you know what it says.

    Thanks,
    Jay
     
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    O.K. thanks.
     
  44. RockenX

    RockenX

    Joined:
    Oct 17, 2012
    Posts:
    14
    Hi I just downloaded the Mesh Baker from the Asset Store. I'm trying to follow the youtube tutorials, but MB3_MeshBaker script doesn't have any of the buttons such as "Open Tools For Adding Objects", "Bake", nor "Disable Renderers On Source Objects" so I can't even follow the Youtube video. I checked the Release Notes and it said the UnityEditor was removed in runtime scripts. So is there any updated tutorial I can follow?
     

    Attached Files:

  45. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi RockenX, all that was removed was a "using UnityEditor" reference. The editor scripts are all still there.

    • Try deselecting and reselecting the mesh baker game object
    • Clicking on MeshBaker folder and reimporting
    • Restarting Unity
    • Check that folder MeshBaker/Scripts/Editor exists and has scripts in it
    • Were there any errors in the console?
    Let me know if none of these things work.
     
  46. RockenX

    RockenX

    Joined:
    Oct 17, 2012
    Posts:
    14
    Okay I found out what the issue is. I had my Inspector mode in Debug mode instead of Normal mode.
     
  47. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,835
    Hello,
    I'm not sure if this is an issue involving MeshBaker or Unity's lightbaking.

    I used MeshBaker to combine multiple meshes together. I choose "Generate new UVs 2". The combined mesh, when lightbaked, has a lot of "space" between the adjoining triangles in the lightbaking atlas. Whereas, in the source mesh, Unity had compacted the triangles closer together.

    padding.png
    You can see in the original, everything is tighly packed. After the MeshCombine (bake into scene object) there is space between the triangles.

    Do you know if this is to be expected or is this a lightbaking option?

    Thank You

    j
     
  48. Phong

    Phong

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

    Not sure but I think
     
  49. Phong

    Phong

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

    My suspicion is that there is more geometry being pack into the lightmap atlas so each island is smaller but the padding which is the same size is larger relative to the size of each island. There is a lot of information in this document https://docs.google.com/document/d/...1ELFUepkXsac2T5Mc/edit#heading=h.ozpwgcmq5wx2 describing how the repacking works and what effect the packing options have in the lighting panel. You might be able to get a better result by altering the packing options.
     
    ArachnidAnimal likes this.
  50. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,835
    OK, thanks. I'll try playing around wit the settings