Skip to main content

VectorComposite

Class

A retained, tessellated vector-image asset (built from an SVG document).

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
  • SnapchatNot supported — Available on SPECS only
  • SPECSFully supported
  • Camera Kit WebNot supported — Available on SPECS only
  • Camera Kit MobileNot supported — Available on SPECS only

Platform details

  • Snapchat — Not supported — Available on SPECS only.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported — Available on SPECS only.

  • Camera Kit Mobile — Not supported — Available on SPECS only.

Since Lens Scripting v368

A retained, tessellated vector-image asset (built from an SVG document). The asset itself produces no image; a VectorRenderer draws it into a caller-owned render-target Texture. Wait for VectorComposite#ready (or poll VectorComposite#isReady) before drawing.

Index

Example

//@input Asset.VectorComposite vectorAsset
//@input Component.Image image
var renderer = new VectorRenderer();
var target = null;
script.vectorAsset.ready().then(function () {
// Size the target to the source so the composite fills it.
var size = script.vectorAsset.intrinsicSize;
target = scene.createRenderTargetTexture();
target.control.outputResolution = RenderTargetProvider.OutputResolution.Custom;
target.control.resolution = new vec2(size.x, size.y);
script.image.mainMaterial.mainPass.baseTex = target;
});
// render() is cheap (replays the retained geometry), so draw every frame.
script.createEvent("UpdateEvent").bind(function () {
if (target) { renderer.render(target, script.vectorAsset, null); }
});

Extends

Properties

fontSource

fontSource: Font | FontFamily | FontCollection

SPECS

The font source used to resolve text in the vector content — a Font, FontFamily, or FontCollection asset, exactly like Text#fontSource. Text is resolved per run: each <text> (or positioned <tspan>) element in the SVG is one run of text. A Font is used for every run. For a FontFamily or FontCollection, each run's font-family attribute selects a face within the source; a run whose font-family does not match still uses the source's default style. The system font is used only when no source is assigned, or for a run whose font-family is "System". Assignable at runtime; a Font referenced only through this property is still shipped with the Lens.

Since

Lens Scripting Version 374

Default Value

null
@snapOS

Example

//@input Asset.VectorComposite vectorAsset
//@input Asset.Font customFont
script.vectorAsset.fontSource = script.customFont;

intrinsicSize

readonly intrinsicSize: vec2

SPECS

The natural size of the source content — the SVG viewBox for a loaded SVG, or the canvas size passed to VectorCompositeBuilder.create for a builder-constructed composite. Reported as (0, 0) until the asset is ready.

Since

Lens Scripting Version 368


isReady

readonly isReady: boolean

SPECS

True once the retained scene is built (i.e. once VectorComposite#ready has resolved). Not ready means the SVG has not been parsed and tessellated yet: before ready is first called, while that one-time build is in flight, or after a parse failure (where ready rejects and the asset stays not ready). While not ready, VectorComposite#intrinsicSize reads (0, 0) and drawing the asset with a VectorRenderer throws. A cheap synchronous guard to check before drawing.

Since

Lens Scripting Version 368


name

name: string

The name of the Asset in Lens Studio.

Default Value

""

Inherited from

Asset.name


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Asset.uniqueIdentifier

Methods

getTypeName()

static getTypeName(): TypeName<VectorComposite>

SPECS

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<VectorComposite>

Since

Lens Scripting Version 368

Overrides

Asset.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Asset.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Asset.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Asset.isSame


ready()

ready(): Promise<void>

SPECS

Returns a Promise that resolves once the source has been parsed and tessellated into the retained scene and the asset is ready to draw; rejects with a parse / unsupported-feature error on failure. The first call kicks off the one-time asynchronous build (parse + tessellate); the same Promise is returned on subsequent calls.

Returns

Promise<void>

Since

Lens Scripting Version 368

Nested types

Enumerations

EnumerationDescription
FillRuleFill rule for closed path regions; determines which points are "inside" when fill contours overlap or self-intersect. Mirrors the SVG fill-rule attribute. Pass to VectorCompositeBuilder#addPath.
GradientKindThe kind of a built VectorGradient. Reported by VectorGradient#kind.
LineCapThe line cap style for a stroked path — how the ends of open sub-paths and dash segments are rendered. Mirrors the SVG stroke-linecap attribute. Pass to VectorStrokeBuilder#setCap.
LineJoinThe line join style for a stroked path — how corners between connected path segments are rendered. Mirrors the SVG stroke-linejoin attribute. Pass to VectorStrokeBuilder#setJoin.
SpreadModeHow a gradient extends beyond its [0, 1] parameter range. Mirrors the SVG spreadMethod attribute. Pass to VectorGradientBuilder#setSpread.

Classes

ClassDescription
RenderRequestPer-draw options for VectorRenderer#render: where to draw (viewport), which part of the source to draw (region), and whether to clear first (clear). Leave viewport or region null — their default — to use the whole target or full source; set either to a Rect to override it.