Search Unity

Change plane texture

Discussion in 'AR' started by Aupuma, Jun 28, 2018.

  1. Aupuma

    Aupuma

    Joined:
    Feb 15, 2017
    Posts:
    42
    Hi, I want to change the plane texture to an opaque seamless texture of my choice, but If I change the material only its base color is visible, not the texture.
    Does this API work with plane materials differently or I'm missing something?
     
  2. blanx

    blanx

    Joined:
    Feb 26, 2016
    Posts:
    73
    If I see it right there are no uv’s Generated for the plane. That is why you do not see a texture.

    Should be easily done by using the xz position as uv data.
     
    Aupuma likes this.
  3. Aupuma

    Aupuma

    Joined:
    Feb 15, 2017
    Posts:
    42
    It worked! I used the code from the Unity example and pasted it at the end of the method GenerateMesh. The texture moves when new vertices are added to the plane, but for the moment it is enough for me. If anyone needs it:

    Code (CSharp):
    1. Vector3[] vertices = mesh.vertices;
    2. Vector2[] uvs = new Vector2[vertices.Length];
    3.  
    4. for (int i = 0; i < uvs.Length; i++)
    5. {
    6.          uvs[i] = new Vector2(vertices[i].x, vertices[i].z);
    7. }
    8. mesh.uv = uvs;
     
  4. blanx

    blanx

    Joined:
    Feb 26, 2016
    Posts:
    73
    Thanks. Will try that too.

    Maybe would be good check the arcore code. I think they had a plane texture in their sample.
     
  5. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    UVs are now generated in 1.0.0-preview.13 of ARFoundation.

    To update, go to Window > Package Manager > AR Foundation > Update to 1.0.0-preview.13
     
    mdurand likes this.