Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    Great, thanks so much for the detailed explanation.

    It looks like SkinnedMeshRenderer is the way to go. How then do I move the SkinnedMeshRenderer that's in combined mesh. Since it's bone based, does this mean that only animation curves? or is there some other functions in MeshBaker that's built specifically to move these objects?
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    You don't move the skinned mesh renderer. You move the bones (source Game Object). Try a simple example yourself:

    • Open Examples/SceneBasic
    • Delete the CombineMesh-MeshBaker0 Game Object
    • Set Renderer = "Skinned Mesh"
    • Click Bake
    • Click "Disable Renderers on Combined Objects"

    Try moving some of the cubes. You may think nothing has happened because the cube moves around, but notice that the MeshRender on the cube is disabled. It is part of the combined mesh that is moving.

    You can move the bones any way you want. A script, physics, an animation. It doesn't mattter what moves them.
     
  3. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    So the Source Game Object becomes Bones and the skinMeshRender is the stored in the Combined_meshbaker game Object.
    Awesome answer. Theory plus simple example that instantly lit up the Light bulb in my head. Aha ! so that's how it works.. Super Nice.

    As each original GO is turned into a bone, does it also mean that each bone is 1 draw call?
     
    Last edited: Apr 22, 2013
  4. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    It seems that SkinnedMeshRenderer has more flexibility than MeshRenderers. What are the advantages of using MeshRenderers over SkinnedMeshRenderer.
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    Performance. With skinned meshes unity has to calculate the position of every vertex in the mesh every frame. This is expensive. An ordinary MeshRenderer can be sent straight to the GPU with no additional work. If meshes are combined you can have about 20 times as many MeshRender vertices in a scene as SkinnedMesh vertices.
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    The bones will only generate a draw call if the MeshRenderer on that bone is enabled. If you are sure you are not going to re-add, or update a source object from the combined mesh you can delete the MeshRender and MeshFilter off the source object. This will save some memory.
     
  7. tinman

    tinman

    Joined:
    Jan 8, 2011
    Posts:
    229
    Hi Phong,

    I'm running into an issue with combining my mesh.
    I have a character who is made up of different objects:
    Boots, gloves, pants, shirt etc. A total of nine objects. They each have their own material so the player can customize him (actually a couple of the object share materials – for a total of 6 materials and 9 objects).

    Using texture baker, I manage to bake all the textures, and keep them separate (which is what I want). I keep “Fix Out-Of-Bounds Uvs” checked.


    However when I try to combine the meshes, I receive the error - “Failed getting triangles. Submesh is out of bounds”. (This error comes up twice when I try to bake). I am trying to combine skinnedMeshRenderers.


    Am I doing something wrong? I would appreciate assistance! :)

    Thank you!

    EDIT: OK after a couple hours of trying different things I managed to get things working. I did that by unchecking "Fix out-of-bounds UVs" and unchecked "Same as texture baker" in the MB2_Mesh Baker script (even though they were the same to the best of my knowledge).


    My problem now is saving it as a prefab. No matter what kind of object I choose I either get "failed to add/delete objects to combined mesh" or a warning that the skinned mesh will not be applied because the bones are missing. (something along those lines). I tried making a new object which includes the bones but it doesn't seem to help.
    Would you mind guiding me through the process?
    I've been working on this all day so support would be greatly appreciated!

    Thank you (again)
     
    Last edited: Apr 25, 2013
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    I could not find that error in the code. The error I presume you are getting is "Object X in the list of objects to combine has overlapping submeshes". If you are getting that error you will have a hard time combining this mesh preserving its submehes. The reason is that each submesh (if it starts with a different material) needs to map to a different part of the atlas. However the different submeshes share vertices. The single UV coordinate associated with each vertex needs to map to two different places in the atlas with is impossible.

    If this is the error you were getting you should be able to combine this mesh if you turn off "multiple combined materials". This collapses all the submesh into a single mesh which solves the vertex needing its UVs to be in two places at once problem.

    Please let me know if this is what was happening as I am trying to improve the error messages.
    Prefabing a Skinned Mesh is tricky, You need to do some of the work by hand because the bones (source objects) are unlikely to be in the correct place in the hierarchy. Here is a step by step example:
    1. Open Examples/SceneBasic
    2. Delete the CombinedMesh-MeshBaker0 object
    3. Set the renderer to "Skinned Mesh"
    4. Leave the output as "BakeIntoSceneObject"
    5. Click "Bake", this will create a combined mesh scene object.
    6. Set the output to "BakeIntoPrefab"
    7. Create a prefab and add an empty game object then drag that to the result prefab field
    8. Click "bake"
      There should be two messages, one reporting that the mesh was saved. The other is a warning that "Prefab will not be updated for skinned mesh. This is because all bones need to be included in the prefab for it to be useful.". Basically you need to do a bit more manual work to include the bones.​
    9. Now drag the combined mesh scene object to your prefab The combined mesh in your scene should turn blue indicating it is a prefab.
    10. Drag the created mesh asset from the project to the "mesh" field in the prefabed SkinnedMeshRenderer component.
    11. Drag all you source objects (bones) so they are children of the combined mesh scene object.
    12. Disable or delete the Renderers and MeshFilters on the bones.
    13. Click "Apply"

    You should be good to go. You can test by closing the scene, opening a new one and instantiating the prefab.

    There does seem to be a bug that it is necessary to bake into a scene object before baking into a prefab otherwise there is an error. I will try to fix this for the next version.
     
    Last edited: Apr 25, 2013
  9. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    I'm curious as to how much of the above series of steps can be done via Coding?
     
  10. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    I am trying to TextureBake and MeshBake using code. I have some questions while trying to learn from the runtime baking example in the docs.

    if (GUILayout.Button("Combine textures build combined mesh")){

    MB2_MeshBaker meshbaker = target.GetComponent<MB2_MeshBaker>();
    MB2_TextureBaker textureBaker = target.GetComponent<MB2_TextureBaker>();

    //These can be assets configured in editor
    // or you can create them
    // on the fly like this
    // Use this for initialization
    textureBaker.textureBakeResults = new MB2_TextureBakeResults();
    textureBaker.resultMaterial =new Material( Shader.Find("Diffuse") );
    textureBaker.CreateAtlases();


    //only necessary if your not sure whats
    //in the combined mesh
    meshbaker.ClearMesh();
    meshbaker.textureBakeResults =textureBaker.textureBakeResults;
    //Add the objects to the combined mesh
    meshbaker.AddDeleteGameObjects(textureBaker.GetObjectsToCombine().ToArray(),null);
    meshbaker.Apply();
    }

    I ran this code and got "Error: Material Bake Results is not set."

    The Texture Baking component in the editor has a button "Create empty assets for combined Materials", it seems that the above example doesn't create this needed asset. Is it possible to do everything that is in the Editor panel using only Code? It has to work for Webplayer also.
     
  11. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    The example above should work. It is used in the example scene SceneBakeTexturesAtRuntime. You just have to press play and click the button to see it bake the textures and create a combined mesh. I highlighted the lines in red where it "Create empty assets for combined Materials". These don't have to be assets, they can be created on the fly as shown on these lines.

    These are things that only work in the editor:
    • Changing the format of textures
    • Changing the compression of textures
    • Setting the read flag on textures
    • Creating assets in the project folder
    • Creating prefabs
    If you avoid these things (set your textures to readable, uncompressed, trucolor before playing) then the whole thing can be done at runtime. That being said, baking atlases is going to be slow on the client platform.

    Combining meshes at runtime is VERY doable. I am working on an LOD system that has 25 combined meshes in the scene and bakes about 6 times per second as objects switch LOD.
     
  12. jrDev

    jrDev

    Joined:
    Nov 5, 2008
    Posts:
    1,674
    How in the world has Unity not contacted you for a sale promotion yet? I'm cautiously waiting to jump in cause I am budget conscious. You probably won't answer but I'll ask anyway, when will you have a sale? :p
     
  13. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    Very nice, is the LOD system something that will be a new offering from Digital Opus ?
     
  14. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    Thanks for the tips. I understand how it works now. I'm able to duplicate the functionality of "SceneBakeTexturesAtRuntime" example in my own test code.

    One last catch.

    I would like for to dynamically populate the "Objects to be Combined" box. In the "SceneBakeTexturesAtRuntime" example, at the moment I have to manually assign each object to be combined.

    I get an error when trying to do it dynamically.
    Error: No meshes to combine. Please assign some meshes to combine.
     
    Last edited: Apr 26, 2013
  15. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    I've been testing the included "SceneBakeTexturesAtRuntime" example in webplayer and in unity's scene view and it works. But when I published to IOS ipad1, the combine texture and mesh functionality doesn't work at all.


    I think there is a bug in IOS, ipad1 export.

    Using the included "SceneBakeTexturesAtRuntime" example

    1. Selected Cube1,Cube2,Cube3,Cube4 and Unchecked their visibility in the inspector so no cubes are visible in the scene view.
    2. Hit play in the Editor, the scene works as expected.
    3. Publish to WebPlayer, it also works.
    4. Published to Ipad1, doesn't work.

    5. Turn on Visibility for all Cubes
    6. Publish to Ipad1, it works.

    Do you know what the problem might be?
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    There is a list attribute

    textureBaker.objsToMesh

    Just fill this up with the objects to be combined.


     
  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    I hope to release it as an asset.
     
  18. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    Strange, is there anything in the XCode log? MeshBaker is quite verbose when something doesn't work.
     
  19. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    Update:

    I just started fresh again and instead of manually setting the cubes in the editor, I used "textureBaker.objsToMesh" in the code and published to Ipad1 with Visibility OFF for all Cubes. It worked. This is really good bc it's been a long day trying to get things working. Hopefully it will also work in my project. Fingers crossed.
     
  20. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    "I hope to release it as an asset."

    Can it work with Loom multithreading framework?
     
  21. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
  22. tinman

    tinman

    Joined:
    Jan 8, 2011
    Posts:
    229

    Thank you very much Phong... After very carefully following your guide I think I managed to get it going. Will need to try now on a few more objects :) Thanks :)
     
  23. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    Hi Phong,

    I've managed to get the core functionality of "SceneBakeTexturesAtRuntime" integrated in my project and it's working successfully on the Ipad. Thanks for your help so far.

    Perhaps you might have an idea how to do the following:

    I would like to dynamically swap Textures and Materials.

    Using the "SceneBakeTexturesAtRuntime" as an example, After baking the textures and combining the meshes, I would like to swap Cube2's texture with Cube1's texture in-game via code.

    Thanks again.
     
    Last edited: Apr 27, 2013
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    All materials should be in the combined materials before you do this. You can include them by creating dummy objects like cubes, adding the material and including the cube in the list of objects to combine. You don't have to include the cube in the combined mesh, just in the texture bake. You can delete it once the atlas is created. Any mesh with any of the baked materials can now be included in the combined mesh.

    To switch the material on an object, switch on the source mesh, delete the object out of the combined mesh and add it back into the combined mesh. Something like this (untested):

    obj.GetComponent<MeshRenderer>().material = myDifferentMaterial;
    GameObject[] objs = new GameObject[] {obj};
    meshBaker.AddDeleteGameObjects(null,objs);
    meshBaker.AddDeleteGameObjects(objs,null);
    meshBaker.Apply();
     
    Last edited: Apr 28, 2013
  25. eiwer

    eiwer

    Joined:
    Sep 26, 2011
    Posts:
    23
    correct me if i am wrong, i think it's a great tool, but I just have one question - does it break the limitation of the unity batching? or it just combine different textures into atlas automatically? is it possible to combine tiled textures into one texture? how could it happen technically?

    thanks
     
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    One question? It looks like three:)

    MeshBaker is similar to batching but much more powerful. With batching all objects must share the same material. Even materials that use the same textures but have different tiling can't be combined. Also objects with non-uniform scaling can't be combined with uniform scaling.

    MeshBaker will build atlases so you can combine different materials. You can even combine materials that have different shaders! MeshBaker has a lot of features designed to make it possible to combine meshes that would otherwise be impossible to combine.

    It builds atlases automatically.
    It bakes the tiling. So if you have a brick texture that is tiled 3x4 times. Then MeshBaker will generate a texture that has 12 copies of your brick texture and include this texture in the atlas. This has the obvious drawback that it is not as efficient as true tiling. It is also to easy to generate tiling that is larger than the largest atlas size.
     
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    A new version of MeshBaker is available 2.6

    • Fixes a bug when fix out of bounds UVs is used on a mesh with submeshes
    • Performance improvements to the multi mesh baker
    • Added GetNumObjectsInCombined and GetNumVerticesForObject to API
    • Improved AddDeleteGameObjects so that an object can be added and deleted in the same call. This is useful for refreshing an object in the mesh. It is more efficient than making two calls.
     
  28. Fufurata1234

    Fufurata1234

    Joined:
    Jun 6, 2009
    Posts:
    45
    Hi,
    I've just watched a tutorial (Video of Mesh Baker 1.6) and noticed that after combining materials on combined models become much brighter. Can you explain the reason of this? If this is the way you baker "works" I don't need it even for free.
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    It is explained here. http://www.digitalopus.ca/site/mesh-baker-2-faq/. Mesh Baker only deals with texture properties. You need to adjust other properties such as base color yourself. In this case I did not bother adjusting the base color. In the next video "Output Options Part 1 Bake Into Scene Object and Bake Into Prefab" I talk about that 2:00 minutes in. You can see me fix it.
     
  30. sheenaeon

    sheenaeon

    Joined:
    May 3, 2013
    Posts:
    8
    hi,

    i just have one question,

    like i have my game with enemy generator, instantiating them like every between (10 - 15 seconds). so on runtime can i put every instantiated enemy on the mesh baker?

    regards,
    sheenaeon
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    Yes. You would do it like this. The combined mesh can be a skinned mesh which works well for moving objects.:This works at runtime and is very efficient. The textures atlases would need to be created in the editor ahead of time.

    List<GameObject> freshEnemies = new List<GameObject>();
    List<GameObject> expiredEnemies = new List<GameObject>();

    ... code where enemies are added to these lists

    meshbaker.AddDeleteGameObjects(freshEnemies.ToArray(), expiredEnemies.ToArray());
    meshbaker.Apply();
     
  32. wana7262

    wana7262

    Joined:
    Jul 2, 2012
    Posts:
    95
    OK my Map is a single mesh with 41 Materials whenever i try to bake materials into 1 material i got this error
    HELP
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    The main error that is stopping the bake is one of the material slots on your Map is None. Look carefully.

    The overlapping submeshes warning presents a serious problem. Different submeshes share vertices. With that error you will have a hard time combining this mesh with others. The reason is that each submesh (if it starts with a different material) needs to map to a different part of the atlas. However the different submeshes share vertices. The single UV coordinate associated with each vertex needs to map to two different places in the atlas with is impossible. My other asset "Mesh Master" can fix your mesh so that the submeshes do not overlap (share vertices).

    I would try first without using multiple materials. If that doesn't work you could try with multiple materials, but you may have to fix the overlapping submeshes to fix this.
     
  34. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,545
    Hi, how would the combining skinned mesh renderers work with Unity LOD system? Does it support it?
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    MeshBaker doesn't attempt to interact with the LOD system. I am currently working on an LOD system that works with MeshBaker but it is still in Alpha.
     
  36. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    359
    Got a potentially complex issue here for you. Let me see if I can explain this as simply as possible...

    - I have a collection of enemies. These enemies have all been previously MaterialBaked.
    - Now in my game scene, I create an enemy pool. There are 12 kinds of enemies, and we pool around 20 of each enemy (a few get up to 60 as they are more common).
    - The code grabs an enemy from the pool, adds it to the MeshBaker, and off we go. When the enemy is busted up, it gets re-added to the pool.

    That all works great. Draw calls are low, enemies spawn, enemies die, they go to / from pool, etc.

    Now the problem comes almost at random. All of a sudden, an enemy will spawn, and I will get an error such as this:

    Object joint1 has an unknown material BodyMat (Instance) (UnityEngine.Material). Try baking textures UnityEngine.Debug:LogError(Object)

    Here's where I start to get confused - the game runs fine for a while. It churns on without an issues - then suddenly, boom. Errors. And when it starts, ALL of the errors are always related to the EXACT same material. This material does of course exist in the MaterialBaker, as it's been used just fine up until a sudden unknown moment where it decides it no longer wants to work with just that mesh.


    So.... that's where I get lost. I guess I will start here with 2 questions...
    1.) From what I said above, is there anything obvious I could be doing wrong?
    2.) Are there known issues of any kind when using MeshBaker with object pooling?

    Thank you very much for your help!

    -Dave C.
     
  37. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    There are no known issues with object pooling.

    Do you have another script that accesses the material on that object? If so are you using renderer.material or renderer.sharedMaterial to access the material?

    Normally all instances a prefab share the same sharedMaterial. However if you access a material with renderer.material then Unity creates a second instance of the material and uses it just for this object. This messes up MeshBaker because MeshBaker uses to the material on an object to look up the UV rectangle in the atlas for that material. The second material instance is a new one that MeshBaker does not know about so the lookup fails.
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    Evaluation Version Now Available!

    If you have been tempted to give Mesh Baker 2 a try, a free version of Mesh Baker 2 is now available (Requires Unity 4.1.2+)!

    It is intended internal, development, evaluation and/or educational use. You are even welcome to include it in Asset Store packages. It cannot be used for commercial purposes other than for Asset Store packages.

    The free version will add a watermark to generated atlases and it will not save meshes as assets or create prefabs. Other than that it is full featured.
     
  39. Pulov

    Pulov

    Joined:
    Feb 20, 2010
    Posts:
    824
    Thanks! I'll try this for sure.
     
  40. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    I got the following error while trying to Bake Meshes on an object that has been loaded into the scene dynamically.

    "The sharedMaterial on object has been 'Instanced'. This was probably caused by a script accessing the meshRender.material property in the editor. The material to UV Rectangle mapping will be incorrect. To fix this recreate the object from its prefab or re-assign its material from the correct asset."

    I'm not really understanding what this "instanced" means. What would be a fix for this problem if the object is being loaded in the game dynamically.

    Thanks.
    .
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    MeshRenderer objects have two fields MeshRenderer.material and MeshRenderer.sharedMaterial. Unity tries to be efficient and create no more Materials in memory than is necessary. Initially it creates one material that all objects that use that material share. "sharedMaterial" references this material for all objects. If you change anything (like a texture) on the material then all objects that use this material see the change.

    MeshRenderer.material is for custom materials. If you access (read from) this variable then Unity creates a new instance (a copy) of the sharedMaterial that this object now uses. If you make any changes to this material it only affect this object.

    Unfortunately it also confuses MeshBaker because MeshBaker uses the material on an object to look up the UV rectangle in the atlas. The second material instance is a new one that MeshBaker does not know about so the lookup fails.

    The problem is probably being caused by another script accessing MeshRenderer.material on that object.
     
  42. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    Thanks for the nice explanation of how the material and shared materials work in unity. Having a better understanding of how this mechanism works.

    As for the confusion with Meshbaker, I'm still not totally clear as to what state the mesh needs to be before baking with MeshBaker.

    At the moment, after the objects are dynamically loaded into the scene, all of their materials have been instanced because the Serializing script (Open source Unity Serializer whydoidoit.com). Then at this point, I start the baking process. Does this mean that MeshBaker needs NON instanced materials before the baking? If MeshBaker does need non-instance, how then can I revert the material to non-instance ?

    void CreateTexture(){
    meshbaker = meshBakerObj.GetComponent<MB2_MeshBaker>();
    textureBaker = meshBakerObj.GetComponent<MB2_TextureBaker>();

    textureBaker.objsToMesh = objsToBake;

    textureBaker.textureBakeResults = ScriptableObject.CreateInstance<MB2_TextureBakeResults>();
    textureBaker.resultMaterial = new Material( Shader.Find("Diffuse") );

    float t1 = Time.realtimeSinceStartup;
    textureBaker.CreateAtlases();
    elapsedTime = Time.realtimeSinceStartup - t1;

    meshbaker.ClearMesh(); //only necessary if your not sure whats in the combined mesh
    meshbaker.textureBakeResults = textureBaker.textureBakeResults;


    meshbaker.AddDeleteGameObjects(objsToBake.ToArray(), null,true,false);

    meshbaker.Apply();

    }
     
    Last edited: May 31, 2013
  43. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    Phew, it's been a tricky and winding road trying to figure out how this material things works. Even by calling "obj.renderer.material.name" will turn the material into an instance. How crazy is this?

    Question.
    I've got a solution where I've put all of the original materials inside of One game object that is named MaterialReferenceObj.
    Each material is added to the Materials list as an element. Then a script checks the names of the instances and replaces it with the original material. This seems to be working. Now I have an idea of baking just the MaterialReferenceObj so that all of the materials are created so I don't need to bake the textures again and again. The problem is that when I do this in my current solution, only the first material gets baked. Is there a better way to set things up so that I can prebake all needed Materials as a reference?

    Thanks.
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    Sounds like a confusing time. Glad to here it is working out. BTW. MeshFilter.mesh and MeshFilter.sharedMesh work the same way as renderer.material and renderer.sharedMaterial.

    Regarding your question about a convenient way to bake all the materials. MeshBaker will only bake as many materials as there are submeshes. Most meshes have only one submesh so MeshBaker is only baking the first material. If you had as many submeshes and materials then MeshBaker would bake them all.

    A convenient way to bake a bunch of materials is to create a bunch of cubes or other simple objects then add a separate material to each one, then add these to the texture baker and bake. It doesn't matter that none of these cubes will be included in the final mesh.

    After that has been done then you can use a completely different set of objects when combining the mesh provided they use the materials that were combined in the texture bake. Note that if the "fix out of bounds uvs" is checked or you are using "Multiple Combined Materials". These values get stored in the combined material and affect how objects are combined in the combined mesh.
     
  45. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    A new version of MeshBaker 2.8 is now available.

    This includes an important bug fix if you are using MeshBaker at runtime. Previously MeshBaker was accessing MeshFilter.mesh to retrieve an objects mesh at runtime. Although this works it causes the GameObject to create a new instance of its mesh which can result in a lot of extra mesh instances in the scene. MeshBaker now always accesses sharedMesh.

    IMPORTANT: This version includes a code reorganization which puts some classes into a namespace. You will now need to add

    Code (csharp):
    1. using DigitalOpus.MB.Core;
    To the top of your scripts if your are using MB2_MeshCombiner or MB2_TextureCombiner directly.

    IMPORTANT: WHEN IMPORTING THIS VERSION IT IS IMPORTANT TO DELETE THE PREVIOUS MESHBAKER FOLDER FIRST. When importing Unity will resolve the references to components on existing objects. It never hurts to do a backup first though.
     
  46. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    Have you seen Marmoset Skyshop?

    Can this work with MeshBaker?
     
  47. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,545
    Hi,

    I've already setup as my own atlas instead of baking it, but it can only accept the baked atlas. Can you add support for our own supplied material?
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,594
    It would be very easy to populate a Material Bake Result object by hand in the inspector to make this work. If you click on it one in the project view you can see all the fields in the "Material Bake Result" (MB2_TextureBakeResults object). I presume that all your source objects are already using the atlas which means that they already use the same material and have their UVs adjusted (let me know if this is not the case and I will write different instructions).

    • "Create empty assets for Combined Materails"
    • Drag your source material to the 'materials' array in the MB2_TextureBakeResults
    • Enter a corresponding 'Prefab UV Rects' entry. This should be 0,0,1,1 since the uvs are already adjusted on the source objects. If the UVs are not adjusted you will need to do this differently.
    • Thats it. everything else can be ignored.
     
  49. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    Hi Phong,

    1. I'm experimenting with using a shader that has no texture. GUI/TextShader -- it's a shader in which we can adjust the color.
    I've been trying to get this to work but no luck so far.
    Is there something special that needs to be done?

    2. Is there a way to turn on/off individual combined meshes. For example, I have 5 separate meshes that's combined. I would like to hide/show a particular mesh without having to do add/delete from the combined mesh?

    3. Is it possible to change the highlight color on individual item that's combined?
    renderer.sharedMaterial.color = HilightColor; The way I am doing it now is to delete the object from the combined mesh, then use the original mesh to highlight. If i can somehow access the individual renderer of the combined mesh then it would be really nice.

    4. As I am integrating MeshBaker more and more into the existing project, there's more and more need for more flexibility and speed requirements. Currently MeshBaker is very slow in Combining and Updating Meshes. Would it be possible to integrate LOOM Multithreading into Meshbaker to make MeshBaker really robust? Do you have plans to include LOOM as an option in the future? If not, can you suggest what would be the best way to integrate LOOM so that future updates of MeshBaker would not break custom integration.

    5. Also, Did you get a chance to check out Marmoset Skyshop, it's a shader that's uses environment maps and the final product looks amazing. I would like to use it for my project and want to know if this will work with MeshBaker.

    Thanks.
     
    Last edited: Jun 22, 2013
  50. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    Sorry for the many questions but it's integration time.

    1. I have 10 cubes which have materials which I am baking with MultiMesh Baker in-editor. These cubes are simply reference holders for the materials which will be used in the scene. After baking, I would like to remove these cubes from the combined mesh. Is there somewhere in the editor that these meshes can be removed after baking.

    P.S. I tried removing these cubes with meshBaker.ClearMesh(); but it's still not removed.