VectorCompositeBuilder
ClassA mutable builder for a VectorComposite assembled from programmatic fills — each a path painted with a VectorPaint (a solid color or a gradient).
- 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
Since Lens Scripting v370
A mutable builder for a VectorComposite assembled from programmatic
fills — each a path painted with a VectorPaint (a solid color or a
gradient). Create one with VectorCompositeBuilder.create, add filled
paths with VectorCompositeBuilder#addPath, then call
VectorCompositeBuilder#build to produce the composite. The builder
remains usable after build(); subsequent addPath calls and another
build() produce an independent composite.
Index
Example
var builder = VectorCompositeBuilder.create(256, 256);
var pathBuilder = VectorPathBuilder.create();
pathBuilder.moveTo(new vec2(0, 0));
pathBuilder.lineTo(new vec2(100, 0));
pathBuilder.lineTo(new vec2(50, 100));
var path = pathBuilder.build();
builder.addPath(path, VectorPaint.solid(new vec4(1, 0, 0, 1)), VectorComposite.FillRule.NonZero);
var composite = builder.build();
composite.ready().then(function () {
var renderer = new VectorRenderer();
var target = scene.createRenderTargetTexture();
target.control.outputResolution = RenderTargetProvider.OutputResolution.Custom;
target.control.resolution = new vec2(256, 256);
// render() is cheap to repeat — call it again (e.g. from an UpdateEvent)
// whenever the target size or placement changes.
renderer.render(target, composite, null);
});
Extends
Methods
addPath()
addPath(
path,paint,fillRule):void
SPECS
Appends a filled path to the composite. path is an immutable
VectorPath; paint is a VectorPaint — a solid color
(VectorPaint.solid) or a gradient (VectorPaint.gradient);
fillRule is one of VectorComposite.FillRule.NonZero (the SVG default
winding rule) or VectorComposite.FillRule.EvenOdd. Both path and paint
are referenced as-is — a single VectorPaint may be passed to multiple
addPath calls to fill several paths with one paint.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | VectorPath | The path geometry to fill. |
paint | VectorPaint | The paint (solid color or gradient) to fill it with. |
fillRule | FillRule | The fill rule for this path. |
Returns
void
Since
Lens Scripting Version 370
Example
var builder = VectorCompositeBuilder.create(512, 512);
// Build a path.
var pathBuilder = VectorPathBuilder.create();
pathBuilder.moveTo(new vec2(0, 0));
pathBuilder.lineTo(new vec2(512, 0));
pathBuilder.lineTo(new vec2(256, 512));
var path = pathBuilder.build();
// Solid fill.
builder.addPath(path, VectorPaint.solid(new vec4(0.92, 0.26, 0.21, 1.0)),
VectorComposite.FillRule.NonZero);
// Gradient fill — build a reusable gradient, then wrap it in a paint.
var gb = VectorGradientBuilder.linear(new vec2(0, 0), new vec2(512, 0));
gb.addColorStop(0.0, new vec4(0.92, 0.26, 0.21, 1.0));
gb.addColorStop(1.0, new vec4(0.13, 0.59, 0.95, 1.0));
builder.addPath(path, VectorPaint.gradient(gb.build()),
VectorComposite.FillRule.NonZero);
var composite = builder.build();
addStroke()
addStroke(
path,paint,stroke):void
SPECS
Appends a stroked path to the composite. path is an immutable
VectorPath; paint is a VectorPaint — a solid color
(VectorPaint.solid) or a gradient (VectorPaint.gradient);
stroke is an immutable VectorStroke that carries the stroke style
(width, line cap, line join, miter limit, and an optional dash pattern).
Both path, paint, and stroke are referenced as-is — a single
VectorStroke may be passed to multiple addStroke calls to stroke
several paths with one style.
To paint a path with both a fill and a stroke, call VectorCompositeBuilder#addPath
followed by addStroke on the same path: the fill (added first) draws under the stroke.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | VectorPath | The path geometry to stroke. |
paint | VectorPaint | The paint (solid color or gradient) to stroke with. |
stroke | VectorStroke | The stroke style. |
Returns
void
Since
Lens Scripting Version 370
Example
var builder = VectorCompositeBuilder.create(512, 512);
// Build a path.
var pathBuilder = VectorPathBuilder.create();
pathBuilder.moveTo(new vec2(0, 0));
pathBuilder.lineTo(new vec2(512, 0));
pathBuilder.lineTo(new vec2(256, 512));
var path = pathBuilder.build();
// Solid stroke.
var sb = VectorStrokeBuilder.create(6);
sb.setCap(VectorComposite.LineCap.Round);
var stroke = sb.build();
builder.addStroke(path, VectorPaint.solid(new vec4(0.92, 0.26, 0.21, 1.0)), stroke);
addText()
addText(
text,paint,position,rotation):void
SPECS
Appends a text run to the composite. text is an immutable VectorText
produced by VectorTextBuilder#build; paint is a VectorPaint —
only a solid color is supported for text in this version (a gradient paint
throws); position is the run's baseline anchor position, in the composite's
coordinate space (where it falls relative to the run's glyphs depends on the
text's anchor); rotation rotates the run
about that position, in degrees, clockwise (0 = axis-aligned).
Parameters
| Parameter | Type | Description |
|---|---|---|
text | VectorText | The text run content and style. |
paint | VectorPaint | The paint to draw the run with (a solid color only). |
position | vec2 | The baseline anchor position, in the composite's coordinate space. |
rotation | number | Rotation about the baseline position, in degrees, clockwise. |
Returns
void
Since
Lens Scripting Version 374
Example
var builder = VectorCompositeBuilder.create(512, 128);
var tb = VectorTextBuilder.create("Hello", 48);
tb.setHorizontalAlignment(HorizontalAlignment.Center);
var text = tb.build();
builder.addText(text, VectorPaint.solid(new vec4(1, 1, 1, 1)), new vec2(256, 64), 0);
var composite = builder.build();
build()
build():
VectorComposite
SPECS
Snapshots the accumulated fills into a new, unregistered
VectorComposite and returns it. The composite is not yet built
(not ready); call VectorComposite#ready to tessellate it
asynchronously, or — in a C++ unit test — call buildRetained() directly.
The builder remains usable after build(); further addPath calls and
another build() produce an independent composite.
Returns
Since
Lens Scripting Version 370
create()
staticcreate(width,height):VectorCompositeBuilder
SPECS
Creates a new, empty builder for a composite of the given pixel dimensions.
width and height define the coordinate space of the composite and its
intrinsic size once built.
Parameters
| Parameter | Type | Description |
|---|---|---|
width | number | Canvas width in pixels (must be > 0). |
height | number | Canvas height in pixels (must be > 0). |
Returns
VectorCompositeBuilder
Since
Lens Scripting Version 370
getTypeName()
staticgetTypeName():TypeName<VectorCompositeBuilder>
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<VectorCompositeBuilder>
Since
Lens Scripting Version 370
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
setFontSource()
setFontSource(
fontSource):void
SPECS
Assigns the font source used to resolve VectorCompositeBuilder#addText runs in the composite produced by VectorCompositeBuilder#build — a Font, FontFamily, or FontCollection asset, exactly like VectorComposite#fontSource.
Parameters
| Parameter | Type | Description |
|---|---|---|
fontSource | Font | FontFamily | FontCollection | The font source (a Font, FontFamily, or FontCollection asset, or null). |
Returns
void
Since
Lens Scripting Version 374
Example
//@input Asset.Font customFont
var builder = VectorCompositeBuilder.create(512, 128);
builder.setFontSource(script.customFont);