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.fromJSON()

Curve.fromJSON() 是 Three.js 中的一种方法,它可以将 JSON 数据转换为曲线对象(curve object)。

参数

Curve.fromJSON() 方法接受一个 JSON 格式的参数,该参数描述了要创建的曲线对象的属性和值,如下所示:

{
    "type" : "曲线类型",
    "vectors" : [
        {"x":0,"y":0,"z":0},
        {"x":1,"y":0,"z":0}
    ],
    "arcLengths" : [0,1],
    "chordalError" : 0.01
}

参数说明:

  • 曲线类型:表示要创建的曲线类型,可能的值有 "LineCurve3""QuadraticBezierCurve3""CubicBezierCurve3""EllipseCurve""ArcCurve""CatmullRomCurve3""SplineCurve"
  • vectors:表示曲线上的向量点,数组类型,每个元素为一个包含 xyz 坐标的 JSON 对象。
  • arcLengths:表示曲线上对应点的弧长,数组类型,每个元素为曲线上对应点的弧长。
  • chordalError:表示曲线上每个向量点之间的距离误差,可选参数,默认值为 0.01

返回值

Curve.fromJSON() 方法返回创建的曲线对象的实例。

使用示例

下面的代码示例演示了如何使用 Curve.fromJSON() 方法创建一个 SplineCurve 曲线对象:

const jsonData = {
    "type": "SplineCurve",
    "vectors": [
        {"x": -10, "y": 0, "z": 0},
        {"x": 0, "y": 10, "z": 0},
        {"x": 10, "y": 0, "z": 0},
        {"x": 0, "y": -10, "z": 0},
        {"x": -10, "y": 0, "z": 0}
    ],
    "arcLengths": [0, 11.180339887498949, 22.360679774997898, 33.54101966249684, 44.721359549995796],
    "chordalError": 0.01
}

const curve = THREE.Curve.fromJSON(jsonData);

参考