如何正确传递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
相关产品推荐
相关产品推荐

