Skip to main content

JavaScript Deformer

Pro Feature

Pro features are only available with a Professional licence. To upgrade, visit cavalry.scenegroup.co.

Intro

The JavaScript Deformer can be used to manipulate the points of a Shape in interesting and novel ways.

For more information on how JavaScript can be used across all JavaScript Layers see JavaScript Layers.

See JavaScript Layers

This deformer is similar to the JavaScript Shape and JavaScript Utility, only it has some additional syntax available to it so that it has access to a Shape's geometry. This has access to all of the Context Module which means data can be saved and loaded for use between frames.

See the Deformer Module for Member Functions exclusive to this Layer.

UI

JavaScript Expression - Enter JavaScript code here.

+ button - Add Dynamic Attributes as variables.

Example
  1. Create a Basic Line.
  2. Create a JavaScript Deformer.
  3. Replace the default JavaScript Expression with:
var points = def.getPoints();
var bbox = def.getBoundingBox();
var maxX = bbox.x+bbox.width;
var frequency = 10;
var amplitude = 50;

for (let pt of points) {
let normX = cavalry.norm(pt.x, bbox.x, maxX);
pt.y += Math.sin((normX+n0*.1)*frequency)*amplitude;
}

def.setPoints(points);
  1. Connect javaScriptDeformer.idbasicLine.deformers.

This will deform the line into a wave. Try replacing let frequency = 10; on line 4 with let frequency = n0; and using the n0 attribute at the bottom to change the deformer's frequency.