Skip to content

Commit

Permalink
Fix Issue #709
Browse files Browse the repository at this point in the history
Be more robust to name munging in surfacd worker string.
  • Loading branch information
dkoes committed Sep 13, 2023
1 parent 6f7cca7 commit ca2d971
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/ProteinSurface4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,15 @@ export class ProteinSurface {
faces: number[] = [];
verts = [];

static MarchingCube = new MarchingCubeInitializer();

constructor() {
if(!ProteinSurface.MarchingCube) {
//this is needed by webworkers
ProteinSurface.MarchingCube = new MarchingCubeInitializer();
}
}

readonly vdwRadii = {
"H" : 1.2,
"Li" : 1.82,
Expand Down Expand Up @@ -1406,10 +1415,10 @@ export class ProteinSurface {
}
};

public marchingcube(stype) {
public marchingcube(stype:number) {
this.marchingcubeinit(stype);
this.verts = []; this.faces = [];
MarchingCube.march(this.vpBits, this.verts, this.faces, {
ProteinSurface.MarchingCube.march(this.vpBits, this.verts, this.faces, {
smooth : 1,
nX : this.pLength,
nY : this.pWidth,
Expand All @@ -1422,7 +1431,7 @@ export class ProteinSurface {
this.verts[i].y + this.verts[i].z];
}

MarchingCube.laplacianSmooth(1, this.verts, this.faces);
ProteinSurface.MarchingCube.laplacianSmooth(1, this.verts, this.faces);

};

Expand Down
6 changes: 3 additions & 3 deletions src/SurfaceWorker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//Hackish way to create webworker (independent of $3Dmol namespace) within minified file
//We need to convert actual javascript into a string, not typescript, so for the time being

//this will remain a JS file
$3Dmol.workerString = function(){

Expand All @@ -21,7 +22,7 @@ $3Dmol.workerString = function(){
ps.boundingatom(false);
ps.fillvoxelswaals(self.atomData, obj.extendedAtoms);
}
ps.marchingcube(type);
ps.marchingcube(type); // jshint ignore:line
var VandF = ps.getFacesAndVertices(obj.atomsToShow);
self.postMessage(VandF);
}
Expand All @@ -33,9 +34,8 @@ $3Dmol.workerString = function(){
// (See: http://stackoverflow.com/questions/1661197/what-characters-are-valid-for-javascript-variable-names)
$3Dmol.workerString += ";\nfunction _classCallCheck() {};"; //hack for babel
$3Dmol.workerString += ";\n"+$3Dmol.Vector3.toString();
$3Dmol.workerString += ";\n"+$3Dmol.MarchingCubeInitializer.toString()+";\nvar MarchingCube = new "+$3Dmol.MarchingCubeInitializer.name+"();";
$3Dmol.workerString += ";\n"+$3Dmol.MarchingCubeInitializer.toString()+";\n\n";
$3Dmol.workerString += ";\n"+$3Dmol.PointGrid.toString()+";\n";
$3Dmol.workerString += ";\nvar ProteinSurface = "+$3Dmol.ProteinSurface.toString()+";\n";
$3Dmol.workerString = $3Dmol.workerString.replace(/[a-zA-Z_$]{1}[0-9a-zA-Z_$]*WEBPACK_IMPORTED_MODULE_[0-9]__\./g,''); //replace webpack generated prefixes
//console.log($3Dmol.workerString);
$3Dmol.SurfaceWorker = window.URL ? window.URL.createObjectURL(new Blob([$3Dmol.workerString],{type: 'text/javascript'})) : undefined;

0 comments on commit ca2d971

Please sign in to comment.