July 12, 2006

Don't mesh with that path

A friend sent me an email today with a question about a logo they were working on. It was an object that was filled with a gradient mesh, and they were trying to punch out a hole from the middle of it. Only it seems that Illustrator wasn't letting him create a compound path because you can't create one with a gradient mesh object.

I thought it would be good to talk about this here, because there are two interesting points to take away from the solution that I gave him. In fact, the solution itself was pretty easy -- create a mask. By creating a compound path (or compound shape) of the final logo, you can simply overlay that shape over the gradient mesh, and use it as a mask. That way you only see the gradient mesh through the mask (imagine if the gradient mesh were a placed image). Perfect, right?

The "problem" though, is creating the shape that will be the mask. You would think that you can just make a copy of your gradient mesh object and use it to create the compound path, but you can't because it isn't a path -- it's a MESH.

A mesh is a special kind of object. If you draw a path and look at the Appearance palette, you'll see that the palette tells you that you have a Path targeted. However, if you draw a path, click in that path with the Mesh tool, and then look at the Appearance palette, you'll notice the target is now a "Mesh Object". A mesh object is not a normal path in Illustrator. It's a special KIND of path called a mesh object. And there are certain things that you can't do with mesh objects -- notably, you can't use them in compound path or compound shape operations. There are other limitations as well.

So the problem is, once you turn a path into a mesh object, you can't turn it back into a path (once a mesh, always a mesh!). So if the logo is a mesh, how do I then get a path that matches my shape that I can then use for a mask?

The answer, my friends, is to create a new path from the mesh object. And you can do so by selecting the mesh object and choosing Object > Path > Offset Path. For the Offset value, enter 0. Zilch. Nada. Nothing. This will create a new PATH that is identical to the mesh object. You can then use the newly-created path to create a compound shape that can then be used as a mask for your mesh object.

Got Flash?

This technique also appeals to Flash designers. When you create a gradient mesh in Illustrator, that artwork can't translate as vector into Flash, and so the result is going to be a big fat juicy raster image when you import it into Flash. Many designers may choose instead to bring a solid-filled object into Flash and apply a gradient to that shape in Flash, which would keep it vector and reduce the file size (of course, the appearance would change). However, how can you get that mesh into a path that Flash will understand? Same technique -- use Offset Path to create a new path with the same dimensions as the mesh object.

6 comments:

Tim said...

Thanks. I encountered this problem two weeks ago and was bewildered by it.

Anonymous said...

Re: "It's a special KIND of path called a mesh object."

No, it isn't any kind of path at all. It's a completely different data structure. (A guide, however, is a kind of path.) A mesh isn't a path "filled with" the mesh colors any more than a raster image is a rectangular path filled with pixels. You could generate a rectangular path from an image, but it wouldn't be one.

A path object is essentially a list of anchor points each having two direction handles, with a flag saying whether the path is open or closed.

A mesh object is an N by M grid of mesh points, where the 4 corner points each have two direction handles, the edge points connecting those corner points each have three direction handles, and the interior points each have four direction handles, with each mesh point also having a color. (Discounting for simplicity's sake the square control points along the mesh lines that are not connected to those in another line and that cannot have colors.)

You can generate a path from a mesh by making a list containing just the edge points and the direction handles between them, but the mesh itself does not contain any data structure corresponding to such a list. Which is why commands that know how to process paths do not know how to process meshes. There is no path there.

Other path things that you can't do with meshes, besides making clipping paths or compound paths from them, include using them to bound text, cutting them, joining them, using the Reshape tool on them, running any vector filter/effect like Zig-Zag or Roughen on them, etc.

The Offset Path filter or effect (and the Outline Object effect) has the ability to "trace around" a mesh and make a new unfilled path, but it can't make a bigger mesh with the same interior structure, like it would be able to do if what you had was some kind of path "filled" with a mesh.

Unknown said...

Thanks for that in-depth definition Teri!

Anonymous said...

One way to punch a hole into such mesh object is to draw the hole, set it any color but with an opacity of 0% than group it with the mesh. In the transparency palette make sure the "Knockout Group" is enable.

Unknown said...

Glad to be of help!

ComBDN said...

When I needed to do the same thing, I've just pressed F1 and have found an the same answer in few seconds…
I mean, this “tip” is in the Illustrator's help.