Scripts de interfaz

Los scripts de interfaz se ejecutan en tu máquina local, siempre que tengas la Interfaz activa y en ejecución. Cada usuario tiene control total sobre cuándo se inician y detienen los scripts de interfaz. Los resultados (como cuando tu script cambia el color de una caja) pueden ser vistos por todos en tu dominio, pero el script en sí se ejecuta en tu máquina local. Tu Interfaz comunicará esa información al Servidor de Entidades, que la comunicará a quien esté visitando el dominio.

With interface scripts, you can do things like add new menus to the interface, create dynamic gadgets or toys, and manipulate your own avatar to change how it looks or moves.

Cargar un Script de Interfaz

Para cargar y ejecutar un script de interfaz:

  1. In Interface, go to Edit > Running Scripts or press Ctrl+J on your keyboard.

  2. For scripts hosted on the internet, click From URL. Enter the URL of your script file and click OK.

  3. For scripts on your local computer, click From Disk. Browse to your script file and click Open.

Ejemplo de un Script de Interfaz

The following script creates a light cube of a randomised colour in front of you when you load it, and shows how you can spawn a text entity whenever you switch into or out of VR.

example-interface-script.js
"use strict"

// Generate a random colour
function generateColour() {
    const randNum = () => (Math.random() * 256) | 0;
    return [randNum(), randNum(), randNum()];
}

// Generate a random colour
const colour = generateColour();

// Spawn a bright cube
const entityID = Entities.addEntity({
    type: "Box",
    name: "example colour box",
    position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -2 })),
    dimensions: { x: 0.5, y: 0.5, z: 0.5 },
    unlit: true, // Cube will always be fully lit
    billboardMode: "yaw", // Cube will always face you
    color: colour, // random colour generated earlier
    canCastShadow: false, // Cube will not block light
    lifetime: 300  // Delete after 5 minutes.
}, "avatar");

// spawn a light inside the cube
const lightID = Entities.addEntity({
    type: "Light",
    name: "example colour light",
    position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -2 })),
    dimensions: { x: 20, y: 20, z: 20 },
    parentID: entityID, // Will be a child of the cube entity
    color: colour, // random colour generated earlier
    intensity: 10, // brightness
    falloffRadius: 1.3, // Light intensity reduced by 25% this far out
    lifetime: 300  // Delete after 5 minutes.
}, "avatar");

// Display some text welcoming you to your new mode when switching in and out of VR
HMD.displayModeChanged.connect(function(isHMDMode) {
    if (isHMDMode) {
        print("Welcome to VR!");
        Entities.addEntity({
            type: "Text",
            name: "example text",
            position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -2 })),
            dimensions: { x: 1.0, y: 0.1, z: 0.5 },
            text: "Welcome to VR!",
            unlit: true, // Text will be fully lit
            billboardMode: "yaw", // Text will always face you
            lifetime: 30  // Delete after 30 seconds.
        }, "local"); // Text is only visible to you
        print("Entity created: " + entityID);
    } else {
        print("Welcome to Desktop!");
        Entities.addEntity({
            type: "Text",
            name: "example text",
            position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -2 })),
            dimensions: { x: 1.0, y: 0.1, z: 0.5 },
            text: "Welcome to Desktop!",
            unlit: true, // Text will be fully lit
            billboardMode: "yaw", // Text will always face you
            lifetime: 30  // Delete after 30 seconds.
        }, "local"); // Text is only visible to you
        print("Entity created: " + entityID);
    }

});

// Clean up when the script stops running
Script.scriptEnding.connect(function() {
    Entities.deleteEntity(entityID); // Removes the Box entity, including its child Light entity.
});

Ver también