Three.js API手册

动画
AnimationAction AnimationClip AnimationMixer AnimationObjectGroup AnimationUtils KeyframeTrack PropertyBinding PropertyMixer
动画 / 轨道
BooleanKeyframeTrack ColorKeyframeTrack NumberKeyframeTrack QuaternionKeyframeTrack StringKeyframeTrack VectorKeyframeTrack
音频
Audio AudioAnalyser AudioContext AudioListener PositionalAudio
摄像机
ArrayCamera Camera CubeCamera OrthographicCamera PerspectiveCamera StereoCamera
常量
Animation Core CustomBlendingEquation DrawModes Materials Renderer Textures
核心
BufferAttribute BufferGeometry Clock DirectGeometry EventDispatcher Face3 Geometry InstancedBufferAttribute InstancedBufferGeometry InstancedInterleavedBuffer InterleavedBuffer InterleavedBufferAttribute Layers Object3D Raycaster Uniform
核心 / BufferAttributes
BufferAttribute_Types
弃用列表
DeprecatedList
附件
Earcut ShapeUtils
附件 / 核心
Curve CurvePath Font Interpolations Path Shape ShapePath
附件 / 曲线
ArcCurve CatmullRomCurve3 CubicBezierCurve CubicBezierCurve3 EllipseCurve LineCurve LineCurve3 QuadraticBezierCurve QuadraticBezierCurve3 SplineCurve
附件 / 物体
ImmediateRenderObject
几何体
BoxBufferGeometry BoxGeometry CircleBufferGeometry CircleGeometry ConeBufferGeometry ConeGeometry CylinderBufferGeometry CylinderGeometry DodecahedronBufferGeometry DodecahedronGeometry EdgesGeometry ExtrudeBufferGeometry ExtrudeGeometry IcosahedronBufferGeometry IcosahedronGeometry LatheBufferGeometry LatheGeometry OctahedronBufferGeometry OctahedronGeometry ParametricBufferGeometry ParametricGeometry PlaneBufferGeometry PlaneGeometry PolyhedronBufferGeometry PolyhedronGeometry RingBufferGeometry RingGeometry ShapeBufferGeometry ShapeGeometry SphereBufferGeometry SphereGeometry TetrahedronBufferGeometry TetrahedronGeometry TextBufferGeometry TextGeometry TorusBufferGeometry TorusGeometry TorusKnotBufferGeometry TorusKnotGeometry TubeBufferGeometry TubeGeometry WireframeGeometry
辅助对象
ArrowHelper AxesHelper BoxHelper Box3Helper CameraHelper DirectionalLightHelper FaceNormalsHelper GridHelper PolarGridHelper PositionalAudioHelper HemisphereLightHelper PlaneHelper PointLightHelper RectAreaLightHelper SkeletonHelper SpotLightHelper VertexNormalsHelper
灯光
AmbientLight DirectionalLight HemisphereLight Light PointLight RectAreaLight SpotLight
灯光 / 阴影
DirectionalLightShadow LightShadow SpotLightShadow
加载器
AnimationLoader AudioLoader BufferGeometryLoader Cache CompressedTextureLoader CubeTextureLoader DataTextureLoader FileLoader FontLoader ImageBitmapLoader ImageLoader Loader LoaderUtils MaterialLoader ObjectLoader TextureLoader
加载器 / 管理器
DefaultLoadingManager LoadingManager
材质
LineBasicMaterial LineDashedMaterial Material MeshBasicMaterial MeshDepthMaterial MeshDistanceMaterial MeshLambertMaterial MeshMatcapMaterial MeshNormalMaterial MeshPhongMaterial MeshPhysicalMaterial MeshStandardMaterial MeshToonMaterial PointsMaterial RawShaderMaterial ShaderMaterial ShadowMaterial SpriteMaterial
数学库
Box2 Box3 Color Cylindrical Euler Frustum Interpolant Line3 Math Matrix3 Matrix4 Plane Quaternion Ray Sphere Spherical Triangle Vector2 Vector3 Vector4
数学库 / 插值
CubicInterpolant DiscreteInterpolant LinearInterpolant QuaternionLinearInterpolant
物体
Bone Group Line LineLoop LineSegments LOD Mesh Points Skeleton SkinnedMesh Sprite
渲染器
WebGLMultisampleRenderTarget WebGLRenderer WebGLRenderTarget WebGLRenderTargetCube
渲染器 / 着色器
ShaderChunk ShaderLib UniformsLib UniformsUtils
场景
Fog FogExp2 Scene
纹理贴图
CanvasTexture CompressedTexture CubeTexture DataTexture DataTexture3D DepthTexture Texture VideoTexture
在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

