Search Unity

Computing uv mapping with ProBuilder

Discussion in 'Scripting' started by SpaceToad, Aug 16, 2019.

  1. SpaceToad

    SpaceToad

    Joined:
    Oct 14, 2013
    Posts:
    6
    Hi all,

    I'm completely new with ProBuilder - but it seems like it's able to generate UV positions for meshes generated programatically - am I understanding this right? If that's the case, this is a very significant support. However, I've been failing at using the API so far (Unity 2019.2 with ProBuilder 4.0.5).

    Essentially, my code looks like:

    Code (CSharp):
    1.    GetComponent<MeshFilter>().mesh = <some mesh I generated separately, without UVs>;
    2.    gameObject.AddComponent<ProBuilderMesh>();
    3.    ProBuilderMesh proBuilderMesh = GetComponent<ProBuilderMesh>();
    4.    MeshImporter importer = new MeshImporter(proBuilderMesh);
    5.    importer.Import(m);
    6.  
    7.    for (int i = 0; i < proBuilderMesh.faces.Count; ++i) {
    8.       proBuilderMesh.faces[i].manualUV = false;
    9.       proBuilderMesh.faces[i].uv = new AutoUnwrapSettings() {
    10.         anchor = AutoUnwrapSettings.Anchor.UpperLeft,
    11.          fill = AutoUnwrapSettings.Fill.Stretch,
    12.          scale = new Vector2(0.33f, 0.33f)
    13.       };
    14.   }
    15.  
    16.   proBuilderMesh.ToMesh();
    17.   proBuilderMesh.Refresh();
    All the faces seemed to be mapped over a small 0.33 by 0.33 rectangle on the texture, one on top of the other, which is (I guess) what I'm asking for.

    Is there any way from this code or ProBuilder to actually generate an entire mapping of uv positions without one triangle overlapping the other, and edges properly connected, so that this uv can then be used for texturing?
     
    awsapps likes this.
  2. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    Hi @SpaceToad did you find a way to map UVs without overlapping at runtime with probuilder? thanks a bunch