Skip to main content

Solving

The Solver class has a solve method that represents the core functionality of the Lively interface. At a high level, it returns a fully-filled state object and accepts the following fields:

note

The optional field can be left empty if the no specification is needed. The Solver will just use the default values for the optional parameters.

FieldTypeOptionalDescription
goalslook-up table of goal indexed by a string keynoThe key of the look-up table should match with that of the objectives to which the goals are corresponded.
weightslook-up table of float value indexed by a string keynoThe key of the look-up table should match with that of the objectives to which the weights are corresponded.
timefloatnoThe current time stamp. It is advised to always pass in a increasing time stamp for the solver to have a more consistent behavior.
shape_updatelist of ShapeUpdate objectsyessee below

Shape Update

The shape_update parameter in solve takes in a list of ShapeUpdate objects specifying the environmental shapes to be introduced, modified, and removed. The ShapeUpdate object allows for three functionalities or types: Add, Move, and Delete each corresponding to the tasks mentioned above. For more information please see the example below.

note

The shape objects passed in the shapes parameter in solver initialization are static and can not be moved or deleted later. Only the shapes that are introduced (Add) to the environment in ShapeUpdate can be moved or deleted by Move and delete.

Example for adding a new environmental shape

When a new shape is introduced to the environment, the id associated with the new shape needs to be unique. The id will be used to identify the shape when a Move or Delete is performed on the same shape.

note

If another shape is added to the environment with the same id, the new shape will replace the old shape with the same id.

const addCube = [
Add: {
// This is an Add ShapeUpdate functionality or type. This introduce a new Cube with "env-box" as the id to the environment.
id: "env-box", // must be an unique id
shape: {
type: "Box", //can be 'Cylinder', 'Capsule', or 'Sphere'
name: "box", // name can be arbitrary
frame: "world", // frame name
physical: true, // physical collision
x: 0.25,
y: 0.25,
z: 0.25, // dimension of the box
localTransform: {
translation: [0.6, 0.05, 0.15],
rotation: [0.0, 0.0, 0.0, 1.0],
},
},
},
];
const d = new Date();
let time = d.getTime(); // Get the time in milliseconds
currentSolver.solve({}, {}, time / 1000, addCube);

Example for moving an existing environmental shape

note

If a wrong id is used, the solver will not change the transformation of any shape.

const moveCube = [
Move: {
// This is a Move ShapeUpdate functionality or type. This modifies the transform of the Cube introduced by Add in the environment
id: "env-box", // must be identical to the id created in the shape is added
transform: {// the shape will be moved to this transformation
translation: [1.6, 1.05, 1.15],
rotation: [0.0, 1.0, 0.0, 1.0],
},
},
];
const d = new Date();
let time = d.getTime(); // Get the time in milliseconds
currentSolver.solve({}, {}, time / 1000, moveCube);

Example for deleting an existing environmental shape

note

If a wrong id is used, the solver will not delete any shape.

const deleteCube = [Delete: "env-box"];// This is a delete ShapeUpdate functionality or type. This deletes the Cube introduced by Add in the environment.
const d = new Date();
let time = d.getTime(); // Get the time in milliseconds
currentSolver.solve({}, {}, time / 1000, deleteCube);