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,085
    It will not help with light baking. Whether you use mesh baker or not the light baking process will be very similar.

    Mesh baker will likely help with frame-rate. If there are a lot of batches in your scene then Mesh Baker can help reduce those which is a very common performance problem.
     
    MegaCo likes this.
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I am planning to re-write the meshcombiner using DOTS-ECS. So yes, this is coming. This change will be 2-6 months away.
     
  3. lucidvyu

    lucidvyu

    Joined:
    Feb 29, 2020
    Posts:
    4
    Hi Ian,

    Thank you for creating the Mesh baker asset.

    I am trying to build an application to be used for providing users a VR experience of their houses before they are built. I fetch the data about the 3D geometry of the houses, furniture, lights etc. from an architecture design software in JSON format from a socket connection. My constraint is that I need to build my objects at runtime as I fetch the data hence I cannot use a lot of editors only optimization features. Currently, my draw calls are way above (500+) the recommended limit of about 100-200 for mobile. I am using unity's static batching utility to combine meshes that use the same material to reduce my draw calls.

    I want to understand how can I use the mesh baker asset in the most optimum way for my application.
    1. Can mesh baker asset combine meshes at runtime?
    2. Can I do texture atlassing at runtime?
    3. What other features of the Mesh Baker asset can I use to optimize my application?

    I am not an expert Unity user so any other suggestions to optimize the application will be greatly appreciated.

    Thanks
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    1) Mesh Baker can combine meshes at runtime.
    2) Mesh Baker can create texture atlases at runtime although there are some limitations. It is better to do this in the editor if you can.

    I would take a good look at Mesh Baker's Batch Prefab Baker. Using this you should be able to make many more of your prefabs share materials (that is probably the factor limiting how much can be combined). The Batch Prefab Baker will create duplicate's of your prefabs and atlases that share materials. These prefabs are much easier to combine at runtime because there is a much reduced set of materials.

    If you can I would recommend creating the atlases in the editor although you may have too many possible permutations of house parts for this to be practical.

    Mesh Baker does support TextureArrays which is incredibly powerful for combining a huge number of large tiling textures into a single TextureArray. However this is an advanced topic as you may need to modify your shaders so they use Texture Arrays.

    Here is a video showing how the Batch Prefab Baker works.



    I would also recommend this video. If you are working with houses you probably have a lot of meshes with Multiple Materials and submeshes. This video shows solutions for dealing with this:

     
  5. V-J

    V-J

    Joined:
    Apr 1, 2015
    Posts:
    73
    Hello, i got a question that is maybe allready answerd in this topic.

    I'm having a scene with three highly detailed gameobjects (3d scan data) and on every gameobject a 8k texture (rgb chrunched etc compression). Is it posible to use meshbaker to combine the meshes and atlas the textures?

    I have bought the easy combine asset but that is not working for me.
     
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Do you want the atlas to be a 16k texture (16384x16384) = 8.5 gig texture uncompressed? TBH I have not tried baking textures that large and I don't know if Unity can handle it.

    If you want to bake these 3 textures into a smaller atlas texture 8k or lower then Mesh Baker should be able to do that. How big are the meshes? Unity can handle meshes larger than 64k vertices but I have found these very slow to bake.
     
  7. lucidvyu

    lucidvyu

    Joined:
    Feb 29, 2020
    Posts:
    4
    Hi Ian

    I am using meshBaker to create the atlas at runtime using:=>

    Code (CSharp):
    1. textureBaker.textureBakeResults = ScriptableObject.CreateInstance<MB2_TextureBakeResults>();
    2. textureBaker.resultMaterial = new Material(Shader.Find("Universal Render Pipeline/Simple Lit"));
    3. textureBaker.objsToMesh = goToCombineList;
    4. textureBaker.CreateAtlases();
    5. meshBaker.ClearMesh();
    6. meshBaker.textureBakeResults = textureBaker.textureBakeResults;
    7. meshBaker.AddDeleteGameObjects(textureBaker.GetObjectsToCombine().ToArray(), null, true);
    8. meshBaker.Apply();
    and setting "MeshBaker texture packer fast" in the editor.

    This creates texture atlas and a combined mesh correctly. But the non-texture properties are not set correctly. I tried creating the MeshBlender for URP/SimpleLit shader, "MeshBlenderSimpleLit" as instructed in the manual. I did this by copying MeshBlenderStandardSpecular and changing keywords such as "_baseColor".
    But this is not combining the colors into a texture atlas. I have attached the script.

    Can you please have a look at the MeshBlenderSimpleLit and suggest ways to improve it?
     

    Attached Files:

  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I will take a look and report back. Note that it is not always possible for the texture blenders to work for all shaders. It depends on how simple/complex the blending in the shader is. Which version of Unity are you using? Also which rendering pipeline? If you are using a "Lit" shader then I presume this is not the default render pipeline.


    BTW: If you are not using the default render pipeline than I am surprised to hear that you were able to get the texture combiner fast to work. I am working on a new version ATM that should work with all three pipelines.
     
  9. lucidvyu

    lucidvyu

    Joined:
    Feb 29, 2020
    Posts:
    4
    Unity 2019.3.2f1, rendering pipeline URP 7.1.8, the shader is Simple Lit.

    We are able to combine the meshes and textures at runtime using mesh baker. The current roadblock is figuring out how to store non-texture property "_BaseColor" into the texture. One workaround for this problem(which avoids meshblenders) is sorting Gameobjects based on the base color they have. forex. grouping all GameObjects with "_BaseColor" = RGBA(1,1,1,1) into a array and running textureBaker+Meshbaker. This is working for us.

    We would really appreciate it if you can help us with correcting the MeshBlenderSimpleLit.
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I had a look, the TextureBlender was almost correct. You need to change the line 63:

    public void OnBeforeTintTexture(Material sourceMat, string shaderTexturePropertyName)
    {
    if (shaderTexturePropertyName.Equals("_MainTex"))
    {
    propertyToDo = Prop.doColor;
    if (sourceMat.HasProperty("_BaseColor"))
    {

    To:

    public void OnBeforeTintTexture(Material sourceMat, string shaderTexturePropertyName)
    {
    if (shaderTexturePropertyName.Equals("_BaseMap"))
    {
    propertyToDo = Prop.doColor;
    if (sourceMat.HasProperty("_BaseColor"))
    {

    There is another problem though. The "BlendNonTextureProperties" won't tint the textures when using "TexturePacker -> MeshBakerCombinerFast" (it works with "TexturePacker -> MeshBaker"). There is a warning about this in the console, but it is easy to not notice. I think I will switch this warning to an error message.
     
  11. jtok4j

    jtok4j

    Joined:
    Dec 6, 2013
    Posts:
    322
    Greetings,
    Have used Mesh Baker for about 5 years now. It's great stuff!

    I have a query, to see you might have insight on what's going on here:

    Added a TextureBaker/Meshbaker object to the scene, selected a nested group of objects, (only static objects) and ran the texturebaker/mesh baker on them, turning them into the prefab option. No errors. Turning off the original below:

    upload_2020-3-7_21-16-13.png

    and putting in/turning on the resulting mesh/prefab
    Reveals This:

    upload_2020-3-7_21-20-22.png

    Note that the green crystals and the huge rock (white color above) are both a part of the replaced nested group of objects, which was run through Mesh Baker.
    Everything is now one mesh, which is great. The green crystals are looking normal/correct texture, but the rock is a blazing white texture...

    Any idea what I might be setting wrong?

    Notes: Using an Atlas, with max size of 4096, single item size limit 1024,
    using multiple atlases option if it's too much for a single atlas.


    Here are my settings to get this result.

    upload_2020-3-7_21-25-43.png

    upload_2020-3-7_21-26-14.png
    and

    upload_2020-3-7_21-24-18.png
     
  12. jtok4j

    jtok4j

    Joined:
    Dec 6, 2013
    Posts:
    322
    Furthermore to the above post, I'd note that this is the resulting Atlas, for the above single mesh, and I believe this looks to be accurate. (One atlas below is set to be the Albedo for the Mesh)
    upload_2020-3-7_21-29-9.png
     
  13. jtok4j

    jtok4j

    Joined:
    Dec 6, 2013
    Posts:
    322
    Hmmm, another questions arises. Does TextureBaker have the ability to bake tree textures into one material, for use with trees generated through unity terrains? I've got trees on the terrain, not individually places, but are part of the Unity Terrain, and I wonder if I can combine their original model materials with TextureBaker into one and see a performance increase?
     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I am not sure what the problem is, but I would suggest looking at the following to debug the issues:

    1) What does the combined material look like, (did the shader change? Is there a detail texture)?
    2) If you are using the standard shader, are you mixing transparent/unlit objects with opaque objects?
    3) Are there any channels (like emission) that the source rock was not using that are present on the combined rock?
    4) The albedo atlas looks correct. Have you tried experimenting with the combined material to set all the other settings on the material the same as the source material? This will probably destroy what the crystals look like, but it may provide insight about where the bright white color is coming from.
    5) Was the shader used by the source rocks using vertex colors or a detail texture. (Did the rocks use a mesh channel that has not been included)?
    6) The atlas probably includes an Alpha channel. Did the textures used by the source rocks have an alpha channel? If not, try setting the format of the atlas to RGB instead of ARGB and re-import the atlas texture. See if that could be fix the issue.

    Would love to know what you discover.
     
    jtok4j likes this.
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    You can likely combine the tree textures. The problem with trees is usually tiling. Often leaf and bark textures are tiled 20+ times. Baking this tiling into the atlas can waste a lot of space and be downscaled. If you can combine the materials you should see a performance boost if the trees share an atlas. Here is a tutorial video explaining how to deal with tiling issues.

     
    jtok4j likes this.
  16. Volkerku

    Volkerku

    Joined:
    Nov 23, 2016
    Posts:
    114
    I'm on Unity 2019.19
    I don't have the menu item GameObject -> Create Other -> Mesh Baker -> TextureBaker & MeshBaker
    showing up. Not even the Create Other item?
     
  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Are there any error messages in the Console? If there are any compile errors in the project then these won't show up until the project can compile.
     
  18. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Hi! Have you had a chance to take a look at disabling generation of additional bones on merging of traditional meshes to a skinned one since we last discussed it? :)

     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Thanks for nudging me on this. I have not worked on this, but will try to prioritize this for the next release.
     
    bac9-flcl likes this.
  20. code749

    code749

    Joined:
    Jan 17, 2009
    Posts:
    100
    do you have any updated tutorials? I would like to purchase but the tutorials are 5 years old and I am sure much of the workflow and UI has been changed /streamlined?

    thank you
     
  21. NotQuiteSmith

    NotQuiteSmith

    Joined:
    Oct 27, 2013
    Posts:
    92
    From the documentation it looks like I should be able to use meshbaker to group objects into a scene, then use lightmapping on the combined object. However I try it the baking never works (lots of black areas). Is there a particular workflow? I disabled the original renderers, made mesh object static, set lightmapping UVs to various options, etc.
     
    Last edited: Apr 11, 2020
  22. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    If you want to bake the lightmaps on the combined mesh you need to use one of the lightmapping options:

    1) Generate new UV2 layout
    2) Copy UV2 to separate rects

    The other options won't work. Even using these options, you may still get spots if the texel density is not high enough. Imagine two UV islands on the lightmap. If the pixels/texels in the lightmap are too big they can span the gap between the UV islands and the lighting of that pixel/texel gets applied to two different meshes (blotches). This can be fixed by increasing the "Pack Margin" in the lightmap settings. You should be able to see this happening when you look a the lightmap in the Light Settings and select meshes in the scene so that you can see the UV2s overlayed on the lightmap.
     
    Last edited: Apr 12, 2020
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I do not have newer videos at this time. I keep planning to make some but it is a moving target since I have plans to add more features which will change the UI yet again.

    I am reluctant to make videos right now, because Unity has just introduced DOTS/ECS which is a MASSIVE change (essentially a new game engine). Over the next six months I am expecting a lot of changes to mesh baker to take advantage of the DOTS/ECS tech which will likely result in major changes to some of the workflows. My intention is to make a new set of videos once that is in place.
     
  24. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Hi, Phong, I have some bricks on the floor, and all the bricks and walls are bake together.
    When there is a light, the light project onto floor cross the wall.
    The light won't be blocked even if the combine result is one mesh.
    What should I do to make the light correct?
    Any advice would be appreciated.Thanks!:)
    brick.png
     
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hello, lighting in video games uses a wide variety of "tricks/techniques" to create the illusion of light and shadows. The "tricks/techniques" that are being used depends on:

    • The version of Unity
    • Build platform
    • Shaders
    • Rendering pipeline
    • Whether or not objects and lights are static
    The shaders need to support whatever lighting/shadow technique you are using.

    I can answer your questions better if you let me know what you are using. Looking at your scene, it looks like you are trying to light static geometry (none of the walls and floor will move and the light doesn't move). Is this the case? You will get the best quality lighting if you use Baked Lightmaps and lightprobes.
    • Mark the geometry as static
    • Mark the light as mixed or baked
    • Make sure meshes are imported with valid UV2 channel (either imported or generated by the importer)
      • If your mesh is combined, then make sure you are using one of:
        • LIghtmap UVs = Generate New UV2 Layout
        • LIghtmap UVs = Copy UV2 To Separate Rects
    • Bake lightmaps
    • You can even add lightprobes to get beautifull lighting on your characters as they wander through your rooms.
    Note this this only works for static lights and geometry. If this is dynamic lights and geometry then you need to use different techniques.
     
  26. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    128
    Hey, I'm looking for the solution for runtime mesh baking for DOTS project. Documentation for MeshBaker has only an example with GameObjects workflow. Is there some API accessible under the hood which I can supply with just raw meshes/transforms? Are there any benchmarks or at least hints on the runtime performance for 100k+ simple meshes?
     
  27. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Thanks for your detailded reply Phong!
    I'm using Unity 2019.3f.
    Building platform is windows.
    The shader is https://github.com/unity3d-jp/UnityChanToonShaderVer2_Project,
    Univeral Render Pipeline.
    And the lights are dynamic spot lights.
    In my case I hope the combined mesh could block this light so that the yellow area is in darkness.
    block.png
     
  28. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    128
    I've tried the free version and I'm confused. 8 cubes next to each other, 8 vertices per cube = 64 total. Baked into, well, 64 vertices big cube with inner polys. I expected it to be a 26 vertices optimized mesh. Otherwise what's the point of baking?
    chrome_6b9w10A8Iq.png
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Not yet. DOTS/ECS is high on my priority list, I have been holding out until there is a clearer picture what the DOTS animation system siwll look like. It will be challenging since a big part of Mesh Baker is skinned meshes and supporting animated meshes and those are currently completely dependent on the Transform hierarchy. The DOTs animation package seems to be pre-preview ATM.

    You might be able to do what you want using Mesh.CombineMeshes. It has an API that take a list of meshes and transforms.
     
  30. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Mesh Baker does not attempt to remove inner faces. The main advantage to baking is "draw call optimization". The way that modern GPUs work, a very common rendering bottleneck is too many drawcalls. Mesh Baker helps create renderers that share materials and to combine meshes that are close together. This helps the GPU operate much more efficiently.
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hmmm, are you sure that shader is compatible with the URP? There is an "issue" in github requesting HDRP/URP support for that shader.

    The usual way to get this to work is to configure the MeshRenderer to cast and receive shadows, and to configure the light to cast shadows. Also you need to ensure that shadows is configured in the Quality settings.

    Note that the shader needs to be written to support shadows and that the URP shader framework is completely different from the default-pipeline shader framework. I am not sure if a shader that works with the default-pipeline shadow system will work with the URP shadow system. I would test this by temporarily switching to the "Lit" shader to see if the shadows work. If they do, then your problem is shader-URP-conflict.

    If this is static geometry then I would recommend using baked lightmaps. The will create the best looking shadows.
     
  32. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    There is a URP dev branch on github.
    And I also tried in default-pipeline.I tried LIghtmap UVs bake setting.This works with "Generate New UV2 Layout" and the strength of light shadow should be 1.
    There's a IndexOutOfRangeException while using "Copy UV2 To Separate Rects".
    Besides, how to check if the model has valid UV2 channel? Thanks again for your patience;)
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Re: Index out of range error. Your source mesh probably does not have aUV2 channel. If you select the "Mesh" asset in your project, (it is probably part of a .fbx or .blend file). You can see the channels listed in the "preview pane". In the Mesh Importer Inspector your can tell it to generate lightmap UVs. You can also add them yourself in your modeler and they should get imported:

    Are you happy with the baked light solution?

    upload_2020-4-15_9-35-35.png
     
  34. CF-Games

    CF-Games

    Joined:
    Jun 2, 2013
    Posts:
    134
    Hello,

    I have been looking for an asset that can create texture atlases from multiple models and still keep those models separate. Like if I have 10 door models each with their own separate textures and materials, can Mesh Baker be used to combine those textures so they can all share one material but still have each of the door models be separate models?

    I'm currently doing this manually in Blender, but it takes a lot of time.
     
    Last edited: Apr 15, 2020
  35. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    The light block problem seems solved.:)
    GIF12.gif block1.png
    Maybe I made some mistakes on bake setting, the texture become unstable.
    I think it's related to transform scale or something else.
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Yes, Mesh Baker does this with the Batch Prefab Baker component. You give it a collection of source prefabs containing renderers. It can create a texture atlas for those renderers and then creates duplicate prefabs with meshes that have adjusted UVs that use the texture atlas. You can use these prefabs instead of the original prefabs.

     
  37. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I am not sure what you mean by "the texture become unstable"? Can you elaborate?
     
  38. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Just like the first gif I uploaded. when view direction is changed, the texture on same face will also change.
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Ahhh, I think this is z-fighting. Did you disable the "source" renderer? I think you have two renderer's exactly on top of each other.
     
  40. code749

    code749

    Joined:
    Jan 17, 2009
    Posts:
    100
    would there be a way to edit the texture atlas once its baked? what if some of the textures are taking up more space then what they need ?

    thank you
     
  41. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    40
    I have been working with Mesh Baker for years. My workflow to this point has been to bake the textures in the editor, then bake the meshes into a skinned mesh at runtime.
    I would like to move to baking the meshes into a prefab.
    I have been able to do this and all the bones and animations are intact in the prefab.
    Moving the source bones does move the piece of the skinned mesh.

    But I am unable to use the runtime commands of Mesh Baker.
    Such as Show/Hide or Add/Delete and then Apply.

    Is there some way to reconnect the baked skinned mesh to Mesh Baker so that I can use these functions to add/remove/show/hide source objects from the baked skinned mesh?

    My workaround is to scale the bone object to 0 to hide it, back to its original scale to show it, but I am not sure if that has the same performance implications as hiding/deleting the source object from the skinned mesh.

    Thanks!

    -mat
     
  42. hertz-rat

    hertz-rat

    Joined:
    Nov 3, 2019
    Posts:
    71
    Since this is a performance improvement tool, are there performance comparisons or benchmarks available somewhere?
     
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    It is hard to edit the atlas because, the "rectangles" are stored in the Material Bake Result asset. You would need to update the values in that asset to make this works. It is probably easier to change the "maximum size" of the source texture in the Texture Importer Inspector and re-bake the atlas.
     
  44. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Mat, this is a tricky problem. Mesh Baker stores references to the source game objects as "keys" to map to parts of the combined mesh. These references are lost when the prefab is saved as an asset and the Mesh Baker component is not included. This should be able to fix the references doing this.

    Find the method "MB3_MeshBakerEditorFunctions.cs._MoveBonesToCombinedMeshPrefabAndDeleteRenderers"
    • Modify it so that it does NOT delete the renderers. Instead it should disable the renderers.

    • Do your initial bake using "clear buffers after bake" = unchecked
    • Drag the "MeshBaker" that was used to create the combined mesh into the "combined mesh Prefab" so that it is part of the combined mesh.
    • Open the Prefab in "prefab edit" mode.
      • Select the MB3_MeshBaker and switch the inspector to "debug" mode so you can see hidden fields.
      • In the inspector look for the List "MB3_MeshBaker.MeshCombiner.mbDynamicObjectsInCombinedMesh"
        • Each entry in this list should have a "GameObject" field. These will be "null". The references were broken when the the prefab was first saved as an asset and the Mesh Baker component was not a part of that asset. Find each source SkinnedMeshRenderer in the prefab and drag it to the correct field. These should be in the same order that that they were originally baked in. Also you can use the "name" field to figure out which original source instance corresponds to each baked instance.
    • Save the prefab.
    You should be able to do Apply, AddDelete now.
     
  45. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    No, I don't have published benchmarks. The problem is that performance improvement will very immensely depending on:
    • Build platform
    • Target device
    • Pipeline
    • How the original scene is set up (number of renderers, shaders used, number of materials used, lighting techniques used, baking settings, shadow settings, static settings, LOD settings, occlusion settings etc...)
    • How the baking is done (how meshes are combined/ draw calls batched)
    The performance improvement is based on "draw call optimization". It is even possible that draw calls are not a bottleneck for your game and there will be no performance improvement. If I post benchmarks then customers will demand to know why they are not seeing the improvement described in the bechmarks in "their" scene. Mesh Baker strives to be a very flexible set of tools that are useful for analyzing scenes, reducing the number of textures/materials used and combining meshes. These operations are generally useful for optimizing games but how useful they are depends on the situation.
     
    hertz-rat likes this.
  46. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    40
    This is exactly what I am looking for, thanks!
    It is not quite working yet.

    I have followed these instructions and I have added the GameObjects to the mbDynamicObjectsInCombinedMesh area of the MeshBaker script will editing the prefab in inspector debug mode. It all looks good.
    But then when I run it and call:

    Code (CSharp):
    1.  mbd3P.AddDeleteGameObjects(null, objsToSkin.ToArray(), true);
    2. mbd3P.Apply();
    to delete a few game objects, i get an error:

    ArgumentException: An item with the same key has already been added. Key: DigitalOpus.MB.Core.MB3_MeshCombinerSingle+BoneAndBindpose

    Which happens in the function BuildBoneIdx2DGOMapIfNecessary.
    Which is called to build a map between bones and gameobjects according to this comment:
    //in order to decide if a bone can be deleted need to know which dgos use it so build a map

    But building that map falls as if it is already built and unnecessary.
    When I manually add the GameObjects to the dynamicGameObject list, is that creating the map? And if so, do I need to tell the script, maybe a flag of something, that the map is already built?

    Thanks,
    -mat
     
  47. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    The map should not be built. It is not serialized so each bake operation will start with an empty map and fill it. One possibility is that one source renderer was assigned more than once (to different dgos). Then the bones for that renderer would get added twice to the map and could generate this error.

    Is there any chance you could send me a simple repo-project with your skinned mesh baking scene (PM or email)? I would be interested in taking a look a this.
     
  48. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    40
    Yeah, I will build a simple repo project. I think that the ability to bake a skinned mesh in the editor and then add/delete and show/hide bones based on source objects at runtime is a game changer feature for me.

    Before I put in the time to create that project I tried to get some more info, in case you can suggest a fix without the project...

    Code (CSharp):
    1.                  
    2. int updated = 0;
    3. int initialCount = bone2idx.Count;
    4. for (int i = 0; i < combiner.bones.Length; i++)
    5.                     {
    6.                         BoneAndBindpose bn = new BoneAndBindpose(combiner.bones[i], combiner.bindPoses[i]);
    7.                         if(bone2idx.ContainsKey(bn)) {
    8.                             bone2idx[bn] = i;
    9.                             updated++;
    10.                         } else {
    11.                             bone2idx.Add(bn, i);
    12.                         }
    13.                     }
    14. Debug.Log("Bone Index InitialLength: " + initialCount.ToString() + " FinalLength: " + bone2idx.Count + " Updated: " + updated);
    15.  
    Sorry, somehow posted before I was done typing...

    I added the above code to see a bit of what is going on. And I get a print of:
    Bone Index InitialLength: 0 FinalLength: 22 Updated: 33

    So there are 55 combiner bones, but only 22 of them are unique, then there appear to be 33 duplicates.

    Does this shed any light on it? Is there a way I can tell in the MeshBaker script in Debug inspector how many bones there are supposed to be in that index?

    Thanks, and I am still planning on sending you a repro project.
    -mat
     
  49. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    40
    bones55.png

    That is what I see for the Bones list in the debug inspector, 55 bones all of which are None.
    Maybe I need to set that to the number of source objects I have?
     
  50. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    40
    I emailed you a project that reproduces the issue.

    I am about to try baking the same skinned mesh at runtime and comparing the values in the mesh baker instance to the ones in the prefab baked in the editor.