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

Material.toJSON()

The Material.toJSON() method in Three.js is used to return a JSON object that represents the current state of the material. This can be useful when you want to save the state of a material to a file or to transmit it over a network.

Syntax

material.toJSON()

Return Value

The Material.toJSON() method returns a JSON object that represents the material. This object can be serialized to a string using the JSON.stringify() method.

Example

var material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
var json = material.toJSON();
console.log(JSON.stringify(json));

The above code creates a new MeshBasicMaterial with a red color and then calls toJSON() on it to get a JSON representation of the material. It then logs the JSON object to the console using JSON.stringify().

Remarks

The toJSON() method is automatically called by the JSON.stringify() method when it serializes an object that has a toJSON() method defined.

The returned JSON object includes many of the material's properties, such as its type, color, map, and transparent settings. However, some properties may be omitted if they have default values.

See Also