Instances

An instance is a unique representation of a model in the scene. One model may be imported to the scene several times and will, therefore, each time as a separate instance. Each instance may be manipulated separately.

Pose

Every model instance present in the scene has a pose.

pose = {
  position: { x: 0, y: 0, z: 0 },            # Vector3 [mm]
  orientation: {w: 1, x: 0, y: 0, z: 0},     # Quaternion
  scale: {x: 1, y: 1, z: 1}                  # Vector3
}
  • Position - real-world coordinates, relative to the point zero of the app coordinates system (the point where the tracking was initialized).
  • Orientation - a quaternion defining the rotation of the instance in the world space. In the ViewAR System the instance's orientation is described with Quaternions.
  • Scale - the stretching of the model along each axis.

The model's pose may be accessed with:

instance.pose
Change the pose of an instance

To change the position of an instance, you can pass a pose object into the setPose method. You can access the current pose through the pose property of an instance.

instance.setPose(newPose);

Alternatively, you may update just the position (optionally - async).

const oldPosition = instance.pose.position;

await instance.setPose({ 
    position: {
        x: oldPosition.x + 300,
        y: 200,
        z: 300
    }
});

The new pose object is merged with the old one, so you do not need to provide every single pose property.

Change visibility of the instance

To change the visibility of an instance, you can use the setVisibility method:

await instance.setVisibility(true);
await instance.setVisibility(false);

It is also possible to set the visibility while inserting a model or a container into a scene by passing the visible property into the configuration object.

const model = await modelManager.getModelFromRepository(20);
await sceneManager.insertModel(model, { visible: false });