Make Things Change on Tap

Featured
  • Hello all !

    I'm trying to switch between a few Audio Effects without any luck.

    I tried to enable them via sceneObject but it doesn't seem to work.

    I tried to modify with audioComponents and no luck either.

    Is it possible ? Can you help me ?

    Thanks a lot

    Comment actions Permalink
  • Hey Jonathan!  I have a similar thread that I started, but I am wondering if I would be able to use this same kind of technique to take the automated rotation I have created on a 3D object, and then pause and resume the motion on a Tap Event.  Am I on the right track?

    Comment actions Permalink
  • Hi Jonathan Solichin Sir I have the same doubt I want tap to change Image and I can't understand the code please can you help and make a same step by step post for it as I have many doubts as I am new to lens studio , I do no what to use a object or what and when I did it with the help of object following your process my image didn't change so can you make a step by step process for the image to change on tap . please help . and what is sprite what does it do ? 

    https://support.lensstudio.com/hc/en-us/community/posts/115020451643/comments/360000849203

    Comment actions Permalink
  • Hi Jeoffrey!

    Can you help me figure out what the issue is? What error or problem do you see when you follow this comment? https://support.lensstudio.com/hc/en-us/community/posts/115020451643/comments/360000834386

     

    Hi Topher!

    I'm glad Peter was able to help you out with this :) for anyone looking at this thread, you can find the answer in Topher's other thread: https://support.lensstudio.com/hc/en-us/community/posts/360042834292-3D-object-rotating-want-it-to-pause-on-tap-and-resume-on-next-tap-

     

    Hi Ujjshah!

    In the latest version of Lens Studio (2.0) we've upgraded the "sprite" component to a new component called "Image". 

    Thanks for pointing it out!

    Please use the following script instead :) (which changes line 1 from Component.SpriteVisual -> Component.Image)

    To create ScreenImage:

    When using the script: 

    The script:

    // @input Component.Image image
    // @input Asset.Texture[] textures

    // Our starting texture index
    var currentItemIndex = 0;

    // Assign the initial texture to our image
    script.image.mainPass.baseTex = script.textures[currentItemIndex]

    // Define what happens when you tap.
    function changeTexture () {

    // Increment the current item index
    currentItemIndex += 1;

    // We need the current item index to wrap around
    // once it's higher than the number of items we have.
    currentItemIndex = currentItemIndex % script.textures.length;

    // Change the image's texture
    script.image.mainPass.baseTex = script.textures[currentItemIndex];
    }

    // Bind the function to the touch event.
    var touchEvent = script.createEvent("TapEvent");
    touchEvent.bind(changeTexture);

     

    Thanks again everyone! 

    Jon

    Comment actions Permalink
  • Hi Jonathan, I have a lens that I used the segmentation guide on and I need to change the segmentation texture on a tap how do I change the script to do this.

    thanks

    Comment actions Permalink
  • Hi Jonathan!

    I'm fairly new to Lens Studio, and I'm trying to create a lens that toggles four different cat/dog head bindings on tap. Each one is a different script in the object panel, using the PetTrackingController (found in the Pet Lens Template).

    I created the TouchCollision object, added the touch event, and added the invisible mesh as the "Mesh Visual 1". However, when I go to add the script component nothing is working (I assume it's because I'm trying to toggle between Script Objects...?).

    Any help is appreciated! Screenshots attached.

     

    Comment actions Permalink
  • Hi Janraps,

    That's a good question. It's a bit tougher to do. If you checkout the Pet Controller script, you'll notice that the Pet effect is not the object the script itself, but rather the script is instantiating a prefab with the pet effect. 

    Thankfully, there's a function in the script to enable and disable all the instantiated object. What we need to do, is add the api to the script, so another script can enable and disable the pet effect.

    in the configureTrackingVisual function of the petTrackingController, we can add the following API:

    script.api.setPetEnabled = function(e) {

    setComponentEnabledRecursively( trackersRoot, "Component.ObjectTracking" , e );

    setComponentEnabledRecursively( trackersRoot, "Component.Image" , e );

    }

     

    Then we can use the original script, but instead of calling .enabled, we can call the api we just defined: 

    // @input Component.ScriptComponent[] items


    function init() {

    // Arrays are indexed from 0.

    // Disable everything but the first (0th) item .

    for (var i = 1; i < script.items.length; i++) {

    script.items[i].api.setPetEnabled(false);

    }

    }

    // We remember what item is currently visible.

    // When we start it's the 0th item.

    var currentItemIndex = 0;




    // Define what happens when you tap.

    function activateNextItem () {

    // Disable the current item.







    script.items[currentItemIndex].api.setPetEnabled(false);




    // Increment the current item index

    currentItemIndex += 1;


    // We need the current item index to wrap around

    // once it's higher than the number of items we have.

    currentItemIndex = currentItemIndex % script.items.length;







    // Enable the new item.

    script.items[currentItemIndex].api.setPetEnabled(true);

    }

    // Bind the function to the touch event.

    var touchEvent = script.createEvent("TapEvent");

    touchEvent.bind(activateNextItem)


    var updateEvent = script.createEvent("UpdateEvent");

    updateEvent.bind(onUpdate)




    function onUpdate() {

    var allReady = true;




    for (var i = 1; i < script.items.length; i++) {

    allReady = allReady && script.items[i].api.setPetEnabled

    }


    if (allReady) {

    init();

    updateEvent.enabled = false;

    }

    }

    Note the detail, where we check first on update whether the petTrackingController is ready, before we call our script to enable and disable the pet effect!

    Let me know if you need any clarification.

    Cheers!

    Jonathan

    Comment actions Permalink
  • Hi Jonathan! 

    I'm new to creator lens Studio, I've been trying to do this but I can't seem to make it work any help will be useful ill link a screenshot of the issue that I think I'm having, I copied the script from above, and yes I understand the script but I can't seem to make it work I think I did something wrong.http://snpy.in/vRUQCL 

    Comment actions Permalink
  • Did you save the script?

    Click inside the script, and ctrl s

    Comment actions Permalink
  • I thought it autosaves but thanks it works now

    Comment actions Permalink
  • THAT WORKED thank you Jonathan!

    Same as itzjustsamuel... I didn't realize you have to ctrl s each time you edit a script.

    Comment actions Permalink
  • **Edited**

    Hi Jonathan,

    The steps you provided worked great. However, once the pet's face is first detected, the scene shows all 4 head bindings at once. The first few screen taps make them disappear one by one until the last one is left, then the tapping cycles through them one by one.

    Any advice on how to have only the first headbinding show right away, then each tap cycles through as usual?

    Comment actions Permalink
  • hey, Janraps you have to uncheck all of the items on the left side then you'll be able to use the script like this for example.

    http://snpy.in/x9GQJW

    Comment actions Permalink
  • Figured it out!

    Jonathan Solichin in the TouchCollision script, I updated from this:

    // Disable everything but the first (0th) item .

    for (var i = 1; i < script.items.length; i++) {

    script.items[currentItemIndex].api.setPetEnabled(false);

    }


    to this:

    // Disable everything but the first (0th) item .

    for (var i = 1; i < script.items.length; i++) {

    script.items[i].api.setPetEnabled(false);

    }

     

    It now starts on the first pet headbinding script and cycles through perfectly on tap.

    Comment actions Permalink
  • Thanks itzjustsamuel, that would indeed work as well; We'll try to make the "save" more obvious! There's a small asterisk right now that denotes that a script hasn't been saved yet. 

    Good catch Janraps! I will update the script above. The perils of copy and pasting code!

    Thanks again everyone! Excited to see what you all come up with. 

    Comment actions Permalink
  • Hi Jonathan, one more thing I'm trying to do before the lens is complete.

    I want a lens hint to appear only after the dog/cat's face is found, indicating that you can tap for more graphics (I'm calling them crowns).

    I added the Lens Hints script and edited Hint Id to say what I want, but the dropdown menu doesn't include "Pet Face Found". "Face Found" isn't working on a pet face.

    Is there a way to initiate the hint once pet face is found?

    Comment actions Permalink
  • Hi Jonathan Solichin

     

    I am having an obscure issue when using this top to change tutorial. 

     

    My lenses work in the editor, but not on my phone (I have an Iphone 11).

    This is true for both the object swap and the image swap. 

     

    Do you know why this might be happening and how I could fix it?

     

    Thanks so much! I look forward to hearing from you.

    Comment actions Permalink
  • Hi Rhea,

    Can you explain a bit more why it doesn't work. Does tap work? Or does the image swapping not work. Can you try using Behavior and see if tap works on that?

    If you are still unable to resolve, can you share the project for us to take a look?

    Thank you!

    Jonathan 

    Comment actions Permalink
  • Jonathan Solichin

    I was actually able to get it to work on my phone, but it only works when I set the event dropdown for the script to "initialized". I need this effect to work on snap camera (on a desktop), so this drop down value needs to be "tapped". However, when I set the dropdown to "tapped", the changing background does not loop back to the first background. (You can tap through the backgrounds, but the tap interface stops working when you get to the last background).

     

    Any ideas why this may be happening? Is there another way to get the tap interface to work on snap camera?

     

    Thanks so much!

    Comment actions Permalink
  • فضلا ارغب معرفة خطوات صناعة عزل للخلفية ؟ بورتريت؟؟

    Comment actions Permalink
  • Hi Rhea,

    Hmm, that is interesting--I've just tried uploading it to snap camera and didn't have any issue. 

    Can you try this minimal project?

    The other thing to try, if you want to try using the Tapped option in the Script component, is you can set the activateNextItem to be an api, and then call the API from another script which is set to activate on the tapped drop down. 

    Let me know if you need any clarification.

    Cheers,

    Jonathan 

     

    on initialized at the bottom of existing script

    ...
    script.api.activateNextItem = activateNextItem

    on another script set to on tapped

    //@input Component.ScriptComponent otherScript
    script.otherScript.api.activateNextItem()
    Comment actions Permalink
  • Danielle Rosenberg

    Give Me the download link to your Project and ill do it for you but when I do it for you look around to see how things work and make sure you learn how to do it by yourself in the future.

    Comment actions Permalink
  • Hey Jonathan Solichin, Could you help me with this Script it works well but I need it to work with scripts as well because when I tap the screen using this the script you made above it works only to go to the next script but it doesn't return to the script on value 0

    Like this I duplicated the script so yes its not copying the same thing over and over its just not going back to Value 0 When I'm using Scripts instead of items

     

    Comment actions Permalink
  • Hi ItzJustSamuel,

    Can you check whether currentItemIndex loops back to 0? 

    This way we can figure out whether the issue is the looping back, or the enabling/disabling.

    Cheers,

    Jonathan 

    Comment actions Permalink
  • Hi ItzJustSamuel,

    Can you check whether currentItemIndex loops back to 0? 

    This way we can figure out whether the issue is the looping back, or the enabling/disabling.

    Cheers,

    Jonathan 

    Comment actions Permalink
  • Enabling works getting it from 0 to 1, but getting it from 1 back to 0 doesn't so looping it back to 0 doesn't I'm using your Script from above

    Thanks for reaching out as well

    Comment actions Permalink
  • Hmm, it seems like it's going back to 0 for me. Can you share your project. Is the API disabling the object correctly?

    I tried using this minimal case:

    script.api.setPetEnabled = function(state) {
    print(state + " " + script.getSceneObject().name)
    return;
    }

    and it seems to call enable and disable correctly.

    Thanks again,

    Jonathan 

    Comment actions Permalink
  • Comment actions Permalink
  • I think the issue I'm having is that the script isn't detecting that the object is another script.

    Can't figure out how to make this work

    Comment actions Permalink
  • Say I wan't to combine this effect with the template "cutout", how would one do that? 

    I can make them work individually but putting them together causes problems

     

     

    Comment actions Permalink
