Skip to content

Commit

Permalink
fix(v2): scene loading demos
Browse files Browse the repository at this point in the history
  • Loading branch information
aamir1995 committed Sep 1, 2023
1 parent 3a0b69d commit 485873c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 57 deletions.
43 changes: 6 additions & 37 deletions v2/demo-snippets/guides/loading_scenes/private_scene.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import * as dataJsApi from "@novorender/data-js-api";
import { createAPI, type SceneData } from "@novorender/data-js-api";
import { type View } from "@novorender/api";
import { type ReadonlyVec3, quat } from "gl-matrix";

const DATA_API_SERVICE_URL = "https://data.novorender.com/api";
export async function main(view: View): Promise<void> {
// For the demo we have simplified the login flow to always run the login call
const accessToken = await login();
// Initialize the data API with the Novorender data server service
// and a callback which returns the auth header with the access token
const dataApi = dataJsApi.createAPI({
const dataApi = createAPI({
serviceUrl: DATA_API_SERVICE_URL,
authHeader: async () => ({
header: "Authorization",
Expand All @@ -21,13 +20,11 @@ export async function main(view: View): Promise<void> {
// Condos scene ID, but can be changed to any public scene ID
const sceneData = await dataApi.loadScene("7a0a302fe9b24ddeb3c496fb36e932b0");
// Destructure relevant properties into variables
const { url, camera } = sceneData as dataJsApi.SceneData;
// Destructure relevant camera properties
const { position, fieldOfView: fov } = camera as any;
const { url } = sceneData as SceneData;
// load the scene using URL gotten from `sceneData`
await view.loadSceneFromURL(new URL(url));
// Assign a camera controller
await view.switchCameraController(camera?.kind as any, { position: flip(position as ReadonlyVec3), fov, rotation: flipGLtoCadQuat([1, 0, 0, 0]) });
const config = await view.loadSceneFromURL(new URL(url));
const { center, radius } = config.boundingSphere;
view.activeController.autoFit(center, radius);
} catch (error) {
console.log("Error while loading scene from URL ", error);
}
Expand All @@ -54,31 +51,3 @@ async function login(): Promise<string> {

return res.token;
}

/**
* helper function to flip the coordinate system
*/
function flip(v: ReadonlyVec3): ReadonlyVec3 {
const flipped: [number, number, number] = [v[0], -v[2], v[1]];
return flipped;
}

/**
* helper function to flip the coordinate system
*/
function flipGLtoCadQuat(b: quat) {
let ax = 0.7071067811865475,
aw = 0.7071067811865475;
let bx = b[0],
by = b[1],
bz = b[2],
bw = b[3];

// prettier-ignore
return quat.fromValues(
ax * bw + aw * bx,
aw * by + - ax * bz,
aw * bz + ax * by,
aw * bw - ax * bx);
}
// HiddenRangeEnded
27 changes: 7 additions & 20 deletions v2/demo-snippets/guides/loading_scenes/public_scene.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
import * as dataJsApi from "@novorender/data-js-api";
import { createAPI, type SceneData } from "@novorender/data-js-api";
import { type View } from "@novorender/api";
import { type ReadonlyVec3 } from "gl-matrix";

const DATA_API_SERVICE_URL = "https://data.novorender.com/api";
export async function main(view: View): Promise<void> {
// Initialize the data API with the Novorender data server service
const dataApi = dataJsApi.createAPI({
serviceUrl: DATA_API_SERVICE_URL,
const dataApi = createAPI({
serviceUrl: "https://data.novorender.com/api",
});

try {
// Load scene metadata
// Condos scene ID, but can be changed to any public scene ID
const sceneData = await dataApi.loadScene("95a89d20dd084d9486e383e131242c4c");
// Destructure relevant properties into variables
const { url, camera } = sceneData as dataJsApi.SceneData;
// Destructure relevant camera properties
const { position, fieldOfView: fov } = camera as any;
const { url } = sceneData as SceneData;
// load the scene using URL gotten from `sceneData`
await view.loadSceneFromURL(new URL(url));
// Assign a camera controller
await view.switchCameraController(camera?.kind as any, { position: flip(position as ReadonlyVec3), fov });
const config = await view.loadSceneFromURL(new URL(url));
const { center, radius } = config.boundingSphere;
view.activeController.autoFit(center, radius);
} catch (error) {
console.log("Error while loading scene from URL ", error);
}
}
// HiddenRangeStarted
/**
* helper function to flip the coordinate system
*/
function flip(v: ReadonlyVec3): ReadonlyVec3 {
const flipped: [number, number, number] = [v[0], -v[2], v[1]];
return flipped;
}
// HiddenRangeEnded
Binary file modified v2/static/assets/demo-screenshots/private_scene.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/assets/demo-screenshots/public_scene.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 485873c

Please sign in to comment.