Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    i think it will be enough for flat platform polygons. if you do it it will help most of my meshes. maybe you can calculate average(normal,tangent) of 2 vertices as optional.


    yes you are right full optimization is a big process. simple optimizations will be enough for the most cases.


    thanks for this. i will try it.
     
  2. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    MultiMeshBaker sounds great! Will try this out later today and let you know if I find any issues.
     
  3. dl_studios

    dl_studios

    Joined:
    Oct 14, 2012
    Posts:
    76
    Looks like an awesome tool. Right now I'm looking for a solution that can combine multiple blocks that have rigid bodies at run time. My goal is to give the player the ability to make enormous walls out of many smaller blocks, and then upon collision with a ball the combined mesh would go back to smaller blocks and fall apart. My guess is that MeshBaker doesn't have all of that functionality built in but would it make sense to extend it for this purpose?
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    This would be fairly easy with the api. Add blocks to the combined mesh as the user creates them. leave original blocks in the scene with renderers disabled. When the ball hits the wall remove affected blocks from combined mesh and enable renderers.

    another approach would be to make the whole wall a skinned mesh. this would just work but might have worse performance.
     
  5. dl_studios

    dl_studios

    Joined:
    Oct 14, 2012
    Posts:
    76
    Wonderful! I just purchased it. Thanks for the help!
     
  6. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    I would like to make a city building game, can mesh baker combine several buildings mesh together and separate it later ?
     
  7. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    Hey Phong,

    The Mesh Baker 2 has helped my project allot with reducing draw calls and making atlases for us. I have 1 question. Is it possible to make a dynamic system that takes objects in a grid and bake the meshes real time and also make it working with the built in LOD system of unity. I'm trying to figure it out on my own but it keeps me worried about the performance impact it may have.
     
  8. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Hi Phong
    I'm trying to get my head around combining meshes and textures etc. Is there a limit to how many models can be joined i.e. this 64K I've read somewhere. So I can combine 20 models with a total less then 64K vertices but not 40 models with 72K combined vertices? Also I'm doing a game for the PC so the quite a few of the textures are 1024 to 2048 in size. How many such materials can I combine? I've been trying to use Mesh Baker but not got any results so far. Down to a lack of understanding on my part I'm sure. Also I have a terrain models with about 100 trees - not Unity terrain. There are 5 types of tree and each type uses one material and texture, when I tried to combine all the one tree together it failed - possibly it exceeded the vertices count etc. I'm not really certain. I'm using Unity free so the other question is, does Mesh Baker 2 follow the batching rules in Unity? Not being certain it does makes it unclear where I should be reading information on combining meshes and batching i.e. should I be following the Unity guidelines and use them to determine how many models can be combined. Sorry if these seem rather dumb questions - it's a bit hard searching through such a large thread to get info from it, so my apologies in advance if I'm asking things which should be obvious. I'd app[reciate any help you can give - even if only pointing me to the correct sources to read.
     
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Yes. The recommended way to use it is to leave the source objects in the scene with renderers disabled. That way colliders, scripts, rigidbodies still work, but rendering is batched. To separate you just delete one or more buildings from the combined mesh and re-enable the renderer on the corresponding source object. The API is very powerful. It is easy and fast to add/remove things from the combined mesh.
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Lots of questions.

    There are two limits in Unity you may run into. The maximum mesh size is 64k vertices. The maximum atlas size is 4096x4096 for standalone. 2048x2048 for mobile. There is no limit to the number of materials.

    Trees can be tricky to combine because they use UVs outside the range 0..1 to tile bark textures. They also use submeshes. For trees you will need to use the multiple-material option and fix-out-of-bounds UVs. See the meshbaker docs for more info on this. Look in the console for information about how the baking is going. Mesh Baker prints a lot of useful information.

    Regarding batching. Unity free only supports Dynamic Batching. If you combine your meshes with meshbaker then Unity's dynamic batching will have no affect since the meshes have already been combined. However you can use the "bake meshes assets in place" feature. This creates modified meshes that are capable of sharing a combined material. If you use these meshes and the combined material then Unity's dynamic will combine meshes at runtime when possible.
     
  11. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    This is something I have thought about myself but have not had a chance to investigate. Will let you know when I get around to it.
     
  12. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Hi Phong

    That clears up a lot of things, and shows me a way forward. Thanks for the help, it's much appreciated.
     
  13. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    Thanks, That would be great. I also will let you know if i come up with something.
     
  14. ZINI-NGR

    ZINI-NGR

    Joined:
    Jan 28, 2013
    Posts:
    20
    Wow, it seems great. :) but i don't understand perfectly this asset yet.
    I have a question. If I have many monsters and they are dynmic model. (they has mecanim animation and 1000 vertex over a head)
    Can I dynamic baching them and reduce their draw calls too? (i want a situation like this. 10~200 monsters total draw call is 1~5)
     
    Last edited: Mar 17, 2013
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    It sounds like these monsters are skinned meshes. Dynamic batching only works with meshes that are less than 300 verts and I don't think it works with skinned meshes either. You could use MeshBaker to combine many monsters into a single skinned mesh. You could get approximately 60 monsters per mesh. Performance would depend on your target platform. Those would be big skinned meshes.
     
  16. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    Unfortunately, I'm not having the experience I was hoping for with Mesh Baker.

    I'm finding that when combining meshes in my scenes - I end up with one submesh per original material. This is true even if the original materials were all on separate meshes.

    For example - I have a 10 flag objects, each with a pole object and a flag object. They are separate mesh renderers on separate child objects with 2 total materials. When I bake all of them together, they look great, but I end up with 2 draw calls for all 10 flags.

    Obviously this is better than 10 draw calls - but I'm confused as to why your plugin would produce multiple submeshes when it bakes to a single mesh with a single material/texture. Are you forgetting to remove unused submeshes?
     
  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Meshbaker will only generate submeshes if you are using the "multi-material" feature. Otherwise it generates a single mesh. To verify this use the "bake into prefab" feature. It will generate a mesh asset in the project select the mesh asset. The Preview in the inspector will tell you if the mesh has submeshes.

    The number of drawcalls is not a perfect measure of the number of meshes/submeshes. Extra drawcalls can be generated by lights, the shader, the render path, the GUI.
     
  18. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    This sounds like it will be very helpful for my project. I'll probably pick this up today. However, just a few questions as I'm very new to the whole optimization concept. I have, at the moment, a lot of draw calls in a typical scene in my game and I would welcome any way to reduce this.

    1 - If I have multiple 3d objects that move around via tweening (NGUI tween scripts specifically), does it make sense for me to bake those objects together? These objects are a part of my GUI and fly around depending on button clicks to various pre-determined positions.

    2 - If I have a terrain and various trees and bushes, should I use the built-in unity tree / bush brush in the terrain or should I add these trees as separate prefabs and then bake them all together as one mesh? Which of those two options is more efficient and results in the fewest draw calls generally?

    thanks,

    Raj
     
  19. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    Thanks Phong - apparently I was getting extra draw calls mostly because I had "Include UV1" checked.

    Having resolved that, I'm now running into another issue - generating lightmap UVs is causing meshes to become extremely distorted for combined meshes with high vert counts. This happens both with the multi-mesh baker and the regular one. It would appear (at least in the case of multi-mesh) that lightmap UVs are being calculated before the mesh is split up, rather than after... thus creating this error message:
    Any ideas?
     
    Last edited: Mar 19, 2013
  20. eXawSt

    eXawSt

    Joined:
    Feb 26, 2013
    Posts:
    6
    Ive been using Mesh Baker, and so far, its good in some ways, but bad in others. Its worked great on the enviro. But, when it comes to skinned meshes, it seems to really help with "visible skinned meshes", but it bumps the draw calls up significantly.

    So, how Ive got it setup right now is I had 15 characters off screen, then when I need them on screen (lane defender type game), I move them to the screen. So, I used mesh baker to bake all 15 guys together. Before baking, each one used just 2 draw calls, but now, as soon as the first one goes on screen, the draw call bumps up by about 50. Im not sure why. It kind of feels like each bone in the character is being shown as a draw call. The bump only happens once, so the second or third character on screen doesnt change anything.

    Any ideas?
     
  21. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Raj, NGUI is highly optimized already. Each panel in NGUI is a single mesh, so baking would only help combining panels together. I doubt you will be able to improve the performance much. If you are using terrains then I think the overhead of NGUI will be insignificant.

    Regarding the trees, I have not investigated this specifically, but I believe Unity's terrain implementation has a lot of performance improvements implemented. I know it uses billboards for distant trees. I would consider meshbaker if you are using a few trees but use Unity's terrain trees for forests. One thing you can do is use the "bake mesh assets in place" feature so that all your trees and bushes share an atlas/material. Then Unity can batch the calls.
     
  22. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    The "generate lightmap UVs" has caused me a lot of pain. I am using Unity's built in feature to do this. It is not well documented and it appears to split vertices which boosts the number of vertices in the mesh. In your case it is boosting them over the 64k limit. The only thing you can do is reduce the number of objects you are combining until the error goes away.
     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Strange. Have you checked that the renderers on the source objects are disabled? I will look into this one.

    I tested this and am unable to reproduce this problem.
     
    Last edited: Mar 22, 2013
  24. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    *Removed as I learned there was an update available which fixed my problem. :)
     
    Last edited: Mar 26, 2013
  25. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    Ok, now I have an actual problem I can post about. :)

    I am working on a project where we are looking to have a large audience. The project uses the Toon Shader 1.5 set of materials and shaders. When combining the skinnedmeshes, we're having 2 core problems.

    1.) The materials look way off.
    Each audience member uses a total of 6 - 8 materials, however in total there are only 2 separate shaders being used. Once the materials are combined, there are 2 main problems. The first is that all of the baked textures come out VERY dark. The second is that the transparent materials used for the facial portions lose their transparency.

    Here is an example image showing the original mesh on the left, and the baked mesh on the right.
    $bgtyxc.jpg

    2.) Animations do not work on bakedmesh unless the original meshes' renderers are active.
    - So this one is weird. If I disable the renderers on the original mesh, the baked mesh does not animate at all. The bones of the original mesh are still active, just the SkinnedMeshRenderers are disabled, and the animations cease. Any tips to make that work properly?

    Thank you very much in advance!! :)
     
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I would look carefully at the settings in the source materials vs. the combined material. There are often sliders and other properties that need to be set. Also if a source shader has no texture for a property Mesh Baker will create a clear texture for that property. Many shaders behave very differently if a clear texture is present vs no texture. A good experiment is to duplicate the source material, replace the textures with the atlases and apply it to the combined mesh and see how it looks.

    Also look carefully at the channels present in the source meshes and make sure these are present in the combined mesh. Many meshes need a colors channel for example.

    On the animation component look at "Culling type". Try setting it to "Always Animate" or one of the other settings. This will probably fix the problem.
     
    Last edited: Mar 26, 2013
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I would look carefully at the settings in the source materials vs. the combined material. There are often sliders and other properties that need to be set. Also if a source shader has not texture for a property, Mesh Baker will create a clear texture for that property. Many shaders behave very differently if a clear texture is present vs no texture.

    Also look carefully at the channels present in the source meshes and make sure these are present in the combined mesh. Many meshes need a colors channel.

    On the animation component look at "Culling type". Try setting it to "Always Animate" or one of the other settings. This will probably fix the problem.
     
  28. cl-apps

    cl-apps

    Joined:
    Mar 16, 2013
    Posts:
    128
    Hi there,

    This is probably such a noob question anyway. I'm trying to use Mesh Baker on a group of static objects (buildings, rocks etc) and keep getting the following error:

    UnityEngine.MissingReferenceException: The object of type 'Texture2D' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.

    Has this something to do with a particular shader I should change before the bake? The scene is made up of a lot of assets so experimenting would be painful if there is a simple solution.

    I'm using Unity 4.1.1

    Chris
     
  29. xaeroxx

    xaeroxx

    Joined:
    Dec 2, 2012
    Posts:
    17
    Hi, I purchased Mesh Baker a while ago. It works just fine, thank you for the software. But I have a problem at the moment. When I try to make prefab from the resulting mesh, it is missing mesh information so it can not be rendered in the scene. How can I convert the mesh into prefab? Thanks in advance
     
  30. cl-apps

    cl-apps

    Joined:
    Mar 16, 2013
    Posts:
    128
    Ok I've now moved along a bit having played around and now get this error:

    System.IndexOutOfRangeException: Array index is out of range.

    I read in this thread another person had this problem because an object didn't have normals. Was there a solution to this?

    Other errors i'm getting when hitting the bake button are:

    Failed to add/delete objects to combined mesh
     
    Last edited: Mar 27, 2013
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    To bake into a prefab set output to "bake into prefab". You will need to create a prefab with an empty game object and assign it to the "result prefab" field.
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Chris, can you email me with the stack trace from the console. It contains line numbers and I should be able to pinpoint the exact point of the problem.
     
  33. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    HI
    I've just started using Mesh Baker, having a great deal of difficulty getting it to do anything. There are 3 log errors below that come from trying to add meshes to multiple meshes and just trying to find out what shaders are used in the scene

    I get the following doing a shader search using the mesh baker tools. As a result I get no log readout in rteh console. Half the items in teh scene are not active - is this likley to be the reason? I couldn't pinpoint whether that was the case from the log and there are a lot of assets in the scene as it's a PC game and not a mobile one.

    Object tStatus does not have a MeshFilter or a SkinnedMeshRenderer component
    UnityEngine.Debug:LogError(Object)


    Then trying to add the meshes earlier I got this. I had checked fix UVs. I moved tham in manually - into a spot in the object list to no result.

    Object Mesh 1 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 this object has not been added. You will have to add it manually
    UnityEngine.Debug:LogWarning(Object)

    Then I got this when it failed - can't even find 'Only objects using shader settings'. Of course all the objects were checked in teh Hierarchy view, then unchecked and checked again. Still could not be loaded. I'm using UNity 4.1 and am assuming that Mesh Baker is compatible.Sorry if you've answered these in an earlier post.

    Any help would be greatly appreciated.

    Added 0 objects. Make sure some or all objects are selected in the hierarchy view. Also check ths 'Only Static Objects' and 'Only Objects Using Shader' settings
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    The report will NOT find inactive objects in the scene, so that is almost certainly the problem.
    The query should still work even with the error. I will clean this up so it doesn't display this error message.
    It is not clear if you are getting these errors when trying to bake or just when using the tools to add objects to the baker. I presume these errors are when adding objects to the baker. The baker won't pick up objects that are inactive so that may be the problem.

    You can move objects manually to the list of objects to combine. I have tested and this does work. It has to be the game object with a skinned mesh renderer or mesh renderer component attached. Adding the parent won't work.

    The "only objects using shader" setting should be "using shader" I will fix this in the next version.

    When you say "All objects were checked in the hierarchy view" what do you mean by "checked"? You need to select these so that they are highlighted by a blue bar.

    Hope this helps.
     
  35. jaegis07

    jaegis07

    Joined:
    Apr 6, 2010
    Posts:
    8
    Just in case you missed the query..
     
  36. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Hi Phong
    Thanks for answering so quickly, I'll check this today. It's probably the fact that a large number of items were not active that caused all the errors.
     
  37. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Hi Phong

    I've managed to figure this out and got it working to some extent - i.e. shaders in scene showing, objects added. It was baking to combined material but seems to have failed - I got the following error - I'm wondering whether this could be somehting to do with the atlas being created and then failing or there is a misisng texture on one of the meshes?

    UnityEngine.MissingReferenceException: The object of type 'Texture2D' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    at (wrapper managed-to-native) UnityEngine.Texture:Internal_GetWidth (UnityEngine.Texture)
    at UnityEngine.Texture.get_width () [0x00000] in C:\BuildAgent\work\7535de4ca26c26ac\Runtime\ExportGenerated\Editor\Graphics.cs:682
    at MB_TextureCombiner.__combineTexturesIntoAtlases (.ProgressUpdateDelegate progressInfo, .MB_AtlasesAndRects results, System.Collections.Generic.List`1 texPropertyNames, System.Collections.Generic.List`1 objsToMesh, System.Collections.Generic.List`1 sourceMaterials, Int32 atlasPadding, Boolean resizePowerOfTwoTextures, Boolean fixOutOfBoundsUVs, Int32 maxTilingBakeSize) [0x0091f] in C:\Users\John\Documents\episodeCathedral\episodeCathedral\Assets\MeshBaker\scripts\MB_TextureCombiner.cs:408
    at MB_TextureCombiner._combineTexturesIntoAtlases (.ProgressUpdateDelegate progressInfo, .MB_AtlasesAndRects results, UnityEngine.Material[] resultMaterials, System.Collections.Generic.List`1 objsToMesh, System.Collections.Generic.List`1 sourceMaterials, Int32 atlasPadding, System.Collections.Generic.List`1 customShaderPropNames, Boolean resizePowerOfTwoTextures, Boolean fixOutOfBoundsUVs, Int32 maxTilingBakeSize) [0x000b7] in C:\Users\John\Documents\episodeCathedral\episodeCathedral\Assets\MeshBaker\scripts\MB_TextureCombiner.cs:191
    at MB_TextureCombiner.combineTexturesIntoAtlases (.ProgressUpdateDelegate progressInfo, .MB_AtlasesAndRects results, UnityEngine.Material[] resultMaterials, System.Collections.Generic.List`1 objsToMesh, System.Collections.Generic.List`1 sourceMaterials, Int32 atlasPadding, System.Collections.Generic.List`1 customShaderPropNames, Boolean resizePowerOfTwoTextures, Boolean fixOutOfBoundsUVs, Int32 maxTilingBakeSize) [0x00002] in C:\Users\John\Documents\episodeCathedral\episodeCathedral\Assets\MeshBaker\scripts\MB_TextureCombiner.cs:105
    UnityEngine.Debug:LogError(Object)
    MB_TextureCombiner:combineTexturesIntoAtlases(ProgressUpdateDelegate, MB_AtlasesAndRects, Material[], List`1, List`1, Int32, List`1, Boolean, Boolean, Int32) (at Assets/MeshBaker/scripts/MB_TextureCombiner.cs:107)
    MB2_TextureBaker:CreateAtlases(ProgressUpdateDelegate) (at Assets/MeshBaker/scripts/MB2_TextureBaker.cs:104)
    MB2_TextureBakerEditorInternal:_bakeTexturesOnly(MB2_TextureBaker) (at Assets/MeshBaker/scripts/Editor/MB2_TextureBakerEditor.cs:204)
    MB2_TextureBakerEditorInternal:bake(MB2_TextureBaker) (at Assets/MeshBaker/scripts/Editor/MB2_TextureBakerEditor.cs:180)
    MB2_TextureBakerEditorInternal:DrawGUI(MB2_TextureBaker) (at Assets/MeshBaker/scripts/Editor/MB2_TextureBakerEditor.cs:167)
    MB_MeshBakerEditorWindow:OnGUI() (at Assets/MeshBaker/scripts/Editor/MB_MeshBakerEditorWindow.cs:69)
    UnityEditor.DockArea:OnGUI()


    I thought this was mentioned in the forum already but I've nore been able to find it again so I don't know the solution. I waking this with a combine dmesh but not multi materials as one of the submeshes shares vertex co-ordinates. I set the max tiling size to 4096 and there are some 79 objects being combine but onle have 30 K + vertices. I was baking this into a prefab in the scene. No mateila bake result appeared in the inspector at the bottom so I assume it didn't work.

    Just to clatify something. When the tools are opened and there are a couple of inspector slots - 'using material', using shader. Is anything supposed to be in these slots normally or only under certain circumstances? I'm getting a bit confused because some of the slots in the inspector such as the game object to use as a prefab for the combined mesh have to be put in as normal, but then others such as the material baking result don't. I'm assuming that for the 'using material, I would actually drag a material from the assets view - e.g. brick01.mat and put this there and for the using shader - drag a blank material from the assets view actually set to the appropriate shader type?

    I appreciate any help you can give.
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Sorry, I did miss this. Yes the output is uncompressed. I don't think there is any way to do compression at runtime with the Unity API.
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    The inspector slots in the "Open Tools For Adding Objects" window are just search filters. They only affect which objects get added to the TextureBaker and MeshBaker components. These can be left blank.

    Most of the fields in the Component Inspector need to be set. The Material Bake Result is set when the "Create New Assets" button is clicked. If it is blank on the MeshBaker component it will look to see if there is a TextureBaker component present and use that.

    Someone else is having the MissingReferenceException problem. I think it may be a problem with the most recent version of Unity. I am looking into this now. Having trouble reproducing the problem.
     
    Last edited: Mar 28, 2013
  40. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Hi Phong

    Ok that clears some stuff up. I've had quite a few problems with the new 4.1, a major bug on an obj import for example. I'm going to run it again to see if I can reproduce it myself.
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I just tested in 4.1.0 and 4.1.2 and can't reproduce this problem.

    If you can get this to happen. Please PM me with the full console log and perhaps a step by step description of what you did.

    Thanks for your patience.
     
  42. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Well it just happened three times again. Here's the latest report:

    UnityEngine.MissingReferenceException: The object of type 'Texture2D' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    at (wrapper managed-to-native) UnityEngine.Texture:Internal_GetWidth (UnityEngine.Texture)
    at UnityEngine.Texture.get_width () [0x00000] in C:\BuildAgent\work\7535de4ca26c26ac\Runtime\ExportGenerated\Editor\Graphics.cs:682
    at MB_TextureCombiner.__combineTexturesIntoAtlases (.ProgressUpdateDelegate progressInfo, .MB_AtlasesAndRects results, System.Collections.Generic.List`1 texPropertyNames, System.Collections.Generic.List`1 objsToMesh, System.Collections.Generic.List`1 sourceMaterials, Int32 atlasPadding, Boolean resizePowerOfTwoTextures, Boolean fixOutOfBoundsUVs, Int32 maxTilingBakeSize) [0x0091f] in C:\Users\John\Documents\episodeCathedral\episodeCathedral\Assets\MeshBaker\scripts\MB_TextureCombiner.cs:408
    at MB_TextureCombiner._combineTexturesIntoAtlases (.ProgressUpdateDelegate progressInfo, .MB_AtlasesAndRects results, UnityEngine.Material[] resultMaterials, System.Collections.Generic.List`1 objsToMesh, System.Collections.Generic.List`1 sourceMaterials, Int32 atlasPadding, System.Collections.Generic.List`1 customShaderPropNames, Boolean resizePowerOfTwoTextures, Boolean fixOutOfBoundsUVs, Int32 maxTilingBakeSize) [0x000b7] in C:\Users\John\Documents\episodeCathedral\episodeCathedral\Assets\MeshBaker\scripts\MB_TextureCombiner.cs:191
    at MB_TextureCombiner.combineTexturesIntoAtlases (.ProgressUpdateDelegate progressInfo, .MB_AtlasesAndRects results, UnityEngine.Material[] resultMaterials, System.Collections.Generic.List`1 objsToMesh, System.Collections.Generic.List`1 sourceMaterials, Int32 atlasPadding, System.Collections.Generic.List`1 customShaderPropNames, Boolean resizePowerOfTwoTextures, Boolean fixOutOfBoundsUVs, Int32 maxTilingBakeSize) [0x00002] in C:\Users\John\Documents\episodeCathedral\episodeCathedral\Assets\MeshBaker\scripts\MB_TextureCombiner.cs:105
    UnityEngine.Debug:LogError(Object)
    MB_TextureCombiner:combineTexturesIntoAtlases(ProgressUpdateDelegate, MB_AtlasesAndRects, Material[], List`1, List`1, Int32, List`1, Boolean, Boolean, Int32) (at Assets/MeshBaker/scripts/MB_TextureCombiner.cs:107)
    MB2_TextureBaker:CreateAtlases(ProgressUpdateDelegate) (at Assets/MeshBaker/scripts/MB2_TextureBaker.cs:104)
    MB2_TextureBakerEditorInternal:_bakeTexturesOnly(MB2_TextureBaker) (at Assets/MeshBaker/scripts/Editor/MB2_TextureBakerEditor.cs:204)
    MB2_TextureBakerEditorInternal:bake(MB2_TextureBaker) (at Assets/MeshBaker/scripts/Editor/MB2_TextureBakerEditor.cs:180)
    MB2_TextureBakerEditorInternal:DrawGUI(MB2_TextureBaker) (at Assets/MeshBaker/scripts/Editor/MB2_TextureBakerEditor.cs:167)
    MB2_TextureBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB2_TextureBakerEditor.cs:21)
    UnityEditor.DockArea:OnGUI()

    all the checkboxes are ticked except for the include UV1, it's set to bake into prefab and there is a prefan in the scene that has been dragged into the inspector slot. static objects only is not checked. Ignore UV2 and meshrenderer are in the other dropdowns.

    Checking the object submeshes some of teh objects have a bumped specular shader. The materia for the mesh baker is set to hardsurface/hardsurface free/cutout/specular

    The question is when the shaders in the scene are shown are submesh shaders shown? In this scene thgere was only the hardsurface and a diffucse shader. So if the submesh shder is different will that matter? I'm going to test that by removing these when I get the opportunity.

    edit: I took out all the submeshes which had a slightly different shader.
    Looking at the best practices possibly I need to set a custom shader property name, I'll have a look and see if that works.

    I set custom preperties names for hardsurface shader - I just got an error saying the material does not have this texture property.

    Edit: I ran a test using meshes in the scene which were just diffuse. I didn't do many, but it worked perfectly. So I would say that this problem has soemthing to do with the shader - hardsurface free cutoff specular - it may be that these shaders are no longer working correctly in 4.1.


    Hope this helps.
     
    Last edited: Mar 28, 2013
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I think the problem is the Cube Map reflection texture. Don't include this in the list of Custom Shader Property Names. If you look in the shader it's data type is not "2D" like the other texture propties, it is "Cube". The TexturePacker doesn't seem to like trying to atlas a cubemap. I will detect this in the next version. I was able to bake the combined material for this if I omitted the _Cube property from the list of Custom Shader Property Names.

    If there are submeshes with different materials then MeshBaker will (depending on whether multi-material is checked):

    • If multi-material is not checked, Mesh Baker will bake all the triangles as if they were one submesh and bake the first material. The combined mesh will be one big mesh, no submeshes.
    • If multi material is checked then Mesh Baker maps each source submesh to a target submesh based on the source materail to target material mapping. See the docs for more info.


    I was able to get this to work if I my list of "Custom Shader Property Names" had one entry (don't include the cube map):

    _Spec_Gloss_Reflec_Masks

    Thanks this is very helpful. I was able to reproduce the error the first time although things seem to be working if I bake again. At least I have a starting point now. Expect an update in the next few days.
     
  44. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Hi Phong

    Thanks, you're a champion. I'll test all that today.
     
  45. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Hi Phong
    I was running the show all shader in scene function on another scene and got this error and no list of shaders.Checked the forum but couldn't find anything about this.

    NullReferenceException
    MB_MeshBakerEditorWindow.listMaterialsInScene () (at Assets/MeshBaker/scripts/Editor/MB_MeshBakerEditorWindow.cs:198)
    MB_MeshBakerEditorWindow.OnGUI () (at Assets/MeshBaker/scripts/Editor/MB_MeshBakerEditorWindow.cs:34)
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
     
  46. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Hi Phong
    I tried doing as suggested. Couldn't get materials - r least the third time round I got a result but no materials actually there

    Material Bake Results has no materials in material to uvRect map. Try baking materials. Can't combine meshes.
    UnityEngine.Debug:LogError(Object)
    MB2_MeshCombiner:_validateTextureBakeResults() (at Assets/MeshBaker/scripts/MB2_MeshCombiner.cs:323)
    MB2_MeshCombiner:_addToCombined(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/MB2_MeshCombiner.cs:369)
    MB2_MeshCombiner:AddDeleteGameObjects(GameObject[], GameObject[], Boolean, Boolean) (at Assets/MeshBaker/scripts/MB2_MeshCombiner.cs:1140)
    MB2_MeshBaker:AddDeleteGameObjects(GameObject[], GameObject[], Boolean, Boolean) (at Assets/MeshBaker/scripts/MB2_MeshBaker.cs:51)
    MB2_MeshBakerEditorInternal:_bakeIntoCombined(MB2_MeshBakerCommon, MB_OutputOptions) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:231)
    MB2_MeshBakerEditorInternal:bake(MB2_MeshBakerCommon) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:189)
    MB2_MeshBakerEditorInternal:DrawGUI(MB2_MeshBakerCommon) (at Assets/MeshBaker/scripts/Editor/MB2_MeshBakerEditor.cs:157)
    MB_MeshBakerEditorWindow:OnGUI() (at Assets/MeshBaker/scripts/Editor/MB_MeshBakerEditorWindow.cs:77)
    UnityEditor.DockArea:OnGUI()

    I will wait for the update.

    Thanks

    For the help.
     
  47. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Did you remember to click "Bake Materials Into Combined Materials" before clicking "Bake"?
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Will fix this in the next version.
     
  49. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Hi Phong
    Well I got the same result as previously i.e. the missing reference exception. However, you mentioned that on the second time you tried to bake you got a result, so I baked to materials three times, on the last occasion there was a combined material shown in the result, but clciking on the material there were no atlases in that folder so I'm pretty certain that the result material was actually blank which is why the report was telling me to bake materials into combied mesh. As far as I can tell I am following the correct instructions, however, I didn't attempt to bake to a multi mesh because all these meshes only have just over 30 K verts according to the shader lookup tool and the report it produced. I think it is down to this shader. With regard to the null reference after getting that a couple of times I upgraded to the latest version of unity but these errors all happened before that so it can't be that I am now using 4.1.2. I think I did have the static only clicked, I'll test it again without that and let you know if I get a result.

    Edit: I watched the material bake on three occasions, each time it failed when it was showing the same item. When I checked the item it had a second material - self illuninating with no texture just a colour. I removed this second material and it still failed at the same spot. Then I removed the mesh for that model but it failed again, although the mesh it was showing only had one material and it was the same as was being baked.. Not quite cerain what else to check really.
     
    Last edited: Mar 29, 2013
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    It appears that often when baking combined materials in Unity 4 + an error is sometimes generated:

    UnityEngine.MissingReferenceException: The object of type 'Texture2D' has been destroyed but you are still trying to access it.

    This is a very strange problem. It appears to be limited to certain shaders. In my tests it is intermittent (if I click bake three times it will only happen once, sometimes not at all) and so far I have only been able to generate it in 4.1.0 and 4.1.2.

    I spent a lot of time this weekend working on this problem. It appears that sometimes unity destroys all texture instances in a scene when operations on the AssetDatabase happen. I reorganized the code so it is much more defensive about how temporary textures are used when creating atlases. This eliminated the problem in all cases where I was able to reproduce it. Unfortunately I cannot grantee that the error is gone because it is intermittant. I will keep users posted about this error.
     
    Last edited: Apr 2, 2013