icn3d
Version:
iCn3D Structure Viewer
1,468 lines (1,455 loc) • 4.92 MB
JavaScript
// make it compatible with nodeJS
var window = {};
var document = {};
var bNodeIcn3d = true;
window.navigator = {};
var $NGL_shaderTextHash = {};
$NGL_shaderTextHash['SphereImpostor.frag'] = ["#define STANDARD",
"#define IMPOSTOR",
"",
"uniform vec3 diffuse;",
"uniform vec3 emissive;",
"uniform float roughness;",
"uniform float metalness;",
"uniform float opacity;",
"uniform float nearClip;",
"uniform mat4 projectionMatrix;",
"uniform float ortho;",
"",
"varying float vRadius;",
"varying float vRadiusSq;",
"varying vec3 vPoint;",
"varying vec3 vPointViewPosition;",
"",
"#ifdef PICKING",
" uniform float objectId;",
" varying vec3 vPickingColor;",
"#else",
" #include common",
" #include color_pars_fragment",
" #include fog_pars_fragment",
" #include bsdfs",
" #include lights_pars_begin",
" #include lights_physical_pars_fragment",
"#endif",
"",
"bool flag2 = false;",
"bool interior = false;",
"vec3 cameraPos;",
"vec3 cameraNormal;",
"",
"// Calculate depth based on the given camera position.",
"float calcDepth( in vec3 cameraPos ){",
" vec2 clipZW = cameraPos.z * projectionMatrix[2].zw + projectionMatrix[3].zw;",
" return 0.5 + 0.5 * clipZW.x / clipZW.y;",
"}",
"",
"float calcClip( vec3 cameraPos ){",
" return dot( vec4( cameraPos, 1.0 ), vec4( 0.0, 0.0, 1.0, nearClip - 0.5 ) );",
"}",
"",
"bool Impostor( out vec3 cameraPos, out vec3 cameraNormal ){",
"",
" vec3 cameraSpherePos = -vPointViewPosition;",
" cameraSpherePos.z += vRadius;",
"",
" vec3 rayOrigin = mix( vec3( 0.0, 0.0, 0.0 ), vPoint, ortho );",
" vec3 rayDirection = mix( normalize( vPoint ), vec3( 0.0, 0.0, 1.0 ), ortho );",
" vec3 cameraSphereDir = mix( cameraSpherePos, rayOrigin - cameraSpherePos, ortho );",
"",
" float B = dot( rayDirection, cameraSphereDir );",
" float det = B * B + vRadiusSq - dot( cameraSphereDir, cameraSphereDir );",
"",
" if( det < 0.0 ){",
" discard;",
" return false;",
" }",
" float sqrtDet = sqrt( det );",
" float posT = mix( B + sqrtDet, B + sqrtDet, ortho );",
" float negT = mix( B - sqrtDet, sqrtDet - B, ortho );",
"",
" cameraPos = rayDirection * negT + rayOrigin;",
"",
" #ifdef NEAR_CLIP",
"if( calcDepth( cameraPos ) <= 0.0 ){",
" cameraPos = rayDirection * posT + rayOrigin;",
" interior = true;",
" return false;",
"}else if( calcClip( cameraPos ) > 0.0 ){",
" cameraPos = rayDirection * posT + rayOrigin;",
" interior = true;",
" flag2 = true;",
" return false;",
"}else{",
" cameraNormal = normalize( cameraPos - cameraSpherePos );",
"}",
" #else",
"if( calcDepth( cameraPos ) <= 0.0 ){",
" cameraPos = rayDirection * posT + rayOrigin;",
" interior = true;",
" return false;",
"}else{",
" cameraNormal = normalize( cameraPos - cameraSpherePos );",
"}",
" #endif",
"",
" cameraNormal = normalize( cameraPos - cameraSpherePos );",
" cameraNormal *= float(!interior) * 2.0 - 1.0;",
" return !interior;",
"",
"}",
"",
"void main(void){",
"",
" bool flag = Impostor( cameraPos, cameraNormal );",
"",
" #ifdef NEAR_CLIP",
" if( calcClip( cameraPos ) > 0.0 )",
" discard;",
" #endif",
"",
" // FIXME not compatible with custom clipping plane",
" //Set the depth based on the new cameraPos.",
" gl_FragDepthEXT = calcDepth( cameraPos );",
" if( !flag ){",
"",
" // clamp to near clipping plane and add a tiny value to",
" // make spheres with a greater radius occlude smaller ones",
" #ifdef NEAR_CLIP",
"if( flag2 ){",
" gl_FragDepthEXT = max( 0.0, calcDepth( vec3( - ( nearClip - 0.5 ) ) ) + ( 0.0000001 / vRadius ) );",
"}else if( gl_FragDepthEXT >= 0.0 ){",
" gl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );",
"}",
" #else",
"if( gl_FragDepthEXT >= 0.0 ){",
" gl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );",
"}",
" #endif",
"",
" }",
"",
" // bugfix (mac only?)",
" if (gl_FragDepthEXT < 0.0)",
" discard;",
" if (gl_FragDepthEXT > 1.0)",
" discard;",
"",
" #ifdef PICKING",
"",
" gl_FragColor = vec4( vPickingColor, objectId );",
"",
" #else",
"",
" vec3 vNormal = cameraNormal;",
" vec3 vViewPosition = -cameraPos;",
"",
" vec4 diffuseColor = vec4( diffuse, opacity );",
" ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
" vec3 totalEmissiveLight = emissive;",
"",
" #include color_fragment",
" #include roughnessmap_fragment",
" #include metalnessmap_fragment",
"",
" // don't use include normal_fragment",
" vec3 normal = normalize( vNormal );",
"",
" #include lights_physical_fragment",
" //include lights_template",
" #include lights_fragment_begin",
" #include lights_fragment_end",
"",
" vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
"",
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
" //gl_FragColor = vec4( reflectedLight.directSpecular, diffuseColor.a );",
"",
" #include premultiplied_alpha_fragment",
" #include tonemapping_fragment",
" #include encodings_fragment",
" //include fog_fragment",
" #ifdef USE_FOG",
" #ifdef USE_LOGDEPTHBUF_EXT",
" float depth = gl_FragDepthEXT / gl_FragCoord.w;",
" #else",
" float depth = gl_FragCoord.z / gl_FragCoord.w;",
" #endif",
" #ifdef FOG_EXP2",
" float fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );",
" #else",
" float fogFactor = smoothstep( fogNear, fogFar, depth );",
" #endif",
" gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );",
" #endif",
"",
" #endif",
"",
"}"
].join("\n");
$NGL_shaderTextHash['SphereImpostor.vert'] = ["uniform mat4 projectionMatrixInverse;",
"uniform float nearClip;",
"",
"varying float vRadius;",
"varying float vRadiusSq;",
"varying vec3 vPoint;",
"varying vec3 vPointViewPosition;",
"varying float fogDepth;",
"varying float fogNear;",
"varying float fogFar;",
"",
"attribute vec2 mapping;",
"//attribute vec3 position;",
"attribute float radius;",
"",
"#ifdef PICKING",
" #include unpack_clr",
" attribute float primitiveId;",
" varying vec3 vPickingColor;",
"#else",
" #include color_pars_vertex",
"#endif",
"",
"//include matrix_scale",
"float matrixScale( in mat4 m ){",
" vec4 r = m[ 0 ];",
" return sqrt( r[ 0 ] * r[ 0 ] + r[ 1 ] * r[ 1 ] + r[ 2 ] * r[ 2 ] );",
"}",
"",
"const mat4 D = mat4(",
" 1.0, 0.0, 0.0, 0.0,",
" 0.0, 1.0, 0.0, 0.0,",
" 0.0, 0.0, 1.0, 0.0,",
" 0.0, 0.0, 0.0, -1.0",
");",
"",
"mat4 transposeTmp( in mat4 inMatrix ) {",
" vec4 i0 = inMatrix[0];",
" vec4 i1 = inMatrix[1];",
" vec4 i2 = inMatrix[2];",
" vec4 i3 = inMatrix[3];",
"",
" mat4 outMatrix = mat4(",
" vec4(i0.x, i1.x, i2.x, i3.x),",
" vec4(i0.y, i1.y, i2.y, i3.y),",
" vec4(i0.z, i1.z, i2.z, i3.z),",
" vec4(i0.w, i1.w, i2.w, i3.w)",
" );",
" return outMatrix;",
"}",
"",
"//------------------------------------------------------------------------------",
"// Compute point size and center using the technique described in:",
"// 'GPU-Based Ray-Casting of Quadratic Surfaces'",
"// by Christian Sigg, Tim Weyrich, Mario Botsch, Markus Gross.",
"//",
"// Code based on",
"/*=========================================================================",
"",
" Program: Visualization Toolkit",
" Module: Quadrics_fs.glsl and Quadrics_vs.glsl",
"",
" Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen",
" All rights reserved.",
" See Copyright.txt or http://www.kitware.com/Copyright.htm for details.",
"",
" This software is distributed WITHOUT ANY WARRANTY; without even",
" the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR",
" PURPOSE. See the above copyright notice for more information.",
"",
" =========================================================================*/",
"",
"// .NAME Quadrics_fs.glsl and Quadrics_vs.glsl",
"// .SECTION Thanks",
"// <verbatim>",
"//",
"// This file is part of the PointSprites plugin developed and contributed by",
"//",
"// Copyright (c) CSCS - Swiss National Supercomputing Centre",
"// EDF - Electricite de France",
"//",
"// John Biddiscombe, Ugo Varetto (CSCS)",
"// Stephane Ploix (EDF)",
"//",
"// </verbatim>",
"//",
"// Contributions by Alexander Rose",
"// - ported to WebGL",
"// - adapted to work with quads",
"void ComputePointSizeAndPositionInClipCoordSphere(){",
"",
" vec2 xbc;",
" vec2 ybc;",
"",
" mat4 T = mat4(",
" radius, 0.0, 0.0, 0.0,",
" 0.0, radius, 0.0, 0.0,",
" 0.0, 0.0, radius, 0.0,",
" position.x, position.y, position.z, 1.0",
" );",
"",
" mat4 R = transposeTmp( projectionMatrix * modelViewMatrix * T );",
" float A = dot( R[ 3 ], D * R[ 3 ] );",
" float B = -2.0 * dot( R[ 0 ], D * R[ 3 ] );",
" float C = dot( R[ 0 ], D * R[ 0 ] );",
" xbc[ 0 ] = ( -B - sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );",
" xbc[ 1 ] = ( -B + sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );",
" float sx = abs( xbc[ 0 ] - xbc[ 1 ] ) * 0.5;",
"",
" A = dot( R[ 3 ], D * R[ 3 ] );",
" B = -2.0 * dot( R[ 1 ], D * R[ 3 ] );",
" C = dot( R[ 1 ], D * R[ 1 ] );",
" ybc[ 0 ] = ( -B - sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );",
" ybc[ 1 ] = ( -B + sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );",
" float sy = abs( ybc[ 0 ] - ybc[ 1 ] ) * 0.5;",
"",
" gl_Position.xy = vec2( 0.5 * ( xbc.x + xbc.y ), 0.5 * ( ybc.x + ybc.y ) );",
" gl_Position.xy -= mapping * vec2( sx, sy );",
" gl_Position.xy *= gl_Position.w;",
"",
"}",
"",
"void main(void){",
"",
" #ifdef PICKING",
" vPickingColor = unpackColor( primitiveId );",
" #else",
" #include color_vertex",
" #endif",
"",
" vRadius = radius * matrixScale( modelViewMatrix );",
"",
" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
" // avoid clipping, added again in fragment shader",
" mvPosition.z -= vRadius;",
"",
" gl_Position = projectionMatrix * vec4( mvPosition.xyz, 1.0 );",
" ComputePointSizeAndPositionInClipCoordSphere();",
"",
"",
" vRadiusSq = vRadius * vRadius;",
" vec4 vPoint4 = projectionMatrixInverse * gl_Position;",
" vPoint = vPoint4.xyz / vPoint4.w;",
" vPointViewPosition = -mvPosition.xyz / mvPosition.w;",
"",
"}"
].join("\n");
$NGL_shaderTextHash['CylinderImpostor.frag'] = ["#define STANDARD",
"#define IMPOSTOR",
"",
"// Open-Source PyMOL is Copyright (C) Schrodinger, LLC.",
"//",
"// All Rights Reserved",
"//",
"// Permission to use, copy, modify, distribute, and distribute modified",
"// versions of this software and its built-in documentation for any",
"// purpose and without fee is hereby granted, provided that the above",
"// copyright notice appears in all copies and that both the copyright",
"// notice and this permission notice appear in supporting documentation,",
"// and that the name of Schrodinger, LLC not be used in advertising or",
"// publicity pertaining to distribution of the software without specific,",
"// written prior permission.",
"//",
"// SCHRODINGER, LLC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,",
"// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN",
"// NO EVENT SHALL SCHRODINGER, LLC BE LIABLE FOR ANY SPECIAL, INDIRECT OR",
"// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS",
"// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE",
"// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE",
"// USE OR PERFORMANCE OF THIS SOFTWARE.",
"",
"// Contributions by Alexander Rose",
"// - ported to WebGL",
"// - dual color",
"// - pk color",
"// - custom clipping",
"// - three.js lighting",
"",
"uniform vec3 diffuse;",
"uniform vec3 emissive;",
"uniform float roughness;",
"uniform float metalness;",
"uniform float opacity;",
"uniform float nearClip;",
"uniform mat4 projectionMatrix;",
"uniform float ortho;",
"",
"varying vec3 axis;",
"varying vec4 base_radius;",
"varying vec4 end_b;",
"varying vec3 U;",
"varying vec3 V;",
"varying vec4 w;",
"",
"#ifdef PICKING",
" uniform float objectId;",
" varying vec3 vPickingColor;",
"#else",
" varying vec3 vColor1;",
" varying vec3 vColor2;",
" #include common",
" #include fog_pars_fragment",
" #include bsdfs",
" #include lights_pars_begin",
" #include lights_physical_pars_fragment",
"#endif",
"",
"bool interior = false;",
"",
"float distSq3( vec3 v3a, vec3 v3b ){",
" return (",
" ( v3a.x - v3b.x ) * ( v3a.x - v3b.x ) +",
" ( v3a.y - v3b.y ) * ( v3a.y - v3b.y ) +",
" ( v3a.z - v3b.z ) * ( v3a.z - v3b.z )",
" );",
"}",
"",
"// Calculate depth based on the given camera position.",
"float calcDepth( in vec3 cameraPos ){",
" vec2 clipZW = cameraPos.z * projectionMatrix[2].zw + projectionMatrix[3].zw;",
" return 0.5 + 0.5 * clipZW.x / clipZW.y;",
"}",
"",
"float calcClip( vec3 cameraPos ){",
" return dot( vec4( cameraPos, 1.0 ), vec4( 0.0, 0.0, 1.0, nearClip - 0.5 ) );",
"}",
"",
"void main(){",
"",
" vec3 point = w.xyz / w.w;",
"",
" // unpacking",
" vec3 base = base_radius.xyz;",
" float vRadius = base_radius.w;",
" vec3 end = end_b.xyz;",
" float b = end_b.w;",
"",
" vec3 end_cyl = end;",
" vec3 surface_point = point;",
"",
" vec3 ray_target = surface_point;",
" vec3 ray_origin = vec3(0.0);",
" vec3 ray_direction = mix(normalize(ray_origin - ray_target), vec3(0.0, 0.0, 1.0), ortho);",
" mat3 basis = mat3( U, V, axis );",
"",
" vec3 diff = ray_target - 0.5 * (base + end_cyl);",
" vec3 P = diff * basis;",
"",
" // angle (cos) between cylinder cylinder_axis and ray direction",
" float dz = dot( axis, ray_direction );",
"",
" float radius2 = vRadius*vRadius;",
"",
" // calculate distance to the cylinder from ray origin",
" vec3 D = vec3(dot(U, ray_direction),",
" dot(V, ray_direction),",
" dz);",
" float a0 = P.x*P.x + P.y*P.y - radius2;",
" float a1 = P.x*D.x + P.y*D.y;",
" float a2 = D.x*D.x + D.y*D.y;",
"",
" // calculate a dicriminant of the above quadratic equation",
" float d = a1*a1 - a0*a2;",
" if (d < 0.0)",
" // outside of the cylinder",
" discard;",
"",
" float dist = (-a1 + sqrt(d)) / a2;",
"",
" // point of intersection on cylinder surface",
" vec3 new_point = ray_target + dist * ray_direction;",
"",
" vec3 tmp_point = new_point - base;",
" vec3 _normal = normalize( tmp_point - axis * dot(tmp_point, axis) );",
"",
" ray_origin = mix( ray_origin, surface_point, ortho );",
"",
" // test caps",
" float front_cap_test = dot( tmp_point, axis );",
" float end_cap_test = dot((new_point - end_cyl), axis);",
"",
" // to calculate caps, simply check the angle between",
" // the point of intersection - cylinder end vector",
" // and a cap plane normal (which is the cylinder cylinder_axis)",
" // if the angle < 0, the point is outside of cylinder",
" // test front cap",
"",
" #ifndef CAP",
" vec3 new_point2 = ray_target + ( (-a1 - sqrt(d)) / a2 ) * ray_direction;",
" vec3 tmp_point2 = new_point2 - base;",
" #endif",
"",
" // flat",
" if (front_cap_test < 0.0)",
" {",
" // ray-plane intersection",
" float dNV = dot(-axis, ray_direction);",
" if (dNV < 0.0)",
" discard;",
" float near = dot(-axis, (base)) / dNV;",
" vec3 front_point = ray_direction * near + ray_origin;",
" // within the cap radius?",
" if (dot(front_point - base, front_point-base) > radius2)",
" discard;",
"",
" #ifdef CAP",
" new_point = front_point;",
" _normal = axis;",
" #else",
" new_point = ray_target + ( (-a1 - sqrt(d)) / a2 ) * ray_direction;",
" dNV = dot(-axis, ray_direction);",
" near = dot(axis, end_cyl) / dNV;",
" new_point2 = ray_direction * near + ray_origin;",
" if (dot(new_point2 - end_cyl, new_point2-base) < radius2)",
" discard;",
" interior = true;",
" #endif",
" }",
"",
" // test end cap",
"",
"",
" // flat",
" if( end_cap_test > 0.0 )",
" {",
" // ray-plane intersection",
" float dNV = dot(axis, ray_direction);",
" if (dNV < 0.0)",
" discard;",
" float near = dot(axis, end_cyl) / dNV;",
" vec3 end_point = ray_direction * near + ray_origin;",
" // within the cap radius?",
" if( dot(end_point - end_cyl, end_point-base) > radius2 )",
" discard;",
"",
" #ifdef CAP",
" new_point = end_point;",
" _normal = axis;",
" #else",
" new_point = ray_target + ( (-a1 - sqrt(d)) / a2 ) * ray_direction;",
" dNV = dot(-axis, ray_direction);",
" near = dot(-axis, (base)) / dNV;",
" new_point2 = ray_direction * near + ray_origin;",
" if (dot(new_point2 - base, new_point2-base) < radius2)",
" discard;",
" interior = true;",
" #endif",
" }",
"",
" gl_FragDepthEXT = calcDepth( new_point );",
"",
" #ifdef NEAR_CLIP",
" if( calcClip( new_point ) > 0.0 ){",
" dist = (-a1 - sqrt(d)) / a2;",
" new_point = ray_target + dist * ray_direction;",
" if( calcClip( new_point ) > 0.0 )",
" discard;",
" interior = true;",
" gl_FragDepthEXT = calcDepth( new_point );",
" if( gl_FragDepthEXT >= 0.0 ){",
" gl_FragDepthEXT = max( 0.0, calcDepth( vec3( - ( nearClip - 0.5 ) ) ) + ( 0.0000001 / vRadius ) );",
" }",
" }else if( gl_FragDepthEXT <= 0.0 ){",
" dist = (-a1 - sqrt(d)) / a2;",
" new_point = ray_target + dist * ray_direction;",
" interior = true;",
" gl_FragDepthEXT = calcDepth( new_point );",
" if( gl_FragDepthEXT >= 0.0 ){",
" gl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );",
" }",
" }",
" #else",
" if( gl_FragDepthEXT <= 0.0 ){",
" dist = (-a1 - sqrt(d)) / a2;",
" new_point = ray_target + dist * ray_direction;",
" interior = true;",
" gl_FragDepthEXT = calcDepth( new_point );",
" if( gl_FragDepthEXT >= 0.0 ){",
" gl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );",
" }",
" }",
" #endif",
"",
" // this is a workaround necessary for Mac",
" // otherwise the modified fragment won't clip properly",
" if (gl_FragDepthEXT < 0.0)",
" discard;",
" if (gl_FragDepthEXT > 1.0)",
" discard;",
"",
" #ifdef PICKING",
"",
" gl_FragColor = vec4( vPickingColor, objectId );",
"",
" #else",
"",
" vec3 vViewPosition = -new_point;",
" vec3 vNormal = _normal;",
" vec3 vColor;",
"",
" if( distSq3( new_point, end_cyl ) < distSq3( new_point, base ) ){",
" if( b < 0.0 ){",
" vColor = vColor1;",
" }else{",
" vColor = vColor2;",
" }",
" }else{",
" if( b > 0.0 ){",
" vColor = vColor1;",
" }else{",
" vColor = vColor2;",
" }",
" }",
"",
" vec4 diffuseColor = vec4( diffuse, opacity );",
" ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
" vec3 totalEmissiveLight = emissive;",
"",
" #include color_fragment",
" //ifdef USE_COLOR",
" //diffuseColor.r *= vColor[0];",
" //diffuseColor.g *= vColor[1];",
" //diffuseColor.b *= vColor[2];",
" //endif",
" #include roughnessmap_fragment",
" #include metalnessmap_fragment",
"",
" // don't use include normal_fragment",
" vec3 normal = normalize( vNormal );",
"",
" #include lights_physical_fragment",
" //include lights_template",
" #include lights_fragment_begin",
" #include lights_fragment_end",
"",
" vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
"",
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
" //gl_FragColor = vec4( reflectedLight.directSpecular, diffuseColor.a );",
"",
" #include premultiplied_alpha_fragment",
" #include tonemapping_fragment",
" #include encodings_fragment",
" //include fog_fragment",
" #ifdef USE_FOG",
" #ifdef USE_LOGDEPTHBUF_EXT",
" float depth = gl_FragDepthEXT / gl_FragCoord.w;",
" #else",
" float depth = gl_FragCoord.z / gl_FragCoord.w;",
" #endif",
" #ifdef FOG_EXP2",
" float fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );",
" #else",
" float fogFactor = smoothstep( fogNear, fogFar, depth );",
" #endif",
" gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );",
" #endif",
"",
" #endif",
"",
"}"
].join("\n");
$NGL_shaderTextHash['CylinderImpostor.vert'] = ["// Open-Source PyMOL is Copyright (C) Schrodinger, LLC.",
"//",
"// All Rights Reserved",
"//",
"// Permission to use, copy, modify, distribute, and distribute modified",
"// versions of this software and its built-in documentation for any",
"// purpose and without fee is hereby granted, provided that the above",
"// copyright notice appears in all copies and that both the copyright",
"// notice and this permission notice appear in supporting documentation,",
"// and that the name of Schrodinger, LLC not be used in advertising or",
"// publicity pertaining to distribution of the software without specific,",
"// written prior permission.",
"//",
"// SCHRODINGER, LLC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,",
"// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN",
"// NO EVENT SHALL SCHRODINGER, LLC BE LIABLE FOR ANY SPECIAL, INDIRECT OR",
"// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS",
"// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE",
"// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE",
"// USE OR PERFORMANCE OF THIS SOFTWARE.",
"",
"// Contributions by Alexander Rose",
"// - ported to WebGL",
"// - dual color",
"// - pk color",
"// - shift",
"",
"attribute vec3 mapping;",
"attribute vec3 position1;",
"attribute vec3 position2;",
"attribute float radius;",
"",
"varying vec3 axis;",
"varying vec4 base_radius;",
"varying vec4 end_b;",
"varying vec3 U;",
"varying vec3 V;",
"varying vec4 w;",
"varying float fogDepth;",
"varying float fogNear;",
"varying float fogFar;",
"",
"#ifdef PICKING",
" #include unpack_clr",
" attribute float primitiveId;",
" varying vec3 vPickingColor;",
"#else",
" //attribute vec3 color;",
" attribute vec3 color2;",
" varying vec3 vColor1;",
" varying vec3 vColor2;",
"#endif",
"",
"uniform mat4 modelViewMatrixInverse;",
"uniform float ortho;",
"",
"//include matrix_scale",
"float matrixScale( in mat4 m ){",
" vec4 r = m[ 0 ];",
" return sqrt( r[ 0 ] * r[ 0 ] + r[ 1 ] * r[ 1 ] + r[ 2 ] * r[ 2 ] );",
"}",
"",
"void main(){",
"",
" #ifdef PICKING",
" vPickingColor = unpackColor( primitiveId );",
" #else",
" vColor1 = color;",
" vColor2 = color2;",
" #endif",
"",
" // vRadius = radius;",
" base_radius.w = radius * matrixScale( modelViewMatrix );",
"",
" //vec3 center = position;",
" vec3 center = ( position2 + position1 ) / 2.0;",
" vec3 dir = normalize( position2 - position1 );",
" float ext = length( position2 - position1 ) / 2.0;",
"",
" // using cameraPosition fails on some machines, not sure why",
" // vec3 cam_dir = normalize( cameraPosition - mix( center, vec3( 0.0 ), ortho ) );",
" vec3 cam_dir;",
" if( ortho == 0.0 ){",
" cam_dir = ( modelViewMatrixInverse * vec4( 0, 0, 0, 1 ) ).xyz - center;",
" }else{",
" cam_dir = ( modelViewMatrixInverse * vec4( 0, 0, 1, 0 ) ).xyz;",
" }",
" cam_dir = normalize( cam_dir );",
"",
" vec3 ldir;",
"",
" float b = dot( cam_dir, dir );",
" end_b.w = b;",
" // direction vector looks away, so flip",
" if( b < 0.0 )",
" ldir = -ext * dir;",
" // direction vector already looks in my direction",
" else",
" ldir = ext * dir;",
"",
" vec3 left = normalize( cross( cam_dir, ldir ) );",
" left = radius * left;",
" vec3 up = radius * normalize( cross( left, ldir ) );",
"",
" // transform to modelview coordinates",
" axis = normalize( normalMatrix * ldir );",
" U = normalize( normalMatrix * up );",
" V = normalize( normalMatrix * left );",
"",
" vec4 base4 = modelViewMatrix * vec4( center - ldir, 1.0 );",
" base_radius.xyz = base4.xyz / base4.w;",
"",
" vec4 top_position = modelViewMatrix * vec4( center + ldir, 1.0 );",
" vec4 end4 = top_position;",
" end_b.xyz = end4.xyz / end4.w;",
"",
" w = modelViewMatrix * vec4(",
" center + mapping.x*ldir + mapping.y*left + mapping.z*up, 1.0",
" );",
"",
" gl_Position = projectionMatrix * w;",
"",
" // avoid clipping (1.0 seems to induce flickering with some drivers)",
" gl_Position.z = 0.99;",
"",
"}"
].join("\n");
$NGL_shaderTextHash['SphereInstancing.frag'] = $NGL_shaderTextHash['SphereImpostor.frag'];
$NGL_shaderTextHash['SphereInstancing.vert'] = ["uniform mat4 projectionMatrixInverse;",
"uniform float nearClip;",
"",
"varying float vRadius;",
"varying float vRadiusSq;",
"varying vec3 vPoint;",
"varying vec3 vPointViewPosition;",
"varying float fogDepth;",
"varying float fogNear;",
"varying float fogFar;",
"",
"attribute vec2 mapping;",
"//attribute vec3 position;",
"attribute float radius;",
"attribute vec4 matrix1;",
"attribute vec4 matrix2;",
"attribute vec4 matrix3;",
"attribute vec4 matrix4;",
"",
"#ifdef PICKING",
" #include unpack_clr",
" attribute float primitiveId;",
" varying vec3 vPickingColor;",
"#else",
" #include color_pars_vertex",
"#endif",
"",
"//include matrix_scale",
"float matrixScale( in mat4 m ){",
" vec4 r = m[ 0 ];",
" return sqrt( r[ 0 ] * r[ 0 ] + r[ 1 ] * r[ 1 ] + r[ 2 ] * r[ 2 ] );",
"}",
"",
"const mat4 D = mat4(",
" 1.0, 0.0, 0.0, 0.0,",
" 0.0, 1.0, 0.0, 0.0,",
" 0.0, 0.0, 1.0, 0.0,",
" 0.0, 0.0, 0.0, -1.0",
");",
"",
"mat4 transposeTmp( in mat4 inMatrix ) {",
" vec4 i0 = inMatrix[0];",
" vec4 i1 = inMatrix[1];",
" vec4 i2 = inMatrix[2];",
" vec4 i3 = inMatrix[3];",
"",
" mat4 outMatrix = mat4(",
" vec4(i0.x, i1.x, i2.x, i3.x),",
" vec4(i0.y, i1.y, i2.y, i3.y),",
" vec4(i0.z, i1.z, i2.z, i3.z),",
" vec4(i0.w, i1.w, i2.w, i3.w)",
" );",
" return outMatrix;",
"}",
"",
"//------------------------------------------------------------------------------",
"// Compute point size and center using the technique described in:",
"// 'GPU-Based Ray-Casting of Quadratic Surfaces'",
"// by Christian Sigg, Tim Weyrich, Mario Botsch, Markus Gross.",
"//",
"// Code based on",
"/*=========================================================================",
"",
" Program: Visualization Toolkit",
" Module: Quadrics_fs.glsl and Quadrics_vs.glsl",
"",
" Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen",
" All rights reserved.",
" See Copyright.txt or http://www.kitware.com/Copyright.htm for details.",
"",
" This software is distributed WITHOUT ANY WARRANTY; without even",
" the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR",
" PURPOSE. See the above copyright notice for more information.",
"",
" =========================================================================*/",
"",
"// .NAME Quadrics_fs.glsl and Quadrics_vs.glsl",
"// .SECTION Thanks",
"// <verbatim>",
"//",
"// This file is part of the PointSprites plugin developed and contributed by",
"//",
"// Copyright (c) CSCS - Swiss National Supercomputing Centre",
"// EDF - Electricite de France",
"//",
"// John Biddiscombe, Ugo Varetto (CSCS)",
"// Stephane Ploix (EDF)",
"//",
"// </verbatim>",
"//",
"// Contributions by Alexander Rose",
"// - ported to WebGL",
"// - adapted to work with quads",
"void ComputePointSizeAndPositionInClipCoordSphere(vec4 updatePosition){",
"",
" vec2 xbc;",
" vec2 ybc;",
"",
" mat4 T = mat4(",
" radius, 0.0, 0.0, 0.0,",
" 0.0, radius, 0.0, 0.0,",
" 0.0, 0.0, radius, 0.0,",
" updatePosition.x, updatePosition.y, updatePosition.z, 1.0",
" );",
"",
" mat4 R = transposeTmp( projectionMatrix * modelViewMatrix * T );",
" float A = dot( R[ 3 ], D * R[ 3 ] );",
" float B = -2.0 * dot( R[ 0 ], D * R[ 3 ] );",
" float C = dot( R[ 0 ], D * R[ 0 ] );",
" xbc[ 0 ] = ( -B - sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );",
" xbc[ 1 ] = ( -B + sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );",
" float sx = abs( xbc[ 0 ] - xbc[ 1 ] ) * 0.5;",
"",
" A = dot( R[ 3 ], D * R[ 3 ] );",
" B = -2.0 * dot( R[ 1 ], D * R[ 3 ] );",
" C = dot( R[ 1 ], D * R[ 1 ] );",
" ybc[ 0 ] = ( -B - sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );",
" ybc[ 1 ] = ( -B + sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );",
" float sy = abs( ybc[ 0 ] - ybc[ 1 ] ) * 0.5;",
"",
" gl_Position.xy = vec2( 0.5 * ( xbc.x + xbc.y ), 0.5 * ( ybc.x + ybc.y ) );",
" gl_Position.xy -= mapping * vec2( sx, sy );",
" gl_Position.xy *= gl_Position.w;",
"",
"}",
"",
" mat4 computeMat(vec4 v1, vec4 v2, vec4 v3, vec4 v4) {",
" return mat4(",
" v1.x, v1.y, v1.z, v1.w,",
" v2.x, v2.y, v2.z, v2.w,",
" v3.x, v3.y, v3.z, v3.w,",
" v4.x, v4.y, v4.z, v4.w",
" );",
" }",
"",
"void main(void){",
"",
" #ifdef PICKING",
" vPickingColor = unpackColor( primitiveId );",
" #else",
" #include color_vertex",
" #endif",
"",
" vRadius = radius * matrixScale( modelViewMatrix );",
"",
" mat4 matrix = computeMat(matrix1, matrix2, matrix3, matrix4);",
" vec4 updatePosition = matrix * vec4(position, 1.0);",
"",
"// vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
" vec4 mvPosition = modelViewMatrix * vec4( updatePosition.xyz, 1.0 );",
" // avoid clipping, added again in fragment shader",
" mvPosition.z -= vRadius;",
"",
"// gl_Position = projectionMatrix * vec4( mvPosition.xyz, 1.0 );",
" gl_Position = projectionMatrix * vec4( mvPosition.xyz, 1.0 );",
" ComputePointSizeAndPositionInClipCoordSphere(updatePosition);",
"",
"",
" vRadiusSq = vRadius * vRadius;",
" vec4 vPoint4 = projectionMatrixInverse * gl_Position;",
" vPoint = vPoint4.xyz / vPoint4.w;",
" vPointViewPosition = -mvPosition.xyz / mvPosition.w;",
"",
"}"
].join("\n");
$NGL_shaderTextHash['CylinderInstancing.frag'] = $NGL_shaderTextHash['CylinderImpostor.frag'];
$NGL_shaderTextHash['CylinderInstancing.vert'] = ["// Open-Source PyMOL is Copyright (C) Schrodinger, LLC.",
"//",
"// All Rights Reserved",
"//",
"// Permission to use, copy, modify, distribute, and distribute modified",
"// versions of this software and its built-in documentation for any",
"// purpose and without fee is hereby granted, provided that the above",
"// copyright notice appears in all copies and that both the copyright",
"// notice and this permission notice appear in supporting documentation,",
"// and that the name of Schrodinger, LLC not be used in advertising or",
"// publicity pertaining to distribution of the software without specific,",
"// written prior permission.",
"//",
"// SCHRODINGER, LLC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,",
"// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN",
"// NO EVENT SHALL SCHRODINGER, LLC BE LIABLE FOR ANY SPECIAL, INDIRECT OR",
"// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS",
"// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE",
"// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE",
"// USE OR PERFORMANCE OF THIS SOFTWARE.",
"",
"// Contributions by Alexander Rose",
"// - ported to WebGL",
"// - dual color",
"// - pk color",
"// - shift",
"",
"attribute vec3 mapping;",
"attribute vec3 position1;",
"attribute vec3 position2;",
"attribute float radius;",
"attribute vec4 matrix1;",
"attribute vec4 matrix2;",
"attribute vec4 matrix3;",
"attribute vec4 matrix4;",
"",
"varying vec3 axis;",
"varying vec4 base_radius;",
"varying vec4 end_b;",
"varying vec3 U;",
"varying vec3 V;",
"varying vec4 w;",
"varying float fogDepth;",
"varying float fogNear;",
"varying float fogFar;",
"",
"#ifdef PICKING",
" #include unpack_clr",
" attribute float primitiveId;",
" varying vec3 vPickingColor;",
"#else",
" //attribute vec3 color;",
" attribute vec3 color2;",
" varying vec3 vColor1;",
" varying vec3 vColor2;",
"#endif",
"",
"uniform mat4 modelViewMatrixInverse;",
"uniform float ortho;",
"",
"//include matrix_scale",
"float matrixScale( in mat4 m ){",
" vec4 r = m[ 0 ];",
" return sqrt( r[ 0 ] * r[ 0 ] + r[ 1 ] * r[ 1 ] + r[ 2 ] * r[ 2 ] );",
"}",
"",
" mat4 computeMat(vec4 v1, vec4 v2, vec4 v3, vec4 v4) {",
" return mat4(",
" v1.x, v1.y, v1.z, v1.w,",
" v2.x, v2.y, v2.z, v2.w,",
" v3.x, v3.y, v3.z, v3.w,",
" v4.x, v4.y, v4.z, v4.w",
" );",
" }",
"",
"void main(){",
"",
" #ifdef PICKING",
" vPickingColor = unpackColor( primitiveId );",
" #else",
" vColor1 = color;",
" vColor2 = color2;",
" #endif",
"",
" // vRadius = radius;",
" base_radius.w = radius * matrixScale( modelViewMatrix );",
"",
" //vec3 center = ( position2 + position1 ) / 2.0;",
"",
" mat4 matrix = computeMat(matrix1, matrix2, matrix3, matrix4);",
" vec4 updatePosition1 = matrix * vec4(position1, 1.0);",
" vec4 updatePosition2 = matrix * vec4(position2, 1.0);",
" vec3 center = ( updatePosition2.xyz + updatePosition1.xyz ) / 2.0;",
"",
" //vec3 dir = normalize( position2 - position1 );",
" vec3 dir = normalize( updatePosition2.xyz - updatePosition1.xyz );",
" float ext = length( position2 - position1 ) / 2.0;",
"",
" // using cameraPosition fails on some machines, not sure why",
" // vec3 cam_dir = normalize( cameraPosition - mix( center, vec3( 0.0 ), ortho ) );",
" vec3 cam_dir;",
" if( ortho == 0.0 ){",
" cam_dir = ( modelViewMatrixInverse * vec4( 0, 0, 0, 1 ) ).xyz - center;",
" }else{",
" cam_dir = ( modelViewMatrixInverse * vec4( 0, 0, 1, 0 ) ).xyz;",
" }",
" cam_dir = normalize( cam_dir );",
"",
" vec3 ldir;",
"",
" float b = dot( cam_dir, dir );",
" end_b.w = b;",
" // direction vector looks away, so flip",
" if( b < 0.0 )",
" ldir = -ext * dir;",
" // direction vector already looks in my direction",
" else",
" ldir = ext * dir;",
"",
" vec3 left = normalize( cross( cam_dir, ldir ) );",
" left = radius * left;",
" vec3 up = radius * normalize( cross( left, ldir ) );",
"",
" // transform to modelview coordinates",
" axis = normalize( normalMatrix * ldir );",
" U = normalize( normalMatrix * up );",
" V = normalize( normalMatrix * left );",
"",
" vec4 base4 = modelViewMatrix * vec4( center - ldir, 1.0 );",
" base_radius.xyz = base4.xyz / base4.w;",
"",
" vec4 top_position = modelViewMatrix * vec4( center + ldir, 1.0 );",
" vec4 end4 = top_position;",
" end_b.xyz = end4.xyz / end4.w;",
"",
" w = modelViewMatrix * vec4(",
" center + mapping.x*ldir + mapping.y*left + mapping.z*up, 1.0",
" );",
"",
" gl_Position = projectionMatrix * w;",
"",
" // avoid clipping (1.0 seems to induce flickering with some drivers)",
" gl_Position.z = 0.99;",
"",
"}"
].join("\n");
$NGL_shaderTextHash['Instancing.frag'] = ["#define STANDARD",
"uniform vec3 diffuse;",
"uniform vec3 emissive;",
"uniform float roughness;",
"uniform float metalness;",
"uniform float opacity;",
"uniform float nearClip;",
"uniform float clipRadius;",
"uniform mat4 projectionMatrix;",
"uniform float ortho;",
"varying float bCylinder;",
"",
"#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || ( !defined( PICKING ) && !defined( NOLIGHT ) )",
" varying vec3 vViewPosition;",
"#endif",
"",
"#if defined( RADIUS_CLIP )",
" varying vec3 vClipCenter;",
"#endif",
"",
"#if defined( PICKING )",
" uniform float objectId;",
" varying vec3 vPickingColor;",
"#elif defined( NOLIGHT )",
" varying vec3 vColor;",
"#else",
" #ifndef FLAT_SHADED",
" varying vec3 vNormal;",
" #endif",
" #include common",
" #include color_pars_fragment",
" #include fog_pars_fragment",
" #include bsdfs",
" #include lights_pars_begin",
" #include lights_physical_pars_fragment",
"#endif",
"",
"void main(){",
" #include nearclip_fragment",
" #include radiusclip_fragment",
"",
" #if defined( PICKING )",
"",
" gl_FragColor = vec4( vPickingColor, objectId );",
"",
" #elif defined( NOLIGHT )",
"",
" gl_FragColor = vec4( vColor, opacity );",
"",
" #else",
"",
" vec4 diffuseColor = vec4( diffuse, opacity );",
" ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
" vec3 totalEmissiveLight = emissive;",
"",
" #include color_fragment",
" #include roughnessmap_fragment",
" #include metalnessmap_fragment",
" #include normal_flip",
" #include normal_fragment_begin",
"",
" //include dull_interior_fragment",
"",
" #include lights_physical_fragment",
" //include lights_template",
" #include lights_fragment_begin",
" #include lights_fragment_end",
"",
" vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
"",
" #include interior_fragment",
"",
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
"",
" #include premultiplied_alpha_fragment",
" #include tonemapping_fragment",
" #include encodings_fragment",
" #include fog_fragment",
"",
" #include opaque_back_fragment",
"",
" #endif",
"",
"}"
].join("\n");
$NGL_shaderTextHash['Instancing.vert'] = ["#define STANDARD",
"",
"uniform mat4 projectionMatrixInverse;",
"uniform float nearClip;",
"uniform vec3 clipCenter;",
"attribute vec4 matrix1;",
"attribute vec4 matrix2;",
"attribute vec4 matrix3;",
"attribute vec4 matrix4;",
"attribute float cylinder;",
"varying float bCylinder;",
"",
"#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || ( !defined( PICKING ) && !defined( NOLIGHT ) )",
" varying vec3 vViewPosition;",
"#endif",
"",
"#if defined( RADIUS_CLIP )",
" varying vec3 vClipCenter;",
"#endif",
"",
"#if defined( PICKING )",
" #include unpack_color",
" attribute float primitiveId;",
" varying vec3 vPickingColor;",
"#elif defined( NOLIGHT )",
" varying vec3 vColor;",
"#else",
" #include color_pars_vertex",
" #ifndef FLAT_SHADED",
" varying vec3 vNormal;",
" #endif",
"#endif",
"",
"#include common",
"",
" mat4 computeMat(vec4 v1, vec4 v2, vec4 v3, vec4 v4) {",
" return mat4(",
" v1.x, v1.y, v1.z, v1.w,",
" v2.x, v2.y, v2.z, v2.w,",
" v3.x, v3.y, v3.z, v3.w,",
" v4.x, v4.y, v4.z, v4.w",
" );",
" }",
"",
"void main(){",
" bCylinder = cylinder;",
"",
" mat4 matrix = computeMat(matrix1, matrix2, matrix3, matrix4);",
" vec4 updatePosition = matrix * vec4(position, 1.0);",
"",
" #if defined( PICKING )",
" vPickingColor = unpackColor( primitiveId );",
" #elif defined( NOLIGHT )",
" vColor = color;",
" #else",
" #include color_vertex",
" //include beginnormal_vertex",
" //vec3 objectNormal = vec3( normal );",
" vec3 objectNormal = vec3(matrix * vec4(normal,0.0));",
" #include defaultnormal_vertex",
" // Normal computed with derivatives when FLAT_SHADED",
" #ifndef FLAT_SHADED",
" vNormal = normalize( transformedNormal );",
" #endif",
" #endif",
"",
" //include begin_vertex",
" vec3 transformed = updatePosition.xyz;",
" //include project_vertex",
" vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );",
" gl_Position = projectionMatrix * mvPosition;",
"",
" #if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || ( !defined( PICKING ) && !defined( NOLIGHT ) )",
" vViewPosition = -mvPosition.xyz;",
" #endif",
"",
" #if defined( RADIUS_CLIP )",
" vClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;",
" #endif",
"",
" #include nearclip_vertex",
"",
"}"
].join("\n");
// ; var __CIFTools = function () {
// 'use strict';
/*
* Copyright (c) 2016 - now David Sehnal, licensed under MIT License, See LICENSE file for more info.
*/
var CIFTools;
(function (CIFTools) {
CIFTools.VERSION = { number: "1.1.7", date: "Oct 30 2018" };
// })(CIFTools || (CIFTools = {}));
/*
* Copyright (c) 2016 - now David Sehnal, licensed under MIT License, See LICENSE file for more info.
*/
// var CIFTools;
// (function (CIFTools) {
var Utils;
(function (Utils) {
var ChunkedArray;
(function (ChunkedArray) {
function is(x) {
return x.creator && x.chunkSize;
}
ChunkedArray.is = is;
function add4(array, x, y, z, w) {
if (array.currentIndex >= array.chunkSize) {
array.currentIndex = 0;
array.current = array.creator(array.chunkSize);
array.parts[array.parts.length] = array.current;
}
array.current[array.currentIndex++] = x;
array.current[array.currentIndex++] = y;
array.current[array.currentIndex++] = z;
array.current[array.currentIndex++] = w;
return array.elementCount++;
}
ChunkedArray.add4 = add4;
function add3(array, x, y, z) {
if (array.currentIndex >= array.chunkSize) {
array.currentIndex = 0;
array.current = array.creator(array.chunkSize);
array.parts[array.parts.length] = array.current;
}
array.current[array.currentIndex++] = x;
array.current[array.currentIndex++] = y;
array.current[array.currentIndex++] = z;
return array.elementCount++;
}
ChunkedArray.add3 = add3;
function add2(array, x, y) {
if (array.currentIndex >= array.chunkSize) {
array.currentIndex = 0;
array.current = array.creator(array.chunkSize);
array.parts[array.parts.length] = array.current;
}
array.current[array.currentIndex++] = x;
array.current[array.currentIndex++] = y;
return array.elementCount++;
}
ChunkedArray.add2 = add2;
function add(array, x) {
if (array.currentIndex >= array.chunkSize) {
array.currentIndex = 0;
array.current = array.creator(array.chunkSize);
array.parts[array.parts.length] = array.current;
}
array.current[array.currentIndex++] = x;
return array.elementCount++;
}
ChunkedArray.add = add;
function compact(array) {
var ret = array.creator(array.elementSize * array.elementCount), offset = (array.parts.length - 1) * array.chunkSize, offsetInner = 0, part;
if (array.parts.length > 1) {
if (array.parts[0].buffer) {
for (var i = 0; i < array.parts.length - 1; i++) {
ret.set(array.parts[i], array.chunkSize * i);
}
}
else {
for (var i = 0; i < array.parts.length - 1; i++) {
offsetInner = array.chunkSize * i;
part = array.parts[i];
for (var j = 0; j < array.chunkSize; j++) {
ret[offsetInner + j] = part[j];
}
}
}
}
if (array.current.buffer && array.currentIndex >= array.chunkSize) {
ret.set(array.current, array.chunkSize * (array.parts.length - 1));
}
else {
for (var i = 0; i < array.currentIndex; i++) {
ret[offset + i] = array.current[i];
}
}
return ret;
}
ChunkedArray.compact = compact;
function forVertex3D(chunkVertexCount) {
if (chunkVertexCount === void 0) { chunkVertexCount = 262144; }
return create(function (size) { return new Float32Array(size); }, chunkVertexCount, 3);
}
ChunkedArray.forVertex3D = forVertex3D;
function forIndexBuffer(chunkIndexCount) {
if (chunkIndexCount === void 0) { chunkIndexCount = 262144; }
return create(function (size) { return new Uint32Array(size); }, chunkIndexCount, 3);
}
ChunkedArray.forIndexBuffer = forIndexBuffer;
function forTokenIndices(chunkTokenCount) {
if (chunkTokenCount === void 0) { chunkTokenCount = 131072; }
return create(function (size) { return new Int32Array(size); }, chunkTokenCount, 2);
}
ChunkedArray.forTokenIndices = forTokenIndices;
function forIndices(chunkTokenCount) {
if (chunkTokenCount === void 0) { chunkTokenCount = 131072; }
return create(function (size) { return new Int32Array(size); }, chunkTokenCount, 1);
}
ChunkedArray.forIndices = forIndices;
function forInt32(chunkSize) {
if (chunkSize === void 0) { chunkSize = 131072; }
return create(function (size) { return new Int32Array(size); }, chunkSize, 1);
}
ChunkedArray.forInt32 = forInt32;
function forFloat32(chunkSize) {
if (chunkSize === void 0) { chunkSize = 131072; }
return create(function (size) { return new Float32Array(size); }, chunkSize, 1);
}
ChunkedArray.forFloat32 = forFloat32;
function forArray(chunkSize) {
if (chunkSize === void 0) { chunkSize = 131072; }
return create(function (size) { return []; }, chunkSize, 1);
}
ChunkedArray.forArray = forArray;
function create(creator, chunkElementCount, elementSize) {
chunkElementCount = chunkElementCount | 0;
if (chunkElementCount <= 0)
chunkElementCount = 1;
var chunkSize = chunkElementCount * elementSize;
var current = creator(chunkSize);
return {
elementSize: elementSize,
chunkSize: chunkSize,
creator: creator,
current: current,
parts: [current],
currentIndex: 0,
elementCount: 0
};
}
ChunkedArray.create = create;
})(ChunkedArray = Utils.ChunkedArray || (Utils.ChunkedArray = {}));
})(Utils = CIFTools.Utils || (CIFTools.Utils = {}));
// })(CIFTools || (CIFTools = {}));
/*
* Copyright (c) 2016 - now David Sehnal, licensed under MIT License, See LICENSE file for more info.
*/
/**
* Efficient integer and float parsers.
*
* For the purposes of parsing numbers from the mmCIF data representations,
* up to 4 times faster than JS parseInt/parseFloat.
*/
// var CIFTools;
// (function (CIFTools) {
// var Utils;
(function (Utils) {
var FastNumberParsers;
(function (FastNumberParsers) {
"use strict";
function parseIntSkipTrailingWhitespace(str, start, end) {
while (start < end && str.charCodeAt(start) === 32)
start++;
return parseInt(str, start, end);
}
FastNumberParsers.parseIntSkipTrailingWhitespace = parseIntSkipTrailingWhitespace;
function parseInt(str, start, end) {
var ret = 0, neg = 1;
if (str.charCodeAt(start) === 45 /* - */) {
neg = -1;
start++;
}
for (; start < end; start++) {
var c = str.charCodeAt(start) - 48;
if (c > 9 || c < 0)
return (neg * ret) | 0;
else
ret = (10 * ret + c) | 0;
}
return neg * ret;
}
FastNumberParsers.parseInt = parseInt;
function parseScientific(main, str, start, end) {
// handle + in '1e+1' separately.
if (str.charCodeAt(start) === 43 /* + */)
start++;
retur