SkinnedMesh.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <script src="../../list.js"></script>
  6. <script src="../../page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="../../page.css" />
  8. </head>
  9. <body>
  10. [page:Object3D] &rarr;
  11. <h1>[name]</h1>
  12. <div class="desc">A mesh that has a [page:Skeleton] with [page:Bone bones] that can then be used to animate the vertices of the geometry.</div>
  13. <h2>Example</h2>
  14. <iframe src='../../scenes/bones-browser.html'></iframe>
  15. <code>
  16. var geometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 );
  17. //Create the skin indices and skin weights
  18. for( var i=0; i < geometry.vertices.length; i++ ) {
  19. // Imaginary functions to calculate the indices and weights
  20. var skinIndex = calculateSkinIndex( geometry.vertices, i );
  21. var skinWeight = calculateSkinWeight( geometry.vertices, i );
  22. // Ease between each bone
  23. geometry.skinIndices.push( new THREE.Vector4( skinIndex, skinIndex+1, 0, 0 ) );
  24. geometry.skinWeights.push( new THREE.Vector4( 1-skinWeight, skinWeight, 0, 0 ) );
  25. }
  26. var mesh = THREE.SkinnedMesh( geometry, material );
  27. // See example from THREE.Skeleton for the armSkeleton
  28. mesh.bind( armSkeleton );
  29. // Add the root bone, then recalculate the skeleton inverses
  30. mesh.add( armSkeleton.bones[0] );
  31. mesh.updateMatrixWorld( true ); // ensure the bones matrices are already recomputed
  32. skeleton.calculateInverses();
  33. // Move the bones and manipulate the model
  34. armSkeleton.bones[0].rotation.x = -0.1;
  35. armSkeleton.bones[1].rotation.x = 0.2;
  36. </code>
  37. <h2>Constructor</h2>
  38. <h3>[name]([page:Geometry geometry], [page:Material material], [page:boolean useVertexTexture])</h3>
  39. <div>
  40. geometry —- An instance of [page:Geometry]. [page:Geometry.skinIndices] and [page:Geometry.skinWeights] should be set.<br />
  41. material —- An instance of [page:Material] (optional).<br />
  42. useVertexTexture -- Defines whether a vertex texture can be used (optional).
  43. </div>
  44. <h2>Properties</h2>
  45. <h3>[property:array bones]</h3>
  46. <div>
  47. This contains the array of bones for this mesh. These should be set in the constructor.
  48. </div>
  49. <h3>[property:Matrix4 identityMatrix]</h3>
  50. <div>
  51. This is an identityMatrix to calculate the bones matrices from.
  52. </div>
  53. <h3>[property:boolean useVertexTexture]</h3>
  54. <div>
  55. The boolean defines whether a vertex texture is used to calculate the bones. This boolean shouldn't be changed after constructor.
  56. </div>
  57. <h3>[property:array boneMatrices]</h3>
  58. <div>
  59. This array of matrices contains the matrices of the bones. These get calculated in the constructor.
  60. </div>
  61. <h2>Methods</h2>
  62. <h3>[method:null pose]()</h3>
  63. <div>
  64. This method sets the skinnedmesh in the rest pose.
  65. </div>
  66. <h3>[method:Bone addBone]([page:Bone bone])</h3>
  67. <div>
  68. bone -- This is the bone that needs to be added. (optional)
  69. </div>
  70. <div>
  71. This method adds the bone to the skinnedmesh when it is provided. It creates a new bone and adds that when no bone is given.
  72. </div>
  73. <h2>Source</h2>
  74. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  75. </body>
  76. </html>