Skip to main content
Skip table of contents

Slot Layout

The VirtualDressingRoom2D component takes care of handling the logic of the dressing room. If your application requires a different logic, you can also trigger the request by hand as can be seen in this section.

The Pictofit.SlotLayout allows you to arrange avatars, garments and also accessories any way you want. This gives you freedom to create collage-style renderings or to annotate the try-on with visual elements. The Pictofit.Slot base class defines properties which tell the rendering engine how to position the slot and how to scale its content. Different types of slots provide different functionality. The Pictofit.TryOnSlot allows you to place an avatar with virtually fitted garments. The Pictofit.GarmentSlotenables you to display a garment or even an accessory while the Pictofit.QuadSlot simply displays an image.

First we have to create a slot layout instance:

// create the slot layout instance and set a custom background & size
let slotLayout = new Pictofit.SlotLayout();
slotLayout.backgroundColor = BABYLON.Color3.White(); // use Babylons color class here
slotLayout.size = new Pictofit.Size(viewerWidth, viewerHeight);

For each slot we need to define its location and size by setting the frame property with an instance of type Pictofit.Rectangle. The scalingMode property defines how the content is scaled to its container. Use a value of the Pictofit.ScalingMode enum for this. All available enum values can be found in the API reference.

Try-On Slot

This type of slot computes a virtual try-on for an avatar and a set of garments and renders it to the specified region.

let slot1 = new Pictofit.TryOnSlot();
slot1.frame = new Pictofit.Rectangle(viewerWidth / 2, 0, viewerWidth / 2, viewerHeight);
slot1.scalingMode = Pictofit.ScalingMode.ASPECT_FIT;

slot1.garmentUrls = [
slot1.avatarUrl = "http://myServer/myAvatar.avatar"

Garment Slot

The garment slot can display a .garment file at a defined location. This is handy if you for example want to create a collage without actually computing the try-on for a specific avatar.

let slot3 = new Pictofit.GarmentSlot();
slot3.scalingMode = Pictofit.ScalingMode.ASPECT_FIT;
slot3.frame = new Pictofit.Rectangle(0, viewerHeight / 2, viewerWidth / 2, viewerHeight / 2);
slot3.garmentUrl = "http://myServer/garment-1.garment"

Quad Slot

Quad slots can hold a single image which allows you to customise the rendering by adding e.g. a background to it.

let slot2 = new Pictofit.QuadSlot();
slot2.scalingMode = Pictofit.ScalingMode.ASPECT_FIT;
slot2.frame = new Pictofit.Rectangle(0, 0, viewerWidth / 2, viewerHeight / 2);
slot2.quadUrl = "http://myServer/myImage.png"

Computing the Try-On

Finally, we have to assign the slots to the layout. The order within the array actually defines the z-order as well. Left to right means bottom to top in other words.

slotLayout.slots = [
  slot3, slot1, slot2,

Finally, we need to actually trigger the request. The compute server now fetches the referenced data and renders the try-on according to the placement of the slots. The resulting image is then display by the Pictofit.WebViewer instance on your page.

let computeServer = new Pictofit.ComputeServer("https://myComputeServer", "myToken");
let tryOn = new Pictofit.VirtualTryOn2D(viewer, computeServer);
tryOn.layout = slotLayout;

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.