SkinnedMesh.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.<br /><br />
  15. [name] può essere utilizzata solo con WebGL 2. Con WebGL 1 è necessario il supporto delle texture del vertice
  16. e `OES_texture_float`.
  17. </p>
  18. <iframe id="scene" src="scenes/bones-browser.html"></iframe>
  19. <script>
  20. // iOS iframe auto-resize workaround
  21. if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
  22. const scene = document.getElementById( 'scene' );
  23. scene.style.width = getComputedStyle( scene ).width;
  24. scene.style.height = getComputedStyle( scene ).height;
  25. scene.setAttribute( 'scrolling', 'no' );
  26. }
  27. </script>
  28. <h2>Codice di Esempio</h2>
  29. <code>
  30. const geometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 );
  31. // crea manualmente gli indici della pelle e i pesi della pelle
  32. // (tipicamente un loader leggerebbe questi dati da un modello 3D per te)
  33. const position = geometry.attributes.position;
  34. const vertex = new THREE.Vector3();
  35. const skinIndices = [];
  36. const skinWeights = [];
  37. for ( let i = 0; i < position.count; i ++ ) {
  38. vertex.fromBufferAttribute( position, i );
  39. // calcola skinIndex e skinWeight in base ad alcuni dati di configurazione
  40. const y = ( vertex.y + sizing.halfHeight );
  41. const skinIndex = Math.floor( y / sizing.segmentHeight );
  42. const skinWeight = ( y % sizing.segmentHeight ) / sizing.segmentHeight;
  43. skinIndices.push( skinIndex, skinIndex + 1, 0, 0 );
  44. skinWeights.push( 1 - skinWeight, skinWeight, 0, 0 );
  45. }
  46. geometry.setAttribute( 'skinIndex', new THREE.Uint16BufferAttribute( skinIndices, 4 ) );
  47. geometry.setAttribute( 'skinWeight', new THREE.Float32BufferAttribute( skinWeights, 4 ) );
  48. // crea skinned mesh e skeleton
  49. const mesh = new THREE.SkinnedMesh( geometry, material );
  50. const skeleton = new THREE.Skeleton( bones );
  51. // vedi esempio da THREE.Skeleton
  52. const rootBone = skeleton.bones[ 0 ];
  53. mesh.add( rootBone );
  54. // lega lo scheletro alla mesh
  55. mesh.bind( skeleton );
  56. // muove le ossa e manipola il modello
  57. skeleton.bones[ 0 ].rotation.x = -0.1;
  58. skeleton.bones[ 1 ].rotation.x = 0.2;
  59. </code>
  60. <h2>Costruttore</h2>
  61. <h3>[name]( [param:BufferGeometry geometry], [param:Material material] )</h3>
  62. <p>
  63. [page:BufferGeometry geometry] - un'istanza di [page:BufferGeometry].<br />
  64. [page:Material material] - (opzionale) un'istanza di [page:Material]. Il valore predefinito è un nuovo [page:MeshBasicMaterial].
  65. </p>
  66. <h2>Proprietà</h2>
  67. <p>Vedi la classe base [page:Mesh] per le proprietà comuni.</p>
  68. <h3>[property:String bindMode]</h3>
  69. <p>
  70. O "attached" o "detached". "attached" utilizza la proprietà [page:SkinnedMesh.matrixWorld]
  71. per la matrice di trasformazione delle ossa. "detached" utilizza [page:SkinnedMesh.bindMatrix]. Il valore predefinito è "attached".
  72. </p>
  73. <h3>[property:Matrix4 bindMatrix]</h3>
  74. <p>
  75. La matrice di base che viene utilizzata per le trasformazioni ossee vincolate.
  76. </p>
  77. <h3>[property:Matrix4 bindMatrixInverse]</h3>
  78. <p>
  79. La matrice di base che viene utilizzata per reimpostare le trasformazioni ossee vincolate.
  80. </p>
  81. <h3>[property:Boolean isSkinnedMesh]</h3>
  82. <p>
  83. Flag di sola lettura per verificare se l'oggetto dato è di tipo [name].
  84. </p>
  85. <h3>[property:Skeleton skeleton]</h3>
  86. <p>
  87. [page:Skeleton] che rappresenta la gerarchia ossea della skinned mesh.
  88. </p>
  89. <h2>Metodi</h2>
  90. <p>Vedi la classe base [page:Mesh] per i metodi comuni.</p>
  91. <h3>[method:undefined bind]( [param:Skeleton skeleton], [param:Matrix4 bindMatrix] )</h3>
  92. <p>
  93. [page:Skeleton skeleton] - [page:Skeleton] creato da un albero di [page:Bone Bones].<br/>
  94. [page:Matrix4 bindMatrix] - [page:Matrix4] che rappresenta la trasformazione base dello scheletro.<br /><br />
  95. Lega uno scheletro alla skinned mesh. Il bindMatrix viene salvato nella proprietà .bindMatrix
  96. e il .bindMatrixInverse viene calcolato.
  97. </p>
  98. <h3>[method:SkinnedMesh clone]()</h3>
  99. <p>
  100. Questo metodo attualmente non clona correttamente un'istanza di [name]. Si prega di utilizzare [page:SkeletonUtils.clone]() nel frattempo.
  101. </p>
  102. <h3>[method:undefined normalizeSkinWeights]()</h3>
  103. <p>
  104. Normalizza i pesi della skin.
  105. </p>
  106. <h3>[method:undefined pose]()</h3>
  107. <p>
  108. Questo metodo imposta la skinned mesh nella posa di riposo (reimposta la posa).
  109. </p>
  110. <h3>[method:Vector3 boneTransform]( [param:Integer index], [param:Vector3 target] )</h3>
  111. <p>
  112. Calcola la posizione del vertice in corrispondenza dell'indice specificato rispetto alle attuali trasformazioni ossee.
  113. Il vettore target deve essere inizializzato con le coordinate del vertice prima della trasformazione:
  114. <code>
  115. const target = new THREE.Vector3();
  116. target.fromBufferAttribute( mesh.geometry.attributes.position, index );
  117. mesh.boneTransform( index, target );
  118. </code>
  119. </p>
  120. <h2>Source</h2>
  121. <p>
  122. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  123. </p>
  124. </body>
  125. </html>