-
-
Save facybenbook/b08b0af69bb596afdc7d183dc3b904d1 to your computer and use it in GitHub Desktop.
Revisions
-
SkaillZ revised this gist
Apr 2, 2019 . 1 changed file with 2 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 @@ -8,8 +8,8 @@ namespace RoboticWeaselAssault.Gamutmamut.Editor public class EditorTools { /// <summary> /// Copies a splat map into a mesh's vertex colors. A mesh and a texture must be selected simultaneously. /// Read/write must be enabled in the texture's import settings. /// </summary> [MenuItem("Tools/Copy SplatMap to Vertex Colors")] public static void SplatMapToVertexColors() -
SkaillZ created this gist
Apr 2, 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,62 @@ using System; using System.Linq; using UnityEditor; using UnityEngine; namespace RoboticWeaselAssault.Gamutmamut.Editor { public class EditorTools { /// <summary> /// Copies a splat map into vertex colors. A mesh and a texture must be selected. Read/write must be enabled in /// the texture's import settings. /// </summary> [MenuItem("Tools/Copy SplatMap to Vertex Colors")] public static void SplatMapToVertexColors() { var mesh = Selection.objects.OfType<Mesh>().FirstOrDefault(); var texture = Selection.objects.OfType<Texture2D>().FirstOrDefault(); if (mesh == null || texture == null) { throw new Exception("Please select a mesh and a texture."); } var newMesh = CopyMesh(mesh); var colors = new Color[newMesh.vertexCount]; var uvs = newMesh.uv; for (var i = 0; i < colors.Length; i++) { // Get the texture coordinates var uv = uvs[i]; // Sample the texture on the given UV position colors[i] = texture.GetPixelBilinear(uv.x, uv.y); } newMesh.colors = colors; // Show a UI to get the path where the new mesh should be saved string targetPath = EditorUtility.SaveFilePanel("Save mesh", "Assets/", mesh.name, "asset"); if (targetPath != null) { AssetDatabase.CreateAsset(newMesh, FileUtil.GetProjectRelativePath(targetPath)); } } private static Mesh CopyMesh(Mesh mesh) { return new Mesh { vertices = mesh.vertices, triangles = mesh.triangles, uv = mesh.uv, uv2 = mesh.uv2, normals = mesh.normals, colors = mesh.colors, tangents = mesh.tangents }; } } }