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

ObjectLoader.load()

ObjectLoader.load()是three.js库中的方法之一,它可以从URL加载JSON格式的3D模型文件,并将其作为three.js场景的子对象添加到该场景中。

语法

ObjectLoader.load(url: String, onLoad: Function, onProgress: Function, onError: Function): void

参数

  • url:要加载的JSON文件的URL路径。
  • onLoad:加载成功时调用的函数。函数的参数是加载的3D模型对象。
  • onProgress:可选参数,加载过程中调用的函数。函数的参数是XMLHttpRequest的进度事件。
  • onError:可选参数,在加载过程中发生错误时调用的函数。

示例

以下是使用ObjectLoader.load()方法加载JSON格式的3D模型文件的示例:

const loader = new THREE.ObjectLoader();

loader.load(
    'model.json',

    function ( model ) {
        scene.add( model );
    },

    function ( xhr ) {
        console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
    },

    function ( error ) {
        console.log( 'An error happened.' );
    }
);

返回值

ObjectLoader.load()方法返回空值。3D模型对象将通过onLoad回调函数传递。

注意事项

  • ObjectLoader.load()只能加载JSON格式的3D模型文件。
  • onProgressonError回调函数是可选的,如果没有提供将不会被调用。
  • ObjectLoader.load()是一个异步加载方法,需要在回调函数中处理返回的对象。