buffered-interpolation-babylon
TypeScript icon, indicating that this package has built-in type declarations

0.2.6 • Public • Published

buffered-interpolation-babylon

This is a port of Mozilla's buffered-interpolation to BabylonJS

This package aims to provide a solution for interpolation of position, rotation, and scale for networked BabylonJS objects.

It specifically aims to work well both in situations with continuous and sparse network updates.

Inspired by: godot-snapshot-interpolation-demo

For position and scale, uses either linear interpolation (default) or hermite function (which takes into account velocity).

For rotation (quaternions), uses spherical interpolation.

Usage

import {
  InterpolationBuffer,
  BufferState,
  BufferMode
} from "buffered-interpolation-babylon";

const buffer = new InterpolationBuffer(BufferMode.MODE_LERP, 0.1);

on receipt of networked data:

buffer.appendBuffer(position, velocity, orientation, scale)

in an onBeforeRender observable:

buffer.update(scene.deltaTime)
if (buffer.state === BufferState.PLAYING) {
  mesh.setEnabled(true);
  mesh.position.copyFrom(buffer.position);
  mesh.rotationQuaternion.copyFrom(buffer.quaternion);
  mesh.scaling.copyFrom(buffer.scale);
}

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i buffered-interpolation-babylon

    Weekly Downloads

    13

    Version

    0.2.6

    License

    MPL-2.0

    Unpacked Size

    44.6 kB

    Total Files

    9

    Last publish

    Collaborators

    • datatitian