For that, you could paint a ID mask manually. Here's how to do it quickly:
- In Texture Paint mode, turn on Face Selection Masking in the header
- Select a face and hit Ctrl+L to select everything attached to that face
- Switch to the Fill brush with a strength of 1 and fill the selection
- Repeat with a different color for each piece.
Hope that helps!