4.13.0 • Published 3 days ago

@cognite/reveal v4.13.0

Weekly downloads
476
License
Apache-2.0
Repository
github
Last release
3 days ago

Reveal viewer

Documentation for the latest version is available at https://cognitedata.github.io/reveal-docs/docs. Documentation for the next release is available from https://cognitedata.github.io/reveal-docs/docs/next/.

The documentation has a bunch of live examples.

Code Example

import { Cognite3DViewer } from "@cognite/reveal";
import { CogniteClient, CogniteAuthentication } from "@cognite/sdk";

const appId = "com.cognite.reveal.example";
const client = new CogniteClient({
  appId,
  project,
  getToken
});

async function start() {
  await client.authenticate();

  const viewer = new Cognite3DViewer({
    sdk: client,
    domElement: document.querySelector("#your-element-for-viewer")
  });
  viewer.addModel({ modelId: 4715379429968321, revisionId: 5688854005909501 });
}

const project = "publicdata";
const legacyInstance = new CogniteAuthentication({
  project,
});

const getToken = async () => {
  await legacyInstance.handleLoginRedirect();
  let token = await legacyInstance.getCDFToken();
  if (token) {
    return token.accessToken;
  }
  token = await legacyInstance.login({ onAuthenticate: "REDIRECT" });
  if (token) {
    return token.accessToken;
  }
  throw new Error("authentication error");
};

start();

Installation

npm install @cognite/reveal @cognite/sdk three@<version>

Please find the correct version of ThreeJS in the release documentation on Github. We only guarantee support for the exact ThreeJS version specified there.

See our documentation for usage.

Prerequisites

For development, you will need to install Node, Yarn and Rust+Cargo.

Run yarn in the viewer

Local Packages

The Reveal viewer is structured using local packages. This allows you to test features in isolation and constrain the dependencies with logical barriers between features. Packages are located in the /packages/ subfolder. There is no enforced structure of the packages and their layout and content will vary depending on what the package exposes to the rest of the system. Dependencies that are located in the viewer/package.json will be shared and are accessible by any package without having to explicitly declare a dependency in the respective package's package.json. Any external dependency (e.g. lodash, threejs, etc.) must be declared in the root package.json such that they will be properly installed by users that consume the Reveal NPM package.

Creating a local package

Create a new folder under the /packages/ folder, e.g. /packages/[MY-PACKAGE-NAME] and include a package with the following structure:

{
  "name": "@reveal/[MY-PACKAGE-NAME]",
  "private": true,
  "main": "index.ts",
}

Technically the private: true field can be omitted but it is highly recommended such that one does not accidentally publish the local package to NPM with the npm publish command. The index.ts should include any types, functions and/or classes you wish to expose to consumers of this package. You should also create a README.md file for your package that explains its intent and any information that is needed to use the package.

If your package depends on another local package, it must be explicitly declared as a dependency:

{
  "name": "@reveal/[MY-PACKAGE-NAME]",
  "private": true,
  "main": "index.ts",
  "dependencies": {
    "@reveal/[SOME-LOCAL-PACKAGE]": "workspace:*"
  }
}

The workspace keyword declares that the dependency is a local package and should never be fetched from NPM. And the ':*' syntax means that it should just grab any version available. See this for more documentation on yarn workspaces.

If you want to add Rust/Webassembly code to a package, you can add the following script in package.json:

{
  "scripts": {
    "run-wasm-pack": "yarn run ws:update-cargo-index && wasm-pack"
  }
}

and let the Cargo crate reside in <package-name>/wasm. Then the crate will automatically be built and tested by the build and test scripts in the workspace root respectively. The ws:update-cargo-index step ensures that the local crates.io index has been updated before running build. Otherwise, the index update will be executed in a quiet manner, and the command may appear to hang for several minutes.

When writing tests in Rust, the tests must be annotated with the #[wasm_bindgen_test] attribute, instead of the conventional #[test], and wasm-bindgen-test must be added as a (dev-)dependency. All tests are run as part of the normal yarn test script in the root folder, but can also be run manually with e.g. wasm-pack test --chrome --headless in the relevant wasm folder.

It is also possible to run and test a local package in isolation from the rest of Reveal. Convenience functionality has been created to make this easy. Add the following script to your package's package.json:

{
  "scripts": {
    "test": "yarn ws:test --config ./../../jest.config.js"
  }
}

Running yarn run test will run all tests in your package that resolves the *.test.* regex pattern.

To run a test app that includes your package (and any dependencies), create a /app/ subfolder in your package that includes an index.ts file. Add the following script to your package's package.json:

{
  "scripts": {
    "start": "yarn ws:start"
  }
}

Running the command yarn start will host a localhost site with a template HTML that includes the /app/index.ts script that has been transpiled to javascript. To see an example of this check out the packages/camera-manager package.

API Extractor

