Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Mesh Baker by Digital Opus [RELEASED]

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

  1. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
    Sorry for jumping in with a presumably very basic question, but does this mean that if you want to bake a metal shader object together with a rough plastic shader object, you need to have the metalness and roughness in textures only? How about transparent glass objects, can that be baked together with metal and plastic?

    Also, the post is from 2013, but I seem to remember seeing something about Unity removing the 64k limit, but I'm not sure that this is the case yet. What is the status of this?
     
  2. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    You can combine plastic and metal together. It works best if the source materials are using textures for the metalness. Unfortunately "smoothness" is a slider so when the materials are combined, the two source mats will need to share a single slider. Mesh Baker now includes a mode "Blend Non-Texture Properties" that will attempt to convert the non-texture properties to small textures to use in the generated atlas. This works fairly well but there are still some properties that are shared (like smoothness) so it is not perfect.

    Combining transparent and non-transparent objects is probably not a great idea. For one thing you will almost certainly run into issues with triangles being drawn in the wrong order. Also even if you make some of the objects opaque on the alpha channel, you will loose the performance benefit of the z-culling where those objects could hide other objects behind them which would not need to have their pixels shaded.
     
    ekergraphics likes this.
  3. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    320
    Thank you so if that works this way, I will buy it for sure :)
     
  4. f0ff886f

    f0ff886f

    Joined:
    Nov 1, 2015
    Posts:
    167
    Is the patch that removes Tizen issues on 2018.2 live? I tested an upgrade of Unity this morning and I was getting issues with Tizen methods not being supported in 2018.2.

    I commented the code, but everything was wrapped in #if UNITY_TIZEN, which seems to be defined somewhere... is that because the project is updated from 2017?
     
  5. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    Tizen should be removed in the last few Mesh Baker releases. I suspect that you are seeing an artifact of the upgrade. Check BuildSettings -> PlayerSettings -> Scripting Define Symbols. Also search your project for any .rsp files. These can have defines in them.
     
  6. f0ff886f

    f0ff886f

    Joined:
    Nov 1, 2015
    Posts:
    167
    Odd. No Tizen symbols, no *.rsp files, no mention of UNITY_TIZEN in the entire project folder. Oh well, I'll just delete the lines.
     
  7. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    568
    Hi Phong
    i have a object that has approx 10 materials , "sub-meshes" on it and i want to combine them all down to 1 they are all the same Unity standard shader. when i pick the object to combine it only adds the first material I then have to manually add the next 9. Once i do this it does combine correctly (and even makes a Metallic & Emission map for me.. Thats Awesome Thank You! ). Is there a way to automatically Add all materials?, as i have 75+ objects to do this too. Thanks..


    Edit: i wrote this to to help out... decided to try an automate as much of it as possible..
    how would i get access to MB3_MeshBaker > Output & Combined mesh prefab
    And if you know of the top of your head how would i save my prefab gameobject to a folder so i can then assign it to CombinedMesh prefab.


    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using DigitalOpus.MB.Core;
    6.  
    7. [ExecuteInEditMode]
    8. public class JBR_MeshBaker_Utility : MonoBehaviour {
    9.  
    10.     public bool transferMaterials;
    11.     public GameObject objectToGet;
    12.     private MB3_TextureBaker mb3_TextureBaker;
    13.     private MB3_MeshBaker mb3_MeshBaker;
    14.     //store gameObject reference
    15.     private GameObject objToSpawn;
    16.     public int MaxTextureAtlasSize = 2048;
    17.  
    18.     // Use this for initialization
    19.     void Start () {
    20.      
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void Update () {
    25.         if (transferMaterials)
    26.         {
    27.             transferMaterials = false;
    28.             TransferMaterials();
    29.         }
    30.     }
    31.  
    32.     public void TransferMaterials()
    33.     {
    34.         //spawn object to be used as prefab
    35.         objToSpawn = new GameObject(objectToGet.name +"_MB");
    36.        // objToSpawn.transform.position = new Vector3(0, 0, 0);
    37.        //ref texture baker
    38.         mb3_TextureBaker = this.gameObject.GetComponent<MB3_TextureBaker>();
    39.         //set max atlas size
    40.         mb3_TextureBaker.maxAtlasSize = MaxTextureAtlasSize;
    41.         mb3_TextureBaker.considerNonTextureProperties = true;
    42.         mb3_TextureBaker.fixOutOfBoundsUVs = true;    
    43.         mb3_TextureBaker.resultMaterials[0].considerMeshUVs = true;
    44.  
    45.         mb3_MeshBaker = this.gameObject.GetComponentInChildren<MB3_MeshBaker>();
    46.  
    47.         foreach (Material mat in objectToGet.GetComponent<MeshRenderer>().sharedMaterials)
    48.         {
    49.             if (!mb3_TextureBaker.resultMaterials[0].sourceMaterials.Contains(mat))
    50.             {
    51.                 mb3_TextureBaker.resultMaterials[0].sourceMaterials.Add(mat);
    52.                 Debug.Log("JBR_Utility Added " + mat + " To TextureBaker");
    53.             }
    54.             else
    55.             {
    56.              //   Debug.Log("Marerial already added " + mat);
    57.             }
    58.         }    
    59.     }
    60. }
    61.  
     
    Last edited: Dec 10, 2018
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    Hi JBR,

    Hi JBR, I am surprised to hear that the result material only has your first material. Mesh Baker should be finding them all and baking them down to a single material unless you are using the multiple-materials feature. I have some Unit Tests that are working that way. And I just tested it and it works for me.

    Are you using the multiple materials feature? You would be easiest to do this without the multiple-materials feature. The default settings will bake down all the materials into a single submesh/atlas. What does your atlas look like after baking the textures? If all your source textures are in there then it should work.

    If you are using the multiple-materials feature, there is only one "source-to-combined" mapping entry. There should be only one combined material and the "source materials" for the one entry should list all of your source materials. When you bake this, the result should be one combined material with all the source textures combined in an atlas.

    Note that if any of your meshes use UVs outside the range 0..1 then check the "consider UVs" or map that material to its own "source-to-combined" mapping entry.

    I don't think the adding the result materials the way you are will work unless there is a corresponding entry in the "MaterialsAndUVRects" that maps the material to a rectangle in the atlas. Do all your source materials show up there?

    Regarding your other questions. You can access the the mesh baker output using:

    MB3_MeshBaker myMeshBaker;
    ...
    myMeshBaker.resultPrefab;
    // other meshcombiner objects are in the meshCombiner property.
    myMeshBaker.meshCombiner.resultSceneObject;

    You can create and work with prefabs using the PrefabUtility (search for PrefabUtility in the MeshBaker sourece to see some examples of usage):

    https://docs.unity3d.com/ScriptReference/PrefabUtility.html
     
    JBR-games likes this.
  9. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    568
    Thanks for the response.
    Ill have a look again later today (maybe reloading unity could fix the issue) and ill also see if i did something wrong, i just clicked Window > Meshbaker

    but for right now only 1 material is added out of 10ish submeshes , and the bake is not correct. But my script does add the proper materials and then bakes correctly... Note: im on newest unity 5.6
     
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    I just tested it and it worked correctly. Here is what I did:

    • Added some prefab buildings that had two materials each to an empty scene.
    • Added a GameObject -> Create Other -> Mesh Baker -> "TextureBaker and MeshBaker"
    • Opened the "Open Tools For Adding Objects" and used them to add the buildings in the scene.
    • Clicked "Create Empty Assets For Combined Materials" and created combined materials.
      • At this point the "Texture Bake Result" asset will have 1 result materials with 0 source materials.
    • Clicked "Bake Materials Into Combined Material":
      • Now the "Texture Bake Result" asset has 1 result material and 4 source materials.
    • On the MB3_MeshBaker clicked "Bake"
      • There is now a combined mesh with a single submesh (material).
    Does this workflow work for you? If not were there any console messages?
     
    Last edited: Dec 10, 2018
    JBR-games likes this.
  11. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    568
    Thank You for the help, it is now working properly either reloading unity or me paying better attention, fixed the material issue (mostlikely i missed a step somewhere).. Sorry to waste your time.

    Great asset..
     
    Phong likes this.
  12. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    30
    I have been working on a background loader for a large skinned mesh. Well, in so much as that can happen in single-threaded unity. So by background I mean in a coroutine spread out over multiple frames leaving enough time to update a UI.
    The skinned mesh has around 6000 small mesh objects. I have figured out all of the physics and texture packing and code required to use this mesh in the game, so once it is loaded it is working great.
    I have split up the objects into prefabs of around 400 bones with everything disabled, I use the new addressable asset system and a sequence of coroutines to load and activate everything without any glitching.
    Then I get to the point where I want to run mb.AddDeleteGOs on all 6000 objects.
    This functions takes around 1.75s with these objects if I run it once.
    The Apply function takes around 0.06s so that is not an issue.

    What I did was split up the objects into 16 arrays of around 400 objects each. Which I already had since the objects were split across multiple prefabs for loading.

    Then I called AddDeleteGOs in a coroutine loop for each of these batches with a yield, followed by a single Apply.
    This almost worked. It definitely split up the 1.75s over multiple frames.

    But it is a little strange. The time it took for each call increased even though the size of array passed to the function was the same.
    Here are the times (not including the yield):
    0.040, 0.046, 0.052, 0.059, 0.064, 0.072, 0.078, 0.091, 0.097, 0.101, 0.109, 0.121, 0.122, 0.131, 0.151, 0.168

    Just eyeballing it, they actually add up to a little bit less (or at least very close) to calling it once. So at least splitting it up does spread it across multiple frames. Add I can always split it up into smaller chunks.

    But why does it increase? Any thoughts? I am not sure I totally get what happens in the AddDeleteGOs function that would cause it to get slower each time.

    Thanks!
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    The high level algorithm for the AddDeleteGOs is:
    1. Count the vertices, triangles in meshes that are being deleted
    2. Count the vertices, triangles in meshes that are being added
    3. Allocate new arrays for new vertices, triangles, ... that are the correct size
    4. Copy the data over from the old arrays to the new arrays
    5. Apply this to the mesh (called separately)
    I think it is step 4 that is taking longer and longer each time. It is on my todo list to multi-thread this part using the new job system.
     
    JBR-games likes this.
  14. Helllllllo

    Helllllllo

    Joined:
    Aug 2, 2015
    Posts:
    10
    When I used baker texture and net on IOS platform or Android platform, he incorrectly rendered uv

    Edit: When I flip TextureResult atlas rect y (0 to 0.75,0.25 to 0.5,0.5 to 0.25,0.75 to 0) The rendered result looks correct
     

    Attached Files:

    Last edited: Dec 13, 2018
  15. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    Are you using the TexturePacker -> MeshBakerFast?
     
  16. Helllllllo

    Helllllllo

    Joined:
    Aug 2, 2015
    Posts:
    10
    Yes,i try other option but still not working
    this is my setup
     

    Attached Files:

  17. jspirate

    jspirate

    Joined:
    Mar 16, 2018
    Posts:
    2

    Hello Ian,

    Is there an estimate of how much smaller a 64K mesh asset is compared to not saving it as an asset? I did one small test and there doesn't seem to be very much difference in scene size? The test I did was on a 10K mesh, but the size savings on a 350mb scene seemed negligible? I created the game object and disabled renders on the mesh render. Maybe there is something more I should do to notice a difference in scene size?

    EDIT: I have a fair number of mesh baker combines in the scene and I am just curious as to weather or not its worth the time to redo them all and save them as assets. I guess I could start re-doing and see what I get, but didn't know if you might have any thoughts on this.

    Thanks
     
    Last edited: Dec 14, 2018
  18. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    I don't think it will save you anything by saving the meshes as assets unless they are re-used in multiple scenes. The saved meshes will still need to be packaged up in the game build if they are assets in the project or hidden in the scene. When the scene is opened the meshes will be loaded into memory, so your scene size in memory will be just as big.
     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    I will try to see if I can reproduce this issue.
     
  20. jspirate

    jspirate

    Joined:
    Mar 16, 2018
    Posts:
    2
    Ahhhh, I understand now. Thanks for the clarification.
     
  21. mlaibow

    mlaibow

    Joined:
    Feb 5, 2014
    Posts:
    30
    Thanks for the info. A multithreaded object adder/deleter would be great, let me know if you need anyone to test it out.

    In the meantime, I am trying a few new things.
    Does there exist a workflow where I can bake a skinned mesh into a prefab in the editor and then link it up to a Mesh Baker component so that I can use Add/Delete and Show/Hide at runtime with it? Thereby skipping the initial Add of all of the source objects during runtime.

    And is it possible to relink the bones to the skinned mesh at runtime? I have been able to create a single prefab that has all the bones and the baked skin mesh on it, and instantiate it. But any changes to it and the skinned mesh does not render. For example, if some of the bones are in different prefabs, I can recreate the original prefab by instantiating the one with the skinned mesh on it and then instantiating the ones with the bones and making them children of the skinned mesh prefab. It will look exactly like the complete single prefab but the skinned mesh does not render.

    Thanks!
     
  22. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    Hi Helllllllo,

    I am having trouble reproducing the issue. Which version of Mesh Baker are you using? And which version of Unity are your using? Does the issue happen in the editor or only on device builds?
     
  23. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    Double check the render bounds of the combined skinned mesh renderer. If this bounds is not correct then the skinned mesh may not display correctly.

    The problem with baking in the editor and modifying at runtime is that Unity recreates the scene with new game objects when the scene is loaded. Mesh Baker stores the InstanceID of the game objects in the mesh. When you want to update the combined mesh and tell Mesh Baker to delete or update a renderer in the combined mesh, Mesh Baker has no way of knowing which renderer you are trying to reference. I have been meaning to switch the instance ID to a game object reference but it still on the todo list.

    The problem with relinking is the SkinnedMeshRenderer.bones array. The bones array is a list of transforms which are game object instances in the scene. If you can rebuild this array with the correct transforms from your newly instantiated prefab, you can assign it to the SkinnedMeshRenderer.bones and it should work. The transforms in this array need to be in the same order that they were originally. Here is how I would try to reconnect the bones.

    • In the old scene where I baked the original skinned mesh into a prefab I would grab the combined mesh SkinnedMeshRender.bones. I would collect the bone names into a list or array of strings and serialize this in a new component attached to the combined mesh.
    • In the new scene after I have instantiated the skinned mesh prefab and the prefab with the bones I want to connect, I would find the transforms in the prefab with bones that match the saved names and put these in an array. Then assign this to the bones array.
     
  24. Helllllllo

    Helllllllo

    Joined:
    Aug 2, 2015
    Posts:
    10

    thank for your reply , the unity version I use is 2017.4.13f1,mesh baker is 3.26.0
    there is my one of the many problems with FBX

    The problem only occurs on mobile devices, and also appear under Android and IOS under Mac.
     

    Attached Files:

  25. jeremyinteractive

    jeremyinteractive

    Joined:
    Jun 2, 2016
    Posts:
    4

    Hi, I'm having the same issue. I tried this on an empty project, and I get the same phantom mesh with no errors reported.
     
    Last edited: Dec 17, 2018
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    Just to be clear, you are doing a double bake? You first bake some objects into a combined mesh, then your bake those combined meshes into another combined mesh? Is this correct?
     
  27. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    Thanks for the reply. I was able to reproduce the problem for iOS/Metal by setting the platform to iOS and forcing the editor to emulate "OpenGL ES". I am still not able to reproduce the problem for Android. Try the following: In file MB3_AtlasPackerRenderTexture.cs add a function:

    Code (CSharp):
    1.     public bool YisFlipped() {
    2.         string graphicsDeviceVersion = SystemInfo.graphicsDeviceVersion.ToLower();
    3.         bool flipY;
    4.         if (graphicsDeviceVersion.Contains("metal"))
    5.         {
    6.             flipY = false;
    7.         } else {
    8.             // "opengl es, direct3d"
    9.             flipY = true;
    10.         }
    11.  
    12.         if (LOG_LEVEL == MB2_LogLevel.debug) Debug.Log("Graphics device version is: " + graphicsDeviceVersion + " flipY:" + flipY);
    13.         return flipY;
    14.     }
    Then at the top of function CopyScaledAndTiledToAtlas there should be some lines like:


    Code (CSharp):
    1.  
    2.         r.y = 1f - (r.y + r.height);  // DrawTexture uses topLeft 0,0, Texture2D uses bottomLeft 0,0
    3.         r.x *= _destinationTexture.width;
    4.         r.y *= _destinationTexture.height;
    5.         r.width *= _destinationTexture.width;
    6.         r.height *= _destinationTexture.height;
    Switch these to:

    Code (CSharp):
    1.         if (YisFlipped())
    2.         {
    3.             // Some graphic APIs flip the y. DrawTexture uses topLeft 0,0, Texture2D uses bottomLeft 0,0
    4.             r.y = 1f - (r.y + r.height);
    5.         }
    6.         r.x *= _destinationTexture.width;
    7.         r.y *= _destinationTexture.height;
    8.         r.width *= _destinationTexture.width;
    9.         r.height *= _destinationTexture.height;
    This should fix the issue for iOS. If the issue is still happening on Android try to print the output of System.graphicsDeviceVersion and add a clause to the YisFlipped function to flip or not-flip for that device type. Please let me know what System.graphicsDeviceVersion is returning for your Android builds if you need to add a clause so I can fix it in the next version.
     
  28. Helllllllo

    Helllllllo

    Joined:
    Aug 2, 2015
    Posts:
    10
    that awesome ,it work perfect
    My Android is using OpenGL ES 3.2
    So I added a condition graphicsDeviceVersion.Contains("opengl es")
     
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    You might want to check that it works on an Open GL ES 3.0 device. In my testing the Open GL ES did need to be flipped on my Open GL ES 3.0 device.
     
  30. jeremyinteractive

    jeremyinteractive

    Joined:
    Jun 2, 2016
    Posts:
    4
    Hi, there is no double bake. It's just the new mesh filter shows no name even though it shows other info about the mesh, and the mesh doesn't move with the transform.
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    It is normal for the mesh to have no name. This is a mesh instance created locally in the scene. It sounds like the mesh has no vertices. What happens when you press "bake" on the Mesh Baker? There should be a message in the console, something like: Successfully baked 2 meshes.
     
  32. hassonhamo3

    hassonhamo3

    Joined:
    May 25, 2018
    Posts:
    38
    Hi Phong , i'm using Vegetation studio to build my terrain with trees and objects , is it possible to use mesh baker with it?
     
  33. jeremyinteractive

    jeremyinteractive

    Joined:
    Jun 2, 2016
    Posts:
    4
    It does message, "Successfully baked 8 meshes", The mesh even has a wireframe and a vert count when I double click on the blank mesh filter.
    This used to work properly, and the mesh filter wasn't blank then, it had a name like "combined-mesh-...". Even the demo scenes don't work right. Like I said, I did this on blank projects too. I'm pretty sure this is a bug. Hopefully there is a fix soon.
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    I do not own Vegetation Studio myself so I have not tried it.

    Reading the description they talk about shaders using the Unity Instancing system. I think that this approach will probably not work with Mesh Baker because, as I understand it, each renderer is setting a block of properties for the shader to use. A batch of trees is renderered together with each renderer (instance) being custom renderered with its block of properties. If many renderers were combined into a single renderer then there would be only one block of properties.

    If your shaders are not using instancing then you probably could use Mesh Baker to group them into combined meshes and bake them togther.

    You also may be able to use the Batch Prefab Baker to make more of your trees share a single combined material. This will help Unity's static batching system to be much more efficient because many more instances are eligible for batching. I use the word 'may' because in my experience, vegetation often has a lot of tiling and there is often a wind system that is based on distance from the mesh origin. The wind system breaks when meshes are combined and some of the trunks move when they are no longer rooted at local position 0,0,0,.
     
  35. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    Would you able to send me an example project that exhibits the problem?
     
  36. hassonhamo3

    hassonhamo3

    Joined:
    May 25, 2018
    Posts:
    38
    thank you so much for your great reply , i had doubt Mesh baker wouldn't work with Vs and now i'm sure that it doesn't :D .
     
  37. jeremyinteractive

    jeremyinteractive

    Joined:
    Jun 2, 2016
    Posts:
    4
    Yes, thank you
     
  38. htryu02

    htryu02

    Joined:
    Mar 26, 2018
    Posts:
    5
    Hi, Phong.
    First of all, I want to let you know my situation.
    I want to "bake" mesh and texture of objects in point cloud.
    Sub mesh is points. not triangles.

    1. I want to "bake" a mesh with points type submesh. Can Asset do it?
    2. If you can't do question 1, can this asset "bake" a texture of a points type sub mesh objects?

    Thank you for reading.
     
  39. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    TBH I am not sure. If you are willing to send me a mesh and texture I will try it and let you know.

    I have not tried this. That being said I think it would probably work or would require modifying a few lines to make it work. Currently I am using _mesh.SetTriangles. These could be switched to _mesh.SetIncies and it would probably work.

    Regarding baking a texture. As long as each vertex has a UV then Mesh Baker should be able to find the enclosing texture and bake that into an atlas. There are a few Mesh Baker features that expect indices to form triangles (generating tangents if a mesh does not have them but the combined mesh wants them).
     
  40. htryu02

    htryu02

    Joined:
    Mar 26, 2018
    Posts:
    5
    Happy new year Phong.
    Ok. I will send you.

    Where i send asset?
     
  41. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    781
    Hello!

    I'd love to know if this asset supports the following:
    • Generating meshes with 32-bit vertex indexes added in 2017.3 (to avoid any multi-part meshes due to 65k+ vertices)
    • Merging without any material/texture manipulation (simply packing untouched source materials into a shared material array in accordance with final submeshes - without any atlasing or material generation).
    • Pure scripting support: getting a merged skinned mesh directly through some class as opposed to invoking baking through the baker component and attempting to find a mesh on a generated GameObject.
     
    Last edited: Jan 2, 2019
  42. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    My work email is contact.digitalopus@gmail.com. Or if the package is large you can share it somewhere and Private Message me a link.
     
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    1) Yes Mesh Baker supports the 32 bit vertex buffers added in 2017.3
    2) Yes, you can combine meshes without creating atlases. If you combine two meshes (with 2 submeshes each for a total of four distinct materials), the combined mesh will have four submeshes. If any of the source meshes share a material then those will be combined into the same submesh on the combined mesh. The easiest way to do this is to not use the TextureCombiner. You can also do this with the TextureCombiner component by creating a detailed map of which source materials map to which submesh in the combined mesh. This way some of your materials can be combined and some left alone.
    3) Yes, the components in Mesh Baker are wrappers for underlying combiner classes that can be used directly from scripts. As much of the functionality as possible is available at runtime. Some functions (manipulating prefabs, creating assets, etc... is only possible in the editor). The package includes full source and a lot of example scripts, many of which are runtime examples. Combining Meshes into skinned meshes is supported at runtime (although you can only make the result into a prefab in the editor).
     
  44. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    781
    This is great, thanks! If its not too much trouble, could you direct me to specific sample scene or a class I should look at? The API is quite complex and peeking at how "Bake" button on sample component works hasn't been very illuminating since it seems to do quite a bit of editor specific things.

    So far I'm guessing that I need to create an instance of DigitalOpus.MB.Core.MB3_MeshCombinerSingle, call AddDeleteGameObjects on it and then call Apply on it, though that might be totally wrong.
     
    Last edited: Jan 2, 2019
  45. AmbOcclusion

    AmbOcclusion

    Joined:
    Sep 17, 2012
    Posts:
    28
    I am attempting to merge multiple meshes and materials together in script at runtime. The problem I'm running into is that material colors are not included in the merged material. Is there a way to include those?
     
  46. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    The Scenes:

    • SkinnedMeshRenderer - Bakes some skinned and MeshRenderer meshes together at runtime.
    • SceneDynamicAddingDelete - Adds and deletes repeatedly at runtime.
    • CustomizeCharacterGame - Mixes and matches different body parts of a character at runtime to create a single customized skinned mesh character. There is a youtube tutorial showing how to prepare body parts for this. There are some issues that are tricky to resolve.
     
  47. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    781
    Thanks! But if I'm not missing anything, all three of these scenes demonstrate use of a component and not a standalone class. Is the following guess correct? :)
    On the subject of 32-bit indexes - does that mean that MB3_MultiMeshCombiner is now only indended for platforms not supporting 32-bit indexes and for older versions of Unity; with MB3_MeshCombinerSingle being the main way to combine arbitrarily large sets of meshes on Unity 2017.3+?
     
  48. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    Yes, check "Blend non-texture properties" when baking the atlas. Note that this requires the use of MeshBaker TextureBlender scripts (see manual for more information). These scripts are specific to the shaders being used. Mesh Baker includes TextureBlenders for the Standard shader variants and diffuse shaders. If you are using a custom shader you may need to write your own TextureBlender scritp to get it to work.
     
  49. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    1,575
    Unfortunately I don't have an example using the MB3_MeshCombinerSingle directly. The steps you describe are close. For a skinned mesh you will need to adjust the render bounds on the generated skinned mesh after bake. Mesh Baker includes some methods for doing this. You can also just set the render bounds yourself.

    I think the most cases the 32-bit indexes is the best option for large meshes. There may still be some reasons to use the MultiMeshBaker in some cases.
     
  50. AmbOcclusion

    AmbOcclusion

    Joined:
    Sep 17, 2012
    Posts:
    28
    I've enabled the bool "considerNonTextureProperties" in script which seems to be what "Blend Non-Texture Properties" is mapped to and it does not bake the material color into the TextureBake'd material. I'm using Standard shader everywhere.

    EDIT: To clarify, I'd like the material color to be baked into the TextureBaker's resulting material texture.
     
    Last edited: Jan 2, 2019