Javascript 如何在react three fiber中使用ApplyMatrix X4

Javascript 如何在react three fiber中使用ApplyMatrix X4,javascript,typescript,react-three-fiber,Javascript,Typescript,React Three Fiber,我在THREE.js中有这个代码: var RASToLPS = new THREE.Matrix4(); RASToLPS.set(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); mesh.applyMatrix(RASToLPS); scene.add(mesh); 我想把它转换成react three fiber。我尝试了以下代码,但不起作用: <mesh {...props}

我在
THREE.js
中有这个代码:

  var RASToLPS = new THREE.Matrix4();
  RASToLPS.set(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  mesh.applyMatrix(RASToLPS);
  scene.add(mesh);
我想把它转换成
react three fiber
。我尝试了以下代码,但不起作用:

    <mesh 
        {...props}
        geometry = {bufferGeometry}
        material = {material}
        applyMatrix4 = {matrix4 => {
            matrix4.set(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
        }}
        >
    </mesh>
{
矩阵4.set(-1,0,0,0,0,0,-1,0,0,0,0,0,1,0,0,0,0,1)
}}
>

我使用以下代码使其在没有
applyMatrix4
mesh属性的情况下工作:

    const Component = ({
        bufferGeometry,
        material,
    }) => {
        const mesh = useRef<THREE.Mesh>()
    
        useEffect(() => { 
            if (mesh.current) {
                const RASToLPS = new THREE.Matrix4()
                RASToLPS.set(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
                mesh.current.applyMatrix4(RASToLPS)
            }
        }, [mesh])
    
        return (
            <mesh
                geometry = {bufferGeometry}
                material = {material}
                ref={mesh}
            >
            </mesh>
        )
    }
const组件=({
缓冲几何,
材料,
}) => {
const mesh=useRef()
useffect(()=>{
if(网格当前){
const RASToLPS=new THREE.Matrix4()
RASToLPS.set(-1,0,0,0,0,-1,0,0,0,0,0,1,0,0,0,0,1)
mesh.current.ApplyMatrix X4(RASToLPS)
}
},[mesh])
返回(
)
}
如果有人知道如何使用applyMatrix4,请回答。

不是全部答案(我有一个类似的问题),但请在原始代码
mesh
attrs上尝试以下操作:


  • applyMatrix4
    替换为
    matrix
    (applyMatrix4可能不存在?)

将我问题中的
applyMatrix4
替换为
matrix
,代码不起作用:(ApplyMatrix X4是一个函数而不是一个属性,您只需用另一个函数覆盖该函数-但这不是您想要的。将引用放到网格上,使用LayoutEffect将在对象在屏幕上渲染之前调用您,在引用上调用ApplyMatrix X4。或者您可以执行
self.ApplyMatrix X4(…)}…/>