How to put a mask into 3d space I'm trying to make a vfx scene where a mesh I created passes behind an object in real life/the video. I've tried to make a mask around the real object, but that makes all of the objects that are supposed to be in front of the real object also disappear. How would I put the mask into my 3d viewport so that anything behind it disappears/is covered by the video, but anything in front of it isn't. I've heard of id-masks, and think those may be able to help, but honestly I have no clue how to use them. (I'm sorry that is worded so poorly, I'm not sure how to go about this.)

**edit I'm rendering/compositing using cycles render. It would be hard to render the objects separately because what I'm trying to do is make a rubix cube shatter and launch the pieces everywhere using some simulations. Because only some of the pieces fall behind a chair or under a table, it would be hard to select all of those and render them separately because they are all part of the same simulation. Also they all start on top of the table then some move under.
Load the background image in the image editor

Set the editor in mask mode

On on the image click while pressing the Ctrl key and draw a mask for the area you want to use as foreground.

Then in the compositor use that mask to combine the foreground and background elements.