icn3d
Version:
iCn3D Structure Viewer
1 lines • 2.04 MB
JavaScript
var CIFTools,$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"),function(e){var t,r,n,i;e.VERSION={number:"1.1.7",date:"Oct 30 2018"},function(e){function t(e,t,r){(t|=0)<=0&&(t=1);var n=t*r,i=e(n);return{elementSize:r,chunkSize:n,creator:e,current:i,parts:[i],currentIndex:0,elementCount:0}}e.is=function(e){return e.creator&&e.chunkSize},e.add4=function(e,t,r,n,i){return e.currentIndex>=e.chunkSize&&(e.currentIndex=0,e.current=e.creator(e.chunkSize),e.parts[e.parts.length]=e.current),e.current[e.currentIndex++]=t,e.current[e.currentIndex++]=r,e.current[e.currentIndex++]=n,e.current[e.currentIndex++]=i,e.elementCount++},e.add3=function(e,t,r,n){return e.currentIndex>=e.chunkSize&&(e.currentIndex=0,e.current=e.creator(e.chunkSize),e.parts[e.parts.length]=e.current),e.current[e.currentIndex++]=t,e.current[e.currentIndex++]=r,e.current[e.currentIndex++]=n,e.elementCount++},e.add2=function(e,t,r){return e.currentIndex>=e.chunkSize&&(e.currentIndex=0,e.current=e.creator(e.chunkSize),e.parts[e.parts.length]=e.current),e.current[e.currentIndex++]=t,e.current[e.currentIndex++]=r,e.elementCount++},e.add=function(e,t){return e.currentIndex>=e.chunkSize&&(e.currentIndex=0,e.current=e.creator(e.chunkSize),e.parts[e.parts.length]=e.current),e.current[e.currentIndex++]=t,e.elementCount++},e.compact=function(e){var t,r=e.creator(e.elementSize*e.elementCount),n=(e.parts.length-1)*e.chunkSize,i=0;if(e.parts.length>1)if(e.parts[0].buffer)for(var o=0;o<e.parts.length-1;o++)r.set(e.parts[o],e.chunkSize*o);else for(o=0;o<e.parts.length-1;o++){i=e.chunkSize*o,t=e.parts[o];for(var a=0;a<e.chunkSize;a++)r[i+a]=t[a]}if(e.current.buffer&&e.currentIndex>=e.chunkSize)r.set(e.current,e.chunkSize*(e.parts.length-1));else for(o=0;o<e.currentIndex;o++)r[n+o]=e.current[o];return r},e.forVertex3D=function(e){return void 0===e&&(e=262144),t(function(e){return new Float32Array(e)},e,3)},e.forIndexBuffer=function(e){return void 0===e&&(e=262144),t(function(e){return new Uint32Array(e)},e,3)},e.forTokenIndices=function(e){return void 0===e&&(e=131072),t(function(e){return new Int32Array(e)},e,2)},e.forIndices=function(e){return void 0===e&&(e=131072),t(function(e){return new Int32Array(e)},e,1)},e.forInt32=function(e){return void 0===e&&(e=131072),t(function(e){return new Int32Array(e)},e,1)},e.forFloat32=function(e){return void 0===e&&(e=131072),t(function(e){return new Float32Array(e)},e,1)},e.forArray=function(e){return void 0===e&&(e=131072),t(function(e){return[]},e,1)},e.create=t}((t=e.Utils||(e.Utils={})).ChunkedArray||(t.ChunkedArray={})),function(e){"use strict";function t(e,t,r){var n=0,i=1;for(45===e.charCodeAt(t)&&(i=-1,t++);t<r;t++){var o=e.charCodeAt(t)-48;if(o>9||o<0)return i*n|0;n=10*n+o|0}return i*n}function r(e,r,n,i){return 43===r.charCodeAt(n)&&n++,e*Math.pow(10,t(r,n,i))}function n(e,t,n){var i=1,o=0,a=0,c=1;for(45===e.charCodeAt(t)&&(i=-1,++t);t<n;){var s=e.charCodeAt(t)-48;if(!(s>=0&&s<10)){if(-2===s){for(++t;t<n;){if(!((s=e.charCodeAt(t)-48)>=0&&s<10))return 53===s||21===s?r(i*(o+a/c),e,t+1,n):i*(o+a/c);a=10*a+s,c*=10,++t}return i*(o+a/c)}if(53===s||21===s)return r(i*o,e,t+1,n);break}o=10*o+s,++t}return i*o}e.parseIntSkipTrailingWhitespace=function(e,r,n){for(;r<n&&32===e.charCodeAt(r);)r++;return t(e,r,n)},e.parseInt=t,e.parseFloatSkipTrailingWhitespace=function(e,t,r){for(;t<r&&32===e.charCodeAt(t);)t++;return n(e,t,r)},e.parseFloat=n}((r=e.Utils||(e.Utils={})).FastNumberParsers||(r.FastNumberParsers={})),n=e.Utils||(e.Utils={}),i=[],function(){for(var e="",t=0;t<512;t++)i[t]=e,e+=" "}(),function(e){function t(e,t){void 0!==t&&null!==t&&(e.chunkOffset===e.chunkCapacity&&(e.data[e.data.length]=e.chunkData.join(""),e.chunkOffset=0),e.chunkData[e.chunkOffset++]=t)}e.create=function(e){return void 0===e&&(e=512),{chunkData:[],chunkOffset:0,chunkCapacity:e,data:[]}},e.asString=function(e){return e.data.length?(e.chunkOffset>0&&(e.data[e.data.length]=e.chunkData.splice(0,e.chunkOffset).join("")),e.data.join("")):e.chunkData.length===e.chunkOffset?e.chunkData.join(""):e.chunkData.splice(0,e.chunkOffset).join("")},e.writeTo=function(e,t){var r;(r=e).chunkOffset>0&&(r.chunkData.length===r.chunkOffset?r.data[r.data.length]=r.chunkData.join(""):r.data[r.data.length]=r.chunkData.splice(0,r.chunkOffset).join(""),r.chunkOffset=0);for(var n=0,i=e.data;n<i.length;n++){var o=i[n];t.writeString(o)}},e.newline=function(e){t(e,"\n")},e.whitespace=function(e,r){t(e,i[r])},e.write=t,e.writeSafe=function(e,t){e.chunkOffset===e.chunkCapacity&&(e.data[e.data.length]=e.chunkData.join(""),e.chunkOffset=0),e.chunkData[e.chunkOffset++]=t},e.writePadLeft=function(e,r,n){void 0!==r&&null!==r||t(e,i[n]);var o=n-r.length;o>0&&t(e,i[o]),t(e,r)},e.writePadRight=function(e,r,n){void 0!==r&&null!==r||t(e,i[n]);var o=n-r.length;t(e,r),o>0&&t(e,i[o])},e.writeInteger=function(e,r){t(e,""+r)},e.writeIntegerPadLeft=function(e,r,n){var o=""+r,a=n-o.length;a>0&&t(e,i[a]),t(e,o)},e.writeIntegerPadRight=function(e,r,n){var o=""+r,a=n-o.length;t(e,o),a>0&&t(e,i[a])},e.writeFloat=function(e,r,n){t(e,""+Math.round(n*r)/n)},e.writeFloatPadLeft=function(e,r,n,o){var a=""+Math.round(n*r)/n,c=o-a.length;c>0&&t(e,i[c]),t(e,a)},e.writeFloatPadRight=function(e,r,n,o){var a=""+Math.round(n*r)/n,c=o-a.length;t(e,a),c>0&&t(e,i[c])}}(n.StringWriter||(n.StringWriter={}));var o=function(){function e(){this.isDefined=!1}return e.prototype.getString=function(e){return null},e.prototype.getInteger=function(e){return 0},e.prototype.getFloat=function(e){return 0},e.prototype.getValuePresence=function(e){return 1},e.prototype.areValuesEqual=function(e,t){return!0},e.prototype.stringEquals=function(e,t){return null===t},e}();e.UndefinedColumn=new o,function(e){e.getMatrix=function(e,t,r,n,i){for(var o=[],a=1;a<=r;a++){for(var c=[],s=1;s<=n;s++)c[s-1]=e.getColumn(t+"["+a+"]["+s+"]").getFloat(i);o[a-1]=c}return o},e.getVector=function(e,t,r,n,i){for(var o=[],a=1;a<=r;a++)o[a-1]=e.getColumn(t+"["+a+"]").getFloat(i);return o}}(e.Category||(e.Category={})),function(e){e.error=function(e,t){return void 0===t&&(t=-1),new a(e,t)},e.success=function(e,t){return void 0===t&&(t=[]),new f(e,t)}}(e.ParserResult||(e.ParserResult={}));var a=function(){function e(e,t){this.message=e,this.line=t,this.isError=!0}return e.prototype.toString=function(){return this.line>=0?"[Line "+this.line+"] "+this.message:this.message},e}();e.ParserError=a;var c,s,u,d,f=function(){return function(e,t){this.result=e,this.warnings=t,this.isError=!1}}();e.ParserSuccess=f,function(t){"use strict";var r;!function(e){e.create=function(){return Object.create(null)},e.get=function(e,t){if(t.length>6)return t;var r=e[t];return void 0!==r?r:(e[t]=t,t)}}(r||(r={}));var n=function(){function e(e){this.dataBlocks=[],this.data=e}return e.prototype.toJSON=function(){return this.dataBlocks.map(function(e){return e.toJSON()})},e}();t.File=n;var i=function(){function e(e,t){this.header=t,this.data=e,this.categoryList=[],this.additionalData={},this.categoryMap=new Map}return Object.defineProperty(e.prototype,"categories",{get:function(){return this.categoryList},enumerable:!0,configurable:!0}),e.prototype.getCategory=function(e){return this.categoryMap.get(e)},e.prototype.addCategory=function(e){this.categoryList[this.categoryList.length]=e,this.categoryMap.set(e.name,e)},e.prototype.toJSON=function(){return{id:this.header,categories:this.categoryList.map(function(e){return e.toJSON()}),additionalData:this.additionalData}},e}();t.DataBlock=i;var o=function(){function t(e,t,r,n,i,o,a){this.name=t,this.tokens=o,this.data=e,this.startIndex=r,this.endIndex=n,this.columnCount=i.length,this.rowCount=a/i.length|0,this.columnIndices=new Map,this.columnNameList=[];for(var c=0;c<i.length;c++){var s=i[c].substr(t.length+1);this.columnIndices.set(s,c),this.columnNameList.push(s)}}return Object.defineProperty(t.prototype,"columnNames",{get:function(){return this.columnNameList},enumerable:!0,configurable:!0}),t.prototype.getColumn=function(t){var r=this.columnIndices.get(t);return void 0!==r?new s(this,this.data,t,r):e.UndefinedColumn},t.prototype.toJSON=function(){for(var e=[],t=this.data,n=this.tokens,i=this.columnNameList,o=r.create(),a=0;a<this.rowCount;a++){for(var c={},s=0;s<this.columnCount;s++){var u=2*(a*this.columnCount+s);c[i[s]]=r.get(o,t.substring(n[u],n[u+1]))}e[a]=c}return{name:this.name,columns:i,rows:e}},t}();t.Category=o;var a=e.Utils.FastNumberParsers.parseInt,c=e.Utils.FastNumberParsers.parseFloat,s=function(){function e(e,t,n,i){this.data=t,this.name=n,this.index=i,this.stringPool=r.create(),this.isDefined=!0,this.tokens=e.tokens,this.columnCount=e.columnCount}return e.prototype.getString=function(e){var t=2*(e*this.columnCount+this.index),n=r.get(this.stringPool,this.data.substring(this.tokens[t],this.tokens[t+1]));return"."===n||"?"===n?null:n},e.prototype.getInteger=function(e){var t=2*(e*this.columnCount+this.index);return a(this.data,this.tokens[t],this.tokens[t+1])},e.prototype.getFloat=function(e){var t=2*(e*this.columnCount+this.index);return c(this.data,this.tokens[t],this.tokens[t+1])},e.prototype.stringEquals=function(e,t){var r=2*(e*this.columnCount+this.index),n=this.tokens[r],i=t.length;if(i!==this.tokens[r+1]-n)return!1;for(var o=0;o<i;o++)if(this.data.charCodeAt(o+n)!==t.charCodeAt(o))return!1;return!0},e.prototype.areValuesEqual=function(e,t){var r=2*(e*this.columnCount+this.index),n=2*(t*this.columnCount+this.index),i=this.tokens[r],o=this.tokens[n],a=this.tokens[r+1]-i;if(a!==this.tokens[n+1]-o)return!1;for(var c=0;c<a;c++)if(this.data.charCodeAt(c+i)!==this.data.charCodeAt(c+o))return!1;return!0},e.prototype.getValuePresence=function(e){var t=e*this.columnCount+this.index,r=this.tokens[2*t];if(this.tokens[2*t+1]-r!=1)return 0;var n=this.data.charCodeAt(r);return 46===n?1:63===n?2:0},e}();t.Column=s}(e.Text||(e.Text={})),function(t){"use strict";var r;function n(e){for(;e.position<e.length;)switch(e.data.charCodeAt(e.position)){case 9:case 10:case 13:case 32:return void(e.currentTokenEnd=e.position);default:++e.position}e.currentTokenEnd=e.position}function i(e,t,r){var n,i=r-t,o=e.currentTokenStart-t,a=e.currentTokenEnd-e.currentTokenStart;if(a<i)return!1;for(n=t;n<r;++n)if(e.data.charCodeAt(n)!==e.data.charCodeAt