Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Mesh Baker by Digital Opus [RELEASED]

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

  1. Fortunato1

    Fortunato1

    Joined:
    Jul 28, 2013
    Posts:
    26
    Hello, I need to create a texture atlas for certain models, but I don't actually want to combine these models; I just want them to share the same texture. At the moment, I can create an atlas using "TextureBaker", then deselect the "Same as Texture Baker" option in the "MeshBaker" component, and bake each mesh individually. However, with the large number of meshes, this process is quite tedious. I've tried modifying your scripts to add a function like "Create Separate Meshes With one Atlas From TextureBakerResults", but I'm struggling due to the complexity of your scripts. Could you provide guidance on how I might have the capability to create copies of objects without combining them, so that they simply use the material and texture (atlas) generated by the "TextureBaker" component?

    I've emailed you. I would appreciate it if you could help with this matter.

    It would be great to have a separate option for creating an atlas for specified meshes, where they don't get combined but just duplicate objects are created with a shared atlas.
     
  2. Rewaken

    Rewaken

    Joined:
    Mar 24, 2015
    Posts:
    128
    @Phong I'm trying to bake a skinmesh but getting following error

    Index was outside the bounds of the array.
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle+MB_MeshCombinerSimpleBonesNewAPI._CollectBonesToAddForDGO_Pass2 (DigitalOpus.MB.Core.MB3_MeshCombinerSingle+MB_DynamicGameObject dgo, System.Boolean noExtraBonesForMeshRenderers) [0x000ff] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimpleBonesNewAPI.cs:468
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle+MB_MeshCombinerSimpleBonesNewAPI._CollectSkinningDataForDGOsInCombinedMesh (System.Collections.Generic.List`1[T] dgosAdding, System.Collections.Generic.List`1[T] dgosInCombinedMesh, DigitalOpus.MB.Core.MB3_MeshCombinerSingle+MeshChannelsCache meshChannelsCache) [0x00017] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimpleBonesNewAPI.cs:572
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle+MB_MeshCombinerSimpleBonesNewAPI.AllocateAndSetupSMRDataStructures (System.Collections.Generic.List`1[T] dgosToAdd, System.Collections.Generic.List`1[T] dgosInCombinedMesh, System.Int32 newVertSize) [0x0002c] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimpleBonesNewAPI.cs:115
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle+MB3_MeshCombinerSimpleSubCombinerLegacy._AddToCombined (DigitalOpus.MB.Core.MB3_MeshCombinerSingle c, System.Int32 totalAddVerts, System.Int32 totalDeleteVerts, System.Int32 numResultMats, System.Int32 totalAddBlendShapes, System.Int32 totalDeleteBlendShapes, System.Int32[] totalAddSubmeshTris, System.Int32[] totalDeleteSubmeshTris, System.Int32[] _goToDelete, System.Collections.Generic.List`1[T] toAddDGOs, UnityEngine.GameObject[] _goToAdd, DigitalOpus.MB.Core.MB3_MeshCombinerSingle+UVAdjuster_Atlas uvAdjuster, System.Diagnostics.Stopwatch sw) [0x0004a] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimpleSubCombinerLegacy.cs:950
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.__AddToCombined (UnityEngine.GameObject[] _goToAdd, System.Int32[] _goToDelete, System.Boolean disableRendererInSource, System.Int32 numResultMats, System.Collections.Specialized.OrderedDictionary sourceMats2submeshIdx_map, System.Diagnostics.Stopwatch sw) [0x0079e] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:764
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle._AddToCombined (UnityEngine.GameObject[] goToAdd, System.Int32[] goToDelete, System.Boolean disableRendererInSource) [0x00278] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:534
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.AddDeleteGameObjectsByID (UnityEngine.GameObject[] gos, System.Int32[] deleteGOinstanceIDs, System.Boolean disableRendererInSource) [0x00148] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:1073
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.AddDeleteGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject[] deleteGOs, System.Boolean disableRendererInSource) [0x0004f] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:1007
    at MB3_MeshBaker.AddDeleteGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject[] deleteGOs, System.Boolean disableRendererInSource) [0x00021] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\MB3_MeshBaker.cs:44
    at MB3_MeshBakerEditorFunctions._BakeIntoCombinedSceneObject (MB3_MeshBakerCommon mom, System.Boolean createdDummyTextureBakeResults, UnityEditor.SerializedObject& so) [0x00006] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\Editor\core\MB3_MeshBakerEditorFunctions.cs:158
    at MB3_MeshBakerEditorFunctions.BakeIntoCombined (MB3_MeshBakerCommon mom, System.Boolean& createdDummyTextureBakeResults, UnityEditor.SerializedObject& so) [0x001bf] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\Editor\core\MB3_MeshBakerEditorFunctions.cs:143
    at DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal.bake (MB3_MeshBakerCommon mom, UnityEditor.SerializedObject& so) [0x0001f] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\Editor\MB3_MeshBakerEditorInternal.cs:597
    UnityEngine.Debug:LogError (object)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:bake (MB3_MeshBakerCommon,UnityEditor.SerializedObject&) (at Assets/_Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:626)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:bake (MB3_MeshBakerCommon) (at Assets/_Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:551)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:DrawGUI (UnityEditor.SerializedObject,MB3_MeshBakerCommon,UnityEngine.Object[],System.Type) (at Assets/_Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:509)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:OnInspectorGUI (UnityEditor.SerializedObject,MB3_MeshBakerCommon,UnityEngine.Object[],System.Type) (at Assets/_Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:157)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditor:OnInspectorGUI () (at Assets/_Assets/MeshBaker/Editor/MB3_MeshBakerEditor.cs:99)
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
     
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Hi talharing, I have run into this issue when there are AssetPostProcessor's in the project. There are other reports of similar problems: https://forum.unity.com/threads/unity-made-full-project-reimport-on-every-small-change.1066844/ it may be that another Asset Store package or Unity Package has an asset post processor.

    I did some digging and discovered that Unity now has an "Import Activity Window".

    https://docs.unity3d.com/Manual/ImportActivityWindow.html

    I would check this window after one of the big imports. It is normal for the textures involved in the bake to require a reimport. If there are other textures being imported I would check this window to see what the reason is. Please reply here as I would very much like to know why this is happening too.
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    It sounds like you want to use the Batch Prefab Baker:
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    I am looking at the code trying to figure out how this can happen. Can you send a screenshot of the Mesh Baker Settings? Are you using the "No Extra Bones For Mesh Renderers" feature?
     
  6. Rewaken

    Rewaken

    Joined:
    Mar 24, 2015
    Posts:
    128
    upload_2023-8-24_10-57-27.png
    If No extra bone property is selected it gives following error

    Object reference not set to an instance of an object
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle+MB_MeshCombinerSimpleBonesNewAPI.GetCachedSMRMeshData (DigitalOpus.MB.Core.MB3_MeshCombinerSingle+MB_DynamicGameObject dgo) [0x0015a] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimpleBonesNewAPI.cs:103
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.__AddToCombined (UnityEngine.GameObject[] _goToAdd, System.Int32[] _goToDelete, System.Boolean disableRendererInSource, System.Int32 numResultMats, System.Collections.Specialized.OrderedDictionary sourceMats2submeshIdx_map, System.Diagnostics.Stopwatch sw) [0x005a1] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:724
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle._AddToCombined (UnityEngine.GameObject[] goToAdd, System.Int32[] goToDelete, System.Boolean disableRendererInSource) [0x00278] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:534
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.AddDeleteGameObjectsByID (UnityEngine.GameObject[] gos, System.Int32[] deleteGOinstanceIDs, System.Boolean disableRendererInSource) [0x00148] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:1073
    at DigitalOpus.MB.Core.MB3_MeshCombinerSingle.AddDeleteGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject[] deleteGOs, System.Boolean disableRendererInSource) [0x0004f] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\core\MB3_MeshCombinerSimple.cs:1007
    at MB3_MeshBaker.AddDeleteGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject[] deleteGOs, System.Boolean disableRendererInSource) [0x00021] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\scripts\MB3_MeshBaker.cs:44
    at MB3_MeshBakerEditorFunctions._BakeIntoCombinedSceneObject (MB3_MeshBakerCommon mom, System.Boolean createdDummyTextureBakeResults, UnityEditor.SerializedObject& so) [0x00006] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\Editor\core\MB3_MeshBakerEditorFunctions.cs:158
    at MB3_MeshBakerEditorFunctions.BakeIntoCombined (MB3_MeshBakerCommon mom, System.Boolean& createdDummyTextureBakeResults, UnityEditor.SerializedObject& so) [0x001bf] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\Editor\core\MB3_MeshBakerEditorFunctions.cs:143
    at DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal.bake (MB3_MeshBakerCommon mom, UnityEditor.SerializedObject& so) [0x0001f] in D:\Unity Projects\Project Prison\Assets\_Assets\MeshBaker\Editor\MB3_MeshBakerEditorInternal.cs:597
    UnityEngine.Debug:LogError (object)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:bake (MB3_MeshBakerCommon,UnityEditor.SerializedObject&) (at Assets/_Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:626)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:bake (MB3_MeshBakerCommon) (at Assets/_Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:551)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:DrawGUI (UnityEditor.SerializedObject,MB3_MeshBakerCommon,UnityEngine.Object[],System.Type) (at Assets/_Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:509)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditorInternal:OnInspectorGUI (UnityEditor.SerializedObject,MB3_MeshBakerCommon,UnityEngine.Object[],System.Type) (at Assets/_Assets/MeshBaker/Editor/MB3_MeshBakerEditorInternal.cs:157)
    DigitalOpus.MB.MBEditor.MB3_MeshBakerEditor:OnInspectorGUI () (at Assets/_Assets/MeshBaker/Editor/MB3_MeshBakerEditor.cs:99)
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
     
  7. shadow_tm

    shadow_tm

    Joined:
    Jul 2, 2014
    Posts:
    13
    Hi!
    I want a combine and instantiate mesh from a prefab that is not on stage in run time.

    Here is my code


    Code (CSharp):
    1. public class RealtimeBaker : MonoBehaviour
    2. {
    3.     public GameObject ModelPrefab;
    4.  
    5.     MB3_MeshCombiner combiner = new MB3_MeshCombinerSingle();
    6.    
    7.     void Start()
    8.     {
    9.         combiner.name = "Character";
    10.         combiner.settings.renderType = MB_RenderType.skinnedMeshRenderer;
    11.         combiner.settings.clearBuffersAfterBake = true;
    12.  
    13.         var parts = new List<GameObject>();
    14.         GetParts(ModelPrefab.transform, parts);
    15.         combiner.AddDeleteGameObjects(parts.ToArray(), null, false);
    16.         combiner.Apply();
    17. }
    18.  
    19.  
    20. public void GetParts(Transform root, List<GameObject> parts)
    21.     {
    22.         var renderer = root.GetComponent<SkinnedMeshRenderer>();
    23.         if (renderer != null)
    24.             parts.Add(root.gameObject);
    25.  
    26.         foreach (var child in root)
    27.             GetParts(child as Transform, parts);
    28.     }
    29. }
    The model will be created and appear on the scene, the model has no animator, animation and no skeleton. Even when I add the animator and skeleton manually, there is no animation.

    upload_2023-8-24_19-50-0.png

    Tell me what I'm doing wrong?
     
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Are there any errors or warnings in the console? Does a new gameobject get created with SkinnedMeshRenderer attached? If so then the bake probably went properly. I would suggest setting the combiner.LOG_LEVEL to "debug". Then you should be able to verify that several meshes were indeed combined.

    It is normal for a baked combined mesh to have no Animator, Animation or skeleton. This is because it shares the bones (skeleton of the original source mesh). Whatever is animating the bones of the source meshes (Animator, scripts, IK, physics) will deform the combined mesh.

    After bake you should have a setup something like this:

    • MySourcePrefabInstance (probably has Animator)
      • BodyPart1 (has SkinnedMeshRenderer)
      • BodyPart2 (has SkinnedMeshRenderer)
      • SkeletonBasePivot
        • Hips (likely has collider, possibly rigidbody and/or scripts)
          • ... more bones
    • CombinedMesh-MeshBaker0
      • CombinedSkinnedMeshRenderer
    You need to leave the original "MySourcePrefabInstance" enabled. The only thing that should be disabled is the source renderer components. Also the Animator may not animate unless the culling settings are set to "always animate" or you move the CombinedSkinnedMeshRenderer in the hierarchy so that it is a child of MySourcePrefabInstance.

    I would suggest watching this video for more information about combining SkinnedMeshRenderers.

     
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Hi Reawaken,

    I am not able to reproduce the "index out of bounds" error. Would it be possible to share the scene so that I can debug the issue (please contact me at contact.digitalopus@gmail.com if so)?

    I can reproduce the "Object reference not set to an instance of an object" and am working on a fix.
     
  10. Rewaken

    Rewaken

    Joined:
    Mar 24, 2015
    Posts:
    128
    Thanks, I've attached sample project and my invoice with mail.
     
    Phong likes this.
  11. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Can I create a texture atlas using texture baker, and remap UVs, without combining meshes?

    Ah it seems this might be it, ill check it:

     
  12. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    @Phong Greetings! I bought Mesh Baker yesterday to optimize a large city scene. I'm struggling to bake a large number of assets.

    To give you a better understanding of what's happening, here's a short video of my steps:
    https://www.loom.com/share/4ca2d3bb808543f6aaf978a5e54ff871?sid=63075d7f-fd09-43fc-af9b-5207c80fe26e

    You'll see some of the objects apparently aren't baked into the new meshes.

    I followed the video tutorials provided, but unfortunately, I have been unable to see where I am going wrong.

    Can you please point me in the right direction?
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Hi Colin, I watched your video. I would suggest a couple of things.

    1) Before your click the "Bake All Mesh Bakers In Scene", you want to bake the Texture Bakers to generate atlases. You will want to do this baker-by-baker since the different bakers will likely need different settings. My mini-workflow for each Texture Baker is:
    • Clear the console.
    • Press "Bake Textures Into Atlases". Look at the generated atlases and check the console for errors. Tweak settings and repeat until the atlases look good.
      • Common problems:
        • If your textures are a power of two and there is a lot of extra space in the atlas, try "Resize Power Of Two Textures"
        • If your meshes have tiling using UVs then choose "consider UVs"
        • If the tiling is extensive you might need to use the Multiple Materials feature (see tutorials about tiling and Multiple Materials)
        • If some materials are significantly different: eg: some have emission and others do not, then use the Multiple Materials feature
        • If some materials are troublesome then use the Multiple Materials feature to put them alone on their own submesh.
    • If the atlases look good. Then, on the MeshBakerGrouper component below the TextureBaker press: "Bake All Child Mesh Bakers" and "Disable All Renderers On Child Mesh Baker Source Objects"
    • Compare the result to the source meshes. Check the console for errors.
    • Tweak the settings in the TextureBakers and/or the MeshBakers until the results are good.
    It is also likely that for some of the TextureBakers, the meshes are scattered in different parts of the scene. It is not good to combine meshes that will rarely appear on screen together because this pumps your tri and verts count (more work for the GPU). After you have created a good set of atlases and have good Mesh Baker settings, it is a good idea to use the MeshBakerGrouper (attached to each TextureBaker), to group meshes that are close together. See the tutorial video for this.
     
  14. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Sorry, I fell at almost the first hurdle. I've looked at the Texture Baker code and watched the Texture Baker video again, and can't see this button/command "Bake Textures Into Atlases" anywhere.

    I even searched every file on the filesystem for this string but came up blank.

    Do you mean "Bake Materials Into Combined Material"?

    upload_2023-9-21_13-57-37.png
     

    Attached Files:

  15. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    @Phong When I press "Bake Materials Into Combined Material" on the first texture baker, it generates and I can play around with it.

    On the second there is an error:

    There is a similar error on all the texture bakers apart from the first one.
     
    Last edited: Sep 21, 2023
  16. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    It seems logical you did mean "Bake Materials into Combined Material." Still, the error has me stumped for now; why are there materials not included? Shouldn't the "Generate Baker" stage have set that up?

    I'm really not sure what to do at this point.
     
  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Hi Colin, Yes, the "Bake Materials into Combined Material" is the name of the button. The reason that the "Generate Bakers" button doesn't bake the textures is because the texture baking is much slower than the mesh baking and usually requires visiting each Texture Baker to check the settings. The Mesh Baker settings are less finicky.
     
  18. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    @Phong Ah, sorry I was referring to something else. You didn't get my previous message - I guess the forum didn't like the Japanese chars.

    Here it is in image form:

    upload_2023-9-22_10-40-37.png

    Any idea what this error message is about?
     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Hi Colin, the Multiple Materials feature has a fairly complex setup. There is a complete tutorial on it:



    [Sorry, originally I posted the wrong video.]

    The "Generate Bakers" doesn't set up the multiple materials automatically for you. Each Texture Baker has a button: "Build Source To Combined Mapping From Objects To Be Combined" that can be used to generate a multiple materials setup. It is usually best to review this setup before using it.
     
    Last edited: Sep 23, 2023
    Colin_MacLeod likes this.
  20. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Ok. I’ll plow through it.
     
    Phong likes this.
  21. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    @Phong I had another go at this today, but it's still not where it needs to be.

    At first, I tried baking the whole city again using the "Build Source to Combined Mapping…"

    That didn't work, so I tried it on a simpler scene with a single building, albeit one with a lot of emissive materials.

    Here's what I tried (you might want to run it at 2x speed!):


    As before, it appears to be missing materials.

    Do I need to manually go through the models and identify all the materials? Seems super laborious. Is there any way to speed this up?

    (Edit: I think I missed a step on the original video - but similar results in updated video above. I'll keep trying would appreciate any advice.)
     
    Last edited: Sep 29, 2023
  22. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Edit 2: I didn't click "Consider Mesh UVs" before - tried that just now and the results are about the same.

    I'm really stuck here. After a spot check of various materials, they do seem to be included. Why does the combined baked mesh appear to be missing parts of the model?
     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Hi Colin,

    This looks like a very complex model. It looks like there are over one hundred materials and a lot of meshes. At 3:47 of your video there are over 53 materials listed in the inspector and from the scrollbar it looks like many more.

    You will need to look very carefully at which materials are being grouped together and whether they will be compatible. Some of the materials have names like: Material_A, Material_A_Glass, Material_A_Glass_Transparent, Material_A_Glass_Transparent_Turquoise, Alpha_01. This looks like a mix of opaque materials and transparent materials. Unfortunately there is no standardized way for mesh baker to determine from a script what technique a shader is using for transparency. The materials that are using different transparency rendering techniques need to be grouped together. Opaque together, Transparent together, Alpha clipping together. For best results I would also group the emmissive material together. Also are the emissive materials on the top animated? If so what technique are they using? There could be a script setting a parameter on a custom shader. These materials are probably best put on your own submesh.

    I hate to say it but for very complex models like this you will need to manually edit the lists of source materials.
     
  24. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Ah, I see. Understood - thanks for the insight.

    Once I work out how to group the materials, It feels like I will need to write editor scripts to group objects based on the materials in some way, and then call Mesh Baker from those editor scripts.
     
    Phong likes this.
  25. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Is this asset in the Unity Asset Store? Could you post a link. I would like to tinker with it. Seeing use cases like this helps me improve Mesh Baker.
     
    Colin_MacLeod likes this.
  26. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Yes, certainly. That would be most excellent.

    I am using two assets from the same publisher:

    https://assetstore.unity.com/packages/3d/environments/sci-fi/cyberpunk-downtown-low-poly-200723 (that's this one)
    https://assetstore.unity.com/packages/3d/environments/sci-fi/cyberpunk-interior-low-poly-216244

    Originally, I reached out to the publisher for help via their Discord - they have recommended Mesh Baker (among other assets) to other users who were also having performance issues with the asset in the past. FWIW, one user in particular (Aaron Victoria) recommended Mesh Baker as the best choice.

    https://discord.com/channels/868038604612583424/868038604612583428
     
  27. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    (Note - I sent you a private message via a forum Conversation)
     
  28. YenCheng1978

    YenCheng1978

    Joined:
    Jul 25, 2021
    Posts:
    11
    Hi Phong

    There seems to be a problem with the display of TextureArray on Android

    We tested PICO and Oculus, using ASTC 6x6 compression format
    We have also tested other texture compression formats that can be used by Android, but there will still be differences in display.(See the attached picture for details)

    We're not sure what the problem is, so we've attached the test file and hope it can help. Thank you.

    https://drive.google.com/file/d/1Q2c53H4VOXG2pm4FS4eqt2dcB3u8Wrbl/view?usp=sharing
     

    Attached Files:

  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    It looks like the TextureArrays are darker.

    You should be able to view the texture arrays in the inspector in Unity. Do they look darker there too?

    What color space is your project using? Linear or gamma? I wonder if this could be a color space issue. Also have you tried comparing the textureArray vs regularTexture using a different shader to see if this could be a shader or material keyword difference?
     
  30. YenCheng1978

    YenCheng1978

    Joined:
    Jul 25, 2021
    Posts:
    11
    Specifically, everything looks fine in Unity, but when I package the APK and view it in VR, it appears quite strange. It's as if there's a strong layer of specular reflection covering the models. The appearance only comes close to what I see in Unity after I remove the Metallic and Normal maps.

    I'm using the shader you provided here: https://github.com/Phong13/BuiltinShadersTextureArrays

    Additionally, when I accidentally switch the view to 2D in Unity, I get a similar erroneous effect as I do in VR.
     

    Attached Files:

  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Do you have a Texture2DArray assigned to the normalmap and metallicglossmap that is in the right format for your target device. I wonder if it can't parse the texture2Darrays? Are they using the same format as the albedo texture array?

    I wonder if this could be the material keywords. Try enabling the _NORMALMAP and _METALLICGLOSSMAP on the material.

    renderer.sharedMaterial.EnableKeyword ("_NORMALMAP");
    renderer.sharedMaterial.EnableKeyword ("_METALLICGLOSSMAP");

    It may be that the code that detects if these maps are present doesn't work.

    Let me know if either of these solve it. If not then which VR device are you targeting? I can try to take a look.
     
  32. YenCheng1978

    YenCheng1978

    Joined:
    Jul 25, 2021
    Posts:
    11
    We tested PICO4 and Oculus2 (Mainly PICO4)
    I would be very grateful if you could help me test it ^^

    I will continue to test Shader myself to see if there is any improvement.
     
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    No promises, but I will try to get to this this week.
     
  34. YenCheng1978

    YenCheng1978

    Joined:
    Jul 25, 2021
    Posts:
    11
    OK, thanks ^^

    I tried to write a basic Standard, but it still didn't seem to work. It didn't feel like it was a problem with the Shader.


    I am more inclined to think that the issue is with the Android texture format. I would like to trouble you to try it again. Thank you.
     

    Attached Files:

  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Hope to have some time Thursday or Friday to look at this. Typically it is a problem with:
    • keywords, params
    • default colors
    Do you have a super simple test case? A couple of cubes with a material and some simple textures? If you do and you can share it that would help.

    Also what version of Unity are you using?
     
  36. YenCheng1978

    YenCheng1978

    Joined:
    Jul 25, 2021
    Posts:
    11
    This link provides a simple test content, which also includes screenshots of VR setup steps.^^
    https://drive.google.com/file/d/1Q2c53H4VOXG2pm4FS4eqt2dcB3u8Wrbl/view?usp=sharing

    We use Unity2021.3.19f1
     
    Phong likes this.
  37. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Hey @Phong, making progress with MeshBaker on the Cyberpunk scenes.

    I'm sure there's a lot more optimization to be done, but already the scenes feel a lot snappier. Thank you for all your help and patience!

    One thing, there are some video displays that use Render Textures via a special material, like this one:

    upload_2023-10-19_23-1-14.png

    In this case, the other two materials (Material_A and Emssion_Orange) have already been baked into an atlas.

    Is there any way I can tell the TextureBaker to ignore the RenderTexture material (use the original material), so that the video output can be incorporated as before while still applying the atlases for the other materials?
     
  38. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Yes, put the RenderTexture material on its own submesh all by itself in the mappings. Then on the combined mesh you can re-use the original material for that submesh.
     
    Colin_MacLeod likes this.
  39. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    So, like this?

    upload_2023-10-20_13-31-4.png

    What happens when I run "Bake Materials into Combined Material" in this case?
     
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    You can do that, or add a dummy combined material that you switch after the bake.
     
  41. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Ah, looks like I need to do that.

    The above gives me this error:


    Code (CSharp):
    1.  
    2. Object 'Signboard_04_1080x1920_LOD0' in the list of objects to mesh uses a Texture that is not a Texture2D. Cannot build atlases with this object.
    3. UnityEngine.Debug:LogError (object)
    4. DigitalOpus.MB.Core.MB3_TextureCombinerPipeline/<__Step1_CollectDistinctMatTexturesAndUsedObjects>d__9:MoveNext () (at Assets/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombinerPipeline.cs:415)
    5. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause (System.Collections.IEnumerator,int) (at Assets/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:294)
    6. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause (System.Collections.IEnumerator,int) (at Assets/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:307)
    7. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause (System.Collections.IEnumerator,int) (at Assets/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:307)
    8. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause (System.Collections.IEnumerator,int) (at Assets/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:307)
    9. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause (System.Collections.IEnumerator,int) (at Assets/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:307)
    10. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause (System.Collections.IEnumerator,int) (at Assets/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:307)
    11. DigitalOpus.MB.Core.MB3_TextureCombiner:RunCorutineWithoutPause (System.Collections.IEnumerator,int) (at Assets/MeshBaker/scripts/core/TextureCombiner/MB3_TextureCombiner.cs:307)
    12. MB3_TextureBaker:CreateAtlases (DigitalOpus.MB.Core.ProgressUpdateDelegate,bool,DigitalOpus.MB.Core.MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/MB3_TextureBaker.cs:574)
    13. DigitalOpus.MB.MBEditor.MB3_TextureBakerEditorInternal:DrawGUI (UnityEditor.SerializedObject,MB3_TextureBaker,UnityEngine.Object[],System.Type) (at Assets/MeshBaker/Editor/MB3_TextureBakerEditorInternal.cs:441)
    14. DigitalOpus.MB.MBEditor.MB3_TextureBakerEditor:OnInspectorGUI () (at Assets/MeshBaker/Editor/MB3_TextureBakerEditor.cs:37)
    15. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:190)
     
  42. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    I can't get past this - it won't let me bake the materials with that object included.
     
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Can you switch the texture on that material to be any normal 2D texture before Mesh Baking and then switch it back after the bake?
     
    Colin_MacLeod likes this.
  44. YenCheng1978

    YenCheng1978

    Joined:
    Jul 25, 2021
    Posts:
    11
    We found that after converting Metallic(R)Gloss(A) to Array, the texture looked different, so we tried changing it to Metallic(R)Gloss(G). After converting Array, the texture displayed the same, but in Android VR The error that occurs is still the same and has not improved.

    This display error does not necessarily appear in Android VR. You can also see the same error when using an Android phone or Android emulator.

    So far I still have no idea how to deal with it, I hope there will be good news from you :D
     

    Attached Files:

  45. YenCheng1978

    YenCheng1978

    Joined:
    Jul 25, 2021
    Posts:
    11
    Found it, we are sure it is a problem with the ArrayNormal texture created by MeshBaker.

    We try to use the tool linked below to re-create the ArrayNormal texture, and then display it normally under Android VR.

    https://github.com/pschraut/UnityTexture2DArrayImportPipeline
     
    Phong likes this.
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Good sleuthing! I started looking into the issue but progress was slow because it takes a long time to cycle making a change and pushing it to the device. I will look into that. It is a pain that Unity doesn't auto covert texture arrays like it does for regular textures.
     
  47. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    @Phong, what do you think may be happening with these corner pieces? It seems like the UVs are screwed up in the baked mesh.

    Original:
    upload_2023-11-3_16-43-40.png

    Baked:
    upload_2023-11-3_16-44-6.png

    There are 3 materials in the original part:

    Material Material_A:
    upload_2023-11-3_16-45-29.png

    Material Color_Yellow:
    upload_2023-11-3_16-46-24.png

    Material Color_Grey_Medium:
    upload_2023-11-3_16-47-25.png
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    Are there any errors or warnings when you bake these meshes. It could be that the different submeshes may be sharing vertices. If this happens it is not possible to map the uvs of a vertex to two different places in the atlas.

    Another possibility: The UV channel in the source mesh may be poor. It may be that the modelers knew that they would be using a color tint to color the triangles so they didn't bother creating a decent UV map. It may be that all the UVs for all vertices are all a single point. When Mesh Baker tries to copy some a block of source atlas based on the UVs it is copying a single pixel to the atlas. Atlases that are single pixels can be trouble. Does increasing the padding help?
     
    Colin_MacLeod likes this.
  49. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    342
    Thanks @Phong, I'll try that out. Do you know any way to edit the UVs from within Unity? I saw that ProBuilder had a UV Editor - do you happen to know whether you can use that on regular meshes?
     
  50. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,096
    IMO the best way is to open the FBX in a modeling program like blender and edit the UVs there.

    The problem with editing UVs on a mesh that is inside a FBX-model-prefab-file is that any changes you make to the mesh get lost when the FBX gets reimported. You can save the mesh as a unity mesh and edit the UVs there. Not sure which is the best asset for editing UVs.