Picker.prototype.pickObject = function()

in packages/miew/src/ui/Picker.js [102:138]


Picker.prototype.pickObject = function (screenPos) {
  if (!this.gfxObj) {
    this.picked = {};
    this.dispatchEvent({ type: 'newpick', obj: {} });
    return;
  }

  const { gfxObj } = this;
  const rayCaster = new THREE.Raycaster();
  rayCaster.ray.origin.setFromMatrixPosition(this.camera.matrixWorld);
  rayCaster.ray.direction.set(screenPos.x, screenPos.y, 0.5).unproject(this.camera).sub(rayCaster.ray.origin).normalize();

  const clipPlane = (settings.now.draft.clipPlane && this.clipPlaneValue) ? this.clipPlaneValue : Infinity;
  const fogFarPlane = (settings.now.fog && this.fogFarValue) ? this.fogFarValue : Infinity;
  const point = rayCaster.intersectVisibleObject(gfxObj, this.camera, clipPlane, fogFarPlane);
  if (!point) {
    this.picked = {};
    this.dispatchEvent({ type: 'newpick', obj: {} });
    return;
  }

  let picked = {};
  if (point.residue || point.atom) {
    const residue = point.residue || point.atom.residue;
    if (settings.now.pick === 'chain') {
      picked = { chain: residue.getChain() };
    } else if (settings.now.pick === 'molecule') {
      picked = { molecule: residue.getMolecule() };
    } else if (point.residue || settings.now.pick === 'residue') {
      picked = { residue };
    } else if (point.atom) {
      picked = { atom: point.atom };
    }
  }
  this.picked = picked;
  this.dispatchEvent({ type: 'newpick', obj: picked });
};