中的动态骨骼动画

中的动态骨骼动画

本文介绍了Three.js 中的动态骨骼动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过使用three.js 对3D 模型的骨骼进行变换来创建动态动画?我尝试移动和旋转 SkinnedMesh 的骨骼,但网格没有更新.

 loader = new THREE.JSONLoader();loader.load('/JS-Projects/Virtual-Jonah/Modelos/initialPose.js',function jsonReady(几何){mesh = new THREE.SkinnedMesh( geometry, new THREE.MeshNormalMaterial({skinning : true}) );mesh.scale.set( 10, 10, 10 );mesh.position.z = mesh.position.y = mesh.position.x = 0;mesh.geometry.dynamic = true;场景添加(网格);无功指数 = 0;for (var i = 0; i 

我使用的模型是用 makeHuman(每晚构建)创建的,导出到 Collada,导入到 Blender 中,然后导出到 Three.js JSON 模型.模型链接如下:

https://www.dropbox.com/sh/x1606vnaoghes1y/gG_BcZcEKd/initial>

谢谢!

解决方案

是的,你可以!您需要设置mesh.skeleton.bones[i]mesh.skeleton.bones[i].rotationmesh.skeleton.bones[i].位置.旋转是 Euler 类型.位置属于 Vector3 类型.我实际上已经使用这里的代码对此进行了测试 https://github.com/lucasdealmeidasm/three-mm3d(包括一个带有骨骼附加对象的工作蒙皮网格),确实可以做到这一点.

请注意 Inateno 的回答是非常错误的,在很多情况下这是必要的.例如,在 FPS 中,可以同时使用动态和非动态动画.当一个角色奔跑并拿着枪时,他指向枪的方向是动态设置的(可以使用 mesh.skeleton.bones[i].rotation 其中i"是分配给手臂的骨骼索引)而其余的动画,包括行走,在编辑器中制作并加载.可以在three.js中使用THREE.AnimationHandler.update(delta);"然后在代码中改变单个骨骼的位置和旋转来解决这些问题.

Is it possible to create a dynamic animation by applying transformations to the bones of a 3D model using three.js? I tried moving and rotating the bones of a SkinnedMesh, but the mesh was not updated.

        loader = new THREE.JSONLoader();
        loader.load('/JS-Projects/Virtual-Jonah/Modelos/initialPose.js',function jsonReady( geometry )
        {
            mesh = new THREE.SkinnedMesh( geometry, new THREE.MeshNormalMaterial({skinning : true}) );
            mesh.scale.set( 10, 10, 10 );
            mesh.position.z = mesh.position.y = mesh.position.x = 0;
            mesh.geometry.dynamic = true;
            scene.add( mesh );

            var index = 0;
            for (var i = 0; i < mesh.bones.length; i++)
            {
                if (mesh.bones[i].name == "forearm_R")
                {
                    index = i;
                    break;
                }
            }


            setInterval (function ()
            {
                mesh.bones[index].useQuaternion = false;
                mesh.bones[index].position.z += 10;
                mesh.bones[index].matrixAutoUpdate = true;
                mesh.bones[index].matrixWorldNeedsUpdate = true;
                mesh.geometry.verticesNeedUpdate = true;
                mesh.geometry.normalsNeedUpdate = true;

                renderer.render(scene, camera);
            }, 33);

            renderer.render(scene, camera);
        });

The model I am using was created with makeHuman (nightly build), exported to Collada, imported in Blender and exported to the three.js JSON model. The link to the model is the following:

https://www.dropbox.com/sh/x1606vnaoghes1y/gG_BcZcEKd/initial

Thank you!

解决方案

Yes, you can!You need to set mesh.skeleton.bones[i], both mesh.skeleton.bones[i].rotation and mesh.skeleton.bones[i].position. Rotation is of type Euler. Position is of type Vector3. I have actually tested this using my code from here https://github.com/lucasdealmeidasm/three-mm3d (that includes a working skinned mesh with bone-attachable objects) and one can indeed do that.

Note that Inateno's answer is very wrong, there are many instances where this is necessary.For example, in a FPS, one uses both dynamic and non-dynamic animation.When a character runs and holds a gun, the direction he points the gun at is dynamically set (one could use mesh.skeleton.bones[i].rotation where "i" is the index for bone assigned to the arm for that) while the rest of the animation, including the walking, is made in the editor and loaded. One can, in three.js, use "THREE.AnimationHandler.update(delta);" and then change single bones' position and rotation in code to solve those issues.

这篇关于Three.js 中的动态骨骼动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 04:37