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

Curve.toJSON()

The Curve.toJSON() method in Three.js is used to serialize a curve object to a JSON format. This can be useful for saving or transmitting a curve data, storing it in a database, or sharing it with other applications.

Syntax

JSON.stringify(curve.toJSON())

The Curve.toJSON() method returns a JSON representation of the curve object.

Parameters

The Curve.toJSON() method doesn't take any parameters.

Description

The Curve.toJSON() method returns a JSON object that represents the curve. The JSON object includes all the data needed to recreate the curve object.

The JSON object has the following properties:

  • "metadata": A metadata object that includes the version of Three.js used to create the JSON object.
  • "type": The type of curve object (i.e., "Curve").
  • "points": An array of points that make up the curve.
  • "closed": A Boolean value that indicates whether the curve is closed or not.

The Curve.toJSON() method can be used to serialize any curve object, including LineCurve, QuadraticBezierCurve, CubicBezierCurve, EllipseCurve, ArcCurve and CatmullRomCurve3.

Example

var lineCurve = new THREE.LineCurve(
  new THREE.Vector2(0, 0),
  new THREE.Vector2(1, 1)
);

var json = JSON.stringify(lineCurve.toJSON());

In this example, lineCurve is a LineCurve object with two points. The Curve.toJSON() method is used to serialize the curve to a JSON format, which is stored in the json variable.