在 three.js 中更新动画蒙皮网格的法线?

Update normals of animated skinned mesh in three.js?

我有一个简单的动画模型,通过蒙皮动画,我给它一个 ShaderMaterial 来显示它的法线:

gl_FragColor = vec4(vNormal, 1.0);

https://codepen.io/marco_fugaro/pen/ZEEBjKz?editors=0010

问题是法线不会随着模型的蒙皮而更新,并且它们始终与对象的非动画位置保持相同(参见 VertexNormalsHelper)。

如何更新法线,或者如何获取动画顶点的法线?

model.geometry.computeVertexNormals() 无效

我结束了 monkeyPatching MeshNormalMaterial 顶点着色器,并删除了法线相对于相机的逻辑,这是最终代码:

import * as THREE from 'three'
import normalVert from 'three/src/renderers/shaders/ShaderLib/normal_vert.glsl'

// like MeshNormalMaterial, but the normals are relative to world not camera
const normalMaterialGlobalvert = normalVert.replace(
  '#include <defaultnormal_vertex>',
  THREE.ShaderChunk['defaultnormal_vertex'].replace(
    'transformedNormal = normalMatrix * transformedNormal;',
    // take into consideration only the model matrix
    'transformedNormal =  mat3(modelMatrix) * transformedNormal;'
  )
)

然后像这样使用它:

mesh.material = new THREE.ShaderMaterial({
  vertexShader: normalMaterialGlobalvert,
  fragmentShader: `
    varying vec3 vNormal;

    void main() {
      gl_FragColor = vec4(vNormal, 1.0);
    }
  `,
})

感谢gman为我指明了正确的方向!