Reputation:
I'm currently working on a Unity project with Minecraft-like world generation. The goal is to generate different blocks in the world, each with their own Material, and then combine them into one big mesh. My problem is that this comining removes all of their Materials (since the new mesh can only have one material). I've heard about a method using a so called texture atlas but couldn't find anything specific so my questions are
One thing I tried was generating a mesh for every cube in the world and then combining them into bigger meshes, but this lost all material data which looked like this: Single meshes on the right, big mesh on the left
Thanks in advance!
Upvotes: 1
Views: 2329
Reputation: 136
If you're talking about texture atlas because you want to save on draw calls (or get better performances in a general way), then you'll have to write a lot of code to create such atlas and update the merged meshes' UVs so they reference the correct texture in the atlas. Doing so also prevents tiling textures (ie: going outside of the [0;1] range on UV), or at least it makes it more complicated and brings some serious limitation.
If you can afford it, this is the tool for it, amongst other ones : https://assetstore.unity.com/packages/tools/modeling/mesh-baker-5017 (I never tried it, I rolled out my own solution)
Upvotes: 0
Reputation: 350
You can use SubMeshes. In that case the "whole" mesh is split into seperate meshes. Each subMesh has its own material. There are many examples out there how submeshes work in unity. e.g. small submesh example
Hope this helps.
Upvotes: 0