hi again guys,
instead of apply the AutoUnwrapSetting face by face
foreach ( var face in mesh.faces )...
could it be possible to select a group of faces and AutoWrap it at once? (it would look like a planar projection…or simply Unwrap that part of the mesh as one UV island)
this would be very useful in simple modifications,
for example, an object that enlarges in one Axis (like an Scale in one Axis but moving vertex instead), with the texture set on Tiled, so the texture would not deform, but would keep the correct aspect
the AutoUnwrap per faces is ok on Objects like Planes or Boxes, but how can be this achieve in a mesh like the picture?
Dont know if this is possible in Unity without Probuilder, or if is only avaible via Probuilder, Im open to any advice because simply Im searching a way to do it, no matter what.
Try this out. I haven’t tested it, but this is the gist of what you’ll need to do.
void ProjectFaces()
{
var mesh = MeshSelection.activeMesh;
var faces = mesh.GetSelectedFaces();
List<int> indices = new List<int>();
// Faces can reference the same vertex more than once. Use this function to get a distinct list of vertex
// indices to work with.
Face.GetDistinctIndices(faces, indices);
// Project only the vertex positions that we care about by passing the indices parameter. The third argument
// determines from what plane positions will be projected.
var projected = Projection.PlanarProject(mesh.positions, indices, -Vector3.forward);
// Get a copy of the textures array, assign the new projected values, then re-apply to the mesh.
var uvs = mesh.textures;
for (int i = 0, c = indices.Count; i < c; ++i)
uvs[indices[i]] = projected[i];
mesh.textures = uvs;
// If you want your changes to UV array to "stick", the faces need to be flagged as manually unwrapped.
// Otherwise the face UVs will be recalculated the next time `ProBuilderMesh.Refresh` is invoked.
foreach (var face in faces)
face.manualUV = true;
}