SkinnedMesh.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. [page:Object3D] &rarr;
  12. <h1>[name]</h1>
  13. <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>
  14. <h2>Example</h2>
  15. <iframe src='scenes/bones-browser.html'></iframe>
  16. <code>
  17. var geometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 );
  18. //Create the skin indices and skin weights
  19. for ( var i = 0; i < geometry.vertices.length; i ++ ) {
  20. // Imaginary functions to calculate the indices and weights
  21. var skinIndex = calculateSkinIndex( geometry.vertices, i );
  22. var skinWeight = calculateSkinWeight( geometry.vertices, i );
  23. // Ease between each bone
  24. geometry.skinIndices.push( new THREE.Vector4( skinIndex, skinIndex + 1, 0, 0 ) );
  25. geometry.skinWeights.push( new THREE.Vector4( 1 - skinWeight, skinWeight, 0, 0 ) );
  26. }
  27. var mesh = THREE.SkinnedMesh( geometry, material );
  28. // See example from THREE.Skeleton for the armSkeleton
  29. var rootBone = armSkeleton.bones[ 0 ];
  30. mesh.add( rootBone );
  31. // Bind the skeleton to the mesh
  32. mesh.bind( armSkeleton );
  33. // Update the inverse matrices in the skeleton to reflect the newly bound skeleton
  34. armSkeleton.calculateInverses();
  35. // Move the bones and manipulate the model
  36. armSkeleton.bones[ 0 ].rotation.x = -0.1;
  37. armSkeleton.bones[ 1 ].rotation.x = 0.2;
  38. </code>
  39. <h2>Constructor</h2>
  40. <h3>[name]([page:Geometry geometry], [page:Material material], [page:boolean useVertexTexture])</h3>
  41. <div>
  42. geometry — An instance of [page:Geometry]. [page:Geometry.skinIndices] and [page:Geometry.skinWeights] should be set.<br />
  43. material — An instance of [page:Material] (optional).<br />
  44. useVertexTexture -- Defines whether a vertex texture can be used (optional).
  45. </div>
  46. <h2>Properties</h2>
  47. <h3>[property:array bones]</h3>
  48. <div>
  49. This contains the array of bones for this mesh. These should be set in the constructor.
  50. </div>
  51. <h3>[property:Matrix4 identityMatrix]</h3>
  52. <div>
  53. This is an identityMatrix to calculate the bones matrices from.
  54. </div>
  55. <h3>[property:boolean useVertexTexture]</h3>
  56. <div>
  57. The boolean defines whether a vertex texture is used to calculate the bones. This boolean shouldn't be changed after constructor.
  58. </div>
  59. <h3>[property:array boneMatrices]</h3>
  60. <div>
  61. This array of matrices contains the matrices of the bones. These get calculated in the constructor.
  62. </div>
  63. <h3>[property:string bindMode]</h3>
  64. <div>
  65. Either "attached" or "detached". "attached" uses the [page:SkinnedMesh.matrixWorld] property for the base transform
  66. matrix of the bones. "detached" uses the [page:SkinnedMesh.bindMatrix].
  67. </div>
  68. <h3>[property:Matrix4 bindMatrix]</h3>
  69. <div>
  70. The base matrix that is used for the bound bone transforms.
  71. </div>
  72. <h3>[property:Matrix4 inverseBindMatrix]</h3>
  73. <div>
  74. The inverse of the bindMatrix.
  75. </div>
  76. <h2>Methods</h2>
  77. <h3>[method:null bind]([page:Skeleton skeleton], [page:Matrix4 bindMatrix])</h3>
  78. <div>
  79. skeleton — [page:Skeleton]<br/>
  80. bindMatrix — [page:Matrix4] that represents the base transform of the skeleton
  81. </div>
  82. <div>
  83. Bind a skeleton to the skinned mesh. The bindMatrix gets saved to .bindMatrix property and the .bindMatrixInverse
  84. gets calculated.
  85. </div>
  86. <h3>[method:null normalizeSkinWeights]()</h3>
  87. <div>
  88. Normalizes the [page:Geometry.skinWeights] vectors. Does not affect [page:BufferGeometry].
  89. </div>
  90. <h3>[method:null pose]()</h3>
  91. <div>
  92. This method sets the skinned mesh in the rest pose.
  93. </div>
  94. <h3>[method:Bone addBone]([page:Bone bone])</h3>
  95. <div>
  96. bone — This is the bone that needs to be added. (optional)
  97. </div>
  98. <div>
  99. This method adds the bone to the skinned mesh when it is provided. It creates a new bone and adds that when no bone is given.
  100. </div>
  101. <h3>[method:Object3D clone]([page:Object3D object])</h3>
  102. <div>
  103. object -- (optional) Object3D which needs to be cloned. If undefined, clone method will create a new cloned SkinnedMesh Object.
  104. </div>
  105. <div>
  106. Clone a SkinnedMesh Object.
  107. </div>
  108. <h2>Source</h2>
  109. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  110. </body>
  111. </html>