How can i make an moving object appear and dissapear when going through a full transparent object?

Hi,

need to dig into the crowd knowledge.

Basically I have a volume which is fully transparent. I want to keframe another item in such a way that it is visible when it enters and is in the volume and disappear when leaving the cube volume again. Principally like the volume outside eats the component passing through the cube when it leaves the cube and hiding it.

Can be (rather fast) fading or instantly switching off. The object should not be visible outside the volume.

Think of it like a moving train which it clipped before the cube volume and behind the cube volume. The train is only visible when in the volume.
Its all part of a flyaround animation with that box in the middle. Guess clipping from 6 sides does not work, does it?

Anyone have a suggestion for a simple setup to achieve that?

Thanks for your ideas & thoughts,

Pretty

I know these aren’t animation based answers but:

One way would be to use the Is Transmission Ray to control a
Transparent BSDF or Principled BSDF on your intersecting object(the parts of it outside the volume are transparent and inside are not) but your volume is going to take on refraction properties and change the way your intersecting property looks.

I’d say the right way to do it would be to somehow use the Compositor to clip the object to the volume but I don’t know how to use the Compositor much at all.