CCDIKSolver.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <p class="desc"> A solver for IK with <a href="https://sites.google.com/site/auraliusproject/ccd-algorithm"><em>CCD Algorithm</em></a>. <br /><br />
  12. [name] solves Inverse Kinematics Problem with CCD Algorithm.
  13. [name] is designed to work with [page:SkinnedMesh] but also can be used with [page:MMDLoader] or [page:GLTFLoader] skeleton.
  14. </p>
  15. <iframe id="scene" src="scenes/ccdiksolver-browser.html"></iframe>
  16. <h2>代码示例</h2>
  17. <code>
  18. let ikSolver;
  19. //
  20. // Bones hierarchy:
  21. //
  22. // root
  23. // ├── bone0
  24. // │ └── bone1
  25. // │ └── bone2
  26. // │ └── bone3
  27. // └── target
  28. //
  29. // Positioned as follow on the cylinder:
  30. //
  31. // o <- target (y = 20)
  32. //
  33. // +----o----+ <- bone3 (y = 12)
  34. // | |
  35. // | o | <- bone2 (y = 4)
  36. // | |
  37. // | o | <- bone1 (y = -4)
  38. // | |
  39. // +----oo---+ <- root, bone0 (y = -12)
  40. //
  41. let bones = []
  42. // "root"
  43. let rootBone = new Bone();
  44. rootBone.position.y = -12;
  45. bones.push( rootBone );
  46. // "bone0"
  47. let prevBone = new Bone();
  48. prevBone.position.y = 0;
  49. rootBone.add( prevBone );
  50. bones.push( prevBone );
  51. // "bone1", "bone2", "bone3"
  52. for ( let i = 1; i <= 3; i ++ ) {
  53. const bone = new Bone();
  54. bone.position.y = 8;
  55. bones.push( bone );
  56. prevBone.add( bone );
  57. prevBone = bone;
  58. }
  59. // "target"
  60. const targetBone = new Bone();
  61. targetBone.position.y = 24 + 8
  62. rootBone.add( targetBone );
  63. bones.push( targetBone );
  64. //
  65. // skinned mesh
  66. //
  67. const mesh = new SkinnedMesh( geometry, material );
  68. const skeleton = new Skeleton( bones );
  69. mesh.add( bones[ 0 ] ); // "root" bone
  70. mesh.bind( skeleton );
  71. //
  72. // ikSolver
  73. //
  74. const iks = [
  75. {
  76. target: 5, // "target"
  77. effector: 4, // "bone3"
  78. links: [ { index: 3 }, { index: 2 }, { index: 1 } ] // "bone2", "bone1", "bone0"
  79. }
  80. ];
  81. ikSolver = new CCDIKSolver( mesh, iks );
  82. function render() {
  83. ikSolver?.update();
  84. renderer.render( scene, camera );
  85. }
  86. </code>
  87. <h2>例子</h2>
  88. <p>
  89. [example:webgl_loader_mmd]<br />
  90. [example:webgl_loader_mmd_pose]<br />
  91. [example:webgl_loader_mmd_audio]
  92. </p>
  93. <h2>Constructor</h2>
  94. <h3>[name]( [param:SkinnedMesh mesh], [param:Array iks] )</h3>
  95. <p>
  96. [page:SkinnedMesh mesh] — [page:SkinnedMesh] for which [name] solves IK problem.<br />
  97. [page:Array iks] — An array of [page:Object] specifying IK parameter. target, effector, and link-index are index integers in .skeleton.bones.
  98. The bones relation should be "links[ n ], links[ n - 1 ], ..., links[ 0 ], effector" in order from parent to child.<br />
  99. <ul>
  100. <li>[page:Integer target] — Target bone.</li>
  101. <li>[page:Integer effector] — Effector bone.</li>
  102. <li>[page:Array links] — An array of [page:Object] specifying link bones.
  103. <ul>
  104. <li>[page:Integer index] — Link bone.</li>
  105. <li>[page:Vector3 limitation] — (optional) Rotation axis. Default is undefined.</li>
  106. <li>[page:Vector3 rotationMin] — (optional) Rotation minimum limit. Default is undefined.</li>
  107. <li>[page:Vector3 rotationMax] — (optional) Rotation maximum limit. Default is undefined.</li>
  108. <li>[page:Boolean enabled] — (optional) Default is true.</li>
  109. </ul>
  110. </li>
  111. <li>[page:Integer iteration] — (optional) Iteration number of calculation. Smaller is faster but less precise. Default is 1.</li>
  112. <li>[page:Number minAngle] — (optional) Minimum rotation angle in a step. Default is undefined.</li>
  113. <li>[page:Number maxAngle] — (optional) Maximum rotation angle in a step. Default is undefined.</li>
  114. </ul>
  115. </p>
  116. <p>
  117. Creates a new [name].
  118. </p>
  119. <h2>Properties</h2>
  120. <h3>[property:Array iks]</h3>
  121. <p>An array of IK parameter passed to the constructor.</p>
  122. <h3>[property:SkinnedMesh mesh]</h3>
  123. <p>[page:SkinnedMesh] passed to the constructor.</p>
  124. <h2>Methods</h2>
  125. <h3>[method:CCDIKHelper createHelper]()</h3>
  126. <p>
  127. Return [page:CCDIKHelper]. You can visualize IK bones by adding the helper to scene.
  128. </p>
  129. <h3>[method:this update]()</h3>
  130. <p>
  131. Update IK bones quaternion by solving CCD algorithm.
  132. </p>
  133. <h3>[method:this updateOne]( [param:Object ikParam] )</h3>
  134. <p>
  135. Update an IK bone quaternion by solving CCD algorithm.
  136. </p>
  137. <h2>Source</h2>
  138. <p>
  139. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/animation/CCDIKSolver.js examples/jsm/animation/CCDIKSolver.js]
  140. </p>
  141. </body>
  142. </html>