Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. link64e

    link64e

    Joined:
    Mar 10, 2013
    Posts:
    5
    No worries it happens! Thanks for figuring it out!

    EDIT: It works!
     
    Last edited: Jun 5, 2015
    hopeful likes this.
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I have submitted a new version with this fix.
     
  3. spiningit

    spiningit

    Joined:
    Jun 3, 2015
    Posts:
    11
    Hi, i'm getting frustated trying to find a way baking a sketchup model in 3ds max before exported to unity. so now exporting a sketchup model directly to unity as .dae file might be another solution. before i decide to purchase this plugin i really wanna make sure if it really can help me baking all meshes in sketchup model into one mesh and one txture, with exact result as the original sektchup model.

    has anyone probably tried this plugin for sketchup file? how big the efforts to spend till we get the results, especially with tilling/applying the baked texture to the mesh?

    thx
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    You can try the free version. It will limit you to diffuse and bumped diffuse shaders but it should bake the meshes together no problem. If some of the textures are tiled many times I would recommend using the multiple materials feature to put those texture on their own submeshs.

    Download the latest from http://digitalopus.ca/UnityAssets/MeshBaker/MeshBakerEvaluation.unitypackage as I just fixed a serious bug (see previous posts) in the asset store version that would affect what you are doing in it is still being reviewed.
     
  5. spiningit

    spiningit

    Joined:
    Jun 3, 2015
    Posts:
    11
    Hey, thanks for the reply.
    I've tried evaluation package from the link, and i have changed all material into diffuse, have also used multiple combined material feature (which automatically generated 59 submeshes), but i get this Error and no combined mesh is created:

    System.NullReferenceException: Object reference not set to an instance of an object
    at DigitalOpus.MB.Core.MB2_TexturePacker._GetRects

    Any Idea what might cause this?
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Were there any errors or warnings above this in the console? Could turn the log level to trace and PM me with the whole console dump I could probably figure out out.

    You could try setting the Texture Packer to Unity. That will use a different texture packer although it often runs out of memory and crashes Unity.

    Regarding the 59 submeshes. Look at the "Source Material To Combined Mapping". This section defines how your materials are mapped to submeshes. You will have one submesh in your combined mesh for each mapping. Mesh Baker will try to put meshes with tiling on their own submesh (their own mapping). If you want one of these tiling materials to share an atlas with other materials, then delete the mapping containing the tiling source material and add the tiling source material to one of the other mappings. Then Mesh Baker should bake the tiling into that atlas.
     
  7. seagle1984

    seagle1984

    Joined:
    Apr 27, 2015
    Posts:
    3
    Hi Phong,
    My project has a character customization system, I split the body into a number of part, each part has its own textures and materials. I have already completed the various part runtime loading and mesh conbine function, animation also play well, but there is such a combine output multiple of materials, drawcalls did not decrease,
    So I want to try to use MeshBaker to solve this problem. I use MeshBaker the runtime combind textures and materials function ,then got a single material combined mesh. Now everything looks well except UV and texture. I had tried all kinds of methods to solve this problem, but failed. So I wonder to know how can I get the right set of UV and texture. Thank you for your help.
    1> Origin Test character.
    TestChar01.jpg
    2> MeshCombine Test character use MeshBaker in tool of editor.
    2th.jpg

    3> MeshCombine Test character assets runtime loading, use MeshBaker script runtime baker
    3th.jpg
     
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    It looks like a situation of multiple materials per source mesh and tiling using out of bounds UVs.

    Check the console for the recommended treatment suggestions and warnings.
    Turning on Fix Out Of Bounds UVs will probably help.

    I would also suggest watching this video


    Try adjusting the color tint property on the combined material. It won't help with the UV problem but it looks like your source meshes were using a color tint that is different from the combined mesh tint. The current version of mesh baker doesn't try to adjust the tint automatically
     
  9. seagle1984

    seagle1984

    Joined:
    Apr 27, 2015
    Posts:
    3
    Thank you very much! The problem has been solved.
     
    Last edited: Jun 17, 2015
  10. helius

    helius

    Joined:
    Feb 15, 2015
    Posts:
    1
    Hey Phong, found a bug in the lightmap UV bits of the code, which causes lightmap uvs to be broken in baked meshes. (this is from a 2 month old build, so ignore if you have already fixed this :)

    These 3 methods:
    MBVersion.GetLightmapTilingOffset()
    MBVersionConcrete.GetLightmapTilingOffset()
    MBVersionInterface.GetLightmapTilingOffset()

    are returning a Vector3, but should be returning a Vector4. this causes the y uvoffset to get set to 0 when reading the lightmapScaleOffset from the renderer
     
  11. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Thanks for the heads up.

    I will try to submit a fix later today.
     
  12. Rabbito

    Rabbito

    Joined:
    Apr 5, 2015
    Posts:
    13
    Hi Phong,
    I have a question:
    I want to use the meshbaker for adding and deleting Objects dynamicly in the scene. This is done pretty often in the scene. (Trees that get cuttet and than plant again) This is working fine but every time i am adding a tree the gc is allocating 40kb and if i am deleting it is allocating 12kb. Can you give me some hints how i could minimize the Garbage that the MeshBaker produce?
     
  13. Phong

    Phong

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

    There is no way around allocating memory. One thing that will help is to call AddDeleteObjects and Apply at most once per frame. It is only slightly more expensive to bake many objects in a batch than to bake one. I would suggest collecting the objects to be combined in a list in Update and do the bake in LateUpdate. You could accumulate objects to be baked over several frames and only do a bake every ten frames or so. Make sure you are not using any more channels than are needed. If your shaders don't use normals and tangents then don't include them. Another strategy to experiment with is to call GC.Collect periodically. It will slow your game down slightly but avoid a long pause occasionally when the GC gets desparate.
     
  14. Sarah-Mainwaring

    Sarah-Mainwaring

    Joined:
    Feb 24, 2014
    Posts:
    9
    Hello Phong,

    I'm currently working on porting one of our projects from Unity 4 to 5. In Unity 4 we were rolling our own simple mesh batcher. However since upgrading to Unity 5 we are having difficultly batching the objects correctly when the objects have baked lightmaps. I spotted your asset and am currently experimenting with the free version to see if it meets our needs, at which time we would require the paid version.

    However on simple cubes baked into the lightmaps in the scene the Preserve Current Lightmapping doesn't seem to be working at all. I see that on your website you mark this as "Experimental". Unfortunately we require this to be un-experimental for our project.

    Did you happen to have an ETA on this feature? Is something in the works at all?

    Sarah
     
  15. Phong

    Phong

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

    Currently the ETA on this is unknown. I am looking into it but the key to the preserving lightmapping feature is the ability to read the Lightmap UV rectangles from the renderer. It appears that Unity 5 does not return these lightmap UVs. Hopefully this will be addressed soon.
     
  16. Sarah-Mainwaring

    Sarah-Mainwaring

    Joined:
    Feb 24, 2014
    Posts:
    9
    Thanks for the quick update Phong. It's a shame that Unity isn't allowing you to update this feature right now.
     
  17. gterveen

    gterveen

    Joined:
    Dec 17, 2012
    Posts:
    22
    Hi,

    any chance we will see an option to create atlases textures at the new max texture size of 8192²? I use a lot of pre atlased assets and being able to preserve all details in those would be awesome as some already come at 4096!

    Cheers,
    Gerald
     
  18. Phong

    Phong

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

    I am planning to get rid of the code which attempts to guess the max texture size and replace it with a field where you can set it. There are too many platforms changing to often for me to keep track of this.

    In the meantime look in the scripts folder at file MB3_MBVersionConcreteEditor.cs method GetMaximumAtlasDimension(). You can edit this to return any size that you like.
     
    gterveen and hopeful like this.
  19. gterveen

    gterveen

    Joined:
    Dec 17, 2012
    Posts:
    22
    Thank you - works great! Needed to rebake the meshes curiously, but that was no issue for me.
     
  20. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I will be away on vacation until Friday July 3rd. So please be patient if there is a no response to questions the next few days.
     
  21. zreek17

    zreek17

    Joined:
    Jun 2, 2013
    Posts:
    21
    Hello! I have got a question about baking meshes:
    In my game, after creating a baked mesh at a runtime(I use this script),
    Code (CSharp):
    1. IEnumerator Start()  
    2.     {
    3.         mbd = GetComponentInChildren<MB3_MeshBaker>();
    4.         yield return new WaitForSeconds (0.1f);
    5.        
    6.         gos = GameObject.FindGameObjectsWithTag(ObjectTag);
    7.        
    8.         mbd.AddDeleteGameObjects(gos, null, true);
    9.         mbd.Apply();      
    10.     }
    I need to "unbake" all the objects back (gos) and delete created optimized mesh before disabling these gameobjects.
    How can I do this?
     
  22. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    Does the mesh baker add additional triangles to the combined mesh?
    For example, if you have two meshes, both with 100 triangles, you combine them together using mesh bakers, will the combined mesh be greater than 200 triangles?
    Thanks.
     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Will definitely fix this with the next update.
     
  24. Phong

    Phong

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

    Hopefully your original objects are still in the scene. You can make them visible again by enabling their renderers.

    mbd.EnableDisableSourceObjectRenderers();

    To get rid of the combined mesh you can destroy the result scene object.

    GameObject.Destroy(mbd.meshCombiner.resultSceneObject);

    To clear all the buffers used by the MeshBaker you can call:

    mbd.meshCombiner.ClearBuffers();
     
    zreek17 likes this.
  25. Phong

    Phong

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

    I don't believe that there is any way that the number of triangles can increase. However it is possible for the number of vertices to increase in some cases. For example if using the GenerateNewUVLayout option some of the vertices can be split.
     
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Try replacing the last two functions in MB3_VersionConcreteEditor.cs with this:

    Code (CSharp):
    1.         public void RegisterUndo(UnityEngine.Object o, string s){
    2.             #if (UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5)
    3.             Undo.RegisterUndo(o, s);
    4.             #else
    5.             Undo.RecordObject(o,s);
    6.             #endif
    7.         }
    8.        
    9.         public void SetInspectorLabelWidth(float width){
    10.             #if (UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5)
    11.             EditorGUIUtility.LookLikeControls(width);
    12.             #else
    13.             EditorGUIUtility.labelWidth = width;
    14.             #endif
    15.         }
    I will include this in the next version.
     
  27. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    Ok thanks. I just downloaded Mesh Baker and am running through the tutorials now.
    I do have a question regarding the definition of "using the same material". I see this over and over again in documentations and don't really know what that means.
    In your PDF, you have the following: "If all the meshes you are combining use the same material then you don’t need to bake the textures."

    Lets say I have two identical cubes. Cube 1 uses material A and material B. Cube 2 uses material A and B. Then are they considered to "use the same material"?

    Another example: If Cube 1 uses only material A and Cube 2 uses material A AND B, then are they considered to NOT be using the same material?

    Thanks for your help.
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Mesh Baker uses the materials on the first object in the list of objects to be combined as the master list of materials. All other objects must have a subset of the materials in the master list. Your first example the objects would "use the same material". In your second example they would not "use the same material" since Cube 2 has an unknown material that is not on the master list. If you reversed the order and Cube 2 was first in the list then they would "use the same material" since the materials on Cube 1 are a subset of those on Cube 2.
     
  29. zreek17

    zreek17

    Joined:
    Jun 2, 2013
    Posts:
    21
    Thank you for your help, removing of created mesh works well, but I have got a problem with enabling renderers:

    If I'm not mistaken, I need to code it like this
    Code (CSharp):
    1. mbd.EnableDisableSourceObjectRenderers(true);
    2. mbd.Apply();
    ,
    But it doesn't work. Am I doing something wrong?
     
  30. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    not sure what happened here but I was using the mesh baker then unity crashed with this error:

    upload_2015-7-4_17-18-19.png

    i cannot start up unity. (v 5.1.1) right now.
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I don't think you need the Apply(). If true doesn't work try false;
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Looks like a folder called "Library" was dragged into or created in your "MeshBaker/Examples" folder. This folder is not part of the Mesh Baker package. You need to move, rename or delete this folder so it is not anywhere in your assets folder. The "Library" folder is a special folder managed by Unity that sits next to the "Assets" folder.
     
  33. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    Ok, everything is working now. Not sure what happened.
     
  34. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    579
    Hello Phong, im about to get your solution,tell me if it combines meshes that are not 1,1,1 scale.
    I have a scene built up from modules that are scaled differently and i need to know if that will work.
     
  35. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    Hello,
    What does the "Include Colors" checkbox do?

    upload_2015-7-5_4-18-2.png
    Thanks.
     
  36. zreek17

    zreek17

    Joined:
    Jun 2, 2013
    Posts:
    21
    Unfortunately, none of these works :(
     
  37. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    Hello,
    I have a question regarding the best approach for dynamic batching.
    I have two gameObjects. Both use the same material, they are essentially duplicates of each other.
    They both going to be dynamic.

    DynamicObjects.png

    Should I use mesh baker to :
    i) combine material a and b to one atlas
    ii) combine GameObject1 submeshes 1 and 2 together

    Or is it a better approach to :
    i) combine gameObject1.submesh1 with gameObject2.submesh1
    ii) combine gameObject1.submesh2 with gameObject2.submesh2
    iii) and dont worry about creating an atlas

    Or would you recommend:
    i) combining all 4 submeshes together to make gameobject1 and gameobject2 to be one entire mesh
    ii) creating an atlas combining material a and b

    They are both very close to eachother in the scene (maybe a couple of meters apart).
    Or is there another approach?

    Thanks for your time
     
  38. JamieVRcade

    JamieVRcade

    Joined:
    Oct 21, 2012
    Posts:
    32
    Hey Phong,

    I am trying to bake some of Michael O's assets (Manufactura K4, Military Pack) and I keep getting errors. Here is one that I keep getting.

    Material Bake Results has no materials in material to uvRect map. Try baking materials. Can't combine meshes.
    UnityEngine.Debug:LogError(Object)
    DigitalOpus.MB.Core.MB3_MultiMeshCombiner:_validateTextureBakeResults() (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:164)
    DigitalOpus.MB.Core.MB3_MultiMeshCombiner:_validate(GameObject[], Int32[]) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:288)
    DigitalOpus.MB.Core.MB3_MultiMeshCombiner:AddDeleteGameObjectsByID(GameObject[], Int32[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:277)
    DigitalOpus.MB.Core.MB3_MultiMeshCombiner:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/core/MB3_MultiMeshCombiner.cs:271)
    MB3_MultiMeshBaker:AddDeleteGameObjects(GameObject[], GameObject[], Boolean) (at Assets/MeshBaker/scripts/MB3_MultiMeshBaker.cs:37)
    MB3_MeshBakerEditorFunctions:BakeIntoCombined(MB3_MeshBakerCommon) (at Assets/MeshBaker/scripts/Editor/core/MB3_MeshBakerEditorFunctions.cs:41)
    MB3_MeshBakerGrouperEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerGrouperEditor.cs:72)
    UnityEditor.DockArea:OnGUI()

    Also, I get this...

    System.IndexOutOfRangeException: Array index is out of range.
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.Apply (Boolean triangles, Boolean vertices, Boolean normals, Boolean tangents, Boolean uvs, Boolean colors, Boolean uv1, Boolean uv2, Boolean bones, DigitalOpus.MB.Core.GenerateUV2Delegate uv2GenerationMethod) [0x00197] in E:\Users\VRcade2\Documents\Bullseye-1.0.1 Military\Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:1067
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.Apply (DigitalOpus.MB.Core.GenerateUV2Delegate uv2GenerationMethod) [0x00010] in E:\Users\VRcade2\Documents\Bullseye-1.0.1 Military\Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:1011
    at DigitalOpus.MB.Core.MB3_MultiMeshCombiner.Apply (DigitalOpus.MB.Core.GenerateUV2Delegate uv2GenerationMethod) [0x0001d] in E:\Users\VRcade2\Documents\Bullseye-1.0.1 Military\Assets\MeshBaker\scripts\core\MB3_MultiMeshCombiner.cs:184
    at MB3_MeshBakerCommon.Apply (DigitalOpus.MB.Core.GenerateUV2Delegate uv2GenerationMethod) [0x0001b] in E:\Users\VRcade2\Documents\Bullseye-1.0.1 Military\Assets\MeshBaker\scripts\MB3_MeshBakerCommon.cs:147
    at MB3_MeshBakerEditorFunctions.BakeIntoCombined (.MB3_MeshBakerCommon mom) [0x00132] in E:\Users\VRcade2\Documents\Bullseye-1.0.1 Military\Assets\MeshBaker\scripts\Editor\core\MB3_MeshBakerEditorFunctions.cs:42
    at MB3_MeshBakerGrouperEditor.OnInspectorGUI () [0x000ec] in E:\Users\VRcade2\Documents\Bullseye-1.0.1 Military\Assets\MeshBaker\scripts\Editor\MB3_MeshBakerGrouperEditor.cs:72
    UnityEngine.Debug:LogError(Object)
    MB3_MeshBakerGrouperEditor:OnInspectorGUI() (at Assets/MeshBaker/scripts/Editor/MB3_MeshBakerGrouperEditor.cs:76)
    UnityEditor.DockArea:OnGUI()
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Yes. The scale, rotation and traslation are built into the combined mesh. It even handles negative scale on one or more axis.
     
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Meshes can have vertex colors. These are a color associated with each vertex in the mesh. Shaders can be written to use these colors instead of a texture. These are great for rolling your own lightmapping or ambient occlusion or super fast shaders for mobile that don't need textures. If this checkbox is checked then the combined mesh will include the color channel from the source meshes.
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Each submesh requires its own drawcall, so you have four drawcalls. If material A and material B use similar shaders e.g. Diffuse and Bump Diffuse then it is worth combining them to save two drawcalls. Often this is not possible because material B is transparent and material A is opaque.

    If your two objects GameObj1 and GameObj2 will always be locked together then it is worth baking them together. If they need to move independently then baking them together will break this so you will need to rely on Dynamic Batching to combine them at runtime. Static Batching is better than dynamic batching so if these objects don't move bake them together and check the static box. Dynamic batching also has some disadvantages. Objects need to have uniform scale and the same scale. Only 800 or so verts per frame can be batched. Lots of info in the manual about this.

    Hope this helps.
     
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Sounds like you need to bake the textures into an atlas first. Looks like you are trying to combine the meshes before baking a texture atlas.
     
  43. Phong

    Phong

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

    I tested it and the following script works for me. If you pause the game after calling EnableDisableRenderers what do the source game objects look like. Are the objects active?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TestEnableDisableRenderer : MonoBehaviour {
    5.  
    6.     bool showHide = true;
    7.    
    8.     void Update () {
    9.         if (Time.frameCount % 100 == 0){
    10.             showHide = !showHide;
    11.             MB3_MeshBaker mb = GetComponentInChildren<MB3_MeshBaker>();
    12.             mb.EnableDisableSourceObjectRenderers(showHide);
    13.         }
    14.     }
    15. }
    Attach this to an MB3_TextureBaker or MB3_MeshBaker that has a few objects.
     
  44. Rabbito

    Rabbito

    Joined:
    Apr 5, 2015
    Posts:
    13
    Hi Phong,
    I have a problem with updating the Mesh at runtime. I only want to update the Color. The Color Array in the MeshFilter is set on another method.

    I am using this function :
    Code (CSharp):
    1. //called on LateUpdate
    2.     public void LateUpdateApplyColorMeshBaker()
    3.     {
    4.         //only update if there is something to update
    5.         if (MeshBakerToColorUpdate.Count > 0) {
    6.             IEnumerator<MeshBakerHolder> enumerator = MeshBakerToColorUpdate.GetEnumerator ();
    7.             while (enumerator.MoveNext()) {
    8.                 //this only holds an MeshBaker component and a List of GameObjects which I want to update
    9.                 MeshBakerHolder holder = enumerator.Current;
    10.                 //get the Array which has to be updated
    11.                 GameObject[] arrayToUpdate = holder.componentsToUpdate.ToArray();
    12.                 //get the right MeshBaker
    13.                 MB3_MultiMeshBaker meshBaker = holder.meshBaker;
    14.  
    15.                 //This is Working
    16.                 //meshBaker.AddDeleteGameObjects(arrayToUpdate,arrayToUpdate,true);
    17.                 //meshBaker.Apply();
    18.  
    19.                 //If I use this Function it dont work
    20.                 meshBaker.UpdateGameObjects(arrayToUpdate,false,false,false,false,false,false,false,true,false);
    21.                 meshBaker.Apply(false,false,false,false,false,true,false,false,false);
    22.  
    23.                 holder.componentsToUpdate.Clear();
    24.             }
    25.             MeshBakerToColorUpdate.Clear ();
    26.         }
    27.     }
    What I am doing wrong? If I use the AddDeleteGameObjects it works but if i use the Update Function it don't.

    Edit: After I call AddDelete with another function to delete an Object all Colors are applyed
     
  45. Phong

    Phong

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

    To use the Update function the MeshBaker needs to have the combined mesh data in its buffers. Make sure that "Clear Buffers After Bake" is NOT checked when you do the first bake that combines the meshes. Also check the console for error messages.
     
  46. Rabbito

    Rabbito

    Joined:
    Apr 5, 2015
    Posts:
    13
    I alredy have the settings for clear buffers. And no error messages from the meshbaker
    Here is the code with i do the init

    Code (CSharp):
    1. private void init()
    2.     {
    3.         //holds ref to all MeshBakers
    4.         allMeshBakers = new MeshBakerHolder[World.totalHeightY];
    5.         for (int i = 0; i < World.totalHeightY; i++) {
    6.             //create new GameObject that will hold the MeshBaker
    7.             GameObject newGamobject = new GameObject("MeshBaker " + i);
    8.             //adds the MB3_MultiMeshBaker Component
    9.             newGamobject.AddComponent<MB3_MultiMeshBaker>();
    10.             MB3_MultiMeshBaker meshBaker = newGamobject.GetComponent<MB3_MultiMeshBaker>();
    11.             //Dont clear the Buffer for Update
    12.             meshBaker.clearBuffersAfterBake = false;
    13.             //The Texture Result from the TextureBaker(all MeshBaker share the same Result)
    14.             meshBaker.textureBakeResults = World.instance.prefabHolder.bakeResult;
    15.             //init needed fields
    16.             meshBaker.meshCombiner.doNorm = true;
    17.             meshBaker.meshCombiner.doCol = true;
    18.             meshBaker.meshCombiner.doTan = false;
    19.             meshBaker.meshCombiner.doUV = true;
    20.             meshBaker.meshCombiner.doUV1 = false;
    21.             //Bake into scene
    22.             meshBaker.meshCombiner.outputOption = DigitalOpus.MB.Core.MB2_OutputOptions.bakeIntoSceneObject;
    23.             //get the Multicombiner
    24.             DigitalOpus.MB.Core.MB3_MultiMeshCombiner multiCombiner = (DigitalOpus.MB.Core.MB3_MultiMeshCombiner) meshBaker.meshCombiner;
    25.             //set its Max verts to 3000
    26.             multiCombiner.maxVertsInMesh = 3000;
    27.             //add to the List which holds all MeshBakers
    28.             allMeshBakers[i] = new MeshBakerHolder();
    29.             allMeshBakers[i].meshBaker = meshBaker;
    30.         }
    31.     }
     
  47. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hmm, I tested this yesterday and it appeared to be working. What version of Unity and platform are you using. I will take a look later today.

    [UPDATE] Hi Rabbito,

    Have been investigating. I did find one bug. The MultiMeshBaker is not serializing its state (remembering what game objects it contains). Although this would only affect you if you first baked the meshes in Edit Mode, then started playing and updated the meshes at runtime. It also generates error messages. There are a few more things I want to try.
     
    Last edited: Jul 10, 2015
  48. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    Hello,
    I noticed some of my combined meshes appear completely black when viewing the mesh in scene view. However, when running the game, then the material is applied appropriately and I can see the material applied. Is the fact that the meshes are completely black in scene view an indication that something is wrong during the texture/mesh bake? This does not happen for all mesh combines I do.
    blackCombine.png

    EDIT: apparently adding additional light to the scene during scene view corrects the issue.
    The issue is resolved

    addLighiting.png

    Thanks
     
    Last edited: Jul 9, 2015
  49. Phong

    Phong

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

    I think this is due to the new Dynamic Lighting in Unity 5. Unity 5 tries to bake lightmaps on the fly. However in the editor the lightmaps are not re-baked as often. I expect if you do something that forces a recalculation of the lighting then everything will be fine.
     
  50. TreasureMap

    TreasureMap

    Joined:
    Apr 23, 2014
    Posts:
    14
    I am using mesh baker on my animated models and have a problem.

    The animation clip animates my mesh objects position scale and rotation.

    Those animations playback fine.

    But I have a custom script attached to each of my mesh objects.

    The script is called CustomAnimation. It has some public variables like Color _Color, Vector2 _UVOffset, Vector2 _UVScale. These parameters are passed to the shader.

    The animation clip has animation keys to animate each of the mesh's CustomAnimation script parameters. This is so we can animate the color and texture for each mesh.

    When I hit play and go to check my baked mesh, the animations related to the CustomAnimation script don't seem to work. Only the animations related to the mesh transform do (Position, Scale, Rotation).

    Does anyone know if there is a way to get this to work ?

    Reference:
    Example Model
    MyModel (Transform, Animator)
    GroupA (Transform)
    Cloud1 (Mesh, CustomAnimation)
    Cloud2(Mesh, CustomAnimation)​
    GroupB(Transform)
    Star1(Mesh, CustomAnimation)
    Star2(Mesh, CustomAnimation)
    Star3(Mesh, CustomAnimation)
    Star4(Mesh, CustomAnimation)​
    Moon(Mesh, CustomAnimation)​

    Example Animation Clip
    Star1 : Scale
    Star1 : Rotation
    Star1 : CustomAnimation.Color
    ...(Rest of the object animation entries look similar)
     
    Last edited: Jul 10, 2015