Advertisement
yskang

threejs-viewer-23

May 5th, 2021 (edited)
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 修改 Viewer.js
  2. buildContextMenu() {
  3.  
  4.     // ... other code snippets
  5.    
  6.     const callBack = (key) => {
  7.       let objects, dbId;
  8.  
  9.       switch (key) {
  10.         case 'hide-selected':
  11.           if (this.selection.length <= 0) return;
  12.  
  13.           dbId = this.selection[0];
  14.           this.clearSelection();
  15.  
  16.           objects = this.models.map(m => m.getObjectById(dbId));
  17.           if (!objects || objects.length <= 0) return;
  18.  
  19.           objects.forEach(obj => obj.visible = false);
  20.  
  21.           break;
  22.         case 'isolate-selected':
  23.           if (this.selection.length <= 0) return;
  24.  
  25.           dbId = this.selection[0];
  26.           this.clearSelection();
  27.  
  28.           this.models.forEach(m => {
  29.             m.traverse(child => {
  30.               if (child.type !== 'Mesh') return;
  31.  
  32.               if (child.id === dbId) {
  33.                 child.visible = true;
  34.                 return;
  35.               }
  36.  
  37.               child.visible = false;
  38.             });
  39.           });
  40.           break;
  41.         case 'show-all':
  42.           this.models.forEach(m => {
  43.             m.traverse(child => {
  44.               if (child.type !== 'Mesh' || child.visible) return;
  45.  
  46.               child.visible = true;
  47.             });
  48.           });
  49.           break;
  50.       }
  51.     };
  52.  
  53.  
  54.     // ... other code snippets
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement