Skip to content

Commit

Permalink
only update the selected atoms if there are selected atoms
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Nov 23, 2024
1 parent 61d3eca commit ff3757c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/atoms/AtomsViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class AtomsViewer {
this._cell = null;
this._atoms = null;
this._currentFrame = 0;
this.selectedAtomsIndices = [];
// set cell
this.cellManager.cell = this.atoms.cell;
// initialize the bond settings
Expand Down
16 changes: 11 additions & 5 deletions src/atoms/plugins/atom.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,31 @@ export class AtomManager {
// Method to update the scale of atoms
updateAtomScale() {
let mesh = this.meshes["atom"];
this.updateMeshScale(mesh, this.viewer.atoms.symbols, this.viewer.atomScale);
// only update the selected atoms if there are selected atoms
const indices = this.viewer.selectedAtomsIndices.length > 0 ? this.viewer.selectedAtomsIndices : [...Array(this.viewer.atoms.positions.length).keys()];
this.updateMeshScale(mesh, indices, this.viewer.atoms.symbols, this.viewer.atomScale);
// update the boundary atoms
mesh = this.meshes["image"];
if (mesh) {
const symbols = [];
const imageAtomsIndices = [];
for (let i = 0; i < this.viewer.imageAtomsList.length; i++) {
symbols.push(this.viewer.atoms.symbols[this.viewer.imageAtomsList[i][0]]);
if (this.viewer.selectedAtomsIndices.includes(this.viewer.imageAtomsList[i][0])) {
imageAtomsIndices.push(i);
}
}
this.updateMeshScale(mesh, symbols, this.viewer.atomScale);
this.updateMeshScale(mesh, imageAtomsIndices, symbols, this.viewer.atomScale);
}
}

updateMeshScale(mesh, symbols, atomScale) {
updateMeshScale(mesh, indices, symbols, atomScale) {
const position = new THREE.Vector3();
const rotation = new THREE.Quaternion();
const scale = new THREE.Vector3();
console.log("settings: ", this.settings);

for (let i = 0; i < mesh.count; i++) {
indices.forEach((i) => {
const instanceMatrix = new THREE.Matrix4();
console.log("symbols[i]: ", symbols[i]);
const radius = this.settings[symbols[i]].radius || 1;
Expand All @@ -218,7 +224,7 @@ export class AtomManager {
// Recompose the matrix with the new scale
instanceMatrix.compose(position, rotation, scale);
mesh.setMatrixAt(i, instanceMatrix);
}
});
mesh.instanceMatrix.needsUpdate = true;
}
}

0 comments on commit ff3757c

Please sign in to comment.