Last active
December 19, 2019 07:35
-
-
Save fuqunaga/c0aa186f85f3ffccf340cc8e45e9f2df to your computer and use it in GitHub Desktop.
Revisions
-
fuqunaga revised this gist
Dec 19, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 positions = vertices.Select(vtx => new Color(vtx.x, vtx.y, vtx.z)); var tex = CreateMap(positions, width, height); -
fuqunaga revised this gist
Dec 19, 2019 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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); -
fuqunaga created this gist
Dec 19, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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; }