Home Reference Source Repository

js/SceneKit/SCNIKConstraint.js

  1. 'use strict'
  2.  
  3. import SCNConstraint from './SCNConstraint'
  4. //import SCNNode from './SCNNode'
  5. //import SCNVector3 from './SCNVector3'
  6.  
  7.  
  8. /**
  9. * A constraint that applies inverse kinematics to make a chain of nodes “reach” toward a target point.
  10. * @access public
  11. * @extends {SCNConstraint}
  12. * @see https://developer.apple.com/documentation/scenekit/scnikconstraint
  13. */
  14. export default class SCNIKConstraint extends SCNConstraint {
  15.  
  16. // Creating an Inverse Kinematics Constraint
  17.  
  18. /**
  19. * Initializes an inverse kinematics constraint whose chain of nodes begins with the specified node.
  20. * @access public
  21. * @param {SCNNode} chainRootNode -
  22. * @returns {void}
  23. * @desc The root node is the highest node in the hierarchy moved by the constraint. For example, a robot arm may have two arm segments and a hand connected to a body. The upper arm is a child node of the body, the lower arm is a child node of the upper arm, and the hand is a child node of the lower arm. In this case, the upper arm is the chain root node, because the body should not move to follow the hand.The node you apply the constraint to (using that node’s constraints property) is the end effector of the chain—the lowest node in the hierarchy. When you set the constraint’s targetPosition property, SceneKit attempts to move this node toward the target point by rotating it relative to its parent node (and rotating its parent and ancestor nodes, up the chain ending with the chainRoot node). Continuing the above example, the end effector of the robot arm is its hand.
  24. * @see https://developer.apple.com/documentation/scenekit/scnikconstraint/1468694-init
  25. */
  26. init(chainRootNode) {
  27.  
  28. // Adjusting the Constraint’s Limits of Motion
  29.  
  30. this._chainRootNode = null
  31.  
  32. // Applying Inverse Kinematics to the Constrained Node
  33.  
  34. /**
  35. * The desired position for the constrained node, in the scene’s world coordinate space. Animatable.
  36. * @type {SCNVector3}
  37. * @see https://developer.apple.com/documentation/scenekit/scnikconstraint/1468651-targetposition
  38. */
  39. this.targetPosition = null
  40.  
  41. }
  42.  
  43. /**
  44. * Creates an inverse kinematics constraint whose chain of nodes begins with the specified node.
  45. * @access public
  46. * @param {SCNNode} chainRootNode -
  47. * @returns {SCNIKConstraint} -
  48. * @desc The root node is the highest node in the hierarchy moved by the constraint. For example, a robot arm may have two arm segments and a hand connected to a body. The upper arm is a child node of the body, the lower arm is a child node of the upper arm, and the hand is a child node of the lower arm. In this case, the upper arm is the chain root node, because the body should not move to follow the hand.The node you apply the constraint to (using that node’s constraints property) is the end effector of the chain—the lowest node in the hierarchy. When you set the constraint’s targetPosition property, SceneKit attempts to move this node toward the target point by rotating it relative to its parent node (and rotating its parent and ancestor nodes, up the chain ending with the chainRoot node). Continuing the above example, the end effector of the robot arm is its hand.
  49. * @see https://developer.apple.com/documentation/scenekit/scnikconstraint/1468653-inversekinematicsconstraint
  50. */
  51. static inverseKinematicsConstraint(chainRootNode) {
  52. return null
  53. }
  54.  
  55. // Adjusting the Constraint’s Limits of Motion
  56.  
  57. /**
  58. * Returns the rotation limit, in degrees, for the specified node.
  59. * @access public
  60. * @param {SCNNode} node - A node affected by the constraint—either the node whose constraints property references the constraint or one of that node’s parent or ancestor nodes, up to the node specified by the constraint’s chainRootNode property.
  61. * @returns {number} -
  62. * @desc When SceneKit evaluates the IK constraint, it checks the target orientations of each node in the chain relative to their initial orientations (as of when the constraint was applied to a node). For each node in the chain, SceneKit limits the rotation (in any direction) between the initial and target orientations to the value returned by this method.The default rotation limit for each joint is 180 degrees in either direction, allowing unconstrained rotation.
  63. * @see https://developer.apple.com/documentation/scenekit/scnikconstraint/1468681-maxallowedrotationangle
  64. */
  65. maxAllowedRotationAngleForJoint(node) {
  66. return 0
  67. }
  68.  
  69. /**
  70. * Sets the rotation limit, in degrees, for the specified node.
  71. * @access public
  72. * @param {number} angle - The maximum rotation, in degrees, that SceneKit should apply to the specified node when evaluating the constraint.
  73. * @param {SCNNode} node - A node affected by the constraint—either the node whose constraints property references the constraint, or one of that node’s parent or ancestor nodes up to the node specified by the constraint’s chainRootNode property.
  74. * @returns {void}
  75. * @desc When SceneKit evaluates the IK constraint, it checks the target orientations of each node in the chain relative to their initial orientations (as of when the constraint was applied to a node). For each node in the chain, SceneKit limits the rotation (in any direction) between the initial and target orientations to the angle value specified with this method.The default rotation limit for each joint is 180 degrees in either direction, allowing unconstrained rotation.
  76. * @see https://developer.apple.com/documentation/scenekit/scnikconstraint/1468649-setmaxallowedrotationangle
  77. */
  78. setMaxAllowedRotationAngleForJoint(angle, node) {
  79. }
  80. /**
  81. * The parent node of the hierarchy affected by the constraint.
  82. * @type {SCNNode}
  83. * @desc The root node is the highest node in the hierarchy moved by the constraint. For example, a robot arm may have two arm segments and a hand connected to a body. The upper arm is a child node of the body, the lower arm is a child node of the upper arm, and the hand is a child node of the lower arm. In this case, the upper arm is the chain root node, because the body should not move to follow the hand.
  84. * @see https://developer.apple.com/documentation/scenekit/scnikconstraint/1468690-chainrootnode
  85. */
  86. get chainRootNode() {
  87. return this._chainRootNode
  88. }
  89. }