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

查看:156
本文介绍了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?

我有一个字符模型,我正在应用 骨骼 表示要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:


  1. 遍历所有顶点

  2. 获取相应的 skinIndices skinWeights

  3. 获取每个骨骼的关联骨骼顶点及其权重

  4. 遍历所有骨骼

  5. 获取骨骼的变换矩阵并将其转换为<$ c $的坐标系c>几何

  6. 通过关联的 skinWeights [boneIdx]
  7. $ b加权矩阵$ b
  8. 应用最终矩阵

  1. Go over all vertices
  2. Get their corresponding skinIndices and skinWeights
  3. Get the associated bones for each vertex and their weights
  4. Go over all bones
  5. Get the transform matrix of the bone and translate it to the coordinate system of the Geometry
  6. Weight the matrix via the associated skinWeights[boneIdx]
  7. 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屋!

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