01 02 03 04 05 06 07 08 09 10 11 12 13 | private static void CreateTangents (Vector3[] vertices, Vector4[] tangents) { for ( int i = 0; i < vertices.Length; i++) { Vector3 v = vertices[i]; v.y = 0f; v = v.normalized; Vector4 tangent; tangent.x = -v.z; tangent.y = 0f; tangent.z = v.x; tangent.w = -1f; tangents[i] = tangent; } } |
1 2 3 4 5 6 7 | tangents[vertices.Length - 4] = tangents[0] = new Vector3(-1f, 0, -1f).normalized; tangents[vertices.Length - 3] = tangents[1] = new Vector3(1f, 0f, -1f).normalized; tangents[vertices.Length - 2] = tangents[2] = new Vector3(1f, 0f, 1f).normalized; tangents[vertices.Length - 1] = tangents[3] = new Vector3(-1f, 0f, 1f).normalized; for ( int i = 0; i < 4; i++) { tangents[vertices.Length - 1 - i].w = tangents[i].w = -1f; } |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 | Vector4[] tangents = new Vector4[vertices.Length]; CreateTangents(vertices, tangents); if (radius != 1f) { for ( int i = 0; i < vertices.Length; i++) { vertices[i] *= radius; } } Mesh mesh = new Mesh(); mesh.name = "Octahedron Sphere" ; mesh.vertices = vertices; mesh.normals = normals; mesh.uv = uv; mesh.tangents = tangents; mesh.triangles = triangles; return mesh; |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | using UnityEditor; using UnityEngine; public class OctahedronSphereWizard : ScriptableWizard { [MenuItem( "Assets/Create/Octahedron Sphere" )] private static void CreateWizard () { ScriptableWizard.DisplayWizard<OctahedronSphereWizard>( "Create Octahedron Sphere" ); } [Range(0, 6)] public int level = 6; public float radius = 1f; private void OnWizardCreate () { string path = EditorUtility.SaveFilePanelInProject( "Save Octahedron Sphere" , "Octahedron Sphere" , "asset" , "Specify where to save the mesh." ); if (path.Length > 0) { Mesh mesh = OctahedronSphereCreator.Create(level, radius); MeshUtility.Optimize(mesh); AssetDatabase.CreateAsset(mesh, path); Selection.activeObject = mesh; } } } |
感谢蛮牛译员“轩辕之子”对本文翻译所做的贡献~~~
联系客服