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
    Are you using "resize power of two textures"? This may help. Without this then packing power-of-two textures + padding is a nightmare.
     
  2. qqepijackxu

    qqepijackxu

    Joined:
    Jun 14, 2019
    Posts:
    26
    On the left are settings and on the right are the results. Textures inside red box should be 2k but are shrank to 1k. heli.png
     
  3. qqepijackxu

    qqepijackxu

    Joined:
    Jun 14, 2019
    Posts:
    26
    Ok i finally got it. I just had to disable "Consider Mesh UVs".
     
    Phong likes this.
  4. matiasges

    matiasges

    Joined:
    Jan 24, 2021
    Posts:
    142
    Hi,
    Regarding Batch Prefab Baker: if my instances of the prefab use a different material, is there an option to combine the material set on the instance instead the one of the prefab?
    I have some material variations for the same prefab, so let's say that a prefab is using material1, but the instance in the scene is using material2, then the atlas will combine the material1 instead of material2. Is there a way to set it up to material2?
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I think that when you bake you will want to to duplicate the original prefab and give each of the duplicates a different material variation for example:

    flowerPotVariation1 : materialA
    flowerPotVariation2 : materialB
    flowerPotVariation3 : materialC

    When you bake the atlas both materials "materialA", "materialB" and "materialC" will get baked into the atlas. Additionally there will be three meshes generatated: flowerPotVariation1-mesh, flowerPotVariation2-mesh, flowerPotVariation3-mesh These meshes will both used the same combinedMaterial but they will have different UVs so they will used different rectangles in the atlas.

    In your scene you can use instances of any of the output bakedPrefabs. You can switch which material gets used by switching the mesh.

    Eg:

    flowePotInSceneInstanceOfVariation1: combinedMaterial mesh: flowerPotVariation1-mesh
    flowePotInSceneInstanceOfVariation1: combinedMaterial mesh: flowerPotVariation2-mesh
    flowePotInSceneInstanceOfVariation1: combinedMaterial mesh: flowerPotVariation3-mesh
     
    matiasges likes this.
  6. matiasges

    matiasges

    Joined:
    Jan 24, 2021
    Posts:
    142
    At what stage should I do this? As the instance is still connected to the original prefab

    What if I replace the material on the SourcePrefabInstances?
     
    Last edited: Oct 21, 2022
  7. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I would setup the variation prefabs and bake the textures in a separate "baking" scene.
    When this process is complete you will have some new assets in your project:
    • for each source material variation
      • One prefab that uses the combined material
      • One mesh that uses a different rectangle in the combined-material-atlas
    • optional
      • Make a prefab of the BatchPrefabBaker gameObject. This makes it easy to replace prefabs in another scene.
    Then open up your game scene that uses instances of the source prefabs. You can temporarily use the optional BatchPrefabBaker prefab in this scene to open the "Replace Prefabs In Scene" window. This makes it easy to replace the prefab instances in your scene with the batch-baked prefab version. However, in your case this step probably won't work properly because you have modified/overriden the material on these instances. The "Replace Prefabs In Scene" will probably try to apply this override (set material to one of the source-material-variations). For each of these broken instances in your scene you will need to do the following:
    • Set the material to be the combined-material
    • Set the mesh to be the correct baked-mesh-variation corresponding to the source material variation that instance was using.
    After this all instances should use the combined material and display the correct material variation.

    Does this make sense?
     
    matiasges likes this.
  8. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    Anyone have a mesh decimator that they would recommend to work along side Mesh Baker?
    Looking to get a baker and decimator and wondering if it’s best to get one asset that does both or two? Feel like Mesh Baker is the best choice, but need a decimator to work alongside it.

    much thanks
     
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    The only one I have tried is Simple LOD. It did a very good job.
     
  10. the_unity_saga

    the_unity_saga

    Joined:
    Sep 17, 2016
    Posts:
    268
    hello dev, I am interested in your asset as an alternative to another one.

    But I need one that has a non-destructive workflow for runtime mesh manipulation for my characters.

    how can I achieve material manipulation of specific combined meshes within a skinned mesh + static mesh combined mesh group?

    I am trying to animate textures using similar functionality as shown in this video:



    also, how would I, at runtime, remove a mesh from a combined mesh group specifically? just store it as a reference in an list and use some API command such as MeshBaker.MeshCombinedMesh.MeshgroupObj.Remove()???

    do you have any in-depth tutorials for runtime API usage? that is my primary interest, I have been looking at your asset for years and really want to try it, for character customization

    edit: also, how would I disable meshes, within a combined mesh? or swap out components, such as change a mesh in real time to another mesh (just the actual mesh object).
     
  11. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hello,

    Re: "how can I achieve material manipulation of specific combined meshes within a skinned mesh + static mesh combined mesh group?" Your skinned meshes and static meshes will be handled independently. I am not sure what you mean by "Material Manipulation". Mesh Baker includes a TextureBaker component that creates atlases. This can be used at runtime but not all features work at runtime and it is slow. We recommend creating the atlases in the editor if possible. Once the atlas has been created, combined meshes can be easily re-baked at runtime to change which part of the atlas they are using. Is this what you mean by material manipulation?

    Re: "how would I, at runtime, remove a mesh from a combined mesh group specifically". This is very easy. The API is:

    GameObject[] meshesToAdd = null;
    GameObject[] meshesToDelete = new GameObject[] {objToRemove1, objToRemove2};
    MeshBaker.AddDelete(meshesToAdd, meshesToDelete);
    MeshBaker.Apply();

    There are several example scenes included that have runtime scripts that do this for both skinned meshes and static meshes.

    Re: your animated blinking material. This should work fine on a combined mesh using a combined material with the following caveats:
    • The materials need to be applied to the mesh using UVs. If you are using tri-planer projection, splatmaps or some other way to project the texture onto the mesh then this might not work.
    • All meshes that share the combined material would blink at the same time. It is very difficult to get one mesh in the combined mesh to blink while others do not.
    Re: Character customization and swapping meshes. You can use the "AddDelete" API. There are three example scenes (two of them using skinned meshes) with scripts included with Mesh Baker. I don't have a tutorial showing runtime usage specifically however there are several scripts to look at. For skinned meshes and character customization I would suggest watching these videos:


    • (older but still relevant)
     
    the_unity_saga likes this.
  12. the_unity_saga

    the_unity_saga

    Joined:
    Sep 17, 2016
    Posts:
    268
    Ok I will get it, since it is on sale. If anything I can use this for furniture combined into houses and such.

    Thank you for your indepth response!!
     
    Phong likes this.
  13. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    873
    I'm having a problem where it seems like it doesn't want to bake tiled texture settings in URP. I remember this working before.
     
  14. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Can you post a pic of the material inspector and the TextureBaker settings? Also what version of URP & Unity are you using?
     
  15. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    873
    Using 2021.3 which is URP 12

    upload_2022-11-26_10-48-41.png

    upload_2022-11-26_10-50-22.png

    Also imo the texture baker should read the "albedo alpha" setting. And maybe exclude that from the alpha channel bake and apply it to the metallic instead?

    upload_2022-11-26_10-49-31.png
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
  17. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I ran some tests and am not able to reproduce the problem. Here is my latest bake:

    upload_2022-11-28_14-19-42.png

    The meshes use a mixture of material tiling and UV tiling.

    I notice that "consider UVs" has been turned off for some of the submeshes in your setup. Have you tried turning it on and re-baking both TextureBaker and MeshBakers? If that doesn't work can you post a pic of your texture baker settings and the bad result?
     
  18. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    873
    Hmm lemme find a more thorough example.
     
    Phong likes this.
  19. Fressno

    Fressno

    Joined:
    Mar 31, 2015
    Posts:
    185
    Hey Phong. Im having a problem where ive baked materials into a combined material(everything still looks like it should), and then when i bake all child MeshBakers i get a wierd trippy error where the shaders move around when i pan around the scene. its like the UVs are moving, but its just me and my scene camera moving around looking at the textures. what might have happend?
     
  20. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Fressno, what shader are you using? Does it use UV to position the texture on the mesh? There are other ways to project a texture onto a mesh.

    Could it be that your source meshes and combined mesh are active in the scene at the same time and they are Z-fighting? Check that the source meshes are disabled. It may be that the combined meshes need a setting like consider-UVs for the textures to position correctly and when they z-fight you get flickering apparently moving textures.

    Does either of these explain what might be happening? If not can you post a video showing the effect?
     
  21. Fressno

    Fressno

    Joined:
    Mar 31, 2015
    Posts:
    185
    ill try and get back to you on this asap. dont know how to add a video here as i dont have somewhere to repo it.
    but i appreciate you reaching out and trying to help. i was going to ask for a refund, but i might stick with it if i get this sorted. as i most likely will need it for my VR projects.
     
    Phong likes this.
  22. the_unity_saga

    the_unity_saga

    Joined:
    Sep 17, 2016
    Posts:
    268
    hello again,

    I have a question based on this video:


    im guessing it isn't possible, but, I thought I'd ask anyway,

    how can I have a meta mesh baker group, on top of smaller sub-grouping, for the same collection of meshes as found in this example tutorial scene in the video, and toggle/swap them based on distance from my camera?

    basically, I'd like to have mesh baker dynamically swap regions into large cull all, and then sub-group cull part, based on distance from my camera.

    thank you again for your work on this asset.
     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I don't think there is an easy way to do this out of the box. I will give it some thought and get back later today or early tomorrow.
     
  24. the_unity_saga

    the_unity_saga

    Joined:
    Sep 17, 2016
    Posts:
    268
    in the meantime, some hacky solution I had was make duplicated groups, where the large one is completely disabled upon a certain distance, however, this means I end up with double vertex count (not that it really matters), but if you come up with a way to utilize same meshes I'd love to hear about it.

    Thanks again for your hard work on this asset.
     
  25. WildcardMoo

    WildcardMoo

    Joined:
    Aug 28, 2020
    Posts:
    19
    Hi there,

    I'm starting to fiddle with Mesh Baker and I'm currently seeing results that I'd rather not see.

    First, my baseline before using Mesh Baker (all numbers directly from the Unity stats window, camera in the same location/rotation):
    - CPU Main thread 34.4ms, render thread 16.8ms
    - Batches: 7171
    - Tris 3.6M, Verts: 7.6M
    - SetPass calls: 1029

    I then went ahead and used Meshbaker on my most commonly used objects: Trees, bushes etc. Stuff that is all around me. This made performance a lot worse. Not so much in the editor, but in the compiled game it almost halfed the framerate.
    - CPU Main thread 39.1ms (BAD), render thread 12.1ms (GOOD)
    - Batches: 4216 (GOOD)
    - Tris: 25M (VERY BAD), Verts 60.6M (VERY BAD)
    - SetPass calls: 1100

    So now we have 7x the Tris and 8x the Verts. I assume that's because my scene is surrounded by trees/bushes etc. in all directions, and now it has to render them all the time? Uninformed conclusion: Don't combine meshes that aren't in close proximity. But if that's the case, why doesn't MeshBaker have an option for that? I'm sure I'm not seeing the whole picture yet.

    I then changed it so that it only combines meshes that are close together. I didn't bother with all the trees etc, but there are a few areas where I have up to 200 objects with the same material, so I combined them.
    Now I'm seeing this:
    - CPU Main thread 33.6ms, render thread 16.4ms
    - Batches 5707
    - Tris 4.3M, Verts 8.8M
    - SetPass calls: 1007
    So now I'm having a decent reduction of Batches (about 20%) which goes hand in hand more Tris/Verts, but the actual performance is nearly unchanged compared to the baseline.

    What am I doing wrong?
     
    Phong likes this.
  26. WildcardMoo

    WildcardMoo

    Joined:
    Aug 28, 2020
    Posts:
    19
    I will answer my own question, because (as so often is the case), now that I've formulated the question properly, I know what to ask myself and what to look for.

    My assumption as correct, BUT Mesh Baker has a solution for it. Instead of adding MeshBaker, I add a TextureBaker with a MeshBakerGrouper. On that Grouper, I change the Cluster Type to Grid with a 10x10x10 resolution (or more, depending on the situation). Now, a new combined mesh is created for each 10x10x10 cell.

    By combining just my grass (1900 instances!) this way, I reduced batches from 7171 to 5890, CPU main thread from 34.4ms to 28.4ms, and improved the FPS from 32 to about 38. That's in the editor. Funnily, in the compiled game there's no difference visible yet. I'll keep baking.
     
    the_unity_saga and Phong like this.
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I don't think there is a much better solution for this than what you are doing. If you combine the meshes in advance then you could use and LODGroup to manage them. You could also use a decimation tool like SimpleLOD to reduce the vertices and the triangles in the large mesh. If it will only ever be viewed from a distance this could save a lot of GPU work.

    If you wanted to do this all dynamically with Mesh Baker, then you could set up several different baker setups in advance. However you will end up with double vertex count because you will have the source meshes and the combined meshes. If you delete the source meshes then you won't be able to undo the combined mesh.
     
    the_unity_saga likes this.
  28. WildcardMoo

    WildcardMoo

    Joined:
    Aug 28, 2020
    Posts:
    19
    This might be just because I haven't got a good idea what I'm doing yet, but I think it would be great if the "Tool for adding objects" allowed you to set certain filters. I currently have them hardcoded in the MB3_MeshBakerEditorWindowAnalyseSceneTab.cs:

    - Ignore disabled renderers: this seems to be a no brainer for me, I can't think of a situation where I would want to bake (which means activate and therefore alter my scene) an inactive renderer.
    - Ignore non-static gameobjects: If you're already using the static flags, this might be all the filter you need.
    - Ignorer renderers that exceed a certain (custom) size: I'm currently checking the renderer.bounds.magnitude, and if this exceeds 15, I ignore the renderer. My idea is that I don't want a large building to be combined with a bunch of tiny models, because of culling. The large building might be almost always visible, the 200 tiny at its feet only when you get close enough.
    - Ignore gameobjects from particular parents (or the other way around: only consider children of particular parents instead of the entire scene).
    - Ignore gameobjects whose name (or parents name) contains a certain string: Same as above, except "quick and dirty". I never want to consider renderers belonging to my player, my vehicle, and certain other objects.

    It would be extra nice to have these exclusions on a per level or global (where applicable) level.

    I know that some of this can be achieved with the group by levels, but that just results in a huge list. Especially when you group by material as well.

    For my scenario at least, it's impossible to not group by material. MeshBaker seems to ignore values like "Metallic" and "Smoothness", and combining meshes/materials that share the same shader/texture but differ in Metallic/Smoothness alters the scene, which is not desired.
     
  29. test1forgoodsingapore

    test1forgoodsingapore

    Joined:
    Jul 4, 2022
    Posts:
    1
    I used mesh baker to combine my different track pieces and I have tried to add a single mesh collider to the end prefab but it still has the same colliders of when the track was build with modular pieces any advice on how should I move forward.

    When the ball or car moves at a fast speed it get's caught between the seams of 2 modular pieces any suggestions?
     
  30. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Thanks for the feedback. I can't commit to implementing all of these, but I do take feedback like this seriously and will try to implement features that give you the ability to search on this criteria.
     
  32. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Mesh Baker only combines the meshes for renderers. It ignores MeshColliders. You could have the MeshColliders on the source prefab instances in your scene. These might be the MeshColliders that are causing the issue. "Disable Source Renderers" won't disable these MeshColliders. This is by design since usually when you combine meshes you want to keep scripts and colliders on the original objects.

    You probably want to keep the MeshColliders on the track pieces separate. This s because optimization for physics and rendering is very different. With physics you want many separate small colliders (preferably convex). Are the gaps between the colliders watertight? Unity has a vertex snap feature that should help align these exactly. If the gaps are watertight. then make sure that the track pieces are marked "physics static". This will help the physics engine use a more optimized algorithm for collision detection and allows convex mesh colliders. You may also want to turn on "Rigidbody.CollisionDetction: = continuous" on your vehicles and vehicle-tires. This should detect and prevent your car-parts from passing through the road parts (teleporting) into the gap between road parts.
     
  33. Ward101

    Ward101

    Joined:
    Mar 22, 2016
    Posts:
    52
    Hi! Can anyone point me or recommend a shader compatible with Texture arrays, for the URP pipeline?
    I assume it will be a Lit variant ...
     
  34. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Hi @Phong ,

    I found a bug. It's not possible to copy\paste the output folder . Meshbaker won't detect the path and requires me to always press browse to add the folder (which slows down workflow) :oops:

    Is this an easy fix?
    Thanks for the help
    upload_2023-1-3_14-28-31.png
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Unfortunately, at this time Mesh Baker does not provide one and I don't know of any publicly available implementations.
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    It appears to work for me. I tried copying and pasting the "Prefab Output Folder" using a drive-root-relative path and an asset-folder-relative path. I was able to paste text using both. Which version of Unity and MeshBaker are you using?

    Note that the path needs to be relative to the assets folder. For example: Assets/ExampleFolder/MyPrefabs
     
  37. Ward101

    Ward101

    Joined:
    Mar 22, 2016
    Posts:
    52
    Thanks! I thought so ...
     
    Phong likes this.
  38. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Yes the path is inside the Assets folder


    hi @Phong
    I have these versions
    Mesh bake 3.35.1
    Unity 2021.1.28f1



    Were you able to successfully generate the mesh bake files?
    upload_2023-1-4_16-9-9.png

    I can paste the path , but when I press generate I get a red error :(

    Also while I have you. Is there a way to export the images to JPG rather than PNG? The file sizes for PNG files get rather large.

    Thanks for the help
    Code (CSharp):
    1. Output Folder must be an existing folder in the Unity project Assets folder
    2. 0x00007ff78a66c2ac (Unity) StackWalker::GetCurrentCallstack
    3. 0x00007ff78a672629 (Unity) StackWalker::ShowCallstack
    4. 0x00007ff78ae6e963 (Unity) GetStacktrace
    5. 0x00007ff78bda397a (Unity) DebugStringToFile
    6. 0x00007ff78a6c5f2d (Unity) DebugLogHandler_CUSTOM_Internal_Log
    7. 0x00000156dad4d7eb (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
    8. 0x00000156dad4d68b (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    9. 0x00000156dad4cbae (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
    10. 0x00000156daf232da (Mono JIT Code) UnityEngine.Debug:LogError (object)
    11. 0x00000156dad9f9b3 (Mono JIT Code) [MB_BatchPrefabBakerEditorFunctions.cs:1434] DigitalOpus.MB.MBEditor.MB_BatchPrefabBakerEditorFunctions:ValidateFolderIsInProject (string,string)
    12. 0x00000156dad9f2cb (Mono JIT Code) [MB3_MeshBakerGrouperEditor.cs:327] DigitalOpus.MB.MBEditor.MB3_MeshBakerGrouperEditor:GenerateMeshBakersEditor (UnityEngine.Object)
    13. 0x00000156daae9bf3 (Mono JIT Code) [MB3_MeshBakerGrouperEditor.cs:107] DigitalOpus.MB.MBEditor.MB3_MeshBakerGrouperEditor:OnInspectorGUI ()
    14. 0x00000156da861db8 (Mono JIT Code) UnityEditor.UIElements.InspectorElement/<>c__DisplayClass59_0:<CreateIMGUIInspectorFromEditor>b__0 ()
    15. 0x00000156da2fabca (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:DoOnGUI (UnityEngine.Event,UnityEngine.Matrix4x4,UnityEngine.Rect,bool,UnityEngine.Rect,System.Action,bool)
    16. 0x00000156da42b1d3 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,UnityEngine.Matrix4x4,UnityEngine.Rect,System.Action,bool)
    17. 0x00000156da59ea7b (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,System.Action,bool)
    18. 0x00000156da59e783 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,bool)
    19. 0x00000156da814e9b (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUIRaw (UnityEngine.UIElements.EventBase,bool,bool)
    20. 0x00000156da814b13 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUI (UnityEngine.UIElements.EventBase,bool,bool)
    21. 0x00000156da01b94b (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleEvent (UnityEngine.UIElements.EventBase)
    22. 0x00000156d9fee666 (Mono JIT Code) UnityEngine.UIElements.CallbackEventHandler:HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase)
    23. 0x00000156da35636b (Mono JIT Code) UnityEngine.UIElements.MouseCaptureDispatchingStrategy:DispatchEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
    24. 0x00000156d9fe87f6 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel,bool)
    25. 0x00000156d9fe73e3 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ProcessEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
    26. 0x00000156d9ff9753 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ProcessEventQueue ()
    27. 0x00000156d9ff487b (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:OpenGate ()
    28. 0x00000156d9ff461b (Mono JIT Code) UnityEngine.UIElements.EventDispatcherGate:Dispose ()
    29. 0x00000156d9fe7d43 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ProcessEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
    30. 0x00000156d9fe64b3 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:Dispatch (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel,UnityEngine.UIElements.DispatchMode)
    31. 0x00000156d9fe601b (Mono JIT Code) UnityEngine.UIElements.BaseVisualElementPanel:SendEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.DispatchMode)
    32. 0x00000156da2a7fb3 (Mono JIT Code) UnityEngine.UIElements.UIElementsUtility:DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel)
    33. 0x00000156da2a7203 (Mono JIT Code) UnityEngine.UIElements.UIElementsUtility:UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (int,intptr,bool&)
    34. 0x00000156da2a6bef (Mono JIT Code) UnityEngine.UIElements.UIEventRegistration:ProcessEvent (int,intptr)
    35. 0x00000156da2a68fb (Mono JIT Code) UnityEngine.UIElements.UIEventRegistration/<>c:<.cctor>b__1_2 (int,intptr)
    36. 0x00000156da2a6415 (Mono JIT Code) UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    37. 0x00000156da2a6636 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_int_intptr_intptr& (object,intptr,intptr,intptr)
    38. 0x00007ffa467ce670 (mono-2.0-bdwgc) [mini-runtime.c:2827] mono_jit_runtime_invoke
    39. 0x00007ffa46752af2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke
    40. 0x00007ffa4675bb4f (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke
    41. 0x00007ff78a5b62c4 (Unity) scripting_method_invoke
    42. 0x00007ff78a5b18a1 (Unity) ScriptingInvocation::Invoke
    43. 0x00007ff78a5abb25 (Unity) ScriptingInvocation::Invoke<void>
    44. 0x00007ff7898ae71a (Unity) Scripting::UnityEngine::GUIUtilityProxy::ProcessEvent
    45. 0x00007ff78a9a6806 (Unity) GUIView::ProcessRetainedMode
    46. 0x00007ff78ae9a4ea (Unity) GUIView::OnInputEvent
    47. 0x00007ff78a9a66f2 (Unity) GUIView::ProcessInputEvent
    48. 0x00007ff78ae9b4d9 (Unity) GUIView::ProcessEventMessages
    49. 0x00007ff78ae9572a (Unity) GUIView::GUIViewWndProc
    50. 0x00007ffa9f62e7e8 (USER32) CallWindowProcW
    51. 0x00007ffa9f62e229 (USER32) DispatchMessageW
    52. 0x00007ff78ae74546 (Unity) MainMessageLoop
    53. 0x00007ff78ae782c6 (Unity) WinMain
    54. 0x00007ff78c9e4852 (Unity) __scrt_common_main_seh
    55. 0x00007ffa9e027614 (KERNEL32) BaseThreadInitThunk
    56. 0x00007ffaa00226a1 (ntdll) RtlUserThreadStart
    57.  
     
    Last edited: Jan 4, 2023
  39. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    We have a large library of prefabs that contain many copies of the same mesh within them in different arrangements - Think something like a flower garden variants with plants arranged in different ways.
    How can I get mesh baker to bake all these prefabs down into unique single meshes per prefab?
     
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Karl, this error message is the key:

    Output Folder must be an existing folder in the Unity project Assets folder

    What path are you pasting? The path should be of the form "Assets/AfolderInYourProject/ADeeperFolderInYourProject" If you do that then it should work.

    Regarding JPG. Unfortunately at this time there is no way to export to jpg.
     
  41. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I would recommend doing the baking in a separate scene. I would arrange your flowers like this in the scene:
    • SourceMeshes
      • Arrangement1
        • Plant1
        • Plant2
        • ...
      • Arrangement2
        • Plant1
        • Plant2
        • ....
      • ...
    Arrange these so that the pivot for each flower arrangement is at 0,0,0.

    Then create a TextureBaker. You might need more than one TextureBaker if there are too many flower textures to fit into a single atlas. Drag all the meshes into the TextureBaker. This is easy to do by dragging "SourceMeshes" to the 'drag and drop' box. This will add all your flowers. Configure and bake the atlas. Check the results, adjust settings and rebake if necessary. You can experiment as much as you like, the process is non-destructive. I would recommed using a throwaway child MeshBaker object to bake a combined mesh for the flowers to see what the results are like. When you are happy, delete the throwaway MeshBaker and combined mesh.

    Then create 1 child Mesh Baker object (child of the TextureBaker) for each flower arrangement
    • TextureBaker // Objects To Combine is ALL source flowers
      • MeshBaker-Arrangement1 // Objects to combine is objects for Arrangement1
      • MeshBaker-Arrangement2 // Objects to combine is objects for Arrangement2
      • ...
    Use the MeshBakerGrouper component on the TextureBaker to configure the MeshBaker children all at once. You can configure them to output to prefab and choose an output folder for your result prefabs. See this video for more info on this workfow.

     
  42. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Ahhhhhhh I realized what was wrong ..
    1. I had the drive path in there ie C:\
    2. the backslash is incorrect.. windows uses "\" .. but Unity needs "/" .... this completely makes copy\paste useless if I need to correct the backslash to forwardslash each time... :eek:

    Is there an easier method to copy \paste that you use? Or are u re-edit-ing the backslash each time too?


    This bottom part may be too difficult ...
    But can we have the path get set when we input it here?
    upload_2023-1-5_15-51-11.png

    Then automatically the path ALSO gets recorded here?
    upload_2023-1-5_15-51-24.png

    This way we don't need to go looking in windows explorer twice? Maybe have the "Auto Generate Prefab" checkbox be in the MBEditor window as well?

    Thanks for the help :)
     
    Last edited: Jan 5, 2023
    Phong likes this.
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I will take a look at the path issue. I thought at one point I had modified the code so that it can accept forward as well as backslashes and switch full path to asset-folder relative path. Perhaps something as changed that breaks this.

    I usually save my bake setups in a scene or a prefab. Then I don't need to update the path very often. Usually I use the browse for folder box, than save it and seldom change it.
     
  44. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Thanks for the help. If its too much trouble.. don't bother.

    Because even if we copy the path.. we still need to edit it by removing the D:\xxx\Assets path ... which no amount of scripting on your end could fix it. :oops:

    I save each prefabs in the same folder as their respective meshbaked files -- so I know where they are when I need to fix specific mesh baked files. I'm a bit too organized perhaps :eek:
     
  45. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    Hi, i have some lightmap artifacts because wallsegments in the modular asset I'm using are not stitched together. This mean they will be alone with margin in the lightmap and shadows will not bleed correctly between them ending up in ugly seams in the shadow cast on the wall.

    Can mesh baker support that I keep the orginal uv2 but that it locates vertices that it can stitch so that in the resulting uv2 the two wall segments will be right by each other without any margin?
     
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Mesh Baker has several different treatments for lightmapping UV2. One of these is "copy UV2 to separate rects". This will copy the UV2 layouts to separate rectangles of the atlas. If there are gaps between the wall segments on the original mesh UV2, then these gaps will still be there on the baked mesh.

    You original mesh should still lightmap correctly without artifacts if the texel resolution is high enough. Unity scenes have a "Baked Illumination" view that shows the texel density. If you get the texel deinsity high enough so that texels do not span the gap between two sections of wall then it should light bake correctly.
     
  47. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    You need to increase resulution well above what's practical to get rid of the artifacts sadly. And that is with very conservative filtering. Im looking for a solution that can identify meshes that share vertice position and not too different angle between their normals. And then stitch those two together and alter their uv2 so that their vertices meet there too.

    Might have to implement it then :)
     
    Phong likes this.
  48. EiknarF

    EiknarF

    Joined:
    Apr 28, 2011
    Posts:
    142
    apologies if I missed this, there's quite a lot of documentation and forum posts to read though

    When adding objects to the list of objects to be combined, is there a way to exclude objects based on something like gameobject tag or name contains string.
     
  49. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    The "Window -> Mesh Baker" includes a tab "Search For Meshes To Add". There you can include/exclude meshes matching certain criteria. There is a "matches regular expression" box. However no "matches tag". More info in this video.

     
    EiknarF likes this.
  50. EiknarF

    EiknarF

    Joined:
    Apr 28, 2011
    Posts:
    142
    Thank you for the quick reply. As I get more into the workflow of baking to use texture arrays I have another question;

    If I have a single mesh with with a lot of materials, say 20, but I only want to convert 10 if them to use texture arrays, is it possible to use your tool to bake the mesh but only change the elements with the materials I have baked into an array. My tests are giving me the error;
    "Source object "object name" that was not in the baked materials."

    I'm not sure if makes any difference but my use case is trying to optimise a town with lots of buildings, I was going to write a script to make a simple hierarchy based on shaders and inside that a mesh for each material so I can visualise what exactly is being used, I would bake the array from these objects. When I'm happy with the arrays I want to bake all the building meshes to convert the applicable materials to use these new arrays.

    Thanks again!