Skip to content
Open
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
9 changes: 7 additions & 2 deletions packages/core/src/core/Viewpoints/src/viewpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Viewpoint {
camera_up_vector: { x: 0, y: 1, z: 0 },
};

customData: Record<string, any> = {}
customData: Record<string, any> = {};

/**
* A list of components GUIDs to hide when defaultVisibility = true or to show when defaultVisibility = false
Expand Down Expand Up @@ -346,6 +346,7 @@ export class Viewpoint {
* @param transition - Indicates whether the camera movement should have a transition effect.
* Default value is `true`.
*
* @throws An error if the viewpoint has no world.
* @throws An error if the world's camera does not have camera controls.
*
* @returns A Promise that resolves when the camera has been set.
Expand All @@ -356,7 +357,11 @@ export class Viewpoint {
clippingsVisibility?: boolean;
applyVisibility?: boolean;
}) {
if (!this.world) return;
if (!this.world) {
throw new Error(
"Viewpoint: no world to apply the viewpoint to. Set `world` on this viewpoint, or set `Viewpoints.world` before creating or loading viewpoints (for example with `BCFTopics.load`).",
);
}

const { camera } = this.world;
if (!(camera instanceof OrthoPerspectiveCamera)) {
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/core/Viewpoints/viewpoint-go.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, expect, it } from "vitest";
import { loadSourceBundle } from "../../../tests/source-bundle";

// Needs the real `Components`: see `loadSourceBundle`.
const OBC = await loadSourceBundle();

describe("Viewpoint.go", () => {
it("rejects with a clear error when the viewpoint has no world", async () => {
const components = new OBC.Components();
const viewpoints = components.get(OBC.Viewpoints);
expect(viewpoints.world).toBeNull();
const viewpoint = viewpoints.create();
await expect(viewpoint.go()).rejects.toThrow(/no world/);
});
});
Loading