I have a problem with setting a pattern on sofas. The image below is a pattern that I set on a sofa:

as you can see, the pattern comes from up to down in a straight line. This is wrong; I need it to covert the corners, do the indent and ....
for better understanding the result I want, please see the below image. I saw this on a website, and as you can see, it isn't in a straight line — it goes in the corners, rotates, and exactly gets the shape of the sofa.

This is exactly what I need to do but I don't know how. How can I do this in Photoshop?