ObjectLoader

A loader for loading a JSON resource in the JSON Object/Scene format.

此加载器内部使用FileLoader进行加载文件。

例子

WebGL / loader / json / claraio
WebGL / materials / lightmap

var loader = new THREE.ObjectLoader(); 
loader.load( 
  // 资源的URL 
  "models/json/example.json", 
  // onLoad回调 
  // Here the loaded data is assumed to be an object 
  function ( obj ) { 
    // Add the loaded object to the scene 
    scene.add( obj ); 
  }, 
  // onProgress回调 
  function ( xhr ) { 
    console.log( (xhr.loaded / xhr.total * 100) + '% loaded' ); 
  }, 
  // onError回调 
  function ( err ) { 
    console.error( 'An error happened' ); 
  } 
); 

// 或者,解析先前加载的JSON结构 
var object = loader.parse( a_json_object ); 
scene.add( object );

构造函数

ObjectLoader( manager : LoadingManager )

manager — 加载器所使用的loadingManager,默认值为THREE.DefaultLoadingManager.

创建一个新的ObjectLoader.

属性

# .crossOrigin : String

如果设置了,在开始加载前, 将为图片分配 crossOrigin 属性,其值为 crossOrigin, 默认为"anonymous"。

# .manager : LoadingManager

加载器正在使用的loadingManager,默认值为DefaultLoadingManager。

# .texturePath : String

将要被加载的纹理的路径或者URL,详情请参考.setTexturePath。 默认值为空字符串。

方法

# .load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : null

url — 文件的URL或者路径,也可以为 Data URI.
onLoad — 加载完成时将调用。回调参数为将要加载的object.
onProgress — 将在加载过程中进行调用。参数为XMLHttpRequest实例,实例包含total和loaded字节。
onError — 在加载错误时被调用。

从URL中进行加载,并将被解析的响应内容传递给onLoad。

# .parse ( json : Object, onLoad : Function ) : Object3D

json — 必选参数,需要被解析的JSON源。

onLoad — 当解析完成时被调用,其中参数被解析为object.

解析一个JSON结构,并返回一个threejs对象. 内部使用.load进行加载, 但也可以直接用于解析先前加载的JSON结构。

# .parseGeometries ( json : Object ) : Object3D

json — 必选参数,需要被解析的JSON源。

此函数以JSON结构,用.parse去解析geometries或buffer geometries。

# .parseMaterials ( json : Object ) : Object3D

json — 必选参数,需要被解析的JSON源。

此函数通过.parse来使用MaterialLoader,以解析JSON结构中任意材质。

# .parseAnimations ( json : Object ) : Object3D

json — 必选参数,需要被解析的JSON源。

此函数通过.parse来使用AnimationClip.parse, 以解析JSON结构中任意动画。

# .parseImages ( json : Object ) : Object3D

json — 必选参数,需要被解析的JSON源。

此函数通过.parse来使用ImageLoader, 以解析JSON结构中任意图片。

# .parseTextures ( json : Object ) : Object3D

json — 必选参数,需要被解析的JSON源。

此函数通过.parse来解析JSON结构中任意纹理。

# .parseObject ( json : Object ) : Object3D

json — 必选参数,需要被解析的JSON源。

此函数通过.parse来解析JSON结构中任意对象。 对象可以为如下类型:

  • Scene
  • PerspectiveCamera
  • OrthographicCamera
  • AmbientLight
  • DirectionalLight
  • PointLight
  • SpotLight
  • HemisphereLight
  • Mesh
  • LOD
  • Line
  • LineSegments
  • Points
  • Sprite
  • Group
  • Object3D

# .setCrossOrigin ( value : String ) : ObjectLoader

value — 在允许CROS时,跨域字段通过实现CORS来加载不同域下的URL。

# .setTexturePath ( value : String ) : ObjectLoader

value — 设置将要加载为纹理的路径或者URL

源 -

src/loaders/ObjectLoader.js