gpt4 book ai didi

animation - Three.js 克隆 FBX 动画

转载 作者:行者123 更新时间:2023-12-05 05:16:08 27 4
gpt4 key购买 nike

我似乎无法在保留动画关键帧的同时克隆 FBX 模型(从 Mixamo 下载的 FBX)。

尝试了多种方法,包括使用 cloneFbx要点(包含在下面的示例中);一切都无济于事。即使将整个 FBXLoader() 函数放在一个循环中也无法按预期工作,因为一次只有一个模型会设置动画。

此问题已部分解决 here ,但我似乎无法像答案建议的那样“复制”动画序列。

谁能指出我哪里出错了?

这是我的一项测试的粗略示例:

加载fbx模型并存储动画:

var loader = new THREE.FBXLoader();
loader.load( 'models/Walking.fbx', function ( fbx ) {
clip = fbx.animations[ 0 ];

// createVehicle(fbx); // Works! Creates one animated model via FBX

// cloneFbx via: https://gist.github.com/kevincharm/bf12a2c673b43a3988f0f171a05794c1
for (var i = 0; i < 2; i++) {
const model = cloneFbx(fbx);
createVehicle(model);
}
});

根据存储的剪辑添加混音器和 Action ,将模型添加到场景:

function createVehicle(model){
model.mixer = new THREE.AnimationMixer( model );
mixers.push( model.mixer );

var action = model.mixer.clipAction( clip );
action.play();

model.traverse( function ( child ) {
if ( child.isMesh ) {
child.castShadow = true;
child.receiveShadow = true;
}
});

const x = Math.random() * groundSize - groundSize/2;
const z = Math.random() * groundSize - groundSize/2;
model.position.set(x, 0, z);

const vehicle = new Vehicle(model, x, z);
vehicles.push(vehicle);

scene.add( model );
}

动画周期:

if ( mixers.length > 0 ) {
for ( var i = 0; i < mixers.length; i ++ ) {
mixers[ 0 ].update( clock.getDelta() );
}
}

最佳答案

无法找到一个优雅的解决方案。我能想到的最好的方法是创建一个循环,其中包含加载顺序;这非常慢(因为每次都必须解析 FBX)。

这里的关键是让动画混合器将动画对象作为一个组来控制,而不是为每个动画对象创建一个混合器。

如果有人能找到更好的解决方案,我会非常想听听(也许正确使用 cloneFbx 脚本)。

创建混音器,加载 FBX:

  // Create mixer to run animations
mixer = new THREE.AnimationMixer( scene );

// Load fbx
var loader = new THREE.FBXLoader();
for (var i = 0; i < 5; i++) {
loader.load( 'models/Walking.fbx', function ( fbx ) {
mixer.clipAction( fbx.animations[ 0 ], fbx )
.startAt( - Math.random() )
.play();

createVehicle(fbx);
});
}

创建类实例,添加到场景:

function createVehicle(model){

const x = Math.random() * groundSize - groundSize/2;
const z = Math.random() * groundSize - groundSize/2;
model.position.set(x, 0, z);

const vehicle = new Vehicle(model, x, z);
vehicles.push(vehicle);

scene.add( model );
}

绘制周期:

mixer.update( clock.getDelta() );

关于animation - Three.js 克隆 FBX 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50792178/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com