Copy link to clipboard
Copied
I can only categorize this as a bug, because it works except under the circumstances I'm about to describe.
I've got a comp set up to change the opacity of layers if they overlap with a PNG file resembling a mouse cursor (I'm re-creating a GUI). This is done by applying this to the layer I want to appear or disappear when the mouse passes over it:
L = thisComp.layer("Layer 2/Mouse Cursor.ai");
p = L.transform.position;
sampleImage(p,[.5,.5],true)[3] > 0 ? 100 : 0
This works flawlessly as long as the layer it's applied to is either an image file or an AE shape layer. When I try to apply it to a composition however, it doesn't work quite right.
In short--the layers don't light up individually when the mouse is over them. Instead, they light up when the mouse is nowhere near them.
See the attached AEP to see what I'm talking about (I also attached the PNG of the mouse cursor). I thought it might have something to do with the fact that several of the layers are scaled, but I've got one here that's not scaled at all and it behaves differently than the others. Then there's a basic shape layer that works exactly the way it's supposed to.
Copy link to clipboard
Copied
Open the Switches and Modes column using the first icon in the bottom left corner of the timeline and turn on Collapse Transformations for all nested comps (pre-comps) so that the actual position of the pixels is sampled. It's not a bug.
Copy link to clipboard
Copied
That does partially fix the problem, but the pre-comps that are scaled down are still behaving oddly. Instead of making the entire object visible, it's just showing a small sliver of it:
Copy link to clipboard
Copied
The problem with that specific frame that is not solved by collapse transformations lies in the nested comp. Render order is critical. Dan's expression, which I didn't think of, will solve the nested comp/transformations problem. I stand by my comments about overcomplicating the project. I have created many projects with dozens of nested comps, and I would always try and avoid a situation where collapsing transformations threw the position and scale of a layer way off. I am sorry that you were so easily offended. I was just trying to be helpful. Here's one of my composites that uses image sampling in the second level of nested comps to control opacity, gaussian blur, and position of a couple of 3D layers and all layers have CT turned on:
Copy link to clipboard
Copied
One thing I noticed is that your sampleImage() point parameter needs to be in coordinates of the layer being sampled, so try this:
L = thisComp.layer("Mouse Cursor.png");
p = L.transform.position;
sampleImage(fromComp(p),[.5,.5],true)[3] > 0 ? 100 : 0
Copy link to clipboard
Copied
Your comp is also over-complicated by the transforms and the expressions applied to the nested comps. The whole thing is kind of a mess. There's no bug here, just improper technique.
Copy link to clipboard
Copied
Actually Rick, my technique is anything but improper. You're just not privy to seeing what it is. This is an extremely basic mockup of a far more elaborate project whose purpose I don't care to divulge to you. So frankly, Rick, I couldn't possibly care less what your opinion is of my approach. For what I'm doing, my technique is exactly what it needs to be. And furthermore, if that's the extent of comment that you have to offer, in the future I suggest you refrain from commenting on my threads. Thank you.
Copy link to clipboard
Copied
I will give that a try! Thanks as usual Dan.