SkinnedMesh.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. <iframe id="scene" src="scenes/bones-browser.html"></iframe>
  15. <script>
  16. // iOS iframe auto-resize workaround
  17. if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
  18. var scene = document.getElementById( 'scene' );
  19. scene.style.width = getComputedStyle( scene ).width;
  20. scene.style.height = getComputedStyle( scene ).height;
  21. scene.setAttribute( 'scrolling', 'no' );
  22. }
  23. </script>
  24. <h2>Example</h2>
  25. <code>
  26. var geometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 );
  27. //Create the skin indices and skin weights
  28. for ( var i = 0; i < geometry.vertices.length; i ++ ) {
  29. // Imaginary functions to calculate the indices and weights
  30. // This part will need to be changed depending your skeleton and model
  31. var skinIndex = calculateSkinIndex( geometry.vertices, i );
  32. var skinWeight = calculateSkinWeight( geometry.vertices, i );
  33. // Ease between each bone
  34. geometry.skinIndices.push( new THREE.Vector4( skinIndex, skinIndex + 1, 0, 0 ) );
  35. geometry.skinWeights.push( new THREE.Vector4( 1 - skinWeight, skinWeight, 0, 0 ) );
  36. }
  37. var mesh = THREE.SkinnedMesh( geometry, material );
  38. // See example from THREE.Skeleton for the armSkeleton
  39. var rootBone = armSkeleton.bones[ 0 ];
  40. mesh.add( rootBone );
  41. // Bind the skeleton to the mesh
  42. mesh.bind( armSkeleton );
  43. // Move the bones and manipulate the model
  44. armSkeleton.bones[ 0 ].rotation.x = -0.1;
  45. armSkeleton.bones[ 1 ].rotation.x = 0.2;
  46. </code>
  47. <h2>Constructor</h2>
  48. <h3>[name]( [page:Geometry geometry], [page:Material material], [page:boolean useVertexTexture] )</h3>
  49. <div>
  50. geometry — An instance of [page:Geometry]. [page:Geometry.skinIndices] and [page:Geometry.skinWeights] should be set.<br />
  51. material — An instance of [page:Material] (optional).<br />
  52. useVertexTexture -- Defines whether a vertex texture can be used (optional).
  53. </div>
  54. <h2>Properties</h2>
  55. <h3>[property:array bones]</h3>
  56. <div>
  57. This contains the array of bones for this mesh. These should be set in the constructor.
  58. </div>
  59. <h3>[property:Matrix4 identityMatrix]</h3>
  60. <div>
  61. This is an identityMatrix to calculate the bones matrices from.
  62. </div>
  63. <h3>[property:boolean useVertexTexture]</h3>
  64. <div>
  65. The boolean defines whether a vertex texture is used to calculate the bones. This boolean shouldn't be changed after constructor.
  66. </div>
  67. <h3>[property:array boneMatrices]</h3>
  68. <div>
  69. This array of matrices contains the matrices of the bones. These get calculated in the constructor.
  70. </div>
  71. <h3>[property:string bindMode]</h3>
  72. <div>
  73. Either "attached" or "detached". "attached" uses the [page:SkinnedMesh.matrixWorld] property for the base transform
  74. matrix of the bones. "detached" uses the [page:SkinnedMesh.bindMatrix].
  75. </div>
  76. <h3>[property:Matrix4 bindMatrix]</h3>
  77. <div>
  78. The base matrix that is used for the bound bone transforms.
  79. </div>
  80. <h3>[property:Matrix4 inverseBindMatrix]</h3>
  81. <div>
  82. The inverse of the bindMatrix.
  83. </div>
  84. <h2>Methods</h2>
  85. <h3>[method:null bind]( [page:Skeleton skeleton], [page:Matrix4 bindMatrix] )</h3>
  86. <div>
  87. skeleton — [page:Skeleton]<br/>
  88. bindMatrix — [page:Matrix4] that represents the base transform of the skeleton
  89. </div>
  90. <div>
  91. Bind a skeleton to the skinned mesh. The bindMatrix gets saved to .bindMatrix property and the .bindMatrixInverse
  92. gets calculated.
  93. </div>
  94. <h3>[method:null normalizeSkinWeights]()</h3>
  95. <div>
  96. Normalizes the [page:Geometry.skinWeights] vectors. Does not affect [page:BufferGeometry].
  97. </div>
  98. <h3>[method:null pose]()</h3>
  99. <div>
  100. This method sets the skinned mesh in the rest pose.
  101. </div>
  102. <h3>[method:Bone addBone]( [page:Bone bone] )</h3>
  103. <div>
  104. bone — This is the bone that needs to be added. (optional)
  105. </div>
  106. <div>
  107. 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.
  108. </div>
  109. <h3>[method:SkinnedMesh clone]()</h3>
  110. <div>
  111. Returns a clone of this SkinnedMesh object and its descendants.
  112. </div>
  113. <h2>Source</h2>
  114. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  115. </body>
  116. </html>