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

CompressedTextureLoader.load()

CompressedTextureLoader.load() 方法用于加载压缩的纹理映射数据。它会返回一个 Promise 对象,当纹理加载完成后,该对象会被解决并返回一个 CompressedTexture 对象,该对象包含了压缩图像的相关信息。

语法

以下是 CompressedTextureLoader.load() 方法的语法:

CompressedTextureLoader.load( url, mapping, onLoad, onProgress, onError );

参数

CompressedTextureLoader.load() 方法接受以下参数:

  • url:(必需)表示要加载的纹理映射数据的 URL 地址。
  • mapping:(可选)表示纹理的映射方式,默认值为 THREE.UVMapping
  • onLoad:(可选)当纹理加载完毕后,需要执行的回调函数。
  • onProgress:(可选)表示加载过程中需要执行的回调函数。该函数的参数为 XMLHttpRequestProgressEvent 对象。
  • onError:(可选)表示加载失败时需要执行的回调函数。该函数的参数为错误信息字符串。

返回值

CompressedTextureLoader.load() 方法返回一个 Promise 对象,该对象在纹理加载完成时被解决。

示例

以下示例展示了如何加载一个压缩的纹理映射数据:

const loader = new THREE.CompressedTextureLoader();

loader.load( 'path/to/compressed_texture.dds', function ( texture ) {

    // 获取压缩纹理的宽和高
    const width = texture.image.width;
    const height = texture.image.height;

    // 将纹理映射到一个立方体对象
    const geometry = new THREE.BoxBufferGeometry( 10, 10, 10 );
    const cubeMaterials = [
        new THREE.MeshBasicMaterial( {
            map: texture,// 将纹理映射到material的map属性中
            side: THREE.BackSide
        } ),
        new THREE.MeshBasicMaterial( {
            map: texture,
            side: THREE.BackSide
        } ),
        new THREE.MeshBasicMaterial( {
            map: texture,
            side: THREE.BackSide
        } ),
        new THREE.MeshBasicMaterial( {
            map: texture,
            side: THREE.BackSide
        } ),
        new THREE.MeshBasicMaterial( {
            map: texture,
            side: THREE.BackSide
        } ),
        new THREE.MeshBasicMaterial( {
            map: texture,
            side: THREE.BackSide
        } )
    ];

    const cube = new THREE.Mesh( geometry, cubeMaterials );
    scene.add( cube );
} );

注意事项

  • CompressedTextureLoader.load() 方法支持加载的压缩格式包括 DDSPVR
  • 由于加载压缩的纹理映射数据需要比较高的计算量,因此,如果你需要加载大量的纹理映射数据,建议使用分段加载,避免卡顿。