Trigger texture change on 3D model

  • Hey there!

    You can just change the texture inside a mouth open event. I made a script here you can use to do it, attach the script to the mesh object as you see in the picture, then change the textures to their respective textures.

    // -----JS CODE-----
    //@input Asset.Texture openTexture

    // remove next line if not using closed event
    //@input Asset.Texture closedTexture

    sceneObj = script.getSceneObject();
    var meshVisual = sceneObj.getFirstComponent("Component.MeshVisual");

    var mouthOpened = script.createEvent("MouthOpenedEvent");
    mouthOpened.faceIndex = 0;
    mouthOpened.bind(function (eventData)
    {
    meshVisual.mainMaterial.mainPass.baseTex = script.openTexture;
    });

    // remove below this to stop it from changing when closed
    var mouthClosed = script.createEvent("MouthClosedEvent");
    mouthClosed.faceIndex = 0;
    mouthClosed.bind(function (eventData)
    {
    meshVisual.mainMaterial.mainPass.baseTex = script.closedTexture;
    });

     

    I added a way to change it back/to another on close but included comments to remove that functionality if you wish. Hope this helps.

    Kinda hard to see pic here, see full size image here

    Comment actions Permalink
  • I was about to answer but realized Apoc already did. Thanks Apoc! 

    Here's a quick script that cyles between an array of Materials and applies them to the inputted mesh. You can bind this to MouthOpened so that it moves to the next material each time you open your mouth. 

    // -----JS CODE-----
    // @input Component.MeshVisual mesh
    // @input Asset.Material[] materialsToCycle

    if( !script.initialized )
    {
    script.materialIndex = 0;
    script.initialized = true;
    }

    script.materialIndex++;
    if( script.materialIndex >= script.materialsToCycle.length )
    {
    script.materialIndex = 0;
    }
    script.mesh.mainMaterial = script.materialsToCycle[ script.materialIndex ];
    Comment actions Permalink
  • Thank you Apoc and Travis! Sorry for the late reply.
    I've copied the scripts and it worked perfectly! I appreciate your guys' help :)

     

    Comment actions Permalink
  • Hey guys, can someone help me, i want to have a standard material which changes into another material when you lower your brows and change back when going into neutral. 

     

    I want to do this with several emotion like smile and mouth open. 

     

    the one you guys included is amazing!

    Comment actions Permalink
  • Hey Maaike,

    Have you tried Behavior script?

    This script allows you to create simple interaction without writing any custom script.

    You can import the Behavior Script by clicking on Add New in the objects panel and search for Behavior Script.

    Then you can customize your script to send a custom trigger so we can change the material.

    the Send Custom trigger response type sends a custom trigger message as a trigger to other scripts.

    With the help of that we need to create a script to change the material when the trigger gets called.

    In the custom script we just need to specify which mesh and what material we want to set after trigger gets called.

    I attached the project file here which you can see how does that works.

    https://storage.googleapis.com/snapchat-lens-assets/f1a09194-f02d-43ed-92b8-62e843179ff0/lensStudio/Forum-Helpers/Change_Material_OnEvent_Example.zip

    Please also read the behavior guide linked below:

    https://lensstudio.snapchat.com/guides/scripting/helper-scripts/behavior/

     

    Hope this will help you to create an effect that you looking for.

    Best,

    Amir.

    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!