Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mesh Baker by Digital Opus [RELEASED]

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

  1. echeg

    echeg

    Joined:
    Aug 1, 2012
    Posts:
    90
    Is it possible now to bake lightmap in prefabs?
    For several days I try to solve the problem of procedural generation dungeon of the individual parts, Unity5.
    I have small rooms of which I create a dungeon.
    Are there any tutorial showing how to do it in unity5?
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I don't know. First off, I should state that I am not any sort of lightmapping expert. I have a basic understanding of how lightmapping works in Unity. I also have not looked into how the lightmapping works in Unity 5. What I am about to describe is how it works in Unity 4. When you save a room to a prefab asset you are saving one or more MeshRenderer objects and their meshes. The meshes have a second set of UVs attached to them, UV2, which the shaders use in conjunction with a lightmap texture to simulate lighting on the mesh.

    Mesh Baker can either re-use existing lightmap UV2s on the source meshes or generate a new set of UV2s which can then be used in a lightmap bake to generate a new lightmap texture that will work with the combined mesh. Generating new UV2s and baking lighting after combining is the more reliable approach.

    Now that the lighting is baked for a room you could save the meshes into a prefab. If you want to use this prefab in a new scene and use the baked lighting then you will somehow have to find the lightmap texture that was generated during the lightmap bake and set that up as one of the lightmap textures in the new scene. I don't know how to do that part or if it is even possible with the Unity API. In the MeshRenderer object there is a "lightmap index" field that tells the mesh renderer which lightmap texture it should be using.
     
    ilmario likes this.
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
     
  4. dl_studios

    dl_studios

    Joined:
    Oct 14, 2012
    Posts:
    76
    I have a runtime API use case question.

    If I have a cube that starts out at localScale 1,1,1 and in game it gets scaled to 3,4,10. Could Mesh Baker (or any of your products, for that matter) bake the cube's mesh so that it's scale is 1,1,1 but have it retain the 3,4,10 dimensions in worldSpace?
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    The combined mesh always has scale 1,1,1 and rotation 0,0,0. You can move and rotate and scale your source object then update the combined mesh and it will still have scale 1,1,1 and rotation 0,0,0. It even handles source meshes with negative scale on one or more axis, correctly handling the normals and tangents for this case

    There is a free version now available that you can try this with.
     
  6. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    974
    I'm getting lots of "Material doesn't have a color property _SpecColor" when generating bakers.
     
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Looks like a debug statement was left in the code. Remove line 327,328 in file MB3_TextureBaerEditorInternal.cs
     
  8. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    I'm getting errors with the samples in U5.01. And it does not seem to batch, even the samples. v3.8
     
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi imtrobin,

    Can you post the error you are getting and the scene that was loaded? I just tested three of the scenes on Windows 8.1 Unity 5.0.1 and they seem to work fine with no errors.
     
  10. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    It's not error. but it does not seem to be batching. Eg. SkinnedMeshRenderer scene, the batch count is 9, there's no batching.
     
  11. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Ahhh, the extra batches are due to the GUI in the scene. Delete the GUIText objects. They each contribute a batch. And the three buttons contribute a total of 6 batches. You need to edit the MB_SkinnedMeshSceneController to get rid of these. At this point you will be down to two batches. Also at the bottom of the stats window it reports visible skinned meshes 1. So I am sure it is working.

    To be honest I am puzzled why there are two and not one. I tried deleting everything out of the scene until I am only left with the camera. The stats window still reports 1 batch. It looks like in Unity 5 there is always one drawcall even if the scene is empty.

    [EDIT] Discovered where the second batch is coming from. I set the camera "Clear Flags" to "don't clear" and the last batch disappeared. Looks like the camera solid background color creates a batch. Interesting... I suspect Unity is using a quad with an unlit shader to fill the background instead of an OpenGL call. Probably turns out to be faster than the OpenGL call.
     
  12. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    ahh...make sense. thanks.
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    No problem. Glad I could help.
     
  14. dl_studios

    dl_studios

    Joined:
    Oct 14, 2012
    Posts:
    76
    @Phong I'm glad to hear that Mesh Baker can do what I need done. I actually purchased MB a while back but haven't been to the stage in development to use it.

    I've been searching over the api and I haven't figured out what exactly to call.

    To recap, at run time I want to "bake" a single mesh that has been scaled and rotated, so that the mesh is actually that size and rotation.

    So far I've tried

    Code (CSharp):
    1.    MB3_MeshCombinerSimple combiner = new MB3_MeshCombinerSimple();
    2.  
    3.                GameObject[] objsToCombine = new GameObject[] { this.gameObject};
    4.  
    5.           combiner.AddDeleteGameObjects(objsToCombine, null, true);
    6.           combiner.textureBakeResults =  ScriptableObject.CreateInstance<MB2_TextureBakeResults>();
    7.           combiner.Apply();
    It runs the error: textureBakeResults must be set.

    Which is true, I haven't set textureBakeResults. I was hoping to satisfy the system with a dumby value, because I don't need to bake textures or use a texture atlas. I only need the mesh to bake so that the current runtime scale, position, and rotation of the mesh will be baked into the mesh's vertices. Is there simply a method to call? What would be the easiest way of doing this?

    Thank you.
     
    Last edited: Apr 16, 2015
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    At the API level you do need to provide a textureBakeResults. You can create a dummy one with this code. This is what the editor script does. I should add this to the MB2_TextureBakeResults class so it is easy to get at. This is from the source file Editor/MB3_MeshBakerInternal.cs

    Code (CSharp):
    1.                        
    2. MB2_TextureBakeResults tbr = (MB2_TextureBakeResults) ScriptableObject.CreateInstance( typeof(MB2_TextureBakeResults) );
    3.                         List<GameObject> gos = ObjectsToCombine;
    4.                         Material[] ms = MB_Utility.GetGOMaterials(gos[0]);
    5.                         tbr.resultMaterial = ms[0];
    6.                         tbr.fixOutOfBoundsUVs = false;
    7.                         tbr.materials = ms;
    8.                         tbr.resultMaterials = new MB_MultiMaterial[ms.Length];
    9.                         if (ms.Length > 1){
    10.                             tbr.prefabUVRects = new Rect[ms.Length];
    11.                             for (int i = 0; i < ms.Length; i++){
    12.                                 tbr.prefabUVRects[i] = new Rect(0f,0f,1f,1f);
    13.                                 tbr.resultMaterials[i] = new MB_MultiMaterial();
    14.                                 List<Material> sourceMats = new List<Material>();
    15.                                 sourceMats.Add (ms[i]);
    16.                                 tbr.resultMaterials[i].sourceMaterials = sourceMats;
    17.                                 tbr.resultMaterials[i].combinedMaterial = ms[i];
    18.                             }
    19.                             tbr.doMultiMaterial = true;
    20.                         } else {
    21.                             tbr.doMultiMaterial = false;
    22.                             tbr.prefabUVRects = new Rect[]{new Rect(0f,0f,1f,1f)};
    23.                         }
    24.                         myMeshCombiner.textureBakeResults = tbr;
    25.  
     
  16. dl_studios

    dl_studios

    Joined:
    Oct 14, 2012
    Posts:
    76
    Awesome! That worked! Thank you!
     
  17. Rabbito

    Rabbito

    Joined:
    Apr 5, 2015
    Posts:
    13
    Hi
    I think it is possible but i wanted to be sure:
    It is possible to bake a normal mesh into a skinned Mesh and the animation still works ? (at runtime)
    In my case a swort(the normal mesh) would be baked into the hand of a character(the skinned Mesh)
     
  18. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Yes. Here is video showing a sword being baked into a combined mesh at runtime. This is one of the example scenes in the project. 4:30 to see the scene running and dynamic adding of objects to a skinned mesh.



    Here is another video that talks about combining skinned meshes and some of the tricky things about them like the bounds, keeping animations playing and prefabs.

     
  19. Rabbito

    Rabbito

    Joined:
    Apr 5, 2015
    Posts:
    13
    Wow thank you very much :)
     
  20. DissidentDan

    DissidentDan

    Joined:
    Jul 6, 2013
    Posts:
    23
    Mesh Baker through us for a loop for a bit because it incorrectly printed out warnings about out-of-bounds UVs when, in fact, the mesh's UVs were fine. The following code will output the warning if hasOutOfBoundsUVs() returns false.

    if (mm != null){
    Rect dummy = new Rect();
    if (MB_Utility.hasOutOfBoundsUVs(mm, ref dummy) && excludeMeshesWithOBuvs){
    if (shader != null){
    numOBuvExcluded++;
    addMe = false;
    }
    } else {
    Debug.LogWarning("Object " + mrs[j].gameObject.name + " uses uvs that are outside the range (0,1)" +
    "this object can only be combined with other objects that use the exact same set of source textures (one image in each atlas)" +
    " unless fix out of bounds UVs is used");
    }
    }
     
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Thanks DissidentDan, I will take a look and change this in the next update.
     
  22. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    There is a new Mesh Baker tutorial video available explaining issues and solutions for tiling textures.

     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Mesh Baker has been chosen for an asset store daily sale and will be 50% off on April 28th!
     
  24. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Ive just bought this tonight, I have a large open world game that is badly in need of some optimising, and judging by this so far it looks like it is prime for mesh baker! Ive made one combined mesh, but my problem is, its picked objects from all over the level, how do I know which are the originals to turn off? Without doing lots of donkey work? There's thousands of game objects and it will be very hard to track down each original to turn it off.

    Also isnt there a way it can skip past errors rather than stopping ? It failed on many of my first attempts with stuff like:

    Object l_R_gland has a MeshRenderer or SkinnedMeshRenderer but no mesh.
    UnityEngine.Debug:LogError(Object)
    DigitalOpus.MB.Core.MB_Utility:GetGOMaterials(GameObject) (at Assets/MeshBaker/scripts/core/MB_Utility.cs:57)
    MB3_MeshBakerRoot:DoCombinedValidate(MB3_MeshBakerRoot, MB_ObjsToCombineTypes, MB2_EditorMethodsInterface, MB2_ValidationLevel) (at Assets/MeshBaker/scripts/MB3_MeshBakerRoot.cs:53)
    MB3_TextureBaker:_CreateAtlases(ProgressUpdateDelegate, Boolean, MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/MB3_TextureBaker.cs:163)
    MB3_TextureBaker:CreateAtlases(ProgressUpdateDelegate, Boolean, MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/MB3_TextureBaker.cs:129)
    MB3_MeshBakerEditorWindow:drawTabAnalyseScene() (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorWindow.cs:155)
    MB3_MeshBakerEditorWindow:OnGUI() (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerEditorWindow.cs:61)
    UnityEditor.DockArea:OnGUI()

    And also its not very clear when you have or havent already generated a baker, or baked its meshbaker in the scene, would be good if it could tell you. Looks like an excellent tool, once i work out how to turn off the original objects I can see how many FPS I gain, I hope its quite a few :)
     
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi Radiantboy, Thanks for the feedback.

    There is a button on the inspector for the MB3_MeshBaker that toggles the renderers on the source objects "Enable/Disable Renderers On Source Objects".

    Regarding reporting whether or not an object has already been included in a baker. I am aware of this weakness and will see what I can do to improve things with the next version. Perhaps adding another filter to exclude objects that are already in a baker and marking objects that are already included in the list shaders report.

    Regarding the errors. Mesh Baker doesn't really error unless the error is pretty serious. Renderers without meshes should not be added to the list of objects to be combined since they arn't really in the scene.

    Also it is safe to re-bake bakers so if your not sure if something hasn't been baked you can always bake everything.

    In your case I would recommend the MeshBakerGrouper for grouping objects that are close together into the same baker.

    Let me know if I didn't answer your questions to your satisfaction.
     
  26. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    My project is a sprawling mess, so I think it is messing it up. Buts its also been a long day, i will try again another time. Would be great if it could by pass things with null materials etc, I have such a mess of objects around with things on and off, its a level Ive been making for 2.5 yrs from learning unity, so its tough to track stuff down like in a normal project. Still I think it might work if the script could leap over stuff it cant deal with, I will look at adding this to the script when I get time, maybe you have some hints where to add it ? :)
     
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hmm, the script is fairly complicated. you may find it easier to try to clean up the scene than to hack the code too much.

    I would start with the file MB3_MeshBakerRoot method DoCombinedValidate. This validation routine is used by both the texture baker and the mesh bakre. You could modify it so that it removes an object from the list of objects rather than erroring.
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Mesh Baker is on sale today for 50% off.
     
    ikemen_blueD and syntystudios like this.
  29. Sprak

    Sprak

    Joined:
    May 20, 2008
    Posts:
    28
    Hey, I'm having trouble updating baked gameobjects at runtime when using a MB3_MultiMeshBaker. It works just fine when using the regular MB3_MeshBaker. I'm using the SceneRuntimeExample as is (except for the MeshBaker component replaced with a MultiMeshBaker of course). All (applicable) settings are identical between the components.
    I'm on MeshBaker version 3.8.1 (and Unity 4.6.4f1)
     
  30. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    What is happening? Are you getting errors? Is it not working? Is the generated mesh mangled?

    I know that the MultiMeshBaker works at runtime because MeshBakerLOD uses it exclusively.
     
  31. Sprak

    Sprak

    Joined:
    May 20, 2008
    Posts:
    28
    Nothing happens, really. No errors or warnings appear. The baked mesh remains exactly the same as before.
    To rule out any weirdness on my behalf I opened the SceneRuntimeExample and replaced the MeshBaker component with a MultiMeshBaker (and hooked everything in the exact same way). Updating won't do anything after that.
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Your right. There is a bug. I thought MeshBakerLOD called this but it does not. To fix it you need to add one line of code. In File MB3_MultiMeshCombiner.cs line 252 insert:

    meshCombiners.isDirty = true;

    It should look like:

    Code (CSharp):
    1.         for (int i = 0; i < meshCombiners.Count; i++){
    2.             if (meshCombiners[i].gosToUpdate.Count > 0){
    3.                 meshCombiners[i].isDirty = true;
    4.                 GameObject[] gosToUpdate = meshCombiners[i].gosToUpdate.ToArray();
    5.                 meshCombiners[i].combinedMesh.UpdateGameObjects(gosToUpdate, recalcBounds,updateVertices, updateNormals, updateTangents, updateUV, updateUV1, updateUV2, updateColors, updateSkinningInfo);
    6.             }
    7.         }
    I will make sure this fix is in the next update.
     
  33. Sprak

    Sprak

    Joined:
    May 20, 2008
    Posts:
    28
    It works! Thank you!
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I have submitted a new Mesh Baker update to the asset store. The update includes a number of enhancements.

    Better support for the Unity 5 Standard Shader

    If a texture slot is blank in a material Mesh Baker will now try to find the appropriate color property and use that instead of using a black color in the atlas.

    More efficient scene analysis and validation.

    Mesh validation checks are now cached. This improves speed if many objects use the same sharedMesh.

    New Filter For Objects That Have Already Been Added To A Baker

    In a complicated scene it can be difficult to ensure that objects are not accidentally added to two different bakers and baked into the scene twice. A new filter is now available to exclude objects that have already been added to a baker.

    The update also includes a few other minor bug fixes. It can take a few days for the updates to be accepted.
     
    hopeful likes this.
  35. Sidx30

    Sidx30

    Joined:
    Mar 7, 2015
    Posts:
    3
    I was recommended to use this by an awesome dev and its working out extremely well! I would love a bit of advice as I am using this in a outdoor jungle type level that is going to be optimized for mobile. I've worked out most of the kinks, but currently I'm stuck with lightmapping. The GI stuff in the latest version of Unity seems to be confusing a great many, but I think I have a good formula going for getting it to work with me.(I think.... lol) My question for you is, What are the differences between "preserving" the UV2 from a bunch of meshes and generating a new UV2 from a bake? From experimenting, I seemed to have notice that the lightmapping system does not like very large meshes and seems to hang on meshes that are way too big.(In my case, large mountains that are made up of multiple meshes that I baked into some giant meshes)

    I'm currently thinking maybe I just want to break my meshes up into even smaller chunks.... or I can lightmap all of my source objects, since they are in their smallest form. One of my test bakes actually went through to completion on the source meshes where as currently I can't seem to get these large baked meshes to lightmap with their generated UV2s. So while I'm waiting for these test bakes to happen, I thought I might ask for your opinion. How well does the "Perserve current Lightmapping" function work? What exactly does it mean by "all source objects must use the same lightmap"?

    Thanks a ton!
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi Sidx30,

    The Generate new UV2 layout is the easiest to understand. After your source meshes have been combined. It generates a brand new UV2 channel for the combined mesh completely ignoring whatever was in the UV2s of the source meshes. Whatever lightmapping you had on the source meshes will be broken. You need to then re-lightmap-bake this mesh and it should work. This is the most robust workflow for lightmapping combined meshes.

    With the Preserve Existing Lightmapping option, Mesh Baker tries to make the existing lightmapping work. To understand what is happening you will need a reasonable understanding of how lightmapping works. Imagine a scene with two cubes and a plane. The cubes share the same mesh instance in memory. However when they are rendered they need different lighting. This is accomplished by each cube's Renderer owning its own rectangle in the lightmap. There is a property in the Renderer component, lightmapScaleOffset, that stores the location and size of this rectangle. When the two cubes are combined, the new mesh will need to encapsulate both of the source cube's rectangles. The UV2s of each cube will need to be adjusted so that the triangles of each cube map to the correct part of this new rectangle. This works as long as both cubes use the same lighmap. Sometimes there is too much lighting in a scene to bake into a single lightmap texture so Unity uses several lightmap textures. If this happens then it is impossible to combine these cubes and preserve lightmapping. The lightmapIndex identifies the lightmap texture used by this Renderer.

    I have not had time yet to look at how the new GI lighting works in Unity 5. I noticed that two new uv channels have been added so I suspect that the GI lighting may require something to be done with these channels. I will try to take a look at this over the next week.
     
  37. Sidx30

    Sidx30

    Joined:
    Mar 7, 2015
    Posts:
    3
    I think I understand. Thanks a ton for your insight! I actually just found out that the baked trees in my level where the culprit. Trying to combine them was probably a bad idea in the first place due to the amount of alpha planes on them. I think I have to lightmap them normally and use LODs on them rather than clumping them all together.
     
  38. JamieVRcade

    JamieVRcade

    Joined:
    Oct 21, 2012
    Posts:
    32
    I cannot get this simple workflow in Unity 5 to work properly.

    • Imported architectural models (high poly)
    • Using Unity 5 standard shaders and Enlighten, I can get the model in and lightbaked
    • Now I want to use Mesh Baker. Because of the high poly amount, I don't want to generate new UV2 maps for fear of exceeding the 62000 limit, so I light it how I like and then tell MeshBaker to preserve the UV2, HOWEVER, I can't find that option in the new version of Mesh Baker.
    • I bake the meshes and they always come out dark. Clearing the lightmaps help, but now I can't lightmap the mesh because I was planning on using the current lightmapping, but I had to delete it in order to see the mesh.
    I just need simple instruction on what to do, in order, in Unity 5, to use both Unity 5 lightmapping AND Meshbaker.

    Thanks!
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi Jamie, I am taking a look at this. Will report back shortly.
     
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi Jamie,

    I did some experimentating and will be honest and say that I do not yet fully understand how the Enlighten lightmapping works. I tested the following two workflows with mixed results.

    The workflow you mention seems to sometimes work with simple setups. I have not yet determined what causes it to break. I suspect with large models it will almost always break because the system is being stressed. I will keep investigating.

    The workflow that does work is the "Generate new UV2 Layout". I would recommend trying this feature. It does not alter your source model so it is safe at least to try. If it doesn't work due to the 64k limit try removing a source model or two and re-trying.

    Pay attention to the console when using mesh baker. If there are problems they will usually be reported in the console.

    Can you elaborate more on the meshes you are trying to combine. If your source meshes are high poly, will there be much benefit baking them together?

    [UPDATE]

    I spent a good part of today looking into the "Preserve Lightmapping" Feature in Unity 5. Although my initial simple tests seemed to work, more complex setups did not. It appears that the MeshRenderer.LightmapScaleOffset does not contain correct values. Lots of people are complaining about this in the forums. At this point in time the "Preserve Lightmapping" feature is broken in Unity 5. Lightmapping using the "Generate new UV2 Layout" does work. I will continue to investigate this.
     
    Last edited: May 23, 2015
  41. Berandas

    Berandas

    Joined:
    Jan 4, 2013
    Posts:
    15
    Hello, I've encountered another problem.
    In my scene I am baking some meshes with Standard (Specular setup) shader, this was working fine last time I did it, but yestrerday I updated both meshbaker and Unity and now the specular map atlases are not created. Every other texture atlas is okay (Albedo, Normal, AO, Glow), but the specularity is not. There are no errors in the console present. I also tried adding the "_SpecMap" as custom shader property name, but that didn't help either, the console says "_SpecMap" is not present in the shader.

    Any ideas what went wrong?
     
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi Berandas,

    [EDIT Looks like there is a bug with the Specular Map]

    Is the Speccular Map slot empty for all the materials?

    I have been updating Mesh Baker to work better with the Standard Shader. The old behavior was to create atlases for all properties that were present in the shader regardless of whether or not textures existed for all properties. This is not very efficient with the Standard Shader since there are so many possible texture maps and most of the time not all of them will be used. This resulted in very long bakes and a lot of build space being used by giant empty atlases.

    The new behavior is to create an atlas only if at least one material is using a texture in a particular slot. For example a "Metalness" atlas will only be created if one of the materials uses a Metalness texture. Mesh Baker also tries to use the value in the corresponding property as the atlas color instead of black for each of the maps.

    Try adding a specular map to at least one of your materials. If this does not fix the problem let me know and I will look into this.

    [EDIT]

    There is a bug with the Specular Map. I did not add it correctly to the list of shader properties. It will work if you add.

    _SpecGlossMap

    To the list of custom shader properties.
     
    Last edited: May 26, 2015
    hopeful likes this.
  43. Berandas

    Berandas

    Joined:
    Jan 4, 2013
    Posts:
    15
    _SpecGlossMap works fine, thanks!
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    I have submitted a new version of Mesh Baker to the asset store that fixes the _SpecGlossMap problem and includes further improvements with the Standard Shader.
     
    hopeful likes this.
  45. link64e

    link64e

    Joined:
    Mar 10, 2013
    Posts:
    5
    Hi, so I'm using Unity 4.6 for a project. (No chance of upgrading to Unity 5) I used the free version to bake out meshes with tiling textures and it worked beautifully. Now I downloaded the full version and when I bake out meshes with tiling textures, the tiling textures aren't put into the map. I am using the standard diffuse Bump shader. It does work on the free version but I need the bake prefabs. My work follow is this:

    1. Add Material Baker and Mesh Baker object
    2. Add meshes with same material
    3. Select Multiple combined materials
    4. Check Fix out of bounds UVS

    Here is what the report says and a screenshot of my console

    Report

    ----------

    This set of textures will be resized to:1x1

    [_MainTex wall3 256x256] obUV scale (0, 0) offset(0, 0)

    [_BumpMap wall3_normals 256x256] obUV scale (0, 0) offset(0, 0)



    Materials using:wall3,

    ----------

    This set of textures will be resized to:1x1

    [_MainTex hull09 256x256] obUV scale (0, 0) offset(0, 0)

    [_BumpMap hull09b 1024x1024] obUV scale (0, 0) offset(0, 0)



    Materials using:hull09,

    ----------

    This set of textures will be resized to:1x1

    [_MainTex building2 512x256] obUV scale (0, 0) offset(0, 0)

    [_BumpMap building2_ normals 512x256] obUV scale (0, 0) offset(0, 0)



    Materials using:building2,

    ----------

    This set of textures will be resized to:1x1

    [_MainTex facade_parts_diffuse 1024x1024] obUV scale (0, 0) offset(0, 0)

    [_BumpMap facade_parts_normals 1024x1024] obUV scale (0, 0) offset(0, 0)



    Materials using:facade_parts,

    ----------

    This set of textures will be resized to:1x1

    [_MainTex facade_main_diffuse 512x512] obUV scale (0, 0) offset(0, 0)

    [_BumpMap facade_main_NRM 512x512] obUV scale (0, 0) offset(0, 0)



    Materials using:facade_main,

    ----------

    This set of textures will be resized to:1022x1022

    [_MainTex facade_parts_diffuse 1024x1024]

    [_BumpMap facade_parts_normals 1024x1024]



    Materials using:facade_parts,

    ---- Atlases ------

    Created Atlas For: _MainTex h=1024 w=1044 Created Atlas For: _BumpMap h=1024 w=1044



    UnityEngine.Debug:Log(Object)

    DigitalOpus.MB.Core.MB3_TextureCombiner:__Step3_BuildAndSaveAtlasesAndStoreResults(ProgressUpdateDelegate, List`1, List`1, Boolean[], Int32, MB2_EditorMethodsInterface, MB_AtlasesAndRects, Material) (at Assets/MeshBaker/scripts/core/MB3_TextureCombiner.cs:629)

    DigitalOpus.MB.Core.MB3_TextureCombiner:__CombineTexturesIntoAtlases(ProgressUpdateDelegate, MB_AtlasesAndRects, Material, List`1, List`1, List`1, MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/core/MB3_TextureCombiner.cs:321)

    DigitalOpus.MB.Core.MB3_TextureCombiner:_CombineTexturesIntoAtlases(ProgressUpdateDelegate, MB_AtlasesAndRects, Material, List`1, List`1, MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/core/MB3_TextureCombiner.cs:268)

    DigitalOpus.MB.Core.MB3_TextureCombiner:CombineTexturesIntoAtlases(ProgressUpdateDelegate, MB_AtlasesAndRects, Material, List`1, List`1, MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/core/MB3_TextureCombiner.cs:190)

    MB3_TextureBaker:_CreateAtlases(ProgressUpdateDelegate, Boolean, MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/MB3_TextureBaker.cs:241)

    MB3_TextureBaker:CreateAtlases(ProgressUpdateDelegate, Boolean, MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/MB3_TextureBaker.cs:129)

    DigitalOpus.MB.Core.MB3_TextureBakerEditorInternal:DrawGUI(MB3_TextureBaker, Type) (at Assets/MeshBaker/scripts/Editor/MB3_TextureBakerEditorInternal.cs:191)

    MB3_TextureBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB3_TextureBakerEditor.cs:22)

    UnityEditor.DockArea:OnGUI()
     

    Attached Files:

  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi Link64e,

    I believe I did make some changes to the "Build Source To Combined Mappings From Objects To Be Combined" behavior. The new mapping is probably different from the. Can you check if they look the same as what you had before. You can edit it if not. Mesh Baker will not bake the tiling if there is only one texture in an atlas. I am guessing that the new mapping is putting tiling textures onto their own submesh. If you move these onto a shared submesh then it should bake the tiling as before.
     
  47. link64e

    link64e

    Joined:
    Mar 10, 2013
    Posts:
    5
    Thanks for getting back to me! I'm a little confused on moving the meshes into a shared submesh. How would I go about doing that?

    Fyi here's what I'm baking. I'm baking 3 separate meshes. Each have two - three materials and out-of-bound UVs. When I do bake the materials and textures without the "Fix UVs" checked the UVs that are in-bounds get put into the one texture. However, when it is checked only the non-tiling texture gets put into the maps.

    (Sorry, I wish I could send screenshots but my project is under NDA. The console was the most I could get)
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    In the MB3_TextureBaker component there should be a section

    "Source Material To Combined Mapping"

    This section defines how your materials are mapped to submeshes. You will have one submesh in your combined mesh for each mapping. Sounds like you want two or three mappings but probably have more than that. Mesh Baker will try to put meshes with tiling on their own submesh (their own mapping). If you want one of these tiling materials to share an atlas with other materials, then delete the mapping containing the tiling source material and add the tiling source material to one of the other mappings. Then Mesh Baker should bake the tiling into that atlas.

    Let me know if this works for you.
     
  49. link64e

    link64e

    Joined:
    Mar 10, 2013
    Posts:
    5
    Yes and no. Yes the tiling materials did go into their own atlas, but the texture size was crunched down to 4x4. I tried it with just one mesh and only one tiling material and the same thing happened. I've tried it with Force Power of two and Resize both off and on.

    EDIT: I was able to take screenshots of the MB3_TextureBaker and the resulting atlas
     

    Attached Files:

    Last edited: Jun 4, 2015
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,083
    Hi link64e,

    Thanks for sending the shot of the inspector. I will see if I can reproduce your result on my end.

    [UPDATE]

    I was able to reproduce the result. It is a fairly serious bug. I can't believe this got through my testing and no one has reported it yet. To fix it, in file MB_Utility.cs, replace the the method hasOutOfBoundsUVs with the one below. I will submit an update on Monday to fix this.

    Code (CSharp):
    1.    
    2. public static bool hasOutOfBoundsUVs(Mesh m, ref Rect uvBounds, ref MeshAnalysisResult putResultHere, int submeshIndex = -1){
    3.         if (m == null){
    4.             putResultHere.hasOutOfBoundsUVs = false;
    5.             return putResultHere.hasOutOfBoundsUVs;
    6.         }
    7.         Vector2[] uvs = m.uv;
    8.         if (uvs.Length == 0){
    9.             putResultHere.hasOutOfBoundsUVs = false;
    10.             putResultHere.uvRect = uvBounds;
    11.             return putResultHere.hasOutOfBoundsUVs;
    12.         }
    13.         float minx,miny,maxx,maxy;
    14.         if (submeshIndex >= m.subMeshCount){
    15.             putResultHere.hasOutOfBoundsUVs = false;
    16.             putResultHere.uvRect = uvBounds;
    17.             return putResultHere.hasOutOfBoundsUVs;
    18.         } else if (submeshIndex >= 0){
    19.             //checking specific submesh
    20.             int[] tris = m.GetTriangles(submeshIndex);
    21.             if (tris.Length == 0) {
    22.                 putResultHere.hasOutOfBoundsUVs = false;
    23.                 putResultHere.uvRect = uvBounds;
    24.                 return putResultHere.hasOutOfBoundsUVs;
    25.             }
    26.             minx = maxx = uvs[tris[0]].x;
    27.             miny = maxy = uvs[tris[0]].y;
    28.             for (int idx = 0; idx < tris.Length; idx++){
    29.                 int i = tris[idx];
    30.                 if (uvs[i].x < minx) minx = uvs[i].x;
    31.                 if (uvs[i].x > maxx) maxx = uvs[i].x;
    32.                 if (uvs[i].y < miny) miny = uvs[i].y;
    33.                 if (uvs[i].y > maxy) maxy = uvs[i].y;
    34.             }          
    35.         } else {
    36.             //checking all UVs
    37.             minx = maxx = uvs[0].x;
    38.             miny = maxy = uvs[0].y;
    39.             for (int i = 0; i < uvs.Length; i++){
    40.                     if (uvs[i].x < minx) minx = uvs[i].x;
    41.                     if (uvs[i].x > maxx) maxx = uvs[i].x;
    42.                     if (uvs[i].y < miny) miny = uvs[i].y;
    43.                     if (uvs[i].y > maxy) maxy = uvs[i].y;
    44.             }
    45.         }
    46.         uvBounds.x = minx;
    47.         uvBounds.y = miny;
    48.         uvBounds.width = maxx - minx;
    49.         uvBounds.height = maxy - miny;
    50.         if (maxx > 1f || minx < 0f || maxy > 1f || miny < 0f){
    51.             putResultHere.hasOutOfBoundsUVs = true;
    52.             putResultHere.uvRect = uvBounds;
    53.             return putResultHere.hasOutOfBoundsUVs;
    54.         }
    55.         //all well behaved objs use the same rect so TexSets compare properly
    56.         uvBounds.x = uvBounds.y = 0f;
    57.         uvBounds.width = uvBounds.height = 1f;
    58.         putResultHere.uvRect = uvBounds;
    59.         putResultHere.hasOutOfBoundsUVs = false;
    60.         return putResultHere.hasOutOfBoundsUVs;
    61.     }
     
    Last edited: Jun 5, 2015