The viewer/reveal.api.md file contains a description of the public API of Reveal. In the CI pipeline, the reveal.api.md file is checked to be up-to-date by API extractor.

In order to update this file locally, run yarn run update-api after having run the build script. This will update the API file with any changes, which should be added and committed in the same PR.

Debugging

Worker source maps

When bundling source maps with inlined web workers, the bundle size grows huge. Therefore source maps for workers are disabled by default. In order to add source maps to workers, pass --env workerSourceMaps=true to the yarn build script.

Creating and running visual tests

Visual test files must be on the format visual-tests/SomeTest.VisualTest.ts. See one of the existing tests for example on how to create a test.

Visual tests can be run from viewer/ using yarn test:visual. This will run all visual tests. You can also run a single test by using yarn test:visual -- -t="SomeTest" (will run all tests with "SomeTest" in the name). Note that arguments only will be passed to the client, to pass arguments to the server you will need to manually start the server and client separately.

For more information about visual tests, see visual-tests/README.md.

Recommended package folder structure

├── app                   # Runnable app
│ └──index.ts             # Entry point for runnable app
├── src                   # Source code for package
├── wasm                  # Rust/Webassembly source code for package
├── test                  # Automated tests
├── package.json          # Package declaration
├── index.ts              # Entry point for package
└── README.md             # Readme
4.13.0

3 days ago

4.12.1

20 days ago

4.12.0

26 days ago

4.11.1

1 month ago

4.11.0

1 month ago

4.10.8

2 months ago

4.10.7

2 months ago

4.10.6

2 months ago

4.10.5

2 months ago

4.10.4

2 months ago

4.10.3

2 months ago

4.10.2

3 months ago

4.10.1

3 months ago

4.10.0

3 months ago

4.9.2

3 months ago

4.9.1

3 months ago

4.9.0

4 months ago

4.8.0

5 months ago

4.7.1

5 months ago

4.4.0-dev.20230808

9 months ago

4.4.0-dev.20230807

9 months ago

4.4.0-dev.20230809

9 months ago

4.4.0-dev.20230802

9 months ago

4.4.1-dev.20230829

8 months ago

4.4.0-dev.20230804

9 months ago

4.4.0-dev.20230803

9 months ago

4.4.0-dev.20230818

9 months ago

4.4.0-dev.20230811

9 months ago

4.4.0-dev.20230810

9 months ago

4.4.0-dev.20230815

9 months ago

4.4.0-dev.20230814

9 months ago

4.4.0-dev.20230817

9 months ago

4.4.0-dev.20230816

9 months ago

4.7.0

6 months ago

4.4.0-dev.20230822

9 months ago

4.4.0-dev.20230821

9 months ago

4.4.0-dev.20230824

9 months ago

4.4.0-dev.20230823

9 months ago

4.4.0-dev.20230825

9 months ago

4.4.0-dev.20230828

8 months ago

4.6.0

6 months ago

4.5.1-dev.20231025

6 months ago

4.5.1-dev.20231027

6 months ago

4.5.1-dev.20231026

6 months ago

4.5.0-dev.20231024

7 months ago

4.6.0-dev.20231108

6 months ago

4.6.0-dev.20231107

6 months ago

4.3.4-dev.20230801

9 months ago

4.5.0

7 months ago

4.5.1

7 months ago

4.5.1-dev.20231030

6 months ago

4.5.1-dev.20231031

6 months ago

4.4.3-dev.20231009

7 months ago

4.4.3-dev.20231006

7 months ago

4.4.3-dev.20231005

7 months ago

4.4.3-dev.20231004

7 months ago

4.4.3-dev.20231003

7 months ago

4.4.3-dev.20231002

7 months ago

4.3.4-dev.20230710

10 months ago

4.3.4-dev.20230711

10 months ago

4.3.4-dev.20230712

10 months ago

4.3.4-dev.20230713

10 months ago

4.3.4-dev.20230718

10 months ago

4.3.4-dev.20230719

10 months ago

4.3.4-dev.20230714

10 months ago

4.4.2-dev.20230919

8 months ago

4.3.4-dev.20230717

10 months ago

4.4.2-dev.20230915

8 months ago

4.4.2-dev.20230918

8 months ago

4.4.2-dev.20230912

8 months ago

4.4.2-dev.20230911

8 months ago

4.4.2-dev.20230914

8 months ago

4.4.2-dev.20230913

8 months ago

4.4.2-dev.20230921

8 months ago

4.4.2-dev.20230920

8 months ago

4.4.1

8 months ago

4.3.4-dev.20230707

10 months ago

4.4.0

9 months ago

4.4.3

7 months ago

4.4.2

8 months ago

4.3.4-dev.20230703

10 months ago

4.3.4-dev.20230704

10 months ago

4.3.4-dev.20230705

10 months ago

4.3.4-dev.20230706

10 months ago

4.4.2-dev.20230922

