From ff3757c35cc25b235e152b75d698a18cb3c0ce63 Mon Sep 17 00:00:00 2001 From: superstar54 Date: Sat, 23 Nov 2024 22:17:08 +0100 Subject: [PATCH] only update the selected atoms if there are selected atoms --- src/atoms/AtomsViewer.js | 1 + src/atoms/plugins/atom.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/atoms/AtomsViewer.js b/src/atoms/AtomsViewer.js index e1b57b0..acce1e4 100644 --- a/src/atoms/AtomsViewer.js +++ b/src/atoms/AtomsViewer.js @@ -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 diff --git a/src/atoms/plugins/atom.js b/src/atoms/plugins/atom.js index dfc54b6..66c1254 100644 --- a/src/atoms/plugins/atom.js +++ b/src/atoms/plugins/atom.js @@ -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; @@ -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; } }