BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

MathUtils.mapLinear()

MathUtils.mapLinear() is a method provided by the Three.js library. It is used to map a given value from one range to another.

Syntax

The syntax for MathUtils.mapLinear() is as follows:

THREE.MathUtils.mapLinear( value, oldMin, oldMax, newMin, newMax )

Parameters

The parameters required for MathUtils.mapLinear() are as follows:

Parameter Description
value The input value that needs to be mapped. This value should be within the range of oldMin and oldMax.
oldMin The lower end of the original range of the input value.
oldMax The upper end of the original range of the input value.
newMin The lower end of the new range to which the input value will be mapped.
newMax The upper end of the new range to which the input value will be mapped.

Return Value

MathUtils.mapLinear() returns the mapped value. This value will be within the range of newMin and newMax.

Example

Here is an example to demonstrate the usage of MathUtils.mapLinear():

let value = 50;
let oldMin = 0;
let oldMax = 100;
let newMin = 0;
let newMax = 1;

let mappedValue = THREE.MathUtils.mapLinear(value, oldMin, oldMax, newMin, newMax);

console.log(mappedValue); // Output: 0.5

In this example, the input value 50 is within the range of oldMin (0) and oldMax (100). We want to remap this value to a new range between newMin (0) and newMax (1).

Using MathUtils.mapLinear(), we get the mapped value of 0.5. This is because 50 is exactly at the middle of the original range 0-100, and therefore it will be approximately halfway between 0 and 1 in the new range.

Conclusion

MathUtils.mapLinear() is a useful method provided by the Three.js library for mapping values from one range to another. Understanding its usage can help make it easier to work with 3D models and animations.