8 months ago

4.4.2-dev.20230925

7 months ago

4.3.4-dev.20230731

9 months ago

4.5.1-dev.20231102

6 months ago

4.5.1-dev.20231101

6 months ago

4.5.1-dev.20231103

6 months ago

4.5.1-dev.20231106

6 months ago

4.3.4-dev.20230721

10 months ago

4.3.4-dev.20230724

10 months ago

4.3.4-dev.20230720

10 months ago

4.3.4-dev.20230725

10 months ago

4.4.2-dev.20230908

8 months ago

4.3.4-dev.20230726

10 months ago

4.3.4-dev.20230727

9 months ago

4.3.4-dev.20230728

9 months ago

4.4.2-dev.20230905

8 months ago

4.4.3-dev.20230929

7 months ago

4.4.2-dev.20230904

8 months ago

4.4.3-dev.20230928

7 months ago

4.4.2-dev.20230907

8 months ago

4.4.3-dev.20230927

7 months ago

4.4.2-dev.20230906

8 months ago

4.4.3-dev.20230926

7 months ago

4.4.2-dev.20230901

8 months ago

4.4.2-dev.20230831

8 months ago

4.4.2-dev.20230830

8 months ago

4.3.4-dev.20230630

10 months ago

4.3.4-dev.20230629

10 months ago

4.4.3-dev.20231023

7 months ago

4.4.3-dev.20231020

7 months ago

4.4.3-dev.20231019

7 months ago

4.4.3-dev.20231018

7 months ago

4.4.3-dev.20231017

7 months ago

4.4.3-dev.20231016

7 months ago

4.4.3-dev.20231013

7 months ago

4.4.3-dev.20231012

7 months ago

4.4.3-dev.20231011

7 months ago

4.4.3-dev.20231010

7 months ago

4.3.4-dev.20230628

10 months ago

4.3.4

11 months ago

4.3.4-dev.20230627

10 months ago

4.3.3-dev.20230626

11 months ago

4.3.2

11 months ago

4.3.3

11 months ago

4.3.2-dev.20230621

11 months ago

4.3.2-dev.20230620

11 months ago

4.3.1-dev.20230609

11 months ago

4.3.1-dev.20230606

11 months ago

4.3.1-dev.20230608

11 months ago

4.3.1-dev.20230607

11 months ago

4.3.2-dev.20230619

11 months ago

4.3.3-dev.20230622

11 months ago

4.3.2-dev.20230616

11 months ago

4.3.2-dev.20230615

11 months ago

4.3.2-dev.20230614

11 months ago

4.3.3-dev.20230623

11 months ago

4.3.2-dev.20230613

11 months ago

4.3.2-dev.20230612

11 months ago

4.3.1-dev.20230605

11 months ago

4.2.0-dev.20230529

11 months ago

4.2.0-dev.20230530

11 months ago

4.2.0-dev.20230531

11 months ago

4.3.1

11 months ago

4.3.0

11 months ago

4.2.0-dev.20230602

11 months ago

4.2.0-dev.20230601

11 months ago

4.2.0-dev.20230509

12 months ago

4.2.0-dev.20230508

12 months ago

4.2.0-dev.20230526

12 months ago

4.2.0-dev.20230523

12 months ago

4.2.0-dev.20230522

12 months ago

4.2.0-dev.20230525

12 months ago

4.2.0-dev.20230524

12 months ago

4.2.0-dev.20230510

12 months ago

4.2.0-dev.20230519

12 months ago

4.2.0-dev.20230516

12 months ago

4.2.0-dev.20230515

12 months ago

4.2.0-dev.20230518

12 months ago

4.2.0-dev.20230517

12 months ago

4.2.0-dev.20230512

12 months ago

4.2.0-dev.20230511

12 months ago

4.2.2

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

4.1.2

1 year ago

4.1.0

1 year ago

4.1.1

1 year ago

3.2.1

2 years ago

4.0.0

1 year ago

3.3.0

1 year ago

3.2.0

2 years ago

3.1.0

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

3.0.0-alpha.1

2 years ago

3.0.0-alpha.0

2 years ago

3.0.0-alpha.2

2 years ago

3.0.0-beta.1

2 years ago

3.0.0-beta.0

2 years ago

2.3.0

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.2.2

2 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

2.0.0-beta.4

3 years ago

2.0.0-beta.2

3 years ago

2.0.0-beta.3

3 years ago

2.0.0-beta.1

3 years ago

2.0.0-beta.0

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

1.0.0-beta-3

4 years ago

1.0.0-beta-2

4 years ago

1.0.0-beta-1

4 years ago

1.0.0-alpha-5

4 years ago

1.0.0-alpha-4

4 years ago

1.0.0-alpha-3

4 years ago

1.0.0-alpha-2

4 years ago

1.0.0-alpha-1

4 years ago

0.5.0

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago