我在一个用 typescript 编写的应用程序中使用React-Three-Fiber。我已经设置好了画布和相机,但我需要在正交相机上实现. setViewOffset。在three.js文档中,setViewOffset的输入为:( fullWidth : Float, fullHeight : Float, x : Float, y : Float, width : Float, height : Float ) : null
我的设置:
<Canvas orthographic camera={{ zoom: 50, position: [0, 100, 100], setViewOffset: SVO }}>
<ambientLight intensity={1.90} color={"rgb(255,255,255)"}/>
<directionalLight position={[150, 250, -150]} castShadow={true}/>
<Box position={[0, 0, 0]} color="red"/>
<Box position={[0, 7, 0]} color="blue"/>
<Box position={[0, -7, 0]} color="green"/>
</Canvas>
我尝试为变量"SVO"实现以下代码:
const SVO = [ 500, 500, 1000, 0, 500, 500 ];
//Typescript error:
//Type 'number[]' is not assignable to type '((fullWidth: number, fullHeight: number, x: number, y: number, width: number, height: number) => void) & ((fullWidth: number, fullHeight: number, offsetX: number, offsetY: number, width: number, height: number) => void)'
const SVO = {fullWidth: 50, fullHeight: 50, offsetX: 50, offsetY: 50, width: 50, height: 50};
//Typescript error:
//Type '{ fullWidth: number; fullHeight: number; offsetX: number; offsetY: number; width: number; height: number; }' is not assignable to type '((fullWidth: number, fullHeight: number, x: number, y: number, width: number, height: number) => void) & ((fullWidth: number, fullHeight: number, offsetX: number, offsetY: number, width: number, height: number) => void)'.
const SVO = ( fullWidth=500, fullHeight=500, offsetX=1000, offsetY=-1000, width=500, height=500 ) => { };
//Accepted by typescript but has no effect.
这是我第一次使用Typescript和react-three-fiber,所以我真的不知道它希望我给setViewOffset什么样的结构,所以我尝试了数组、对象和函数。我在其他项目中使用vanilla three.js实现了setViewOffset,如下所示:
const [ w, h, cam, frust ] = [ this.mount.clientWidth, this.mount.clientHeight, this.camera, this.frustumSize ];
cam.setViewOffset( w, h, -225, -120, w, h);
1条答案
按热度按时间y4ekin9u1#
我认为答案在于使用@react-three/drei摄像机的onUpdate属性
...