FaceMask Touch Textures
Hello,
I'm having trouble with the code provided by https://lensstudio.zendesk.com/hc/en-us/community/posts/115020451643-Make-Things-Change-on-Tap
Instead of sprite I want to change the textures/images of a facemask, ideally I want to change the lips and eyelashes to a different texture.
Here is the code so far, but I get a error.
16:49:17 Error: Argument -1: Value is not a native object
at [anon] () native strict preventsyield
at [anon] (FaceChangeScript:10) preventsyield
// -----JS CODE-----
// @input Component.FaceMaskVisual faceMask
// @input Asset.Texture[] textures
// Our starting texture index
var currentItemIndex = 0;
// Assign the initial texture to our sprite
script.faceMask.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 sprite's texture
script.faceMask.mainPass.baseTex = script.textures[currentItemIndex];
}
// Bind the function to the touch event.
var touchEvent = script.createEvent("TapEvent");
touchEvent.bind(changeTexture);
Thanks,
Hey Ahernandez,
I think you're very close. Did you add the different textures to the textures list?
With your code above and the Script component looking like this in the Inspector panel, I don't have any error.
Let me know if it still doesn't work for you.
Cheers,
Jon
Yes, sorry! I figured it out and forgot to comment back to this thread. Pretty much what you have said. I guess Lens Studio was giving me this error because I didn't add texture images to the values, but once I did it was working!
Thanks,