title: How to get the global position of a vertex of a skinned mesh in Three.js?
body: <p>In Three.js, we are now able to get the global position of a vertex of a <strong>non-skinned</strong> mesh thanks to <a href="https://stackoverflow.com/questions/11495089/how-to-get-the-absolute-position-of-a-vertex-in-three-js">this question</a>, but how can I get the global position of a vertex of a <strong>skinned</strong> mesh with bones and morph targets?</p>
  
  <p>For example, how can I print <code>(2.5, 1.5, 0.5)</code> in the following situation?
  <code>mesh.geometry.vertices[0]</code> is originally at <code>(0.5, 0.5, 0.5)</code>.
  Then, <code>bones[1]</code> moves the vertex to <code>(2.5, 0.5, 0.5)</code>.
  Finally, morphing moves the vertex to <code>(2.5, 1.5, 0.5)</code>.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const scene = new THREE.Scene();
  
  const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 200);
  camera.position.z = 3;
  camera.position.y = 2;
  camera.lookAt(0, 0, 0);
  
  const renderer = new THREE.WebGLRenderer({antialias: true});
  renderer.setPixelRatio(window.devicePixelRatio);
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);
  
  const geometry = new THREE.BoxGeometry(1, 1, 1);
  geometry.morphTargets.push({name: "morph", vertices: []});
  for (const vertex of geometry.vertices) {
    geometry.skinIndices.push(new THREE.Vector4(vertex.x &lt; 0 ? 0 : 1, 0, 0, 0));
    geometry.skinWeights.push(new THREE.Vector4(1, 0, 0, 0));
    geometry.morphTargets[0].vertices.push(vertex.clone().add(new THREE.Vector3(0, 1, 0)));
  }
  
  const material = new THREE.MeshPhongMaterial({
    skinning: true,
    emissive: 0xffffff,
    wireframe: true,
    morphTargets: true
  });
  
  const mesh = new THREE.SkinnedMesh(geometry, material);
  
  const bones = [new THREE.Bone(), new THREE.Bone()];
  for (const bone of bones) {
    mesh.add(bone);
  }
  
  const skeleton = new THREE.Skeleton(bones);
  mesh.bind(skeleton);
  
  bones[0].position.x = -2;
  bones[1].position.x = 2;
  mesh.morphTargetInfluences[0] = 1;
  scene.add(mesh);
  
  // This code assigns (0.5, 0.5, 0.5) to pos,
  // but I want to know the code which assigns (2.5, 1.5, 0.5) to pos. 
  const pos = mesh.geometry.vertices[0].clone().applyMatrix4(mesh.matrixWorld);
  console.log(`(${pos.x}, ${pos.y}, ${pos.z})`);
  
  (function render() {
    requestAnimationFrame(render);
    renderer.render(scene, camera);
  })();</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    margin: 0;
    overflow: hidden;
  }
  canvas {
    width: 100%;
    height: 100%;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/94/three.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>