【问题标题】:Three js: How to get normal of rotated plane三个js:如何获得旋转平面的法线
【发布时间】:2020-11-23 06:52:28
【问题描述】:

我正在尝试使旋转平面正常。我的解决方案是复制更新的平面,然后获取法线。 当我只旋转 1 个角度时它可以工作,但不能旋转 2 或 3 个角度。 jsFiddle

绿色的是复制平面,紫色的是旋转平面。 enter image description here

如何解决这个问题?请帮帮我

我的复制功能:

 function copyPlane() {
    let copyPlaneGeom = new THREE.PlaneGeometry(3, 3, 3);
    copyPlaneGeom.rotateX(plane.rotation.x);
    copyPlaneGeom.rotateY(plane.rotation.y);
    copyPlaneGeom.rotateZ(plane.rotation.z);
    let copyPlane = new THREE.Mesh(copyPlaneGeom, new THREE.MeshBasicMaterial({color: 0x00ff00}));
        scene.add(copyPlane)
    
    let normals = copyPlane.geometry.faces[0].normal

【问题讨论】:

    标签: three.js plane


    【解决方案1】:

    我认为使用这种方法,您将始终得到 0, 0, 1 的向量,因为飞机的面法线始终是 (0, 0, 1) * objectRotation

    相反,尝试从0, 0, 1 的 Vector3 开始,然后将对象的旋转应用到它:

    var originalNormal = new Vector3(0, 0, 1);
    
    // Get the mesh rotation
    var objRotation = plane.rotation;
    
    // Apply mesh rotation to vector
    originalNormal.applyEuler(objRotation);
    

    现在你有了一个带有更新后的 wold 法线的 Vector3,而不是本地法线!阅读.applyEuler() here

    【讨论】:

    • 非常感谢!这正是我想要的。你拯救了我的一天:)
    猜你喜欢
    • 2015-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-12
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 2014-02-28
    相关资源
    最近更新 更多