简体   繁体   English

如何使用Three.js定位Blender动画导出

[英]How to position a Blender animation export using Three.js

I've successfully exported an animation from Blender using the Three.js export utility, and can add it to a Three.js scene: 我已经使用Three.js导出实用程序从Blender成功导出动画,并可以将其添加到Three.js场景:

http://jsfiddle.net/frogt/6HxRP/1/ http://jsfiddle.net/frogt/6HxRP/1/

However, once I've added the object to my scene, I can't seem to position it manually. 但是,一旦我将对象添加到我的场景中,我似乎无法手动定位它。 Here's the code I'm using to create the mesh and animation from the Blender export: 这是我用来从Blender导出创建网格和动画的代码:

var callback = function (geometry, materials) {

        var skinnedMesh = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial({
            color: 'green'
        }));
        skinnedMesh.receiveShadow = true;

        THREE.AnimationHandler.add(skinnedMesh.geometry.animation);

        var animation = new THREE.Animation(skinnedMesh,
                "ArmatureAction",
                THREE.AnimationHandler.CATMULLROM
        );

        animation.interpolationType = THREE.AnimationHandler.CATMULLROM_FORWARD;

        // This positioning doesn't work....
        skinnedMesh.position.y = 50;
        skinnedMesh.position.x = 50;
        skinnedMesh.position.z = 50;

        animation.play();

        scene.add(skinnedMesh);

    };

and here's the animation in the Blender export: 这是Blender导出中的动画:

"animation": {
    "name": "ArmatureAction",
    "fps": 24,
    "length": 4.125,
    "hierarchy": [{
        "parent": -1,
        "keys": [{
            "time": 0,
            "pos": [0, -0.998347, -0],
            "rot": [0, 0, -0, 1],
            "scl": [1, 1, 1]
        }, {
            "time": 2,
            "pos": [0, 3.92237, -0],
            "rot": [0, 0, -0, 1]
        }, {
            "time": 4.125,
            "pos": [0, -0.667432, 1.77636e-15],
            "rot": [0, 0, -0, 1],
            "scl": [1, 1, 1]
        }]
    }]

The position of the animation appears to be locked to the 'pos' array in the exported animation. 动画的位置似乎被锁定到导出动画中的“pos”数组。

My question is: how can I manually position (and move) the animation once added to my Three.js scene? 我的问题是:一旦添加到我的Three.js场景,我怎样才能手动定位(和移动)动画?

Am using Three.js r67 我使用的是Three.js r67

I managed to find a solution by modifying the Three.js source. 我设法通过修改Three.js源找到了解决方案。 Inside the THREE.Animation.prototype.update() method I replaced 我更换了THREE.Animation.prototype.update()方法

vector.x = vector.x + ( currentPoint[ 0 ] - vector.x ) * proportionalWeight;
vector.y = vector.y + ( currentPoint[ 1 ] - vector.y ) * proportionalWeight;
vector.z = vector.z + ( currentPoint[ 2 ] - vector.z ) * proportionalWeight;

with

var xOrig = this.root.position.x;
var yOrig = this.root.position.y;
var zOrig = this.root.position.z;

vector.x = (vector.x + ( currentPoint[ 0 ] - vector.x ) * proportionalWeight) + xOrig;
vector.y = (vector.y + ( currentPoint[ 1 ] - vector.y ) * proportionalWeight);
vector.z = (vector.z + ( currentPoint[ 2 ] - vector.z ) * proportionalWeight) + zOrig;

This only applies to the X and Z axis, which is all I need for my specific application. 这仅适用于X轴和Z轴,这是我特定应用所需的全部内容。 However, this doesn't seem like the "correct" way to solve the problem. 但是,这似乎不是解决问题的“正确”方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM