SkinnedMesh.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!DOCTYPE html>
  2. <html lang="it">
  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. Una mesh che ha uno [page:Skeleton scheletro] con [page:Bone ossa] che può essere
  14. utilizzata per animare i vertici della geometria.
  15. </p>
  16. <iframe id="scene" src="scenes/bones-browser.html"></iframe>
  17. <script>
  18. // iOS iframe auto-resize workaround
  19. if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
  20. const scene = document.getElementById( 'scene' );
  21. scene.style.width = getComputedStyle( scene ).width;
  22. scene.style.height = getComputedStyle( scene ).height;
  23. scene.setAttribute( 'scrolling', 'no' );
  24. }
  25. </script>
  26. <h2>Codice di Esempio</h2>
  27. <code>
  28. const geometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 );
  29. // crea manualmente gli indici della pelle e i pesi della pelle
  30. // (tipicamente un loader leggerebbe questi dati da un modello 3D per te)
  31. const position = geometry.attributes.position;
  32. const vertex = new THREE.Vector3();
  33. const skinIndices = [];
  34. const skinWeights = [];
  35. for ( let i = 0; i < position.count; i ++ ) {
  36. vertex.fromBufferAttribute( position, i );
  37. // calcola skinIndex e skinWeight in base ad alcuni dati di configurazione
  38. const y = ( vertex.y + sizing.halfHeight );
  39. const skinIndex = Math.floor( y / sizing.segmentHeight );
  40. const 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.setAttribute( 'skinIndex', new THREE.Uint16BufferAttribute( skinIndices, 4 ) );
  45. geometry.setAttribute( 'skinWeight', new THREE.Float32BufferAttribute( skinWeights, 4 ) );
  46. // crea skinned mesh e skeleton
  47. const mesh = new THREE.SkinnedMesh( geometry, material );
  48. const skeleton = new THREE.Skeleton( bones );
  49. // vedi esempio da THREE.Skeleton
  50. const rootBone = skeleton.bones[ 0 ];
  51. mesh.add( rootBone );
  52. // lega lo scheletro alla mesh
  53. mesh.bind( skeleton );
  54. // muove le ossa e manipola il modello
  55. skeleton.bones[ 0 ].rotation.x = -0.1;
  56. skeleton.bones[ 1 ].rotation.x = 0.2;
  57. </code>
  58. <h2>Costruttore</h2>
  59. <h3>[name]( [param:BufferGeometry geometry], [param:Material material] )</h3>
  60. <p>
  61. [page:BufferGeometry geometry] - un'istanza di [page:BufferGeometry].<br />
  62. [page:Material material] - (opzionale) un'istanza di [page:Material]. Il valore predefinito è un nuovo [page:MeshBasicMaterial].
  63. </p>
  64. <h2>Proprietà</h2>
  65. <p>Vedi la classe base [page:Mesh] per le proprietà comuni.</p>
  66. <p>
  67. Either `AttachedBindMode` or `DetachedBindMode`. `AttachedBindMode` means the skinned mesh
  68. shares the same world space as the skeleton. This is not true when using `DetachedBindMode`
  69. which is useful when sharing a skeleton across multiple skinned meshes.
  70. Default is `AttachedBindMode`.
  71. </p>
  72. <h3>[property:Matrix4 bindMatrix]</h3>
  73. <p>
  74. La matrice di base che viene utilizzata per le trasformazioni ossee vincolate.
  75. </p>
  76. <h3>[property:Matrix4 bindMatrixInverse]</h3>
  77. <p>
  78. La matrice di base che viene utilizzata per reimpostare le trasformazioni ossee vincolate.
  79. </p>
  80. <h3>[property:Box3 boundingBox]</h3>
  81. <p>
  82. Bounding box per la [name], che può essere calcolato con [page:.computeBoundingBox](). Il valore predefinito è `null`.
  83. </p>
  84. <h3>[property:Sphere boundingSphere]</h3>
  85. <p>
  86. Bounding sphere per la [name], che può essere calcolato con [page:.computeBoundingSphere](). Il valore predefinito è `null`.
  87. </p>
  88. <h3>[property:Boolean isSkinnedMesh]</h3>
  89. <p>
  90. Flag di sola lettura per verificare se l'oggetto dato è di tipo [name].
  91. </p>
  92. <h3>[property:Skeleton skeleton]</h3>
  93. <p>
  94. [page:Skeleton] che rappresenta la gerarchia ossea della skinned mesh.
  95. </p>
  96. <h2>Metodi</h2>
  97. <p>Vedi la classe base [page:Mesh] per i metodi comuni.</p>
  98. <h3>[method:undefined bind]( [param:Skeleton skeleton], [param:Matrix4 bindMatrix] )</h3>
  99. <p>
  100. [page:Skeleton skeleton] - [page:Skeleton] creato da un albero di [page:Bone Bones].<br/>
  101. [page:Matrix4 bindMatrix] - [page:Matrix4] che rappresenta la trasformazione base dello scheletro.<br /><br />
  102. Lega uno scheletro alla skinned mesh. Il bindMatrix viene salvato nella proprietà .bindMatrix
  103. e il .bindMatrixInverse viene calcolato.
  104. </p>
  105. <h3>[method:SkinnedMesh clone]()</h3>
  106. <p>
  107. Questo metodo attualmente non clona correttamente un'istanza di [name]. Si prega di utilizzare [page:SkeletonUtils.clone]() nel frattempo.
  108. </p>
  109. <h3>[method:undefined computeBoundingBox]()</h3>
  110. <p>
  111. Computes the bounding box, updating [page:.boundingBox] attribute.<br />
  112. Bounding boxes aren't computed by default. They need to be explicitly computed, otherwise they are `null`.
  113. If an instance of [name] is animated, this method should be called per frame to compute a correct bounding box.
  114. </p>
  115. <h3>[method:undefined computeBoundingSphere]()</h3>
  116. <p>
  117. Computes the bounding sphere, updating [page:.boundingSphere] attribute.<br />
  118. Bounding spheres aren't computed by default. They need to be explicitly computed, otherwise they are `null`.
  119. If an instance of [name] is animated, this method should be called per frame to compute a correct bounding sphere.
  120. </p>
  121. <h3>[method:undefined normalizeSkinWeights]()</h3>
  122. <p>
  123. Normalizza i pesi della skin.
  124. </p>
  125. <h3>[method:undefined pose]()</h3>
  126. <p>
  127. Questo metodo imposta la skinned mesh nella posa di riposo (reimposta la posa).
  128. </p>
  129. <h3>[method:Vector3 applyBoneTransform]( [param:Integer index], [param:Vector3 vector] )</h3>
  130. <p>
  131. Applies the bone transform associated with the given index to the given position vector. Returns the updated vector.
  132. </p>
  133. <h2>Source</h2>
  134. <p>
  135. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  136. </p>
  137. </body>
  138. </html>