Probuilder Scripting, Autounwrap several faces at one

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

is this possible in Probuilder API?
thanks!!!

to clarify what Im triyng to achieve, I made this montage:

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.

thanks guys!!

Yes, this can be done using Projection class Class Projection | Package Manager UI website

1 Like

Many Thanks Kaarrrllll, I had not found any information about it, is there any example of usage out there?
thanks!!

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;
}

Many many thanks kaarrrlll, you are great!

Hi, I’m having a problem with probuilder and I think is related to the topic of this thread.

I’m building a mesh with multiple materials. The problem is I can’t get rid of the seams in the corners of this frame.


Something similar happens in the back of the image.

I sort of fixed it by making the fill of the uvs of type Tile, but I was wondering if its possible to get rid of the seams using the fill type of Fit.

Thank you.