Blinking commands

Options

Hey dev fam!

I am trying to create a glasses lens that alternates between 2-3 glasses whenever the Snapchat user blinks.

Any leads on how I can do this :)

Thanks

Richie

Answers

  • Bakari Mustafa
    Bakari Mustafa Posts: 178 🔥🔥🔥
    Options

    You can detect blinks using the Blink Detection feature in the Face Tracking component. Here's how you can use it to alternate between glasses:

    1. Add a Face Tracking component to your scene and enable Blink Detection.
    2. Create a script and attach it to the root object in your scene.
    3. In the script, get a reference to the Face Tracking component and the glasses you want to alternate between. You can do this in the script's start function:
    // Get a reference to the Face Tracking component
    var faceTracking = script.getSceneObject().getFirstComponent("Component.FaceTracking");
    
    // Get a reference to the glasses objects
    var glasses1 = script.getSceneObject().getObjectByName("Glasses1");
    var glasses2 = script.getSceneObject().getObjectByName("Glasses2");
    
    In the script's update function, check the blink strength of the Face Tracking component. If it's above a certain threshold, toggle the visibility of the glasses objects:
    Copy code
    // Check the blink strength
    if (faceTracking.blinkStrength > 0.5) {
      // Toggle the visibility of the glasses
      glasses1.enabled = !glasses1.enabled;
      glasses2.enabled = !glasses2.enabled;
    }
    

    This will toggle the visibility of the glasses objects whenever the user blinks with strength above 0.5. You can adjust the threshold to suit your needs.

  • Damon Smith
    Options

    I do not see a face tracking component in Lens studio. Was it removed or renamed? I'm on version 4.55.1