SkinnedMesh.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.CylinderBufferGeometry( 5, 5, 5, 5, 15, 5, 30 );
  30. // create the skin indices and skin weights
  31. var position = geometry.attributes.position;
  32. var vertex = new THREE.Vector3();
  33. var skinIndices = [];
  34. var skinWeights = [];
  35. for ( var i = 0; i < position.count; i ++ ) {
  36. vertex.fromBufferAttribute( position, i );
  37. // compute skinIndex and skinWeight based on some configuration data
  38. var y = ( vertex.y + sizing.halfHeight );
  39. var skinIndex = Math.floor( y / sizing.segmentHeight );
  40. var skinWeight = ( y % sizing.segmentHeight ) / sizing.segmentHeight;
  41. skinIndices.push( skinIndex, skinIndex + 1, 0, 0 );
  42. skinWeights.push( 1 - skinWeight, skinWeight, 0, 0 );
  43. }
  44. geometry.addAttribute( 'skinIndex', new THREE.Uint16BufferAttribute( skinIndices, 4 ) );
  45. geometry.addAttribute( 'skinWeight', new THREE.Float32BufferAttribute( skinWeights, 4 ) );
  46. // create skinned mesh and skeleton
  47. var mesh = new THREE.SkinnedMesh( geometry, material );
  48. var skeleton = new THREE.Skeleton( bones );
  49. // see example from THREE.Skeleton
  50. var rootBone = skeleton.bones[ 0 ];
  51. mesh.add( rootBone );
  52. // bind the skeleton to the mesh
  53. mesh.bind( skeleton );
  54. // move the bones and manipulate the model
  55. skeleton.bones[ 0 ].rotation.x = -0.1;
  56. skeleton.bones[ 1 ].rotation.x = 0.2;
  57. </code>
  58. <h2>构造器</h2>
  59. <h3>[name]( [param:BufferGeometry geometry], [param:Material material] )</h3>
  60. <p>
  61. [page:BufferGeometry geometry] —— 一个[page:BufferGeometry]实例。<br />
  62. [page:Material material] —— (可选)一个[page:Material]实例,默认值是一个新的[page:MeshBasicMaterial]。
  63. </p>
  64. <h2>属性</h2>
  65. <p>共有属性请参见其基类[page:Mesh]。</p>
  66. <h3>[property:string bindMode]</h3>
  67. <p>
  68. “attached”(附加)或者“detached”(分离)。“attached”使用[page:SkinnedMesh.matrixWorld]
  69. 属性作为对骨骼的基本变换矩阵,“detached”则使用[page:SkinnedMesh.bindMatrix]。
  70. 默认值是“attached”。
  71. </p>
  72. <h3>[property:Matrix4 bindMatrix]</h3>
  73. <p>
  74. 该基础矩阵用于绑定骨骼的变换。
  75. </p>
  76. <h3>[property:Matrix4 bindMatrixInverse]</h3>
  77. <p>
  78. 该基础矩阵用于重置绑定骨骼的变换。
  79. </p>
  80. <h3>[property:Boolean isSkinnedMesh]</h3>
  81. <p>
  82. 用于检查这个类或者其派生类是否为蒙皮网格,默认值为*true*。<br /><br />
  83. 你不应当对这个属性进行改变,因为它在使用,以用于优化。
  84. </p>
  85. <h3>[property:Skeleton skeleton]</h3>
  86. <p>
  87. 用于表示蒙皮网格中骨骼的层次结构的[page:Skeleton](骨架)。
  88. </p>
  89. <h2>方法</h2>
  90. <p>共有方法请参见其基类[page:Mesh]。</p>
  91. <h3>[method:null bind]( [param:Skeleton skeleton], [param:Matrix4 bindMatrix] )</h3>
  92. <p>
  93. [page:Skeleton skeleton] —— 由一棵[page:Bone Bones]树创建的[page:Skeleton]。<br/>
  94. [page:Matrix4 bindMatrix] —— 表示骨架基本变换的[page:Matrix4](4x4矩阵)。<br /><br />
  95. 将骨架绑定到一个蒙皮网格上。bindMatrix会被保存到.bindMatrix属性中,其逆矩阵.bindMatrixInverse也会被计算出来。
  96. </p>
  97. <h3>[method:SkinnedMesh clone]()</h3>
  98. <p>
  99. 返回当前SkinnedMesh对象的一个克隆及其任何后代。
  100. </p>
  101. <h3>[method:null normalizeSkinWeights]()</h3>
  102. <p>
  103. 标准化蒙皮的权重。
  104. </p>
  105. <h3>[method:null pose]()</h3>
  106. <p>
  107. 这个方法设置了在“休息”状态下蒙皮网格的姿势(重置姿势)。
  108. </p>
  109. <h3>[method:null updateMatrixWorld]( [param:Boolean force] )</h3>
  110. <p>
  111. 更新[page:Matrix4 MatrixWorld]矩阵。
  112. </p>
  113. <h2>源代码</h2>
  114. <p>
  115. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  116. </p>
  117. </body>
  118. </html>