Skip to content

A class for interpolation of position, rotation, and scale for networked BabylonJS objects.

License

Notifications You must be signed in to change notification settings

torchesburn/buffered-interpolation

 
 

Repository files navigation

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);
}

About

A class for interpolation of position, rotation, and scale for networked BabylonJS objects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%