private void load(AtlasNode root) { // heavily based on // http://www.blackpawn.com/texts/lightmaps/default.html // basically it uses a kd-tree to pack the lightmaps // TODO: this shoudln't be hardcoded!! int outputWidth = 512; int outputHeight = 512; _packedTexture = new BitmapSurface(512, 512, null); root.AddToBitmap(_packedTexture); // create the packed rectangles root.UpdateRectList(_packedTextureRects); // now we have the rects, but they need to be converted from pixel coords /* for (int i = 0; i < _packedTextureRects.Length; i++) * { * Rect r = _packedTextureRects[i]; * r.X /= outputWidth; * r.Y /= outputHeight; * r.Width /= outputWidth; * r.Height /= outputHeight; * * _packedTextureRects[i] = r; * }*/ Utils.WriteTga("lightmap.tga", _packedTexture.Pixels, 512, 512); }
public void UpdateRectList(Rect[] packedRects) { if (Surface != null) { // HACK: this problably only improves the direct3d9 renderer, // with its weird texturing coordinate nonsense... Rect r = Rectangle; /*r.X += 0.5f; * r.Y += 0.5f; * r.Width -= 1.0f; * r.Height -= 1.0f;*/ packedRects[Index] = r; } if (Child1 != null) { Child1.UpdateRectList(packedRects); } if (Child2 != null) { Child2.UpdateRectList(packedRects); } }