• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

SampleImage Behaving Oddly

Engaged ,
Mar 29, 2023 Mar 29, 2023

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.

TOPICS
Expressions , Performance , Scripting

Views

350

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2023 Mar 29, 2023

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 29, 2023 Mar 29, 2023

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:

 

2023-03-29 (1).png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2023 Mar 30, 2023

Copy link to clipboard

Copied

LATEST

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:

RickGerard_0-1630463799096.png

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2023 Mar 29, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2023 Mar 29, 2023

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 29, 2023 Mar 29, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 30, 2023 Mar 30, 2023

Copy link to clipboard

Copied

I will give that a try! Thanks as usual Dan.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines