Skip to content

Instantly share code, notes, and snippets.

@fuqunaga
Last active December 19, 2019 07:35
Show Gist options
  • Select an option

  • Save fuqunaga/c0aa186f85f3ffccf340cc8e45e9f2df to your computer and use it in GitHub Desktop.

Select an option

Save fuqunaga/c0aa186f85f3ffccf340cc8e45e9f2df to your computer and use it in GitHub Desktop.

Revisions

  1. fuqunaga revised this gist Dec 19, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MeshToMap.cs
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ static Texture2D MeshToMap(Mesh mesh)
    var width = (int)Mathf.Ceil(r);
    var height = width;

    var vertices.Select(vtx => new Color(vtx.x, vtx.y, vtx.z));
    var positions = vertices.Select(vtx => new Color(vtx.x, vtx.y, vtx.z));

    var tex = CreateMap(positions, width, height);

  2. fuqunaga revised this gist Dec 19, 2019. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions MeshToMap.cs
    Original file line number Diff line number Diff line change
    @@ -14,8 +14,6 @@ static Texture2D MeshToMap(Mesh mesh)
    return tex;
    }



    static Texture2D CreateMap(IEnumerable<Color> colors, int width, int height)
    {
    var tex = new Texture2D(width, height, TextureFormat.RGBAFloat, false);
  3. fuqunaga created this gist Dec 19, 2019.
    38 changes: 38 additions & 0 deletions MeshToMap.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    static Texture2D MeshToMap(Mesh mesh)
    {
    var vertices = mesh.vertices;
    var count = vertices.Count();

    float r = Mathf.Sqrt(count);
    var width = (int)Mathf.Ceil(r);
    var height = width;

    var vertices.Select(vtx => new Color(vtx.x, vtx.y, vtx.z));

    var tex = CreateMap(positions, width, height);

    return tex;
    }



    static Texture2D CreateMap(IEnumerable<Color> colors, int width, int height)
    {
    var tex = new Texture2D(width, height, TextureFormat.RGBAFloat, false);
    tex.filterMode = FilterMode.Point;
    tex.wrapMode = TextureWrapMode.Clamp;

    var buf = new Color[width * height];

    var idx = 0;
    foreach (var color in colors)
    {
    buf[idx] = color;
    idx++;
    }

    tex.SetPixels(buf);
    tex.Apply();

    return tex;
    }