@@ -17,6 +17,16 @@ import { decode, toRGBA8, encode } from 'upng-js'
17
17
18
18
export const CONTEXTS_PER_VIEWPORT = 16 ;
19
19
20
+ interface SurfObj {
21
+ geo : Geometry ;
22
+ mat : Material ;
23
+ done : Boolean ;
24
+ finished : Boolean ;
25
+ lastGL ?: any ;
26
+ symmetries ?: any [ ] ;
27
+ style ?: SurfaceStyleSpec ;
28
+ }
29
+
20
30
/**
21
31
* WebGL-based 3Dmol.js viewer
22
32
* Note: The preferred method of instantiating a GLViewer is through {@link createViewer}
@@ -38,7 +48,7 @@ export class GLViewer {
38
48
private glDOM : HTMLCanvasElement | null = null ;
39
49
40
50
private models : GLModel [ ] = [ ] ; // atomistic molecular models
41
- private surfaces : any = { } ;
51
+ private surfaces : Record < number , SurfObj [ ] > = { } ;
42
52
private shapes = [ ] ; // Generic shapes
43
53
private labels : Label [ ] = [ ] ;
44
54
private clickables = [ ] ; //things you can click on
@@ -1826,7 +1836,6 @@ export class GLViewer {
1826
1836
geo . normalsNeedUpdate = true ;
1827
1837
geo . colorsNeedUpdate = true ;
1828
1838
geo . buffersNeedUpdate = true ;
1829
- geo . boundingSphere = null ;
1830
1839
surfArr [ n ] . mat . needsUpdate = true ;
1831
1840
1832
1841
if ( surfArr [ n ] . done )
@@ -2512,7 +2521,7 @@ export class GLViewer {
2512
2521
viewer.render();
2513
2522
});
2514
2523
*/
2515
- public addPropertyLabels ( prop : string , sel : AtomSelectionSpec , style : AtomStyleSpec ) {
2524
+ public addPropertyLabels ( prop : string , sel : AtomSelectionSpec , style : LabelSpec ) {
2516
2525
this . applyToModels ( "addPropertyLabels" , prop , sel , this , style ) ;
2517
2526
this . show ( ) ;
2518
2527
return this ;
@@ -4083,19 +4092,22 @@ export class GLViewer {
4083
4092
4084
4093
//set colorArray of there are per-atom colors
4085
4094
var colorArray = geoGroup . colorArray ;
4095
+ let atomArray = geoGroup . atomArray ;
4086
4096
4087
4097
if ( mat . voldata && mat . volscheme ) {
4088
4098
//convert volumetric data into colors
4089
4099
var scheme = mat . volscheme ;
4090
4100
var voldata = mat . voldata ;
4091
4101
var range = scheme . range ( ) || [ - 1 , 1 ] ;
4092
4102
for ( let i = 0 , il = v . length ; i < il ; i ++ ) {
4103
+ let A = v [ i ] . atomid ;
4093
4104
let val = voldata . getVal ( v [ i ] . x , v [ i ] . y , v [ i ] . z ) ;
4094
4105
let col = CC . color ( scheme . valueToHex ( val , range ) ) ;
4095
4106
let offset = i * 3 ;
4096
4107
colorArray [ offset ] = col . r ;
4097
4108
colorArray [ offset + 1 ] = col . g ;
4098
4109
colorArray [ offset + 2 ] = col . b ;
4110
+ atomArray [ i ] = atoms [ A ] ;
4099
4111
}
4100
4112
}
4101
4113
else if ( colors . length > 0 ) { //have atom colors
@@ -4106,6 +4118,7 @@ export class GLViewer {
4106
4118
colorArray [ offsetA ] = colors [ A ] . r ;
4107
4119
colorArray [ offsetA + 1 ] = colors [ A ] . g ;
4108
4120
colorArray [ offsetA + 2 ] = colors [ A ] . b ;
4121
+ atomArray [ i ] = atoms [ A ] ;
4109
4122
}
4110
4123
}
4111
4124
@@ -4237,7 +4250,6 @@ export class GLViewer {
4237
4250
return mat ;
4238
4251
}
4239
4252
4240
-
4241
4253
/**
4242
4254
* Adds an explicit mesh as a surface object.
4243
4255
* @param {Mesh }
@@ -4254,7 +4266,7 @@ export class GLViewer {
4254
4266
finished : false //the rendered finishes surfaces when they are done
4255
4267
} ;
4256
4268
var surfid = this . nextSurfID ( ) ;
4257
- this . surfaces [ surfid ] = surfobj ;
4269
+ this . surfaces [ surfid ] = [ surfobj ] ;
4258
4270
return surfid ;
4259
4271
} ;
4260
4272
@@ -4597,15 +4609,14 @@ export class GLViewer {
4597
4609
adjustVolumeStyle ( style ) ;
4598
4610
if ( this . surfaces [ surf ] ) {
4599
4611
var surfArr = this . surfaces [ surf ] ;
4600
- surfArr . style = style ;
4601
- for ( var i = 0 ; i < surfArr . length ; i ++ ) {
4612
+ for ( let i = 0 ; i < surfArr . length ; i ++ ) {
4602
4613
var mat = surfArr [ i ] . mat = GLViewer . getMatWithStyle ( style ) ;
4603
4614
surfArr [ i ] . mat . side = FrontSide ;
4604
4615
if ( style . color ) {
4605
- surfArr [ i ] . mat . color = style . color ;
4616
+ surfArr [ i ] . mat . color = CC . color ( style . color ) ;
4606
4617
surfArr [ i ] . geo . colorsNeedUpdate = true ;
4607
4618
const c = CC . color ( style . color ) ;
4608
- surfArr [ i ] . geo . setColors ( function ( ) { return c ; } ) ;
4619
+ surfArr [ i ] . geo . setColor ( c ) ;
4609
4620
}
4610
4621
else if ( mat . voldata && mat . volscheme ) {
4611
4622
//convert volumetric data into colors
@@ -4618,6 +4629,17 @@ export class GLViewer {
4618
4629
let col = cc . color ( scheme . valueToHex ( val , range ) ) ;
4619
4630
return col ;
4620
4631
} ) ;
4632
+ } else {
4633
+ surfArr [ i ] . geo . colorsNeedUpdate = true ;
4634
+ for ( let geo of surfArr [ i ] . geo . geometryGroups ) {
4635
+ for ( let j = 0 ; j < geo . vertices ; j ++ ) {
4636
+ let c = getColorFromStyle ( geo . atomArray [ j ] , style ) ;
4637
+ let off = 3 * j ;
4638
+ geo . colorArray [ off ] = c . r ;
4639
+ geo . colorArray [ off + 1 ] = c . g ;
4640
+ geo . colorArray [ off + 2 ] = c . b ;
4641
+ }
4642
+ }
4621
4643
}
4622
4644
surfArr [ i ] . finished = false ; // trigger redraw
4623
4645
}
0 commit comments