1.0.3 • Published 8 years ago

mun-three-utils v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

mun-three-utils

This is a collection of utilitites we use at MUN when working with three.js. Many of them are adapted from Jack Rugile.

Installation

npm install --save mun-three-utils

ES6

import * as THREEUTILS from 'mun-three-utils

ES5

var THREEUTILS = require(mun-three-utils)

Table of Contents

-Calc -Ease

Calc

This utility provides commonly used calculations for three.js.

rand(min, max, ease)

Returns a random float between two values, with the option of easing bias.

ParameterTypeDescription
minNumberThe minimum float value.
maxNumberThe maximum float value.
easeFunctionEasing function to apply to the random value

randInt(min, max, ease)

Returns a random integer between two values, with the option of easing bias.

ParameterTypeDescription
minNumberThe minimum integer value.
maxNumberThe maximum integer value.
easeFunctionEasing function to apply to the random value

randArr(arr)

Returns a random item from an array.

ParameterTypeDescription
arrArrayThe array to randomly pull from.

map(val, inputMin, inputMax, outputMin, outputMax)

Returns a mapped value from and input min/max to an output min/max.

ParameterTypeDescription
valNumberInput value.
inputMinNumberMinimum of input range.
inputMaxNumberMaximum of input range.
outputMinNumberMinimum of output range.
outputMaxNumberMaximum of output range.

clamp(val, min, max)

Restricts a value to a min/max range.

ParameterTypeDescription
valNumberValue to be clamped.
minNumberMinimum of clamped range.
maxNumberMaximum of clamped range.

lerp(current, target, mix)

Linearly interpolates between two vectors.

ParameterTypeDescription
currentNumberCurrent position.
targetNumberTarget position.
mixNumberSpeed of the interpolation.

roundToUpperInterval(value, interval)

Round up a value to the next highest interval.

ParameterTypeDescription
valueNumberValue to be rounded.
intervalNumberInterval.

roundToLowerInterval(value, interval)

Round down a value to the next lowest interval.

ParameterTypeDescription
valueNumberValue to be rounded.
intervalNumberInterval.

roundToNearestInterval(value, interval)

Round a value to the nearest interval.

ParameterTypeDescription
valueNumberValue to be rounded.
intervalNumberInterval.

intersectSphere(a, b)

Check if two sphere are intersecting in 3D space.

ParameterTypeDescription
aObjectSphere 1 with radius, x, y, and z.
bObjectSphere 2 with radius, x, y, and z.

getIndexFromCoords(x, y, w)

Convert from grid coords to index.

ParameterTypeDescription
xNumberX value (column).
yNumberY value (row).
xNumberWidth of grid.

getCoordsFromIndex(i, w)

Convert from index to grid coords.

ParameterTypeDescription
iNumberIndex.
wNumberWidth of grid.

visibleHeightAtZDepth(depth, camera)

Returns the visible height in your scene at a given distance from a PerspectiveCamera.

ParameterTypeDescription
depthNumberDepth of current plane.
cameraObjectPerspectiveCamera object.

visibleWidthAtZDepth(depth, camera)

Returns the visible width in your scene at a given distance from a PerspectiveCamera.

ParameterTypeDescription
depthNumberDepth of current plane.
cameraObjectPerspectiveCamera object.

Ease

A collection of commonly used easing functions.

inQuad(t, b, c, d)

Returns an eased float value based on inQuad.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

outQuad(t, b, c, d)

Returns an eased float value based on outQuad.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inOutQuad(t, b, c, d)

Returns an eased float value based on inOutQuad.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inCubic(t, b, c, d)

Returns an eased float value based on inCubic.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

outCubic(t, b, c, d)

Returns an eased float value based on outCubic.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inOutCubic(t, b, c, d)

Returns an eased float value based on inOutCubic.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inQuart(t, b, c, d)

Returns an eased float value based on inQuart.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

outQuart(t, b, c, d)

Returns an eased float value based on outQuart.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inOutQuart(t, b, c, d)

Returns an eased float value based on inOutQuart.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inQuint(t, b, c, d)

Returns an eased float value based on inQuint.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

outQuint(t, b, c, d)

Returns an eased float value based on outQuint.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inOutQuint(t, b, c, d)

Returns an eased float value based on inOutQuint.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inSine(t, b, c, d)

Returns an eased float value based on inSine.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

outSine(t, b, c, d)

Returns an eased float value based on outSine.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inOutSine(t, b, c, d)

Returns an eased float value based on inOutSine.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inExpo(t, b, c, d)

Returns an eased float value based on inExpo.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

outExpo(t, b, c, d)

Returns an eased float value based on outExpo.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inCirc(t, b, c, d)

Returns an eased float value based on inCirc.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

outCirc(t, b, c, d)

Returns an eased float value based on outCirc.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inOutCirc(t, b, c, d)

Returns an eased float value based on inOutCirc.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inOutExpo(t, b, c, d)

Returns an eased float value based on inOutExpo.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inElastic(t, b, c, d)

Returns an eased float value based on inElastic.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

outElastic(t, b, c, d)

Returns an eased float value based on outElastic.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inOutElastic(t, b, c, d)

Returns an eased float value based on inOutElastic.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inBack(t, b, c, d)

Returns an eased float value based on inBack.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

outBack(t, b, c, d)

Returns an eased float value based on outBack.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.

inOutBack(t, b, c, d)

Returns an eased float value based on inOutBack.

ParameterTypeDescription
tNumberCurrent time.
bNumberBegining time.
cNumberChange in value.
dNumberDuration.
1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago