1
0

SkinnedMesh.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Object3D] &rarr; [page:Mesh] &rarr;
  11. <h1>蒙皮网格([name])</h1>
  12. <p class="desc">
  13. 具有[page:Skeleton](骨架)和[page:Bone bones](骨骼)的网格,可用于给几何体上的顶点添加动画。
  14. </p>
  15. <iframe id="scene" src="scenes/bones-browser.html"></iframe>
  16. <script>
  17. // iOS iframe auto-resize workaround
  18. if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
  19. const scene = document.getElementById( 'scene' );
  20. scene.style.width = getComputedStyle( scene ).width;
  21. scene.style.height = getComputedStyle( scene ).height;
  22. scene.setAttribute( 'scrolling', 'no' );
  23. }
  24. </script>
  25. <h2>代码示例</h2>
  26. <code>
  27. const geometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 );
  28. // create the skin indices and skin weights
  29. const position = geometry.attributes.position;
  30. const vertex = new THREE.Vector3();
  31. const skinIndices = [];
  32. const skinWeights = [];
  33. for ( let i = 0; i < position.count; i ++ ) {
  34. vertex.fromBufferAttribute( position, i );
  35. // compute skinIndex and skinWeight based on some configuration data
  36. const y = ( vertex.y + sizing.halfHeight );
  37. const skinIndex = Math.floor( y / sizing.segmentHeight );
  38. const skinWeight = ( y % sizing.segmentHeight ) / sizing.segmentHeight;
  39. skinIndices.push( skinIndex, skinIndex + 1, 0, 0 );
  40. skinWeights.push( 1 - skinWeight, skinWeight, 0, 0 );
  41. }
  42. geometry.setAttribute( 'skinIndex', new THREE.Uint16BufferAttribute( skinIndices, 4 ) );
  43. geometry.setAttribute( 'skinWeight', new THREE.Float32BufferAttribute( skinWeights, 4 ) );
  44. // create skinned mesh and skeleton
  45. const mesh = new THREE.SkinnedMesh( geometry, material );
  46. const skeleton = new THREE.Skeleton( bones );
  47. // see example from THREE.Skeleton
  48. const rootBone = skeleton.bones[ 0 ];
  49. mesh.add( rootBone );
  50. // bind the skeleton to the mesh
  51. mesh.bind( skeleton );
  52. // move the bones and manipulate the model
  53. skeleton.bones[ 0 ].rotation.x = -0.1;
  54. skeleton.bones[ 1 ].rotation.x = 0.2;
  55. </code>
  56. <h2>构造器</h2>
  57. <h3>[name]( [param:BufferGeometry geometry], [param:Material material] )</h3>
  58. <p>
  59. [page:BufferGeometry geometry] —— 一个[page:BufferGeometry]实例。<br />
  60. [page:Material material] —— (可选)一个[page:Material]实例,默认值是一个新的[page:MeshBasicMaterial]。
  61. </p>
  62. <h2>属性</h2>
  63. <p>共有属性请参见其基类[page:Mesh]。</p>
  64. <h3>[property:String bindMode]</h3>
  65. <p>
  66. Either `AttachedBindMode` or `DetachedBindMode`. `AttachedBindMode` means the skinned mesh
  67. shares the same world space as the skeleton. This is not true when using `DetachedBindMode`
  68. which is useful when sharing a skeleton across multiple skinned meshes.
  69. Default is `AttachedBindMode`.
  70. </p>
  71. <h3>[property:Matrix4 bindMatrix]</h3>
  72. <p>
  73. 该基础矩阵用于绑定骨骼的变换。
  74. </p>
  75. <h3>[property:Matrix4 bindMatrixInverse]</h3>
  76. <p>
  77. 该基础矩阵用于重置绑定骨骼的变换。
  78. </p>
  79. <h3>[property:Box3 boundingBox]</h3>
  80. <p>
  81. The bounding box of the [name]. Can be calculated with [page:.computeBoundingBox](). Default is `null`.
  82. </p>
  83. <h3>[property:Sphere boundingSphere]</h3>
  84. <p>
  85. The bounding sphere of the [name]. Can be calculated with [page:.computeBoundingSphere](). Default is `null`.
  86. </p>
  87. <h3>[property:Boolean isSkinnedMesh]</h3>
  88. <p>
  89. Read-only flag to check if a given object is of type [name].
  90. </p>
  91. <h3>[property:Skeleton skeleton]</h3>
  92. <p>
  93. 用于表示蒙皮网格中骨骼的层次结构的[page:Skeleton](骨架)。
  94. </p>
  95. <h2>方法</h2>
  96. <p>共有方法请参见其基类[page:Mesh]。</p>
  97. <h3>[method:Vector3 applyBoneTransform]( [param:Integer index], [param:Vector3 vector] )</h3>
  98. <p>
  99. Applies the bone transform associated with the given index to the given position vector. Returns the updated vector.
  100. </p>
  101. <h3>[method:undefined bind]( [param:Skeleton skeleton], [param:Matrix4 bindMatrix] )</h3>
  102. <p>
  103. [page:Skeleton skeleton] —— 由一棵[page:Bone Bones]树创建的[page:Skeleton]。<br/>
  104. [page:Matrix4 bindMatrix] —— 表示骨架基本变换的[page:Matrix4](4x4矩阵)。<br /><br />
  105. 将骨架绑定到一个蒙皮网格上。bindMatrix会被保存到.bindMatrix属性中,其逆矩阵.bindMatrixInverse也会被计算出来。
  106. </p>
  107. <h3>[method:SkinnedMesh clone]()</h3>
  108. <p>
  109. This method does currently not clone an instance of [name] correctly. Please use [page:SkeletonUtils.clone]() in the meanwhile.
  110. </p>
  111. <h3>[method:undefined computeBoundingBox]()</h3>
  112. <p>
  113. Computes the bounding box, updating [page:.boundingBox] attribute.<br />
  114. Bounding boxes aren't computed by default. They need to be explicitly computed, otherwise they are `null`.
  115. If an instance of [name] is animated, this method should be called per frame to compute a correct bounding box.
  116. </p>
  117. <h3>[method:undefined computeBoundingSphere]()</h3>
  118. <p>
  119. Computes the bounding sphere, updating [page:.boundingSphere] attribute.<br />
  120. Bounding spheres aren't computed by default. They need to be explicitly computed, otherwise they are `null`.
  121. If an instance of [name] is animated, this method should be called per frame to compute a correct bounding sphere.
  122. </p>
  123. <h3>[method:undefined normalizeSkinWeights]()</h3>
  124. <p>
  125. 标准化蒙皮的权重。
  126. </p>
  127. <h3>[method:undefined pose]()</h3>
  128. <p>
  129. 这个方法设置了在“休息”状态下蒙皮网格的姿势(重置姿势)。
  130. </p>
  131. <h2>源代码</h2>
  132. <p>
  133. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  134. </p>
  135. </body>
  136. </html>