static GameObject CreateLeafBillboard(float leafSize, Material leafMaterial) { GameObject leafBillboard = new GameObject("Leaf"); leafBillboard.AddComponent <MeshRenderer>().sharedMaterial = leafMaterial; leafBillboard.AddComponent <MeshFilter>().sharedMesh = ProceduralMeshes.CreateXZPlane(leafSize, leafSize, 1, 1, new Vector3(-leafSize, 0, leafSize * 0.5f)); return(leafBillboard); }
void OnEnable() { #if UNITY_EDITOR capsuleMesh = ProceduralMeshes.GenerateCapsule(Height, Radius); #endif }
static void CreateSegment( int segmentAxisSamples, int segmentRadialSamples, float segmentWidth, float segmentHeight, bool narrowBranches, Material trunkMaterial, Turtle turtle, int nestingLevel, ref Mesh currentMesh, ref int chunkCount, GameObject trunk, Dictionary <int, Mesh> segmentsCache) { Vector3[] newVertices; Vector3[] newNormals; Vector2[] newUVs; int[] newIndices; Mesh segment; if (segmentsCache.ContainsKey(nestingLevel)) { segment = segmentsCache[nestingLevel]; } else { float thickness = (narrowBranches) ? segmentWidth * (0.5f / (nestingLevel + 1)) : segmentWidth * 0.5f; segment = ProceduralMeshes.CreateCylinder(segmentAxisSamples, segmentRadialSamples, thickness, segmentHeight); segmentsCache[nestingLevel] = segment; } newVertices = segment.vertices; newNormals = segment.normals; newUVs = segment.uv; newIndices = segment.triangles; if (currentMesh.vertices.Length + newVertices.Length > 65000) { CreateNewChunk(currentMesh, ref chunkCount, trunkMaterial, trunk); currentMesh = new Mesh(); } int numVertices = currentMesh.vertices.Length + newVertices.Length; int numTriangles = currentMesh.triangles.Length + newIndices.Length; Vector3[] vertices = new Vector3[numVertices]; Vector3[] normals = new Vector3[numVertices]; int[] indices = new int[numTriangles]; Vector2[] uvs = new Vector2[numVertices]; Array.Copy(currentMesh.vertices, 0, vertices, 0, currentMesh.vertices.Length); Array.Copy(currentMesh.normals, 0, normals, 0, currentMesh.normals.Length); Array.Copy(currentMesh.triangles, 0, indices, 0, currentMesh.triangles.Length); Array.Copy(currentMesh.uv, 0, uvs, 0, currentMesh.uv.Length); int offset = currentMesh.vertices.Length; for (int i = 0; i < newVertices.Length; i++) { vertices[offset + i] = turtle.position + (turtle.direction * newVertices[i]); } int trianglesOffset = currentMesh.vertices.Length; offset = currentMesh.triangles.Length; for (int i = 0; i < newIndices.Length; i++) { indices[offset + i] = (trianglesOffset + newIndices[i]); } Array.Copy(newNormals, 0, normals, currentMesh.normals.Length, newNormals.Length); Array.Copy(newUVs, 0, uvs, currentMesh.uv.Length, newUVs.Length); currentMesh.vertices = vertices; currentMesh.normals = normals; currentMesh.triangles = indices; currentMesh.uv = uvs; currentMesh.Optimize(); }