Javascript /传递正确的可选参数



如果有这个对象:WebGLCubeRenderTarget

其构造函数是:

constructor(size?: number, options?: WebGLRenderTargetOptions);

在选项中我需要指定编码:

export interface WebGLRenderTargetOptions {
wrapS?: Wrapping | undefined;
wrapT?: Wrapping | undefined;
encoding?: TextureEncoding | undefined;

编码为enum:

export enum TextureEncoding {}
export const LinearEncoding: TextureEncoding;
export const sRGBEncoding: TextureEncoding;

传递sRGBEncoding的正确语法是什么?

这个不行:

const formatted = new THREE.WebGLCubeRenderTarget(texture.image.height, "sRGBEncoding")
编辑:完整代码
const Background = props => {
const texture = useLoader(THREE.TextureLoader, "/03milkyway.jpg")
const { gl } = useThree();
const formatted = new THREE.WebGLCubeRenderTarget(texture.image.height, "sRGBEncoding").fromEquirectangularTexture(gl, texture)
return (
<primitive attach='background' object={formatted} />
)
}

WebGLCubeRenderTarget的第二个参数应该是一个对象,你传递给它一个字符串。

我相信从文档中,"编码"的值;选项也不应该是字符串;参见"编码"。部分。

所以试试这个:

const formatted = new THREE.WebGLCubeRenderTarget(
texture.image.height, 
{encoding: THREE.sRGBEncoding}
)

你必须传递一个对象作为第二个参数:

const formatted = new THREE.WebGLCubeRenderTarget(texture.image.height, {encoding: "sRGBEncoding"})

最新更新