/// <summary> /// Gets an object group's thumbnail provided an array of objects. /// </summary> /// <param name="objects">The object components to draw.</param> /// <param name="gd">GraphicsDevice instance.</param> /// <param name="state">WorldState instance.</param> /// <returns>Object's ID if the object was found at the given position.</returns> public Texture2D GetObjectThumb(ObjectComponent[] objects, Vector3[] positions, GraphicsDevice gd, WorldState state) { var oldZoom = state.Zoom; var oldRotation = state.Rotation; /** Center average position **/ Vector3 average = new Vector3(); for (int i = 0; i < positions.Length; i++) { average += positions[i]; } average /= positions.Length; state.SilentZoom = WorldZoom.Near; state.SilentRotation = WorldRotation.BottomRight; state.WorldSpace.Invalidate(); state.InvalidateCamera(); state.TempDraw = true; var pxOffset = new Vector2(442, 275) - state.WorldSpace.GetScreenFromTile(average); var _2d = state._2D; Promise<Texture2D> bufferTexture = null; state._2D.OBJIDMode = false; Rectangle bounds = new Rectangle(); using (var buffer = state._2D.WithBuffer(BUFFER_THUMB, ref bufferTexture)) { while (buffer.NextPass()) { for (int i=0; i<objects.Length; i++) { var obj = objects[i]; var tilePosition = positions[i]; //we need to trick the object into believing it is in a set world state. var oldObjRot = obj.Direction; obj.Direction = Direction.NORTH; state.SilentZoom = WorldZoom.Near; state.SilentRotation = WorldRotation.BottomRight; obj.OnRotationChanged(state); obj.OnZoomChanged(state); _2d.OffsetPixel(state.WorldSpace.GetScreenFromTile(tilePosition) + pxOffset); _2d.OffsetTile(tilePosition); _2d.SetObjID(obj.ObjectID); obj.Draw(gd, state); //return everything to normal obj.Direction = oldObjRot; state.SilentZoom = oldZoom; state.SilentRotation = oldRotation; obj.OnRotationChanged(state); obj.OnZoomChanged(state); } bounds = _2d.GetSpriteListBounds(); } } bounds.X = Math.Max(0, Math.Min(1023, bounds.X)); bounds.Y = Math.Max(0, Math.Min(1023, bounds.Y)); if (bounds.Width + bounds.X > 1024) bounds.Width = 1024 - bounds.X; if (bounds.Height + bounds.Y > 1024) bounds.Height = 1024 - bounds.Y; //return things to normal state.WorldSpace.Invalidate(); state.InvalidateCamera(); state.TempDraw = false; var tex = bufferTexture.Get(); return TextureUtils.Clip(gd, tex, bounds); }