0
\$\begingroup\$

I have two cubes, one parent and one child. I want to use the parent's cube mesh as a mask for the child cube. I want to make visible only the part of the child cube that it is inside the parent cube.

I can easily achieve this effect with 2D sprites using the Sprite Mask, but I can't find a way to do it for 3D areas or 3D objects.

What I have:

What I have

What I want:

What I want

\$\endgroup\$
2
  • \$\begingroup\$ What should we see if we look at the cut-off side of the small cube? It's reasonably easy to just leave it as an open hole, but capping it off can be significantly trickier. \$\endgroup\$
    – DMGregory
    Apr 9, 2020 at 11:21
  • \$\begingroup\$ I don't really care about the hole, but it would look better without it. \$\endgroup\$ Apr 9, 2020 at 14:24

1 Answer 1

0
\$\begingroup\$

In 3d editing it is called a Boolean Operation and not a mask.

The operation you are talking about is an Intersection. https://docs.unity3d.com/Packages/[email protected]/manual/boolean.html

You can use this library:

https://github.com/karl-/pb_CSG

It should work with the cubes fine.

\$\endgroup\$
3
  • \$\begingroup\$ Recomputing the mesh with CSG might be strictly more work than just clipping the unwanted portion in the shader. \$\endgroup\$
    – DMGregory
    Apr 9, 2020 at 11:22
  • 1
    \$\begingroup\$ Thanks for the answer. What I didn't clarify is that I want it to change in real time while the child cube moves in space in and out of the parent cube. I have used Boolean in the past for 3D model modifications but not sure it will be optimal in this case. \$\endgroup\$ Apr 9, 2020 at 14:22
  • \$\begingroup\$ @user2975038 I think that using a boolean operation should be perfectly ok since it seems like you are planning to use cubes? This is a quick operation and spending unneeded time optimizing this in advance might waste the more important resource -> your time. \$\endgroup\$
    – AturSams
    Apr 26, 2020 at 19:20

Not the answer you're looking for? Browse other questions tagged .