in packages/miew/src/ComplexVisualEdit.js [194:265]
begin() {
const visual = this._complexVisual;
const selection = this._complexVisual.getSelectionGeo();
const atoms = this._getSelectionBorderAtoms();
if (atoms.length < 1 || atoms.length > 2) {
logger.error('Can only edit fragments with one or two bound atoms.');
return false;
}
this._fragmentBoundAtoms = atoms;
const selectionMask = 1 << visual.getSelectionBit();
// hide selected fragment in main model
visual.disableSubset(selectionMask, true);
// hide selection geo in main model
for (let k = 0; k < selection.children.length; ++k) {
selection.children[k].visible = false;
}
// create visible fragment representation to rotate
const pivotPos = atoms[0].position.clone();
if (atoms.length === 2) {
pivotPos.lerp(atoms[1].position, 0.5);
}
this._fragmentGeo = new THREE.Group();
visual.add(this._fragmentGeo);
this._fragmentGeo.position.copy(pivotPos);
this._fragmentSelectionGeo = new THREE.Group();
selection.add(this._fragmentSelectionGeo);
this._fragmentSelectionGeo.position.copy(pivotPos);
const offset = pivotPos.clone();
offset.negate();
for (let i = 0; i < visual.children.length; ++i) {
const g = visual.children[i];
if (!('getSubset' in g)) {
continue;
}
const vg = new THREE.Group();
this._fragmentGeo.add(vg);
const sg = new THREE.Group();
this._fragmentSelectionGeo.add(sg);
const meshes = g.getSubset(selectionMask, true);
for (let j = 0; j < meshes.length; j++) {
const m = meshes[j];
vg.add(m);
m.position.copy(offset);
}
const smeshes = g.getSubset(selectionMask, true);
for (let h = 0; h < smeshes.length; h++) {
const sm = smeshes[h];
sg.add(sm);
sm.position.copy(offset);
}
}
gfxutils.applySelectionMaterial(this._fragmentSelectionGeo);
this._inProgress = true;
return true;
}