首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在react-three-fiber中使用applyMatrix4

如何在react-three-fiber中使用applyMatrix4
EN

Stack Overflow用户
提问于 2020-12-30 02:10:51
回答 2查看 352关注 0票数 1

我在THREE.js中有这段代码

代码语言:javascript
复制
  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。我尝试了下面的代码,但它不起作用:

代码语言:javascript
复制
    <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>
EN

回答 2

Stack Overflow用户

发布于 2020-12-30 03:08:54

我使用下面的代码在没有applyMatrix4 mesh属性的情况下让它工作:

代码语言:javascript
复制
    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>
        )
    }

如果有人知道如何使用applyMatrix4,请回答。

票数 1
EN

Stack Overflow用户

发布于 2021-01-02 14:13:42

不是全部答案(我也有类似的问题),但是在你的原始代码mesh attrs上试试以下代码:

  • applyMatrix4替换为matrix (applyMatrix4可能已失效?)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65496749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档