You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何正确传递sRGBEncoding给WebGLCubeRenderTarget构造函数?

正确传递WebGLCubeRenderTarget编码参数的语法

你当前的问题出在两个核心点:

  • WebGLCubeRenderTarget的第二个参数需要传入**WebGLRenderTargetOptions配置对象**,而非直接传编码字符串
  • 编码值必须使用Three.js提供的枚举常量,不能用字符串字面量

修正后的代码

const Background = props => {
    const texture = useLoader(THREE.TextureLoader, "/03milkyway.jpg")
    const { gl } = useThree();
    // 传入包含encoding属性的配置对象,使用THREE内置的枚举常量
    const formatted = new THREE.WebGLCubeRenderTarget(texture.image.height, {
        encoding: THREE.sRGBEncoding
    }).fromEquirectangularTexture(gl, texture)
    return (
        <primitive attach='background' object={formatted} />
    )
}

关键说明

  • WebGLRenderTargetOptions是一个结构化配置对象,你需要在其中明确指定encoding属性,值只能是Three.js预定义的枚举成员(比如THREE.LinearEncoding或THREE.sRGBEncoding)
  • 字符串"sRGBEncoding"不属于合法参数类型,Three.js的编码枚举是内部常量,并非字符串类型

内容的提问来源于stack exchange,提问作者fransua

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 13:05:17