private void CopyToMesh(TrackRenderData data, Vector3[] positions, Vector2[] uvs, Vector3[] normals, Color[] colors, int[] triangles, int firstVertex, int firstIndex, out int nextIndex, out int nextVertex) { int index = data.lastSectorIndex - data.sectorCount; if (index < 0) { index += data.maxSectorCountPerTrack; } float halfAlpha = 0.5f / ((float)(data.maxSectorCountPerTrack - data.firstSectorToHide)); Vector3 vector = new Vector3(); Vector3 vector2 = new Vector3(); for (int i = data.sectorCount; i > 0; i--) { Vector3 vector3; Vector3 vector4; Vector3 vector5; Vector3 vector6; float num4; float num5; TrackSector sector = data.sectors[index]; this.ComputeSectorVertices(sector, data.sectorCount, i, index, vector, vector2, out num4, out num5, out vector3, out vector4, out vector5, out vector6); this.CopySectorToMesh(data, vector3, vector4, vector5, vector6, sector.normal, i, positions, uvs, normals, colors, triangles, firstVertex, firstIndex, halfAlpha, num4, num5, sector.rotationCos); firstVertex += 4; firstIndex += 6; index = (index + 1) % data.maxSectorCountPerTrack; vector = vector3; vector2 = vector4; } nextIndex = firstIndex; nextVertex = firstVertex; }
private void CopySectorToMesh(TrackRenderData data, Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 normal, int indexByOrder, Vector3[] positions, Vector2[] uvs, Vector3[] normals, Color[] colors, int[] triangles, int firstVertex, int firstIndex, float halfAlpha, float startTextureWidth, float endTextureWidth, float rotationCos) { positions[firstVertex] = v0; positions[firstVertex + 1] = v1; positions[firstVertex + 2] = v2; positions[firstVertex + 3] = v3; float y = (indexByOrder - (data.currentPart % data.parts)) * data.texturePart; float num2 = y - data.texturePart; float s = Mathf.Sin(Mathf.Acos(rotationCos)); Vector2 vector = new Vector2(0f, num2); Vector2 vector2 = new Vector2(startTextureWidth, num2); Vector2 vector3 = new Vector2(0f, y); Vector2 vector4 = new Vector2(endTextureWidth, y); this.RotateTextureCoords(ref vector, ref vector2, ref vector3, ref vector4, out uvs[firstVertex], out uvs[firstVertex + 1], out uvs[firstVertex + 2], out uvs[firstVertex + 3], rotationCos, s); normals[firstVertex] = normal; normals[firstVertex + 1] = normal; normals[firstVertex + 2] = normal; normals[firstVertex + 3] = normal; float baseAlpha = data.baseAlpha; float num6 = data.baseAlpha; if (indexByOrder > data.firstSectorToHide) { int num7 = data.maxSectorCountPerTrack - data.firstSectorToHide; float num9 = 1f - (((float)(indexByOrder - data.firstSectorToHide)) / ((float)num7)); baseAlpha *= num9 + halfAlpha; num6 *= num9 - halfAlpha; } Color color = Color.white * baseAlpha; Color color2 = Color.white * num6; colors[firstVertex] = color; colors[firstVertex + 1] = color; colors[firstVertex + 2] = color2; colors[firstVertex + 3] = color2; triangles[firstIndex] = firstVertex; triangles[firstIndex + 1] = firstVertex + 1; triangles[firstIndex + 2] = firstVertex + 2; triangles[firstIndex + 3] = firstVertex + 3; triangles[firstIndex + 4] = firstVertex + 2; triangles[firstIndex + 5] = firstVertex + 1; }
private void AddSectorToRender(ref TrackRenderData data, Vector3 startPosition, Vector3 startForward, Vector3 endPosition, Vector3 endForward, Vector3 normal, float width, float textureWidth, float rotationCos, bool contiguous) { data.lastSectorIndex++; data.lastSectorIndex = data.lastSectorIndex % data.maxSectorCountPerTrack; data.sectors[data.lastSectorIndex] = new TrackSector { startPosition = startPosition, startForward = startForward, endPosition = endPosition, endForward = endForward, normal = normal, width = width, rotationCos = rotationCos, textureWidth = textureWidth, contiguous = contiguous }; data.sectorCount++; if (data.sectorCount > data.maxSectorCountPerTrack) { data.sectorCount = data.maxSectorCountPerTrack; } data.currentPart++; data.currentPart = data.currentPart % data.parts; }