Skip to main content
Version: 4.55.1

Scripting API Changes in Lens Studio 2.3

In Lens Studio 2.3, some changes were made to the API to improve how Lenses are developed. Please take a look below to see the new changes and examples of the new APIs.

Take a look at the API section for more information on each API.

Visuals

Starting from Lens Studio 2.3, the Mesh Visual component has been separated into three different components to better distinguish what the component is intended to display and what properties are available.

BaseMeshVisual

Component.BaseMeshVisual is the top level parent which provides access to any existing Mesh Visuals. However, since this component encompasses many types of visual, it does not have certain properties or methods associated with it.

Example types of visuals

  • Text
  • ParticlesVisual
  • FaceStretchVisual
  • RetouchVisual
  • LiquifyVisual

MaterialMeshVisual

Component.MaterialMeshVisual is a subclass of Component.BaseMeshVisual. This component provides access to materials. You should use this class, for example, when you want to modify the properties (such as a texture) on a visual.

// @input Component.MaterialMeshVisual myVisual
// @input Asset.Texture myTexture
script.myVisual.mainPass.baseTex = script.myTexture;

Example types of visuals

  • Image
  • EyeColorVisual
  • PostEffectVisual

RenderMeshVisual

Component.RenderMeshVisual is a subclass of Component.MaterialMeshVisual. This component provides you access not only to the materials of a visual, but also to the mesh of the visual that is being rendered. You should use this class, for example, when you want to modify the mesh being used on this visual.

// @input Component.RenderMeshVisual myVisual
// @input Asset.Texture myTexture
// @input Asset.RenderMesh myMesh
script.myVisual.mesh = script.myMesh;
script.myVisual.mainPass.baseTex = script.myTexture;

Components

In Lens Studio 2.3, it is now easier to access components on a scene object.

To get a component, you can use getComponent() to get the first component in an object:

// @input SceneObject myObject
var componentType = 'Component.RenderMeshVisual';
var renderMeshVisual = myObject.getComponent(componentType);

To get an array of component of types, use getComponents():

// Enable all RenderMeshVisual on an object
// @input SceneObject myObject
var componentType = 'Component.RenderMeshVisual';
var renderMeshVisuals = myObject.getComponents(componentType);
for (var i = 0; i < renderMeshVisuals.length; i++) {
var renderMeshVisual = renderMeshVisuals[i];
renderMeshVisual.enabled = true;
}

Also note that both getComponent() and getComponents() support type hierarchies. So if you request a parent class, any child classes will be returned as well. For example, getComponents("Component.BaseMeshVisual") will return all instances of BaseMeshVisual child classes like Image, Text, RenderMeshVisual, etc.

You can use getComponents("Component") to get an array of all components on a SceneObject.

Animations

AnimationMixer

In Lens Studio 2.3, you’re now able to both get and set the weight of an animation layer. You can do this by directly accessing the weight property of an animation layer.

// Set the weight of an animation layer
// @input Component.AnimationMixer animationMixer
var animationWeight = 1.0;
var animationLayerName = 'BaseLayer';
script.animationMixer.getLayer(animationLayerName).weight = animationWeight;

You can use this property to both get and set weight:

// Halve the current weight of an animation layer
// @input Component.AnimationMixer animationMixer
var animationLayerName = 'BaseLayer';
var animationLayer = script.animationMixer.getLayer(animationLayerName);
var animationWeight = animationLayer.weight;
var newWeight = animationWeight / 2;
animationLayer.weight = newWeight;
Was this page helpful?
Yes
No

AI-Powered Search