SkinnedMesh.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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; [page:Mesh] &rarr;
  12. <h1>蒙皮网格([name])</h1>
  13. <p class="desc">
  14. 具有[page:Skeleton](骨架)和[page:Bone bones](骨骼)的网格,可用于给几何体上的顶点添加动画。
  15. 其材质必须支持蒙皮,并且已经启用了蒙皮 —— 请阅读[page:MeshStandardMaterial.skinning]。
  16. </p>
  17. <iframe id="scene" src="scenes/bones-browser.html"></iframe>
  18. <script>
  19. // iOS iframe auto-resize workaround
  20. if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
  21. var scene = document.getElementById( 'scene' );
  22. scene.style.width = getComputedStyle( scene ).width;
  23. scene.style.height = getComputedStyle( scene ).height;
  24. scene.setAttribute( 'scrolling', 'no' );
  25. }
  26. </script>
  27. <h2>示例</h2>
  28. <code>
  29. var geometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 );
  30. //Create the skin indices and skin weights
  31. for ( var i = 0; i < geometry.vertices.length; i ++ ) {
  32. // Imaginary functions to calculate the indices and weights
  33. // This part will need to be changed depending your skeleton and model
  34. var skinIndex = calculateSkinIndex( geometry.vertices, i );
  35. var skinWeight = calculateSkinWeight( geometry.vertices, i );
  36. // Ease between each bone
  37. geometry.skinIndices.push( new THREE.Vector4( skinIndex, skinIndex + 1, 0, 0 ) );
  38. geometry.skinWeights.push( new THREE.Vector4( 1 - skinWeight, skinWeight, 0, 0 ) );
  39. }
  40. var mesh = new THREE.SkinnedMesh( geometry, material );
  41. // See example from THREE.Skeleton for the armSkeleton
  42. var rootBone = armSkeleton.bones[ 0 ];
  43. mesh.add( rootBone );
  44. // Bind the skeleton to the mesh
  45. mesh.bind( armSkeleton );
  46. // Move the bones and manipulate the model
  47. armSkeleton.bones[ 0 ].rotation.x = -0.1;
  48. armSkeleton.bones[ 1 ].rotation.x = 0.2;
  49. </code>
  50. <h2>构造器</h2>
  51. <h3>[name]( [param:Geometry geometry], [param:Material material] )</h3>
  52. <p>
  53. [page:Geometry geometry] —— 一个[page:Geometry]或者[page:BufferGeometry](推荐)的实例。
  54. [page:Geometry.skinIndices skinIndices] 和 [page:Geometry.skinWeights skinWeights] 在几何体上应当被设置为true。<br />
  55. [page:Material material] —— (可选)一个[page:Material]的实例,默认值是一个新的[page:MeshBasicMaterial]。
  56. </p>
  57. <h2>属性</h2>
  58. <p>请参阅其基类[page:Mesh]来查看共有属性。</p>
  59. <h3>[property:string bindMode]</h3>
  60. <p>
  61. “attached”(附加)或者“detached”(分离)。“attached”使用[page:SkinnedMesh.matrixWorld]
  62. 属性作为对骨骼的基本变换矩阵,“detached”则使用[page:SkinnedMesh.bindMatrix]。
  63. 默认值是“attached”。
  64. </p>
  65. <h3>[property:Matrix4 bindMatrix]</h3>
  66. <p>
  67. 用于绑定的骨骼变换的基础矩阵。
  68. </p>
  69. <h3>[property:Matrix4 bindMatrixInverse]</h3>
  70. <p>
  71. 用于重置绑定的骨骼变换的基础矩阵。
  72. </p>
  73. <h3>[property:Boolean isSkinnedMesh]</h3>
  74. <p>
  75. 用于检查这个类或者其派生类是否为蒙皮网格,默认值为*true*。<br /><br />
  76. 你不应当对这个属性进行改变,因为它在使用,以用于优化。
  77. </p>
  78. <h3>[property:Skeleton skeleton]</h3>
  79. <p>
  80. [page:Skeleton]是由从构造函数中传入的[page:Geometry]中的[page:Geometry.bones bones]来创建的。
  81. </p>
  82. <h2>方法</h2>
  83. <p>请参阅其基类[page:Mesh]来查看共有方法。</p>
  84. <h3>[method:null bind]( [param:Skeleton skeleton], [param:Matrix4 bindMatrix] )</h3>
  85. <p>
  86. [page:Skeleton skeleton] —— 由一棵[page:Bone Bones]树创建的[page:Skeleton]。<br/>
  87. [page:Matrix4 bindMatrix] —— 代表着骨架基本变换的[page:Matrix4](4x4矩阵)。<br /><br />
  88. 将骨架绑定到一个蒙皮网格上。bindMatrix会被保存到.bindMatrix属性中,其逆矩阵.bindMatrixInverse也会被计算出来。
  89. 它在构造函数中会被自动调用,其骨架是由传入到构造函数的[page:Geometry]中的[page:Geometry.bones bones]来创建的。
  90. </p>
  91. <h3>[method:SkinnedMesh clone]()</h3>
  92. <p>
  93. 返回当前SkinnedMesh对象的一个克隆及其任何后代。
  94. </p>
  95. <h3>[method:null normalizeSkinWeights]()</h3>
  96. <p>
  97. 规范化[page:Geometry.skinWeights]矢量。不会对[page:BufferGeometry]产生影响。
  98. </p>
  99. <h3>[method:null pose]()</h3>
  100. <p>
  101. 这个方法设置了在“休息”状态下蒙皮网格的姿势(重置姿势)。
  102. </p>
  103. <h3>[method:null updateMatrixWorld]( [param:Boolean force] )</h3>
  104. <p>
  105. 更新[page:Matrix4 MatrixWorld]矩阵。
  106. </p>
  107. <h3>[method:null initBones]()</h3>
  108. <p>
  109. 从内部几何体中创建一个分层[page:Bone bones]对象的数组。
  110. </p>
  111. <h2>源代码</h2>
  112. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  113. </body>
  114. </html>