npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@onirix/camera-controls-module

v1.1.0

Published

Onirix helper library for camera controls.

Downloads

272

Readme

Onirix Camera Controls Module

Version Documentation Twitter: onirix

This library is an addon to Onirix Embed SDK that allows manipulating the camera in a more intuitive and direct way to perform effects such as:

  • Camera animations when entering a scene.
  • Moving the camera to different points of interests around the scene.
  • Advanced camera controls, e.g., zoom customization using interface elements.
  • Restricting camera movement in some ways.

Full documentation available at Onirix Docs.

Install

npm install @onirix/embed-sdk
npm install @onirix/camera-controls-module

Or include the dependency with the HTML head tag:

<head>
    <script src="https://unpkg.com/@onirix/[email protected]/dist/ox-embed-sdk.umd.js"></script>
    <script src="https://unpkg.com/@onirix/[email protected]/dist/ox-camera-controls-module.umd.js"></script>
</head>

Or as ESM modules:

import OnirixEmbedSDK from 'https://www.unpkg.com/@onirix/[email protected]/dist/ox-embed-sdk.esm.js';
import OnirixCameraModule from 'https://www.unpkg.com/@onirix/[email protected]/dist/ox-camera-controls-module.esm.js';

Usage

Initialization

Before accessing any of its functions, the camera module must be initialized by providing an instance of the Onirix Embed SDK as shown below:

import OnirixEmbedSDK from 'https://www.unpkg.com/@onirix/[email protected]/dist/ox-embed-sdk.esm.js';
import OnirixCameraModule from 'https://www.unpkg.com/@onirix/[email protected]/dist/ox-camera-controls-module.esm.js';

const embedSDK = new OnirixEmbedSDK();
embedSDK.connect();

const camera = new OnirixCameraModule(embedSDK);

Onirix Studio experiences can be loaded in two modes: AR and PREVIEW. By default Onirix Camera Controls works in PREVIEW mode. If the experience is loaded in AR mode, the camera controls will be ignored. The modes in which Onirix Camera Controls is enabled can be configured through the second parameter of the constructor:

// Default: Only on PREVIEW mode
const camera = new OnirixCameraModule(embedSDK);

// Only on AR mode
const camera = new OnirixCameraModule(embedSDK, ['AR']);

// Both modes: AR and PREVIEW
const camera = new OnirixCameraModule(embedSDK, ['AR', 'PREVIEW']);

Camera manipulation and animations

The camera can be moved using the camera.animate(...) function. This function receives the following parameters:

  • position_x, position_y, and position_z: The coordinates the camera should move to. If any of them is undefined, the camera will stay in place.
  • look_at_x, look_at_y, and look_at_z: The coordinates the camera should look at. If any of them is undefined, the camera will keep looking at the point it is currently looking at.
  • mode: How to animate the transition to these positions. It is specified by a string with two components: an interpolator (a component that describes the path the camera should take) and an easing function (a component that describes the speed of the camera along said path). This string must be formated as '<interpolator> <ease function>'. Alternatively, any of the components can be omitted. If the mode is optional (can be undefined).

There are two interpolators available:

  • linear: The camera moves in a straight line.
  • spherical: The camera moves following and arc around a center.

There are seven easing functions available:

  • linear-in-out: The camera moves always at the same speed.
  • ease-in: The camera starts slower.
  • ease-out: The camera reduces its speed as it reaches its destination.
  • ease-in-out: The camera starts accelerates at the begining and decelerates as it reaches the end.
  • bounce-in: The camera anticipates the movement by going in the opposite direction for a short period of time.
  • bounce-out: The camera overshoots the destination for a short period of time.
  • bounce-in-out: The camera anticipates the movement by going in the opposite direction and overshoots the destination for a short period of time.

Some examples of valid modes are 'linear', 'ease-in-out', 'spherical bounce-out'.

  • time: Length of the animation in seconds. If not provided it is assumed to be 0 .
  • center_x, center_y, and center_z: When using a spherical interpolator, the center of the arc. Otherwise it is ignored.

Controls

The camera controls are the components that describe how user interactions (touches, mouse clicks, key presses...) are translated to camera movements around the scene. Camera controls are optional and you may use none if the camera cannot be controlled by the user.

Currently, the camera module supports the following camera controls:

  • Orbit controls: The camera moves around a point (the target). The user can zoom using the mouse wheel or by doing pinch gestures, pan by dragging while pressing right mouse botton or sliding with two fingers, and cycle around by dragging while pressing left mouse button or sliding with a single finger. They can be enabled using camera.enableOrbitControls().

The function camera.disableControls() can be used to disable the current camera controls.

Orbit controls

Some functions allow setting limits to the transformations that the user can perform:

  • camera.setOrbitControlsPanRange(min_x, max_x, min_y, max_y, min_z, max_z) allows setting a minimum and maximum pan value for each of the coordinate axes.
  • camera.setOrbitControlsRotateRange(min_x, max_x, min_y, max_y, min_z, max_z) allows setting a minimum and maximum rotation value for each of the coordiante axes. This rotation is measured as the angle from the camera to the axis.
  • camera.setOrbitControlsZoomRange(min, max) allows setting a minimum and maximum zoom value.

Also, there is a function that allows setting the orbit target: camera.setOrbitControlsTarget(x, y, z).

Examples

Moving to a position on scene load

import OnirixEmbedSDK from 'https://www.unpkg.com/@onirix/[email protected]/dist/ox-embed-sdk.esm.js';
import OnirixCameraModule from 'https://www.unpkg.com/@onirix/[email protected]/dist/ox-camera-controls-module.esm.js';

const embedSDK = new OnirixEmbedSDK();
embedSDK.connect();

const camera = new OnirixCameraModule(embedSDK);
camera.enableOrbitControls();

embedSDK.subscribe(OnirixEmbedSDK.Events.SCENE_LOAD_END, () => {
    camera.animateTo(
      -1, 0, 1,
      1, 0, -1,
      'spherical ease-in-out',
      5
    );
});

An orbit and zoom animation on scene load

import OnirixEmbedSDK from 'https://www.unpkg.com/@onirix/[email protected]/dist/ox-embed-sdk.esm.js';
import OnirixCameraModule from 'https://www.unpkg.com/@onirix/[email protected]/dist/ox-camera-controls-module.esm.js';

const embedSDK = new OnirixEmbedSDK();
embedSDK.connect();

const camera = new OnirixCameraModule(embedSDK);
camera.enableOrbitControls();

embedSDK.subscribe(OnirixEmbedSDK.Events.SCENE_LOAD_END, async () => {
    await camera.animateTo(
        0, 0.5, -5,
        0, 0.5, 0
    );
    await camera.animateTo(
        0, 0.5, 5,
        0, 0.5, 0,
        'spherical ease-in-out',
        2,
        0, 0.5, 0
    );
    await camera.animateTo(
        0, 0.5, 2,
        0, 0.5, 0,
        'linear ease-in-out',
        2,
        0, 0.5, 0
    );
});

Author

👤 Onirix