Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create singleton Configs class for managing global configurations #758

Closed
xeolabs opened this issue Nov 2, 2021 · 2 comments
Closed

Create singleton Configs class for managing global configurations #758

xeolabs opened this issue Nov 2, 2021 · 2 comments

Comments

@xeolabs
Copy link
Member

xeolabs commented Nov 2, 2021

Add a new Configs class to manage global configurations for all Viewers.

  • See API docs for Configs
  • Published in npm xeokit-sdk 2.0.12

Usage

In the example below, we'll disable xeokit's double-precision support, which gives a performance and memory boost
on low-power devices, but means that we can no longer render double-precision models without jittering. This is OK if we know that we're not going to view models that are geographically vast, or offset far from the World coordinate origin.

We'll also switch from window.requestAnimationFrame to window.setInterval for xeokit's animations, which can also give a
performance boost in some cases.

import {Configs, Viewer, XKTLoaderPlugin} from "../dist/xeokit-sdk.min.es.js";

// Access xeoit-sdk global configs.
// We typically set configs only before we create any Viewers.
const configs = new Configs();

// Disable 64-bit precision for extra speed.
// Only set this config once, before you create any Viewers.
configs.doublePrecisionEnabled = false;

// Disable window.requestAnimationFrame (RAF) and use
// window.setInterval for Viewer render loops.
// This config can be switched dynamically, if needed.
configs.rafEnabled = false;

// This Viewer will now have 64-precision disabled and 
// will use window.setInterval for its render loop.
const viewer = new Viewer({
     canvasId: "myCanvas"
});

viewer.camera.eye = [-3.933, 2.855, 27.018];
viewer.camera.look = [4.400, 3.724, 8.899];
viewer.camera.up = [-0.018, 0.999, 0.039];

const xktLoader = new XKTLoaderPlugin(viewer);

const model = xktLoader.load({
    src: "../assets/models/xkt/v8/ifc/Duplex.ifc.xkt"
});
xeolabs added a commit that referenced this issue Nov 2, 2021
@Amoki
Copy link
Contributor

Amoki commented Nov 2, 2021

So we never use configs as a param of new Viewer ?
This would make it impossible to have 2 xeokit instances with different configs on the same page

@xeolabs
Copy link
Member Author

xeolabs commented Nov 2, 2021

Configs are for intentionally for handling global configs that would always apply to all Viewers.

@xeolabs xeolabs closed this as completed Nov 11, 2021
xeolabs added a commit that referenced this issue Nov 30, 2021
@xeolabs xeolabs changed the title Global configs management Create singleton Configs class for managing global configurations Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants