11 Replies Latest reply on May 12, 2016 10:21 AM by Rick Gerard

    Trigger an Effect if Touching a Solid/shape/?

    Fishbottle

      I want to do a series of animation of data visualizations where large groups of dots on a map would become selected and light up (glow effect on) and then deselected with the (glow effect off) this would change throughout the animation with different groups turning on and off periodically.

       

      Rather than keyframe dozens of dots on and of, I'm sure there must be a clever way to do this with a line of script that perhaps checks if it is overlapping a solid, or within a shape's boundary and I can move an invisible solid over the dots to 'activate' them or...or... any ideas?

       

      I'm open to any solution to this, doesn't have to be a script. Maybe there's an additive effect with an overlay solid that has a binary on/off effect.

       

      Thanks in advance for your brain time!

        • 1. Re: Trigger an Effect if Touching a Solid/shape/?
          Mylenium Most Valuable Participant

          Expressions. Here's a simple thing you can do apply to opacity for instance.

           

          //reference to animated slider

          mValue=Math.round(thisComp.layer("XYZ").effect("Group ID")("Slider"));

           

          //add additional group indices to array as needed

          mGroups=[1,2,5,9];

           

          //check if element is in a group

           

          for (i=0;i<mGroups.length,i++)

          {

          if (mGroup[i] == mValue)

          {100}

          else

          {0}

          }

          Based on the array, elements can be members of multiple groups. Just change values as needed and animate the slider with hold keyframes for a hard switch toggle.

           

          Mylenium

          1 person found this helpful
          • 2. Re: Trigger an Effect if Touching a Solid/shape/?
            Fishbottle Level 1

            Very neat! Thanks very much for that but I'm looking for a solution where I don't have to keyframe anything on the individual dots and there will be about 100 of them - and they will go on and off in geographic 'waves' (think of a searchlight)

             

            That's why I thought of the solid layer idea, if I could move some boundary shape around and have the dots light up if they were touching/overlapping it then I only have to keyframe the shape moving. Or if the effect has some kind of binary threshold where a 1% transparent shape would push it over the edge and trigger it being 'on'...that kind of thing,

            • 3. Re: Trigger an Effect if Touching a Solid/shape/?
              Mylenium Most Valuable Participant

              You are overcomplicating this. There's nothing to stop you from creating "sequential" groups and animating this one single slider a bunch of times, including it's ability to reset and repeat. Genuine shape detection would still require you to apply some expression to the actual dots and a convoluted one at that. You know, it would have to test for intersections using complex vector math and the same expression used on 100 layers clearly would make AE slow as hog. Quite generally I also think you have simply a wrong understanding of how this stuff works in AE and based thereon wrong expectations. You seem to think that the trigger object magically could address properties, when in fact it's the other way around - expressions on the properties react to external inputs. Of course anything can be done, but a) your info is too generic to come up with a specific bit of code and b) based on what I said it would most likely have to be something you pay for. This is nothing anyone whips up en passant, unless he already has something handy in his code library.

               

              Mylenium

              • 4. Re: Trigger an Effect if Touching a Solid/shape/?
                Rick Gerard Adobe Community Professional & MVP

                You can use sampleImage to detect the alpha of a layer. The sample size is stated as a radius but unfortunately for finding the edges of circles it's really a square.

                 

                Something like this applied to glow radius would let you know when a the edge of the layer touched the edge of a red solid that was 100 X 100 pixels:

                 

                v = thisLayer.sampleImage(thisComp.layer("Red Solid 1").transform.position, radius = [50, 50], postEffect = true, t = time);

                if (v[3] > 0) 50 else 0

                 

                Unfortunately the sample area is a square not a circle.

                I would have to do serious figuring to see if the sample could be turned into a circle or to figure out how to detect a collision with any other layer. This would be a good question for Dan Ebberts

                1 person found this helpful
                • 5. Re: Trigger an Effect if Touching a Solid/shape/?
                  Fishbottle Level 1

                  Thanks. Sorry if I didn't explain it properly and I didn't mean to offend nor was I expecting anyone to write me a script for free, I was just wondering if my problem might remind someone of a solution they had to solve something like this (free paid, simple, copmplex) I've spent thousands on scripts over the years so I really do appreciate their worth. I will try to be more mindful of what I post in the future.

                   

                  I think you are right that I am over complicating this. I may try a low tech solution instead. Thanks so much for your help.

                  • 6. Re: Trigger an Effect if Touching a Solid/shape/?
                    Fishbottle Level 1

                    Thanks for this Rick! I almost got it working the way I needed it to, triggering it by moving the solid around. Almost!

                     

                    I am going to try an experiment with my second avenue, the additive effect route and I think it might work. Your 100x100 Red Solid got me thinking:

                     

                    If I move a solid or a mask around a duplicate comp of my dots, covering and uncovering the dots, I can apply a mosic effect to the whole comp, make it black and white and then clamp the levels so that each mosaic square is either on or off (making sure each mosaic square is bigger than each dot) Then I essentially have a luma matte that I can use to reveal or hide a duplicate layer of all the dots that has a glow applied to it, effectively turning on or off the glow.

                    • 7. Re: Trigger an Effect if Touching a Solid/shape/?
                      Mylenium Most Valuable Participant

                      Nothing to do with being offensive or any of that, people just all too often assume that everything can be fixed with three lines of code and that there would be some magic that gives them features that are not accessible otherwise, which of course isn't true. Scripts and expressions are just a way of doing things differently. Anyway, your points being in a grid-like layout would have been a useful info to have in the first place, as indeed then things are easy using Mosaic to quantize data or use effects like Card Dance to directly animate some stuff...

                       

                      Mylenium

                      • 8. Re: Trigger an Effect if Touching a Solid/shape/?
                        Fishbottle Level 1

                        Yes, that's true, people often do. Occasionally though, it can and does, you never know if you don't ask. 

                         

                        My dots are not actually on a grid, anymore than cities are on a grid. If I overlay a grid on them, everything falls either mostly inside or mostly outside of a grid section, so when I add the mosaic effect with a brightness levels clamp on it and my solid is more than 50% in a grid section, it turns white (on) when it is less than 50% in that grid it turns black (off) If I make that grid square big enough to cover the dots it works as a matte to turn on or off the glow layer.

                         

                        Then I can move the solid(s) around and run it through the mosaic & brightness process  to generate my animated 'on off' pattern sequences.

                        • 9. Re: Trigger an Effect if Touching a Solid/shape/?
                          Rick Gerard Adobe Community Professional & MVP

                          I probably would approach the project by putting all of my dots on one layer then creating my animated gradient map so the animated map showed the areas that I wanted to light up. I would then have used that gradient map as a track matte for an adjustment layer with Glow applied.

                           

                          If, on the other hand, you wanted to create something like an animated target that glowed when it passed over an area where the alpha channel changed, like a bunch of dots, then you could name you dots layer Glow Map and apply this expression to your Target layer's glow property:

                           

                          v = thisComp.layer("Glow Map").sampleImage(thisLayer.transform.position, radius = [5, 5], postEffect = true, t = time);

                          if (v[3] > 0) v[3] * 10 else 0

                           

                          Screen Shot 2016-05-12 at 8.57.55 AM.png

                          1 person found this helpful
                          • 10. Re: Trigger an Effect if Touching a Solid/shape/?
                            Fishbottle Level 1

                            Great ideas Rick!

                            Thanks to you both for the great scripts in reposonse to this post. I've been playing around with them and I can see many more uses. I like that this one can ramp a value up and down according to the value of the gradient.

                             

                            My mosaic approach seems to be doing the trick on my current project, it's a quick way to create an 'on/off switch' based on the content of the layer.

                            • 11. Re: Trigger an Effect if Touching a Solid/shape/?
                              Rick Gerard Adobe Community Professional & MVP

                              I just realized you don't need the if statement if you're ramping the values up and down. Color channel values go from 0 to 1 so all you have to do is multiply the sample by the eventual maximum value you want. That's what I get for writing expressions on three hours sleep. Don't you love deadlines when clients put off approval meetings till the last minute.