Skeleton.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Skeleton - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <h1 translate="no">Skeleton</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>Class for representing the armatures in <code>three.js</code>. The skeleton
  16. is defined by a hierarchy of bones.</p></div>
  17. <h2>Code Example</h2>
  18. <div translate="no"><pre><code class="language-js">const bones = [];
  19. const shoulder = new THREE.Bone();
  20. const elbow = new THREE.Bone();
  21. const hand = new THREE.Bone();
  22. shoulder.add( elbow );
  23. elbow.add( hand );
  24. bones.push( shoulder , elbow, hand);
  25. shoulder.position.y = -5;
  26. elbow.position.y = 0;
  27. hand.position.y = 5;
  28. const armSkeleton = new THREE.Skeleton( bones );
  29. </code></pre></div>
  30. </header>
  31. <article>
  32. <div class="container-overview">
  33. <h2>Constructor</h2>
  34. <h3 class="name name-method" id="Skeleton" translate="no">new <a href="#Skeleton">Skeleton</a><span class="signature">( bones : <span class="param-type">Array.&lt;Bone></span>, boneInverses : <span class="param-type">Array.&lt;Matrix4></span> )</span> </h3>
  35. <div class="method">
  36. <div class="description">
  37. <p>Constructs a new skeleton.</p>
  38. </div>
  39. <table class="params">
  40. <tbody>
  41. <tr>
  42. <td class="name"><code>bones</code></td>
  43. <td class="description last"><p>An array of bones.</p></td>
  44. </tr>
  45. <tr>
  46. <td class="name"><code>boneInverses</code></td>
  47. <td class="description last"><p>An array of bone inverse matrices.
  48. If not provided, these matrices will be computed automatically via <a href="Skeleton.html#calculateInverses">Skeleton#calculateInverses</a>.</p></td>
  49. </tr>
  50. </tbody>
  51. </table>
  52. </div>
  53. </div>
  54. <h2 class="subsection-title">Properties</h2>
  55. <div class="member">
  56. <h3 class="name" id="boneInverses" translate="no">.<a href="#boneInverses">boneInverses</a><span class="type-signature"> : Array.&lt;<a href="Matrix4.html">Matrix4</a>></span> </h3>
  57. <div class="description">
  58. <p>An array of bone inverse matrices.</p>
  59. </div>
  60. </div>
  61. <div class="member">
  62. <h3 class="name" id="boneMatrices" translate="no">.<a href="#boneMatrices">boneMatrices</a><span class="type-signature"> : Float32Array</span> </h3>
  63. <div class="description">
  64. <p>An array buffer holding the bone data.
  65. Input data for <a href="Skeleton.html#boneTexture">Skeleton#boneTexture</a>.<br/>Default is <code>null</code>.</p>
  66. </div>
  67. </div>
  68. <div class="member">
  69. <h3 class="name" id="boneTexture" translate="no">.<a href="#boneTexture">boneTexture</a><span class="type-signature"> : <a href="DataTexture.html">DataTexture</a></span> </h3>
  70. <div class="description">
  71. <p>A texture holding the bone data for use
  72. in the vertex shader.<br/>Default is <code>null</code>.</p>
  73. </div>
  74. </div>
  75. <div class="member">
  76. <h3 class="name" id="bones" translate="no">.<a href="#bones">bones</a><span class="type-signature"> : Array.&lt;<a href="Bone.html">Bone</a>></span> </h3>
  77. <div class="description">
  78. <p>An array of bones defining the skeleton.</p>
  79. </div>
  80. </div>
  81. <h2 class="subsection-title">Methods</h2>
  82. <h3 class="name name-method" id="calculateInverses" translate="no">.<a href="#calculateInverses">calculateInverses</a><span class="signature">()</span> </h3>
  83. <div class="method">
  84. <div class="description">
  85. <p>Computes the bone inverse matrices. This method resets <a href="Skeleton.html#boneInverses">Skeleton#boneInverses</a>
  86. and fills it with new matrices.</p>
  87. </div>
  88. </div>
  89. <h3 class="name name-method" id="clone" translate="no">.<a href="#clone">clone</a><span class="signature">()</span><span class="type-signature"> : <a href="Skeleton.html">Skeleton</a></span> </h3>
  90. <div class="method">
  91. <div class="description">
  92. <p>Returns a new skeleton with copied values from this instance.</p>
  93. </div>
  94. <dl class="details">
  95. <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
  96. </dl>
  97. </div>
  98. <h3 class="name name-method" id="computeBoneTexture" translate="no">.<a href="#computeBoneTexture">computeBoneTexture</a><span class="signature">()</span><span class="type-signature"> : <a href="Skeleton.html">Skeleton</a></span> </h3>
  99. <div class="method">
  100. <div class="description">
  101. <p>Computes a data texture for passing bone data to the vertex shader.</p>
  102. </div>
  103. <dl class="details">
  104. <dt class="tag-returns"><strong>Returns:</strong> A reference of this instance.</dt>
  105. </dl>
  106. </div>
  107. <h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
  108. <div class="method">
  109. <div class="description">
  110. <p>Frees the GPU-related resources allocated by this instance. Call this
  111. method whenever this instance is no longer used in your app.</p>
  112. </div>
  113. </div>
  114. <h3 class="name name-method" id="fromJSON" translate="no">.<a href="#fromJSON">fromJSON</a><span class="signature">( json : <span class="param-type">Object</span>, bones : <span class="param-type">Object.&lt;string, Bone></span> )</span><span class="type-signature"> : <a href="Skeleton.html">Skeleton</a></span> </h3>
  115. <div class="method">
  116. <div class="description">
  117. <p>Setups the skeleton by the given JSON and bones.</p>
  118. </div>
  119. <table class="params">
  120. <tbody>
  121. <tr>
  122. <td class="name"><code>json</code></td>
  123. <td class="description last"><p>The skeleton as serialized JSON.</p></td>
  124. </tr>
  125. <tr>
  126. <td class="name"><code>bones</code></td>
  127. <td class="description last"><p>An array of bones.</p></td>
  128. </tr>
  129. </tbody>
  130. </table>
  131. <dl class="details">
  132. <dt class="tag-returns"><strong>Returns:</strong> A reference of this instance.</dt>
  133. </dl>
  134. </div>
  135. <h3 class="name name-method" id="getBoneByName" translate="no">.<a href="#getBoneByName">getBoneByName</a><span class="signature">( name : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="Bone.html">Bone</a> | undefined</span> </h3>
  136. <div class="method">
  137. <div class="description">
  138. <p>Searches through the skeleton's bone array and returns the first with a
  139. matching name.</p>
  140. </div>
  141. <table class="params">
  142. <tbody>
  143. <tr>
  144. <td class="name"><code>name</code></td>
  145. <td class="description last"><p>The name of the bone.</p></td>
  146. </tr>
  147. </tbody>
  148. </table>
  149. <dl class="details">
  150. <dt class="tag-returns"><strong>Returns:</strong> The found bone. <code>undefined</code> if no bone has been found.</dt>
  151. </dl>
  152. </div>
  153. <h3 class="name name-method" id="init" translate="no">.<a href="#init">init</a><span class="signature">()</span> </h3>
  154. <div class="method">
  155. <div class="description">
  156. <p>Initializes the skeleton. This method gets automatically called by the constructor
  157. but depending on how the skeleton is created it might be necessary to call this method
  158. manually.</p>
  159. </div>
  160. </div>
  161. <h3 class="name name-method" id="pose" translate="no">.<a href="#pose">pose</a><span class="signature">()</span> </h3>
  162. <div class="method">
  163. <div class="description">
  164. <p>Resets the skeleton to the base pose.</p>
  165. </div>
  166. </div>
  167. <h3 class="name name-method" id="toJSON" translate="no">.<a href="#toJSON">toJSON</a><span class="signature">()</span><span class="type-signature"> : Object</span> </h3>
  168. <div class="method">
  169. <div class="description">
  170. <p>Serializes the skeleton into JSON.</p>
  171. </div>
  172. <dl class="details">
  173. <dt class="tag-see">See:</dt>
  174. <dd class="tag-see">
  175. <ul>
  176. <li><a href="ObjectLoader.html#parse">ObjectLoader#parse</a></li>
  177. </ul>
  178. </dd>
  179. </dl>
  180. <dl class="details">
  181. <dt class="tag-returns"><strong>Returns:</strong> A JSON object representing the serialized skeleton.</dt>
  182. </dl>
  183. </div>
  184. <h3 class="name name-method" id="update" translate="no">.<a href="#update">update</a><span class="signature">()</span> </h3>
  185. <div class="method">
  186. <div class="description">
  187. <p>Resets the skeleton to the base pose.</p>
  188. </div>
  189. </div>
  190. <h2 class="subsection-title">Source</h2>
  191. <p>
  192. <a href="https://github.com/mrdoob/three.js/blob/master/src/objects/Skeleton.js" target="_blank" rel="noopener" translate="no">src/objects/Skeleton.js</a>
  193. </p>
  194. </article>
  195. </section>
  196. <script src="../scripts/linenumber.js"></script>
  197. <script src="../scripts/page.js"></script>
  198. </body>
  199. </html>
粤ICP备19079148号