protected override void OnBeginRenderLightmap( StaticLightingCalculationWorld.MeshObject meshObject, LightmapImage renderingImage) { lightmapMeshObject = meshObject; lightmapRenderingImage = renderingImage; lightmapBucketIndex = Vec2I.Zero; Vec2I textureSize = lightmapRenderingImage.Size; //generate lightmapTriangleMap { lightmapTriangleMap = new int[textureSize.Y][]; for (int y = 0; y < textureSize.Y; y++) { lightmapTriangleMap[y] = new int[textureSize.X]; for (int x = 0; x < textureSize.X; x++) { lightmapTriangleMap[y][x] = -1; } } Mesh mesh = meshObject.Mesh; int triangleCount = mesh.Indices.Length / 3; for (int triangleIndex = 0; triangleIndex < triangleCount; triangleIndex++) { int index0 = mesh.Indices[triangleIndex * 3 + 0]; int index1 = mesh.Indices[triangleIndex * 3 + 1]; int index2 = mesh.Indices[triangleIndex * 3 + 2]; Vec3 position0 = mesh.Positions[index0]; Vec3 position1 = mesh.Positions[index1]; Vec3 position2 = mesh.Positions[index2]; if (MathUtils.IsDegenerateTriangle(position0, position1, position2)) { continue; } Vec2 texCoord0 = mesh.LightmapTexCoords[index0]; Vec2 texCoord1 = mesh.LightmapTexCoords[index1]; Vec2 texCoord2 = mesh.LightmapTexCoords[index2]; Vec2I pixelIndex0 = GetPixelIndexByTexCoord(texCoord0); Vec2I pixelIndex1 = GetPixelIndexByTexCoord(texCoord1); Vec2I pixelIndex2 = GetPixelIndexByTexCoord(texCoord2); Geometry2D.FillTriangle(pixelIndex0, pixelIndex1, pixelIndex2, new RectI(Vec2I.Zero, textureSize), delegate(Vec2I point) { lightmapTriangleMap[point.Y][point.X] = triangleIndex; }); } } }