Three.js-将骨架烘焙为几何 [英] Three.js - Bake skeleton transform into geometry
问题描述
应用 bone $ c的正确方法是什么? $ c>
到顶点的矩阵,以便实际的几何图形表示不使用GPU的变换形状?
What is the proper way of applying bone
matrices to vertices so that the actual geometry represents the transformed shape without using GPU?
我有一个字符模型,我正在应用 骨骼
表示要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()
在每个 SkinnedMesh
和 geometry.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
} );
}
}
} );
推荐答案
看看这个拉取请求: 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:
- 遍历所有顶点
- 获取相应的
skinIndices
和skinWeights
- 获取每个骨骼的关联骨骼顶点及其权重
- 遍历所有骨骼
- 获取骨骼的变换矩阵并将其转换为<$ c $的坐标系c>几何
- 通过关联的
skinWeights [boneIdx]
$ b加权矩阵$ b - 应用最终矩阵
- Go over all vertices
- Get their corresponding
skinIndices
andskinWeights
- Get the associated bones for each vertex and their weights
- Go over all bones
- Get the transform matrix of the bone and translate it to the coordinate system of the
Geometry
- Weight the matrix via the associated
skinWeights[boneIdx]
- Apply the final matrix
编辑:解决此问题的出口商版本。 ( https://github.com/mrdoob /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屋!