简体   繁体   English

使用 SCNIKConstraint 时,如何根据目标 position 更改设置 SCNNode 的方向转换?

[英]How to set the orientation transformation of a SCNNode based on the target position change when using SCNIKConstraint?

I'm creating a human skeleton 3D animation using SceneKit .我正在使用SceneKit创建人体骨架 3D animation 。 Here is the diagram explaining my node relationship:这是解释我的节点关系的图表:

节点关系

I set the Spine node as the root node of all the nodes above it.我将 Spine 节点设置为它上面所有节点的根节点。 I'm creating an animation for the movement of the arms using data retrieved from motion capture using the device's camera.我正在创建一个 animation 用于使用设备相机从运动捕捉中检索到的数据来移动手臂。 For now, I set the Neck as the root chain node for creating an SCNIKConstraint to move the position of the hand node.现在,我将 Neck 设置为创建SCNIKConstraint根链节点,以移动手节点的 position。 My code looks pretty much like this:我的代码看起来很像这样:

// The nodes to create an arm
var spineNode: SCNNode!
var neckNode: SCNNode!
var shoulderNode: SCNNode!
var elbowNode: SCNNode!
var handNode: SCNNode!

// Setting the initial positions
spineNode.position = setSpinePosition()
neckNode.position = setNeckPosition()
// and so on for the other nodes...

// Setting the constraint to the hand node
let handIkConstraint: SCNIKConstraint = .inverseKinematicsConstraint(chainRootNode: neckNode)
handNode.constraints = [handIkConstraint]

And for position change, since I'm using data retrieved from motion capture from a video, I set the position based on a new data like this:对于 position 更改,由于我使用的是从视频的动作捕捉中检索到的数据,因此我根据如下新数据设置了 position:

func changeFrame(data: HumanKeypointData) {
    spineNode.position = getNewPosition(data.spinePosition)
    handIkConstraint.targetPosition = data.handPosition
}

It works mostly fine, the Hand node moves as expected and so does it's parent.它大部分工作正常,Hand 节点按预期移动,它的父节点也是如此。 But the shoulder node doesn't move as expected.但是肩节点没有按预期移动。 It rotates based on the hand movement/position change, but it stays in its place.它会根据手的移动/位置变化进行旋转,但会保持在原位。 It looks like this (the black boxes are the shoulder nodes, as you can see it's fixed in its place while it rotates based on the hand node/blue box):它看起来像这样(黑框是肩节点,你可以看到它固定在它的位置,同时它基于手节点/蓝框旋转):

肩节点不动

But I want to achieve something like this (the shoulder nodes/black box moves based on the target position change of the hand nodes using the SCNIKConstraint ):但我想实现这样的事情(肩节点/黑框移动基于目标 position 使用SCNIKConstraint的手节点变化):

肩膀动了

Now to also move the shoulder nodes I just set the position on the new data as I did with the spine node.现在也移动肩节点,我只是在新数据上设置 position,就像我对脊椎节点所做的那样。 But just in case the data is not accurate, I want to make it automatically moves based on the IK constraint target position. I'm wondering if is there any way to achieve this?但是为了防止数据不准确,我想让它根据IK约束目标position自动移动。请问有什么办法可以实现吗? If you need more information please let me know, thank you.如果您需要更多信息,请告诉我,谢谢。

Skeleton and its IK system骨骼及其 IK 系统

I think that the best solution in your case would be to use SCNSkinner .我认为您的最佳解决方案是使用SCNSkinner Using the skinner object, you can initialize the character's skeleton with inverse transform, and implement in the bound skin not only the Parent-Child dependency, but also such an important parameter as bone weight .使用skinner object,可以对角色的骨骼进行逆变换初始化,绑定的皮肤中不仅实现了Parent-Child依赖,还实现了骨骼权重这样一个重要的参数。

See Rigging a Model for Motion Capture article for more information on character rigging.有关角色绑定的更多信息,请参阅为运动捕捉绑定 Model 一文。

Necessary IK tools, missing in SceneKit必要的 IK 工具,在 SceneKit 中缺失

However, all of the aforementioned is a very laborious process in SceneKit.但是,上述所有操作在 SceneKit 中都是一个非常费力的过程。 The most efficient way is to animate a character using IK/FK in Autodesk Maya, and then export that character with the baked animation in .dae or .usdz format.最有效的方法是在 Autodesk Maya 中使用 IK/FK 为角色设置动画,然后使用烘焙后的 animation.dae.usdz格式导出该角色。 Maya app has a full arsenal of animation tools and animatable properties for fine-tuning Inverse Kinematics, including IK solvers (Single Chain, Rotate Plane, Spline, Human IK, Multi-chain, etc), effector pinning, IK/FK switching and blending, Pole Vector constraints, MEL and Python scripting. Maya 应用程序拥有完整的 animation 种工具和可动画属性,用于微调反向运动学,包括IK 解算器(单链、旋转平面、样条、人体 IK、多链等)、效应器固定、IK/FK 切换和混合,极向量约束,MEL 和 Python 脚本。 All those features are simply unavailable in SceneKit.所有这些功能在 SceneKit 中根本不可用。

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

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