DebugDraw

Description

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts • Server Entity Scripts • Assignment Client Scripts

The DebugDraw API renders debug markers and lines. These markers are only visible locally; they are not visible to other users.

Methods

Name Return Value Summary
addMarker None

Adds or updates a debug marker in world coordinates. This marker is drawn every frame until it is removed using removeMarker. If a world coordinates debug marker of the specified name already exists, its parameters are updated.

addMyAvatarMarker None

Adds or updates a debug marker to the world in avatar coordinates. This marker is drawn every frame until it is removed using removeMyAvatarMarker. If an avatar coordinates debug marker of the specified name already exists, its parameters are updated. The debug marker moves with your avatar.

drawRay None

Draws a line in world space, visible for a single frame. To make the line visually persist, you need to repeatedly draw it.

drawRays None

Draws lines in world space, visible for a single frame. To make the lines visually persist, you need to repeatedly draw them.

Note: Currently doesn't work.

removeMarker None

Removes a debug marker that was added in world coordinates.

removeMyAvatarMarker None

Removes a debug marker that was added in avatar coordinates.

Method Details

(static) addMarker( key, rotation, position, color, size )

Adds or updates a debug marker in world coordinates. This marker is drawn every frame until it is removed using removeMarker. If a world coordinates debug marker of the specified name already exists, its parameters are updated.

Parameters

Name Type Description
key string

A name that uniquely identifies the marker.

rotation Quat

The orientation of the marker in world coordinates.

position Vec3

The position of the market in world coordinates.

color Vec4

The color of the marker.

size float

A float between 0.0 and 1.0 (10 cm) to control the size of the marker.

Example

Briefly draw a debug marker in front of your avatar, in world coordinates.

var MARKER_NAME = "my marker";
DebugDraw.addMarker(
    MARKER_NAME,
    Quat.ZERO,
    Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -5})),
    { red: 255, green: 0, blue: 0 },
    1.0
);
Script.setTimeout(function () {
    DebugDraw.removeMarker(MARKER_NAME);
}, 5000);
(static) addMyAvatarMarker( key, rotation, position, color, size )

Adds or updates a debug marker to the world in avatar coordinates. This marker is drawn every frame until it is removed using removeMyAvatarMarker. If an avatar coordinates debug marker of the specified name already exists, its parameters are updated. The debug marker moves with your avatar.

Parameters

Name Type Description
key string

A name that uniquely identifies the marker.

rotation Quat

The orientation of the marker in avatar coordinates.

position Vec3

The position of the market in avatar coordinates.

color Vec4

color of the marker.

size float

A float between 0.0 and 1.0 (10 cm) to control the size of the marker.

Example

Briefly draw a debug marker in front of your avatar, in avatar coordinates.

var MARKER_NAME = "My avatar marker";
DebugDraw.addMyAvatarMarker(
    MARKER_NAME,
    Quat.ZERO,
    { x: 0, y: 0, z: -5 },
    { red: 255, green: 0, blue: 0 },
    1.0
);
Script.setTimeout(function () {
    DebugDraw.removeMyAvatarMarker(MARKER_NAME);
}, 5000);
(static) drawRay( start, end, color )

Draws a line in world space, visible for a single frame. To make the line visually persist, you need to repeatedly draw it.

Parameters

Name Type Description
start Vec3

The start position of the line, in world coordinates.

end Vec3

The end position of the line, in world coordinates.

color Vec4

The color of the line. Each component should be in the range 0.01.0, with x = red, y = green, z = blue, and w = alpha.

Example

Draw a red ray from your initial avatar position to 10m in front of it.

var start = MyAvatar.position;
var end = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -10 }));
var color = { x: 1.0, y: 0.0, z: 0.0, w: 1.0 };

Script.update.connect(function () {
    DebugDraw.drawRay(start, end, color);
});
(static) drawRays( lines, color, translationopt, rotationopt )

Draws lines in world space, visible for a single frame. To make the lines visually persist, you need to repeatedly draw them.

Note: Currently doesn't work.

Parameters

Name Type Attributes Default Value Description
lines Array.<Vec3Pair>

The start and end points of the lines to draw.

color Vec4

The color of the lines. Each component should be in the range 0.01.0, with x = red, y = green, z = blue, and w = alpha.

translation Vec3 <optional>
0,0,0

A translation applied to each line.

rotation Quat <optional>
Quat.IDENTITY

A rotation applied to each line.

Example

Draw a red "V" in front of your initial avatar position.

var lines = [
    [{ x: -1, y: 0.5, z: 0 }, { x: 0, y: 0, z: 0 }],
    [{ x: 0, y: 0, z: 0 }, { x: 1, y: 0.5, z: 0 }]
];
var color = { x: 1, y: 0, z: 0, w: 1 };
var translation = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0.75, z: -5 }));
var rotation = MyAvatar.orientation;

Script.update.connect(function () {
    DebugDraw.drawRays(lines, color, translation, rotation);
});
(static) removeMarker( key )

Removes a debug marker that was added in world coordinates.

Parameters

Name Type Description
key string

The name of the world coordinates debug marker to remove.

(static) removeMyAvatarMarker( key )

Removes a debug marker that was added in avatar coordinates.

Parameters

Name Type Description
key string

The name of the avatar coordinates debug marker to remove.