A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Discussion in 'Assets and Asset Store' started by Phong, Nov 20, 2012.
Thanks for letting me know. Will take a look.
Looked into this. The problem is that the example scene is mis-configured. The "Texture Bake Results" has no materials. If click bake on the TextureBaker, this will bake the materials on the source objects. After this has been done the scene will run correctly.
Will fix this in the next release.
Thanks, that fixed the problem.
Hello and gongrats for
One of the best assets in assetstore
Im using it for a while now and sholud tell its awsome!
I only have one question and that is what about baking terrain stuffs?i mean tree,grass,stone or whatever that painted on terrain
Doese mash baker capable of baking its textures and meshes?
Any help will appreciated
Hi, i am using this asset it works great but there is some problem
this is my windows build and it is prefect.
but this happens with my android build.lighting issues.
help me solve this problem
Hey Phong, quick question for you. I am trying to apply Texture/Mesh Baker in a prefab in Unity 2019, but as soon as I drag objects into the "Objects to be combined" array the Mesh Baker game asset disappears from the hierarchy. Any idea why this is happening? Does it not work in a prefab?
I noticed that there are plans to improve the Unity Mesh API:
The ability to update only part of the mesh instead of uploading the entire mesh is especially useful for modifying baked meshes I think.
Is there any reason why a lightmap generated by meshbaker would get cannibalized during runtime? When I hit the play button, our baked lightmap vanishes. Poof! It is clearly visible in the editor, and when I rebake it returns.
Sorry for the slow reply. For some reason the email alerts from the forums don't seem to work.
Re: Baking terrain stuff.
It is always a good idea to reduce the number of materials as much as possible. The Batch Prefab Baker is great for this. If many terrain props share a material then Unity has a much easier time batching them.
Regarding Mesh Baking. For vegetation and grass I would recommend letting the Unity Terrain system manage things for you. The terrain LOD system handles this fairly efficiently and uses billboards for distant trees. For mesh props it is also a good idea to use Unity's mesh system if possible too however you can often help it by baking a few clusters of pebbles and such together. Then Unity needs to manage far fewer instances of detail meshes.
Try to make sure that the details all use "instancing" materials. Unity can be much more efficient if the props use instancing.
Sorry for the slow response. Sometimes the forum email notifications don't arrive.
You need to use scene object instances in the list of objects to combine. The reason is that many of the things that effect how things are baked (lightmap indexes, negative scaling on one axis) are only available in the context of a scene.
Try setting the lightmapping UVs settings to "generate new UV2 layout" or "copy UV2 to separate rects". The preserve_current_lightmapping is only reliable in certain versions of Unity. I should remove that option.
Hi there no problem at all
And thank you for the tips!
Wish luck for you and your project
How do I combine materials without combining meshes?
Edit - I found "Preparing Models For Static/Dynamic Batching (Batch Prefab Baker) AKA Combining Textures Without Combining Meshes" but it doesn't work. While it swaps the mesh, the material remains the original. If I manually assign the new material that mesh baker created, certain meshes have a bad appearance
Edit 2 - After manually assigning the new materials, I also had to change the Mesh Renderer number of materials to 1.
Edit 3 - So I got it working, but there are a lot of unnecessary manual steps, such as dragging the prefab in the scene and duplicating the prefab because "Batch Bake Prefabs" can't take the source and destination the same. There's no reason you can't have a one-click solution "Combine Materials" that finds all materials on the objects, creates a new material that combines them, then replaces all materials with the new material on the same prefab.
Hi. I am considering buying mesh baker but I am wondering if it's compatible with HDRP or scriptable rendering pipeline in general?
Hi! MeshBaker bake all geometry with LODs into single mesh or it bake only LOD 0 without other LODs ?
Yes, Mesh Baker works with Unity Materials and the assigned textures. It does not care what rendering pipeline is being used.
Thanks for the feedback. Are you using the full version of Mesh Baker?
There should be no problem with the HDRP pipeline. Mesh Baker works with Unity Materials and the textures used by those materials. It doesn't care what is happening within the shaders themselves.
You can set up a baker for each LOD level so that all geometry in several LOD0s will be baked together into a combined LOD0 mesh and all geometry for the LOD1 meshes will be baked together into a combined LOD1 mesh etc...
I have a question regarding combining skinned mesh renderers at runtime. I have a MeshBaker object in my scene. I can combine the meshes without an issue. This is the code I'm using to do so:
SkinnedMeshRenderer skinnedMeshRenderers = playerHolder.GetComponentsInChildren<SkinnedMeshRenderer>(true);
GameObject objectsToCombine = new GameObject[skinnedMeshRenderers.Length];
for (int i = 0; i < skinnedMeshRenderers.Length; i++)
objectsToCombine[i] = skinnedMeshRenderers[i].gameObject;
Debug.Log("smrCount = " + skinnedMeshRenderers.Length);
playerBaker.AddDeleteGameObjects(objectsToCombine, null, true);
The problem I am running into is when I try to remove meshes. It'll often give me an error, but never seems to actually remove the meshes. In fact, the meshes that I'm attempting to remove stop animating and move to the local origin of the mesh baker object. This is the code I'm using.
playerBaker.AddDeleteGameObjects(null, skins, true);
where skins is an array of game objects with skinned mesh renders that I'd like to remove.
The errors I get are:
Could not get bounds. Not updating skinned mesh bounds
DigitalOpus.MB.Core.MB3_MeshCombiner:UpdateSkinnedMeshApproximateBoundsFromBoundsStatic(List`1, SkinnedMeshRenderer) (at Assets/MeshBaker/scripts/core/MB3_MeshCombiner.cs:414)
go paramater was null
DigitalOpus.MB.Core.MB_Utility:GetBounds(GameObject, Bounds&) (at Assets/MeshBaker/scripts/core/MB_Utility.cs:375)
DigitalOpus.MB.Core.MB3_MeshCombiner:UpdateSkinnedMeshApproximateBoundsFromBoundsStatic(List`1, SkinnedMeshRenderer) (at Assets/MeshBaker/scripts/core/MB3_MeshCombiner.cs:411)
Any ideas what I could be doing wrong here?
I was able to resolve this. I'm using a mesh baker on a bunch of skinned meshes in my scene. I instantiate them and add them at the start of the scene. As they are killed in the game, I flag them for removal and add them to a list. I was handling the removal in LateUpdate. Instead, I now copy that flagged list to a new one, clear that initial list, and then remove all of the objects in a coroutine. This does the trick in a not too convoluted manner.
Hi again. Now that I've managed to resolve the previous issues, I'm running across a new problem. When I remove skinned meshes and apply the changes, I get a whole flood of errors along the lines of:
Assertion failed on expression: 'IsFinite(distanceForSort)'
Invalid AABB inAABB
Invalid AABB in a
Assertion failed on expression: 'IsFinite(distanceAlongView)'
I've done some googling and saw the previous mention in this thread but nothing there seems to help with the issue. Any ideas?
And... never mind on this as well. I managed to fix it. Thanks!
I am trying to combine the textures of 2 different meshes. I use texture baker tool , add the wanted meshes. Yet the atlas produced doesn't seem to have the right texture coordinates , for none of the two meshes. tried everything what should I do?
nevermind I used batch prefab baker. but I want to use this tool on runtime . can I script to combine the materials of multiple gameobjets while running the game using prefab baker?
Regarding the texture coordinates being wrong. Do the meshes use tiling? That is most likely the problem. This video explains the issue and different solutions to fix it.
Regarding using the batch prefab baker at runtime. This cannot be used at runtime because it is not possible to create project assets at runtime and prefabs are project assets. However you can still create meshes with adjusted UVs without creating a prefab at runtime. These meshes can be used with the combined material.
Set the output of the baker to "bake mesh assets in place".
Visit the source meshes one renderer/mesh at a time
Assign the renderer to the mesh baker so that it is the only object in the list of objects to combine.
Position the renderer at pos: 0,0,0 rot: 0,0,0 scale: 1,1,1
Assign a new Mesh to the combiner.
Assign a new game object to "Combined Mesh Object"
Now that you have your duplicated meshes you can replace the source meshes with your baked versions and the source materials with your combined materials.
You can combine materials at runtime, however there are limitations. The textures must be readable and be in a format that supports fetching pixels. Some compressed texture formats do not allow this.
The solution was to use a script to force the lightmap back on during runtime.
Also, the modes you discussed resulted in failure in my setup. I strongly recommend not removing the option, but fixing it.
Hey Phong, I have a question for you.
I have a character from MakeHuman and it has 9 Skinned Meshes. I use the Mesh Baker to first combine all the textures (selecting all the skinned meshes and put them into Texture_Baker and it outputs a flawless combined texture atlas for me. For the next step, I want to combine all the meshes into 1 single skinned renderer mesh, so I go to MB3_Mesh_Baker and select (Same as Texture Baker) and output it to "Bake into Scene Object" as well as "Bake into Prefab". I get the log message as "Successfully baked 9 Meshes".
It also creates a new object in my scene with a child object named "MeshCombiner-mesh-mesh". Now, this is where things get tricky. I can't move the new scene object or the child, it's like moving an empty object. It doesn't move the transform of the new object. I can clearly see the new combined object in the scene but somehow it is stuck with the source object and only moves if I move the source object.
As you can see above, if I move the child object or the parent combined object, all it moves is that huge square and not the combined object.
Now this is what I want to achieve:
1) I want the combined object to be an independant entity (no link to the source object) and act as a seperate object
P.S: I have tried baking it to Prefab but it's the same problem.
2) The combined texture and automatically assigned material is always "Legacy/Diffuse" instead of Standard shader (as all my Skinned Rendered Meshes use Standard Shader so I don't know why it automatically switches to Diffuse)
I am using Unity 2019.1.5f1.
1) The bones for your baked skinned mesh will be the same as the bones for your source meshes. If you move the source mesh bones then the combined mesh should deform. You can create a prefab by:
Baking as you did using the bake into prefab option.
Moving the skeletons from the source rigs so they are a child of the "MeshCombiner-mesh-mesh" parent.
Delete any source SkinnedMeshRenderer components that may have been moved.
Make sure the render bounds of the combined skinned mesh renderer is resonable.
Set the animator culling settings to "always animate" if the animator(s) are not above the combined skinned mesh in the hierarchy.
Make a prefab of this.
2) Are you using Mesh Baker Free? It is limited to diffuse and bump-diffuse. If you are using pro, you can control the output shader type by setting the shader on the combined material before baking.
Hope this answers your questions. You might be interested in these two videos. They show how to bake skinned meshes into prefabs and mix an match multiple skinned mesh parts.
in ur tutorial ep 8 I cannot clearly understand how to make-mimic the mesh u have created in blender.when I try to extract ur mesh from example scene I get some weirst stuff going on. so I cannot mimic the way u modelled the mesh (blender noob). can u profid some screenshots with the hierarchy in blender? or is it possible please to attach the .blend file to a message thanks.
Hey Phong, I was able to solve the issue with your help. Thanks a ton!!
And no, I am using Mesh Baker paid version (not the free version).
I have a few more queries if you don't mind. I have a lot of prefabs that I want to programatically convert to mesh while also combining the materials. I have an array of objects in which each object has children that I want to combine. If I set the size of the array to 1 and add one parent object (with 9 skinned submeshes), it creates the texture atlas and creates a combined mesh on runtime. However, if I add 1 more parent to the array (now the array has 2 parent objects), it would still work for only the first parent object.
I think I may have to reset something but I am not sure why. I am attaching my code below for you to review. I would be glad if you help me with this as well.
I have one more question, how do I save the texture atlas as an asset during runtime; and when I say runtime, I will enable [RunInEditMode] as soon as this script works as I don't plan to use this in runtime but only want to automate the process of creating the combined mesh with their combined texture atlas.
public class Auto_Merge_Sample : MonoBehaviour
public GameObject objectsToBeMerged;
public GameObject FinalCombinedObjects;
// Start is called before the first frame update
textureBakerObject = gameObject.GetComponent<MB3_TextureBaker>();
meshBakerObject = gameObject.GetComponent<MB3_MeshBaker>();
for (int i = 0; i < objectsToBeMerged.Length; i++)
//Make sure all the textures are set to RGBA32 or else this will not work. Also make sure it has the "Read" flag enabled.
IEnumerator MeshTextureCombiner(float time, GameObject parent)
yield return new WaitForSeconds(time/10f);
SkinnedMeshRenderer smr = parent.transform.GetComponentsInChildren<SkinnedMeshRenderer>();
// GameObject objsToAdd = new GameObject[smr.Length];
for (int i = 0; i < smr.Length; i++)
// objsToAdd[i] = smr[i].gameObject;
//These can be assets configured at runtime or you can create them
// on the fly like this
textureBakerObject.textureBakeResults = ScriptableObject.CreateInstance<MB2_TextureBakeResults>();
textureBakerObject.resultMaterial = new Material(Shader.Find("Standard"));
//only necessary if your not sure whats
//in the combined mesh
meshBakerObject.textureBakeResults = textureBakerObject.textureBakeResults;
//Add the objects to the combined mesh
// meshBakerObject.AddDeleteGameObjects(objsToAdd, null, true);
meshBakerObject.AddDeleteGameObjects(textureBakerObject.GetObjectsToCombine().ToArray(), null, false);
// GameObject finalObj = GameObject.Find("CombinedMesh-Advance_Merge_Sample-mesh");
GameObject finalObj = meshBakerObject.resultPrefab;
if (finalObj != null )
parent.transform.Find("CMU compliant skeleton").SetParent(finalObj.transform);
finalObj.name = parent.name + "_Combined";
Debug.Log("Cannot find the final combined mesh. Please try again");
Hey Phong! I was wondering if there was a tutorial or explanation of how the agglomerative grouper works. I THINK I'm using it correctly - but I'm not sure lol.
Regarding your code. I can see two things:
The Mesh Baker re-uses the same mesh for the second bake. This will overwrite the results of the first bake. You need to replace the reference to the mesh between bakes so that you are baking into a different, new mesh the second time. You should be able to do this with meshBakerObject.meshCombiner.SetMesh(myNewMesh);
It is a bit sketchy that you are creating multiple coroutines (one for each parent) that you are kicking off at the same time and all of these coroutines are sharing the same texture baker and mesh baker. If you add a yield statement to the middle your MeshTextureCombiner coroutine then everything will break because each coroutine will get a chance to do some work, then will pause to let the other coroutines do some work. When the first coroutine tries to resume its work, the TextureBaker and MeshBaker data will be messed up because it will have been reset by the last coroutine.
You don't need to do the baking in playmode, it is better to do it in edit mode. When Unity enters playmode it creates temporary duplicates all the objects in the scene so that any changes can be undone. It is likely that assets you create during playmode will end up with broken references when the temporary objects are cleaned up when you return to edit mode. Also I don't think you can do things like re-importing a Texture in a different format in runtime.
If you run the code in edit mode then you don't need the coroutine, you can just use a regular function.
There are a few ways to trigger the execution:
You can add [ContextMenu("My Custom Operation")] to one of the functions on your monobehaviour.
You can create a custom menu operation add: [MenuItem("MyMenu/Do Something")] to a static method.
You can create a custom inspector with a button to do what you want.
Re: Saving the atlas as a texture. This is a multi step process:
byte bytes = myAtlasTex.EncodeToPNG();
string myPathInAssetsFolder = "MyFolder/mySavedTex.png";
System.File.File.WriteAllBytes(Application.dataPath + myPathInAssetsFolder , bytes);
// Now that there is a saved PNG in the assets folder we need to get a reference to it.
// These lines probably won't work in playmode because I don't think the asset database will refresh and import new assets while the game is running.
Texture2D myNewTextureAssetReference = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/" Textures/" + myPathInAssetsFolder , typeof(Texture2D))
Unfortunately I don't have a tutorial. The main steps are:
Click "Click To Build Clusters"
Move the mouse around in the main window. You should see some white wire gizmo spheres in the scene representing the clusters appear.
Adjust the "Max Distance" slider. As you do this you should see the white spheres change. There should be more or fewer as the number of clusters change.
When you are happy with the result, click, "Generate Mesh Bakers"
The blender file is in a .UnityPackage in the example scenes. (It is packaged this way because the Asset Store does not allow Blender files). Assets/MeshBaker/Examples/CharacterCustomization/blenderFile.unitypackage. If you import the Unity Package you should have the blender file.
Note that I have not tested this file with the latest version of blender. Will try that today.
[UPDATE] The blender file in the package should work with all recent versions of blender (2.77+)
When merging a mesh with the Generate Lightmap UVs in the importer is it possible to copy the generated UV instead of the one packaged with the mesh?
Yes, you should use the "Copy UV2 To Separate Rects" option. If you copy the UV2 unchanged you will have UV triangles that overlap in the combined mesh which will produce strange blotches in the lightmap. The "Copy UV2 To Separate Rects" option ensures that there are no overlaps.
I just tried that but got an error as soon as I click Bake:
System.IndexOutOfRangeException: Array index is out of range.
at DigitalOpus.MB.Core.MB3_MeshCombinerSingle._copyUV2unchangedToSeparateRects () [0x0014a] in MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:2679
at DigitalOpus.MB.Core.MB3_MeshCombinerSingle._addToCombined (UnityEngine.GameObject goToAdd, System.Int32 goToDelete, Boolean disableRendererInSource) [0x01a82] in MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:1062
at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.AddDeleteGameObjectsByID (UnityEngine.GameObject gos, System.Int32 deleteGOinstanceIDs, Boolean disableRendererInSource) [0x001b3] in MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:1938
at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.AddDeleteGameObjects (UnityEngine.GameObject gos, UnityEngine.GameObject deleteGOs, Boolean disableRendererInSource) [0x0006a] in MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:1872
at MB3_MeshBaker.AddDeleteGameObjects (UnityEngine.GameObject gos, UnityEngine.GameObject deleteGOs, Boolean disableRendererInSource) [0x00025] in MeshBaker\scripts\MB3_MeshBaker.cs:43
at MB3_MeshBakerEditorFunctions.BakeIntoCombined (.MB3_MeshBakerCommon mom, System.Boolean& createdDummyTextureBakeResults, UnityEditor.SerializedObject& so) [0x001e3] in MeshBaker\Editor\core\MB3_MeshBakerEditorFunctions.cs:94
at DigitalOpus.MB.MBEditor.MB3_MeshBakerGrouperEditor.OnInspectorGUI () [0x00190] in MeshBaker\Editor\MB3_MeshBakerGrouperEditor.cs:139
DigitalOpus.MB.MBEditor.MB3_MeshBakerGrouperEditor:OnInspectorGUI() (at Assets/MeshBaker/Editor/MB3_MeshBakerGrouperEditor.cs:144)
Just tested it and it worked for me.
Which version of Mesh Baker are you using.
Also, was this a clean, mesh baker or were you updating a baker that had some existing meshes already combined? Was "clear buffers after bake" checked? I think it might be possible to get this error if that was unchecked, you baked without lightmapping UVs, then turned on the lightmap UVs option and re-baked.
in texture baking is legacy diffuse the only shader available? is there any chance for support of unlit shaders?
::::Game object Spine030(Clone) (UnityEngine.GameObject) does not use shader Legacy Shaders/Diffuse (UnityEngine.Shader)
Mesh Baker can work with any shader that uses texture properties. Set the shader in the combined material after it gets created. If you do this then Mesh Baker will look for the texture properties in that material.
Note that if you are using the free version, it is limited to Diffuse and Bump Diffuse shaders.
I am using Unity 2018.4.0 and latest version of Mesh Baker, the "preserve current lightmaping" seems out of work.
Lightmap can only be fetched on the first time of baking, everything is perfect until reopenning the scene, all combined meshes are unlinked from lightmap.
I tried several times and the issue is remaining. Is it likely to be a bug?
Yes, this is a bug. I will try to address it in the next version of Mesh Baker.
I´m having this error when trying to use batch prefab baker:
Mesh Mech_01_Head (UnityEngine.Mesh) is used by both the source and result prefabs. New meshes will be created.
DigitalOpus.MB.MBEditor.MB3_BatchPrefabBakerEditor:BakePrefabs(MB3_BatchPrefabBaker, Boolean) (at Assets/MeshBaker/Editor/MB3_BatchPrefabBakerEditor.cs:315)
DigitalOpus.MB.MBEditor.MB3_BatchPrefabBakerEditor:OnInspectorGUI() (at Assets/MeshBaker/Editor/MB3_BatchPrefabBakerEditor.cs:150)
I have absolutely no idea what I´m doing wrong...
To give you some more information:
The objects I´m trying to atlas are parts of a customizable mech, there are 7 different mechs and they combine parts like heads, torsos, arms, legs, etc...
The objects itself are inside a root empty object, inside this empty object there are two other containers, one with the skeleton and the other with the mesh of the relevant part.
It´s necessary so I can combine them in the game.
Using this objects, everything in MB works perfectly, until I try to Batch prefabs then I get this weird message.
I followed ur instruction on ep 8 mesh baker. I went on blender and on ur .blend file I add a mesh on the character with a bone just like all the subparts of Player rig. I then import it on unity press bake meshes on mesh baker and get this message:
Bones do not match bindpose.///what am I doing wrong?
edit: I also get warning : Mesh 'Head' has 1 (out of 575) vertices with no weight and bone assigned (they will be assigned to bone #0 with weight 1). The list of vertices: 523.
ok I figured it out went on avatar and did auto configure
Is it a warning (Yellow) or error (Red)?
If it is a warning you can ignore it. The warning is there because the SourcePrefab and ResultPrefab are using the same "Mesh" asset. This is a problem because the BatchPrefabBaker will replace the UVs in the mesh which would also replace the UVs for the source mesh. This message lets you know that the BatchPrefabBaker will create a new mesh asset for the ResultPrefab so that this doesn't happen.
Hi, Well, yes, it´s a warning, but I´m also having some errors mentioning something about the bones structure...
And, it´s not modifying the result prefabs UVs, so, It´s not working...
I naver had any problem with batchprefabbaker before, but also, I never tried it with skinned meshes and I think it´s the problem...
I´ll upload three of those files and, whenever you find some time, if you tried it to reproduce the error I´d really appreciate that...
I removed the textures to reduce the file size, you can use anything you see fit
thanks a lot in advance
I have a question to ask you.
In runtime, I need to create more than one "Combined Mesh Object", since by the logic of my application, I only need to combine parts of an object, for example:
In this case I have this object:
And I just need to create a combination of 1.a + 1.b and in parallel 4.a + 4.b + 4.c.
I'm not sure how to do this, I made some quick attempts but it seems that the plugin always comes to the first "Combined Mesh Object".
What am I missing?
The MeshBaker/MeshCombiner has a reference to the "resultSceneObject" and to a mesh. If you want to re-use the same MeshBaker/MeshCombiner several times baking different "combined mesh object" each time, then you need unset its references to these objects or the second bake will overwrite the result of the first bake.
mb.meshCombiner.resultSceneObject = null;