Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Main methods:

Represents JSON setup/update messages.

A setup message exposes a root `Container`, which can recursively contain scenes, zones and generic containers. Common fields include name, address, position, rotation, color and children.
A setup message exposes a root `Container`, which can recursively contain scenes, zones and generic containers. Common fields include name, address, UUID, position, rotation, color and children. `getUUID()` exposes the stable server-side container UUID when provided.

Scene containers expose scene size. Zone containers expose the shape information currently provided by Pleiades: Box, Cylinder, Sphere, Path, Grid, Polygon and Segment.

Expand Down
6 changes: 5 additions & 1 deletion src/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function parseContainer(value: unknown): Container {
const position = vec3(value.position);
const rotation = vec3(value.rotation);
const color = vec4(value.color);
const uuid = typeof value.uuid === 'string' ? value.uuid : '';
const rawChildren = Array.isArray(value.children)
? value.children
: isRecord(value.children)
Expand All @@ -52,6 +53,7 @@ function parseContainer(value: unknown): Container {
position,
rotation,
color,
uuid,
{},
children
);
Expand Down Expand Up @@ -93,6 +95,7 @@ function parseContainer(value: unknown): Container {
position,
rotation,
color,
uuid,
new ZoneParameters(shapeType, shapeParameters, localSliderAxis),
children
);
Expand All @@ -106,13 +109,14 @@ function parseContainer(value: unknown): Container {
position,
rotation,
color,
uuid,
{ size: vec3(value.size) },
children
);
}

const type = rawType ? ContainerType.Container : ContainerType.Unknown;
return new Container(type, name, address, position, rotation, color, {}, children);
return new Container(type, name, address, position, rotation, color, uuid, {}, children);
}

function parseContainerPayload(value: unknown): Container {
Expand Down
3 changes: 3 additions & 0 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ export class Container {
public readonly position: Vector3 = [0, 0, 0],
public readonly rotation: Vector3 = [0, 0, 0],
public readonly color: Vector4 = [0, 0, 0, 0],
/** Stable UUID supplied by the server for setup/update containers. */
public readonly uuid = '',
public readonly parameters?: ContainerSpecificParameters,
public readonly children: readonly Container[] = []
) {}
Expand All @@ -268,6 +270,7 @@ export class Container {
getPosition(): Vector3 { return this.position; }
getRotation(): Vector3 { return this.rotation; }
getColor(): Vector4 { return this.color; }
getUUID(): string { return this.uuid; }
getSceneParameters(): SceneParameters {
if (!this.isScene()) throw new Error('Container is not a scene.');
return this.parameters as SceneParameters;
Expand Down
2 changes: 2 additions & 0 deletions tests/sdk.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ test('Control setup messages expose scene and zone hierarchy', () => {
name: 'Zone',
type: 'Zone',
address: '/world/scene/zone',
uuid: 'zone-uuid-123',
position: [1, 2, 3],
rotation: [0, 45, 0],
localSliderAxis: 'z',
Expand All @@ -207,6 +208,7 @@ test('Control setup messages expose scene and zone hierarchy', () => {
assert.deepEqual(scene.getSceneParameters().size, [10, 3, 8]);
const zone = scene.getChildren()[0];
assert.equal(zone.getType(), ContainerType.Zone);
assert.equal(zone.getUUID(), 'zone-uuid-123');
assert.equal(zone.getZoneParameters().getShapeType(), ShapeType.Box);
assert.equal(zone.getZoneParameters().getLocalSliderAxis(), 'z');
assert.deepEqual(zone.getZoneParameters().getBoxShapeParameters().size, [2, 1, 4]);
Expand Down
Loading