Search Unity

Mesh Baker by Digital Opus [RELEASED]

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

  1. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Interesting problem.

    If you can find a shader that does just an outline and nothing else, you could re-enable the renderer on the source game object and give the outline material. I am not sure how well this would work I think it wold depend a lot on the shader.

    If it were me I would hide or remove the character from the combined mesh using the showHide method or AddDelete in the API and re-enable the original character. Then when the character is deselected use the reverse of ShowHide or AddDelete. Check out the example scripts to show how to add and remove from the combined mesh.
     
  2. digO

    digO

    Joined:
    Mar 20, 2014
    Posts:
    23
    Yeah, i liked the second idea too, but im having some problem to implement that.
    i'll try to explain what im doing.
    From the start im using mesh baker in each monster/hero and im creating for each monster/hero a separate prefab.
    I did what u did in this video below:


    But i did that for each different monster, i didint put 2 monsters together as u did.
    And when im trying to apply the border from the monster im doing that in the monster script:
    GameObject.FindGameObjectWithTag("MeshBaker").GetComponent<RemoverMeshBaker>().Remover(gameObject);
    transform.FindChild(BorderPlace).renderer.material.shader = newShader;
    transform.FindChild(BorderPlace).renderer.material.SetFloat("_Outline", outlineSize);
    transform.FindChild(BorderPlace).renderer.material.SetColor("_OutlineColor", outlineColor);

    And i put the script below in the gameobject with MB3_MeshBaker and MB3_TextureBaker.
    public class RemoverMeshBaker : MonoBehaviour {
    MB3_MeshBaker mbd;
    // Use this for initialization
    void Start () {
    mbd = GetComponent<MB3_MeshBaker>();
    }


    public void Add(GameObject monstro) {
    GameObject[] aux = new GameObject[1];
    aux[0] = monstro;
    mbd.AddDeleteGameObjects(aux, null);
    mbd.Apply();
    }

    public void Remover(GameObject monstro) {
    GameObject[] aux = new GameObject[1];
    aux[0] = monstro;
    mbd.AddDeleteGameObjects(null, aux);
    mbd.Apply();
    }
    }

    But im getting 4 errors:
    textureBakeResults must be set.
    Material Bake Results is null. Can't combine meshes.
    Failed to add/delete objects to combined mesh
    Target Renderer was not set.
     
  3. digO

    digO

    Joined:
    Mar 20, 2014
    Posts:
    23
    Man you didn't say anything. :/
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Sorry, I ran out of time yesterday responding and might have posted something empty by accident.

    To update the combined mesh you need to use the same mesh baker object that baked the combined mesh. This is a bit tricky because the combined mesh was baked into a prefab. I think you have two choices.

    1) Don't bother with the prefab. Use your source objects in the scene and do all the combining at runtime. All of the examples work this way.

    2) EDIT THIS DOESN'T WORK Include the Mesh Baker that created the combined mesh in the prefab with the combined mesh. Do the AddDelete using this MeshBaker. I have not actually tested this approach but it should work. I will try this out to verify that it works. EDIT This doesn't work. The problem is that the mesh baker stores a list of instance IDs of the objects that were combined. When an object is removed, mesh baker looks up its instance ID in the list so it knows which verts and tris to remove. When you create a prefab asset, the instance IDs (which are instance IDs of scene objects) loose their references and can't be used in a new scene.

    BTW: There is something I don't understand. If each of your combined meshes has one hero/monster in it, then can't you use your original method to outline it? I thought the outlining problem was that you had several characters in one combined mesh and wanted to outline only one of them.
     
    Last edited: Nov 24, 2014
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    There is a new version of Mesh Baker in the asset store:
    • Texture colors bleed into atlas padding
    • Meshes can be baked without creating atlases if all meshes use the same material
    • New script for culling animations on combined meshes
    • Buffers are cleared after baking in the editor to reduce scene size and memory use
     
    kurylo3d, hopeful and Razmot like this.
  6. SkermunkelStudios

    SkermunkelStudios

    Joined:
    Dec 29, 2012
    Posts:
    156
    Hi,

    I just bought Mesh Baker yesterday and Im currently diving into it trying to figure it our and get comfortable with it.

    However, Im struggling to create atlasses for my materials. I followed the instructions in the pdf manual, by creating a mesh baker object (for Texture and mesh baking) and then adding objects to the list via the "Add selected objects button" after creating the empty objects for the texturebake results and the new material and checking my settings I baked the material and the mesh.

    The Mesh seems to combine just fine, but the combined material being used only uses the first material's texture and does not create an atlas out of the four materials like it should.

    Apologies, I tried to send an email via your website, but its giving me problems when Im trying to send the message, so I thought I would post here.

    Pleas any help or advice on the matter as I dont know if I am setting something up incorrectly.

    UPDATE: I noticed that the shader in use on the 4 (all four of them using the same overlay bumped shader) materials has a _MainTex2 and a _BumpMap2 properties so I added them to the Mesh Baker settings.

    I also unticked Include UV1 but left Include UV ticked, UV2 is just being copied over (no new one being generated) and Include color is also being ignored, I then rebaked the combined material and it seems like it was going through a much more intense process with these settings.

    Unfortunately, my project crashed with a memory overload and when I reopend my project again, all of the source materials that I was testing on were bungled up even though their textures and tiling are still the same, this is extremely weird.

    Ah well copying my project backup over now and going to try again with less objects activated in the scene, hopefully then I wont get the memory overload.
     
    Last edited: Dec 5, 2014
  7. justinhdmeijer

    justinhdmeijer

    Joined:
    Oct 13, 2014
    Posts:
    8
    Hi Phong,

    I've downloaded the evaluation version and got by draw call reduced from 450 to 30. However, I do not see any improvement in my GPU usage. What can I do to improve that?
     
  8. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    I would think lowering poly count, amount of over draw... LODs. Maybe even less complex shaders.. etc etc.. all the traditional stuff. Draw calls are a cpu bottle neck.
     
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Were the tris and verts reduced in the stats window? Combining meshes can actually slow you down sometimes if you are combining lots of off screen meshes with a few on screen ones. If this is the case try to combine meshes that are grouped together. If you are targeting mobile are you using Alpha Blending? This can be a big drag.

    Optimization is a big topic. Make sure you have read this section of the Unity Manual http://docs.unity3d.com/Manual/OptimizingGraphicsPerformance.html

    There are also some good videos in the Unite archives
    2012 Performance Optimization Tips and Tricks for Unity
    2014 Mobile performance poor man's tips and tricks
    2014 Big Android: Best Performance on the Most Devices
     
    Last edited: Dec 8, 2014
    OnePxl likes this.
  10. jdurnil

    jdurnil

    Joined:
    Dec 26, 2013
    Posts:
    16
    Hey I am trying to create a single skinned mesh for a character, first problem is i am using mecanim to animate the character i am not able to create an avatar for the combined skinned mesh, i am also not able to assign a root bone for the combined skinned mesh. So no animations are available and I am not sure if they would work if they were available. Second issue is the create a prefab for the character does not work, maybe this doesn't work with skinned meshes, i followed the video exactly but the when you put the created prefab in the scene nothing is there. Please help.
     
  11. jdurnil

    jdurnil

    Joined:
    Dec 26, 2013
    Posts:
    16
    nevermind about the animations i got that working, here is a problem i really cannot understand, the player character is walking and suddenly dissappears when he gets to a certain point, the server will not let me upload the video it says its too large its only 2mb anyway do you know what might be happening here?
     
  12. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Hi jdurnil, The problem is almost certain to be the render bounds on the combined skinned mesh renderer. Check out this video 5:00 minutes in.
    . It explains all about the skinned mesh renderer bounds and how to deal with it.
     
  13. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Does having a really big renderer bounds (for example the whole level) for a group of skinned meshes cause performance slowdown?

    It'd be convenient to have a huge renderer bounds if I don't know where the individual meshes will end up walking (for example if they are randomly wandering).

    Thanks!
     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    There is a cost, yes. Skinning meshes is expensive. Ideally Unity should only be skinning meshes that are visible. It is a waste to skin non-visible meshes. You may need to do some experimentation to discover whether the extra skinning or the extra drawcalls are more expensive. It will depend a lot on the complexity and number of vertices in the meshes.
     
  15. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    I see... Then what about having the render bounds dynamically adjust according to where the camera is looking? Is that even feasible? Thank you
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    There are some scripts that come with Mesh Baker that dynamically adjust the bounds to encapsulate the combined skinned meshes. If any part of the this bounds interects the camera fustrum then the full combined mesh will be skinned. It is not possible to tell Unity that only part of the skinned mesh should be skinned.

    Could you use pooling? For examples if you have 30 enemies on your level, But only five are ever visible at once, Then you combine five into a single skinned mesh and move these around as the player encounters them. They did this in the old PS2 Medal of Honor games. Even though it felt like the player was fighting the entire German army, only four enemies were ever visible at a time.
     
  17. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Very good info Phong, I think I understand now... multiple enemies combined would be treated by Unity just like a single skinned mesh.

    The pooling sounds like a great idea, thanks! Maybe pool small groups of soldiers to compromise a tradeoff... if I combine 4 groups of soldiers consisting of 3 soldiers per group, that would be a maximum of 4 draw calls even if all 12 soldiers are onscreen at once, is that correct?
     
  18. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Yes, this is correct.
     
    eridani likes this.
  19. directx

    directx

    Joined:
    Dec 11, 2014
    Posts:
    47
    i have problem with combine materials

    one mesh 2 materials and 2 draw calls for this
    and no way to bake using meshbaker
     

    Attached Files:

    • qu.png
      qu.png
      File size:
      1 MB
      Views:
      717
  20. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    It should work with "multiple materials" turned off. It will collapse the submeshes and build an atlas with two textures.
     
  21. directx

    directx

    Joined:
    Dec 11, 2014
    Posts:
    47
    i have try that also but
    martial not map correctly to object
    why is that ?
     

    Attached Files:

  22. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Were there any warnings in the console? There might have been something about tiling or out of bounds UVs. It looks like the wheel on the right has stripes which the source wheel must be using tiling. If this is the case then you can bake the tiling but your textures will loose quality. This is fine if you want the wheel to be one solid color and the hub to be another solid color. If you want to preserve the pattern then you will need to either use two submeshes (two drawcalls), or bake the tiling (big atlas) or manually re-edit the UVs for this object in a modeler using an atlas.
     
  23. directx

    directx

    Joined:
    Dec 11, 2014
    Posts:
    47
    another problem
    left side - before baked
    right side - after bake

    darker why is that
     

    Attached Files:

  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Hi Directx,

    The answer is covered in the first question in the FAQ.

    http://www.digitalopus.ca/site/mesh-baker-2-faq/

    Please let me know if this doesn't answer you question.
     
  25. directx

    directx

    Joined:
    Dec 11, 2014
    Posts:
    47
    no it doesn't i have used two textures for trunk and leafs
    texture 1 and 2
     

    Attached Files:

  26. directx

    directx

    Joined:
    Dec 11, 2014
    Posts:
    47
    here is the result
     

    Attached Files:

  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Hi Directx,

    Looking at the pictures, the atlas looks correct. It appears to have the same color as that used by your source tree.

    Try putting the atlas texture on your original mesh and your original texture on the combined mesh. The UVs will be wrong but you should be able to tell if the problem is the generated mesh or the shader/atlas.

    What shaders are you using for the source trunk, leaves and combined mesh? Are they the same as the one used for the combined mesh? Are you using vertex colors or baked lighting of some kind? Are there any warnings or errors in the console? Does the combined mesh have the same channels as the source meshes?
     
  28. directx

    directx

    Joined:
    Dec 11, 2014
    Posts:
    47
    i have used 2 textures on original mesh
    there is 2 mesh es on original tree
    all shaders are defuse
     
  29. directx

    directx

    Joined:
    Dec 11, 2014
    Posts:
    47
    console
     

    Attached Files:

  30. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Hi directx,

    Did you try the atlas texture on the original and the original texture on the new mesh? What happened?

    Is there any sort of baked lighting in the scene?
     
  31. GLID3R82

    GLID3R82

    Joined:
    Aug 7, 2013
    Posts:
    10
    this is a fantastic asset, so why don't you make a bundle??
    Mesh Baker + Mesh Baker LOD BUNDLE
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    That is a good idea. I will check to see if the asset store allows it. Would make a good start to the new year.
     
  33. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,686
    They definitely do allow bundling. There's several bundles in the store.

    I agree that the bundling is a natural move, in that many people with Mesh Baker probably don't know about the LOD add-on.
     
  34. EmperorShmoo

    EmperorShmoo

    Joined:
    Nov 25, 2012
    Posts:
    2
    Hi,

    Thank you for making this fantastic product!

    Is there a way for MeshBaker to work with Decals?

    I understand that static pre-set objects such as alternate clothes or gear can be added to a skinned mesh using MeshBaker. I am using Decal System Pro to allow players to place images like patches or symbols onto their character, and would like to use MeshBaker to bake that decal into the character's skinned mesh.
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    If the decal system is mesh based then this may be possible. I think the problem will be attaching the decal to the correct bone on the skinned mesh. Also if the decal is at a joint such as a shoulder where there are blended bone weights Mesh Baker will not blend the weights.

    I watched the video for Decal System Pro and in the hierarchy there is an object "Decals -> Decal Mesh Renderer". If you add a single decal, then move this game object so that it is a child of the correct bone, then bake Decal Mesh Renderer with your skinned mesh renderer in a mesh baker then you should end up with a single skinned mesh with one decal. I would test at this point. If it looks O.K. You could then use the combined skinned mesh and add a second decal etc...

    I haven't tested this so I don't know how well it will work.
     
  36. EmperorShmoo

    EmperorShmoo

    Joined:
    Nov 25, 2012
    Posts:
    2
    Thanks for such a fast and thought out response!
     
  37. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Thanks. I just realized another problem will be that the decal shader is probably transparent alpha blended and the skinned mesh renderer shader is probably solid. These might not combine well. you may need to use multiple materials feature to map the decals onto a separate submesh. You will end up with a second drawcall. Otherwise you will need to use the transparent shader for the entire skinned mesh which may be more expensive.

    If your patches are rectangles. You may be better off using a quad instead of a decal and baking that onto your skinned mesh. This way the patch could use the same shader as the skinned mesh and it would bake better.
     
    Last edited: Dec 30, 2014
  38. Jack62Lewis

    Jack62Lewis

    Joined:
    Jun 17, 2013
    Posts:
    105
    Hi,

    I just bought mesh baker and following the tutorial on its asset store page didn't work for me. It baked the atlas texture and material but the prefab remained empty with no combined mesh to be seen.
    What did I do wrong?

    Thanks,
    Jack Lewis
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Hi Jack,

    Were there any error messages in the console? Also there are two bake buttons, one on the MB3_TextureBaker and one on the MB3_MeshBaker. Did you click the bake button on the MB3_MeshBaker?

    FYI, for baking prefabs I would recommend using the prefab baker.
     
  40. Jack62Lewis

    Jack62Lewis

    Joined:
    Jun 17, 2013
    Posts:
    105
    Not got access to my computer at the moment so can't check exactly what I pressed. I was following the tutorial but I think it's outdated as there is options I can see that weren't seen in that video.

    What's the fifference between what I used and the prefab baker?

    Thanks,
    Jack Lewis
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Hi Jack,

    The prefab baker is a newer tool. It looks after many of the tedious steps involved with baking prefabs. Here is a video showing how to use it.



    Sometimes you need to do it the old way but most if the time this is faster.
     
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    A new version of MeshBaker has been submitted to the Unity Asset Store. The new version includes clustering tools to make it easier to group meshes together. I will post a tutorial video over the next few days showing how it works.
     
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Version 3.5 with clustering tools is now live in the asset store. Video coming today or tomorrow.
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    A new version 3.5.1 has been submitted to the Unity Asset Store. The new version includes:

    - Added gizmos to the MeshBakerGrouper
    - Added button to bake all child MeshBakers of a MaterialBaker
    - Added button to disable renderers of child material baker
    - Fixed bugs where multi-mesh bakers would not bake when baking all bakers.

    Also released a new tutorial video showing how to use the new clustering features:

     
  45. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    A new version of Mesh Baker 3.6 is available in the asset store.

    This version fixes compiler errors when importing into Unity 5.
     
  46. SteveXu

    SteveXu

    Joined:
    Jul 22, 2013
    Posts:
    15
    Does this works with Particle Systems? I have 10 Particle Systems in the sense and they are active at the same time,each Particle System have a material so they are 10 draw calls in total. Can I use Mesh Baker to reduce thr draw call to 1 time?
     
  47. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    No, I don't believe there is any way to do that in Unity. Unity doesn't provide access to the internal mesh of the particle system. Mesh Bake only works with MeshRenderers and SkinnedMeshRenderers.
     
  48. SteveXu

    SteveXu

    Joined:
    Jul 22, 2013
    Posts:
    15
    I wonder if Mesh Baker can merge several material which have different shader into a single one ? If so, Particle Systems can be merged to a single draw call by using "Texture sheet animation".
     
  49. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,086
    Yes, Mesh Baker can create atlases from the textures used by different materials which use different shaders. To bake the textures you would need to put your particle system materials on some cubes. Once the atlas texture(s) have been created you can find the UV coordinates of the textures in the atlas in the "Material Bake Result" asset.
     
  50. SteveXu

    SteveXu

    Joined:
    Jul 22, 2013
    Posts:
    15
    Thank you , Phong!