Three.js - 烘焙骨架转化为几何体 [英] Three.js - Bake skeleton transform into geometry

查看:49
本文介绍了Three.js - 烘焙骨架转化为几何体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用bone 矩阵到顶点,以便实际几何图形在不使用 GPU 的情况下表示变换后的形状?

What is the proper way of applying bone matrices to vertices so that the actual geometry represents the transformed shape without using GPU?

我有一个角色模型,我正在应用 skeleton 我想以不同的姿势进行 3D 打印,所以我想使用 STLExporter 导出 3D 可打印文件,但它只导出原始几何体.

I have a character model I am applying a skeleton to that I want to 3D print in different poses, so I want to use the STLExporter to export a 3D printable file, but it only exports the original geometry.

如果我可以scene.traverse() 在每个 SkinnedMeshgeometry.applyMatrix(???) 使用正确的骨骼矩阵按正确的顺序,我应该能够导出应用了变换的 STL,对吗?

If I can scene.traverse() over each SkinnedMesh and geometry.applyMatrix(???) with the correct bone matrix in the right order, I should be able to export an STL with the transform applied, right?

var objects = [];
var triangles = 0;
scene.traverse( function ( object ) {
    if ( object.isMesh ) {
        var geometry = object.geometry;
        if ( geometry.isBufferGeometry ) {
            geometry = new THREE.Geometry().fromBufferGeometry( geometry );
        }
        // TODO: Apply skeleton transform
        if ( geometry.isGeometry ) {
            triangles += geometry.faces.length;
            objects.push( {
                geometry: geometry,
                matrixWorld: object.matrixWorld
            } );
        }
    }
} );

推荐答案

看看这个 pull request:https://github.com/mrdoob/three.js/pull/8953/files

have a look at this pull request: https://github.com/mrdoob/three.js/pull/8953/files

特别是这部分:

THREE.SkinnedMesh.prototype.boneTransform = 
...snip...
for ( var i = 0; i < 4; i ++ ) {
+
+           var skinWeight = skinWeights[ properties[ i ] ];
+
+           if ( skinWeight != 0 ) {
+
+               var boneIndex = skinIndices[ properties[ i ] ];
+               tempMatrix.multiplyMatrices( this.skeleton.bones[ boneIndex ].matrixWorld, this.skeleton.boneInverses[ boneIndex ] );
+               result.add( temp.copy( clone ).applyMatrix4( tempMatrix ).multiplyScalar( skinWeight ) );
+
+           }
+
+       }

所以要烘焙变形,您必须执行以下步骤:

So to bake the deformations you have to do the following steps:

  1. 遍历所有顶点
  2. 获取它们对应的skinIndicesskinWeights
  3. 获取每个顶点的关联骨骼及其权重
  4. 检查所有骨骼
  5. 获取骨骼的变换矩阵并将其转换为Geometry
  6. 的坐标系
  7. 通过关联的skinWeights[boneIdx]
  8. 对矩阵进行加权
  9. 应用最终矩阵

edit:修复该问题的导出器版本.(https://github.com/m/three.js/blob/1be00d5ad075b2305b86c6385403d0e56b4621dd/examples/js/exporters/STLExporter.js)

edit: A version of the exporter that fixes the issue. (https://github.com/mrdoob/three.js/blob/1be00d5ad075b2305b86c6385403d0e56b4621dd/examples/js/exporters/STLExporter.js)

这篇关于Three.js - 烘焙骨架转化为几何体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