Accessing Segmentation Texture Properties through script
Hi!
I created a "tap to change" script to toggle through two different backgrounds that use segmentation, but I need to be able to swap the type of segmentation for each background. For the first option, I want the whole user to be seen, but for the second option, I only want the user's face to be seen.
When I create two different segmentation texture assets in the resources panel, it does not work. So, I am trying to access the segmentation "Type" of a segmentation texture through script. Also, I want to access the boolean determining whether the mask is inverted or not.
What is the correct scripting language to access these properties?
Any help would be greatly appreciated. Thanks!!
Hi Rhea!
The available scripting language in LS is JavaScript. I would solve this issue this way:
1. Create two Portrait Segmentation textures. One for face and one for background. Setup them correspondingly to remove everything except face and to remove background.
2. Create the following script and add it to an empty Scene Object:
// @input Asset.Texture background
// @input Asset.Texture face
// @input Component.Camera camera
var current = false;
function onTap() {
if (current)
script.camera.maskTexture = script.face;
else
script.camera.maskTexture = script.background;
current = !current;
}
script.createEvent("TapEvent").bind(onTap);
3. Assign the textures and the camera into the corresponding inputs of the script.
4. Create a test Sphere to see the switching effect in action.
With that, when you make a tap on the screen, you will see that the sphere will be segmented in two opposite ways.
Hope that helps!
Artem.