Combining Trigger script with Fullscreen script
Hey guys,
First of all I want to show my appreciation for the new update. The long awaited ability to work with the face tracker is really awesome!
I noticed that in the Trigger template, the script is somewhat similar to the Fullscreen template. However, there are only option to initiate 3D or 2D animation. I would like to have the ability to Enable and Disable 3D and 2D objects and End 3D and 2D animations when a Trigger starts and ends.
I have tried combining the two scripts (FaceTriggerAnim and FullscreenTemplateState) manually, but with no success. Probably because I'm not that good at coding :)
Do you think you can help me out there?
Much appreciated!!
Hey Bram!
That's a great idea. We can take code from FullscreenTemplateState.js to help us with this.
First we need to get a list of the objects we want to enable from the Inspector panel. So at the top of FaceTriggerAnim.js add
what we're saying here is basically we want to be able to add objects in the Inspector panel when we use FaceTriggerAnim.js
Then, from FullscreenTemplateState.js we can take the code to enable or disable a list of objects. You can put this at the end of FaceTriggerAnim.js. The function is below for convenience.
What we're saying here is given a list of objects, go through it and set its "enabled" property to "status". the enabled property is like clicking the checkbox in the Objects panel. We don't have to worry about onModifyObject here since it's optional (notice the if statement).
Now all we need to do is call this function when we want to enable or disable objects!
So when we start the lens, we want to disable all listed objects so we can enable them later.
So after all the //@input at the top of the file, we can start writing our code. Add
which is basically saying set all the objects listed in script.enableObjects to false (disabled).
When a trigger happens in the lens, the function onTriggered gets called. So, at the bottom of the onTriggered function we can say:
Similar to earlier, we're telling every object under script.enableObjects to true (enabled).
Now, when you use FaceTriggerAnim.js, you should see an Enable Objects field where you can add the objects you want to enable!
Can't wait to see what you make!
Jon
Thanks for the amazing help again Jon! I was able to get it to work, but now it only enables the objects. I understand that with a trigger, there is no 'end' like there is in a State. But is there a way to Enable some objects on MouthOpen and then disable them on MouthClose?
Thanks again!
Hi Bram,
No problem! Remember how the second flag in setObjectsEnabled defines whether the function enables or disables?
So in order to get a trigger that disables the object, similar to above, add an input at the top of the file to get a list of objects you want to disable on trigger:
then at the bottom of onTriggered, we'll pass those objects and set it to disabled by by setting the second flag to false.
Finally, to use the script, you can add another Script component with FaceTriggerAnim.js and add an object to disable, and set it's animation trigger!
Cheers!
Jon
Jon, you absolute hero!
Here's a little progress
Looking great! Glad I could help.
Can't wait to see the final Lens!