Have a comment?

Please sign in to leave a comment.

We're here to help! We just need a little bit of information...

What system are you using?

Have you downloaded the latest version of Lens Studio?

Please download the latest version of Lens Studio. If you still run into this issue, please come back and report it!

Is this issue causing Lens Studio to crash?

What system do you run Lens Studio on?

Version

Graphics

Follow the next steps to help us solve your issue:

  • Copy and paste this text into your TerminalCommand Window
    open ~/Library/Preferences/Snap/Lens\ Studio/ %LOCALAPPDATA%\Snap\Lens Studio Copy Text
  • Press ReturnEnter to run the command. The Lens Studio folder will automatically open
  • Prepare to upload your files: zip the "Log" Folder by right-clicking and choosing "compress."
    Locate the Log.txt file right above it.

    Attach a screenshot of the issue:

Name:

Email:

What is this most relevant to?

Please enter a brief description of your issue:

Thanks for submitting this issue.

Unfortunately, it's likely due to the operating system or hardware you're using – since they don't meet the system requirements for Lens Studio.

Still, we hear you loud and clear, and are logging the issue in case there's ever a workaround we can provide!

Minimum Requirements

Operating System: Windows 10 (64 bit); MacOS 10.11+

Hardware: Minimum of Intel Core i3 2.5Ghz or AMD Phenom II 2.6Ghz with 4 GB RAM; Intel HD Graphics 4000 / Nvidia GeForce 710 / AMD Radeon HD 6450 or better; screen resolution of 1280x768 or higher

We'll try to resolve this issue as soon as possible. Thanks for letting us know about it!

Keep an eye out for a followup email from us. We may have a couple more questions for you, or we might already have a solution to offer.

Happy creating!